00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <Python.h>
00011
00012 #ifndef IMPORT_MODULE
00013 #error IMPORT_MODULE must be defined when compiling ppython.cxx !
00014 #endif
00015
00016 #define _STRINGIFY(s) #s
00017 #define STRINGIFY(s) _STRINGIFY(s)
00018 #define IMPORT_MODULE_STR STRINGIFY(IMPORT_MODULE)
00019
00020 int main(int argc, char **argv) {
00021 int sts = 0;
00022
00023 Py_SetProgramName(argv[0]);
00024
00025
00026
00027 #ifdef _WIN32
00028 char *path = getenv("PATH");
00029 char *result = strtok(path, ";");
00030 while (result != NULL) {
00031 struct stat st;
00032 char *ppython = (char*) malloc(strlen(result) + 13);
00033 strcpy(ppython, result);
00034 strcat(ppython, "\\ppython.exe");
00035 if (stat(ppython, &st) == 0) {
00036 Py_SetPythonHome(result);
00037 free(ppython);
00038 break;
00039 }
00040 result = strtok(NULL, ";");
00041 free(ppython);
00042 }
00043 #endif
00044
00045 Py_Initialize();
00046
00047 if (Py_VerboseFlag) {
00048 fprintf(stderr, "Python %s\\n%s\\n", Py_GetVersion(), Py_GetCopyright());
00049 }
00050
00051 PySys_SetArgv(argc, argv);
00052
00053 PyObject* m = PyImport_ImportModule(IMPORT_MODULE_STR);
00054 if (m <= 0) {
00055 PyErr_Print();
00056 sts = 1;
00057 }
00058
00059 Py_Finalize();
00060 return sts;
00061 }