Guido van Rossum | 228d807 | 2001-03-02 05:58:11 +0000 | [diff] [blame] | 1 | #include "Python.h" |
| 2 | #include "osdefs.h" |
| 3 | |
| 4 | static char *prefix,*exec_prefix,*progpath,*module_search_path=0; |
| 5 | |
| 6 | static void |
| 7 | calculate_path() |
| 8 | { char *pypath=getenv("Python$Path"); |
| 9 | if(pypath) |
| 10 | { module_search_path=malloc(strlen(pypath)+1); |
| 11 | if (module_search_path) sprintf(module_search_path,"%s",pypath); |
| 12 | else |
| 13 | { /* We can't exit, so print a warning and limp along */ |
| 14 | fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n"); |
| 15 | fprintf(stderr, "Using default static PYTHONPATH.\n"); |
| 16 | } |
| 17 | } |
| 18 | if(!module_search_path) module_search_path = "<Python$Dir>.Lib"; |
| 19 | prefix=""; |
| 20 | exec_prefix=prefix; |
| 21 | progpath="<Python$Dir>"; |
| 22 | } |
| 23 | |
| 24 | /* External interface */ |
| 25 | |
| 26 | char * |
| 27 | Py_GetPath() |
| 28 | { |
| 29 | if (!module_search_path) |
| 30 | calculate_path(); |
| 31 | return module_search_path; |
| 32 | } |
| 33 | |
| 34 | char * |
| 35 | Py_GetPrefix() |
| 36 | { |
| 37 | if (!module_search_path) |
| 38 | calculate_path(); |
| 39 | return prefix; |
| 40 | } |
| 41 | |
| 42 | char * |
| 43 | Py_GetExecPrefix() |
| 44 | { |
| 45 | if (!module_search_path) |
| 46 | calculate_path(); |
| 47 | return exec_prefix; |
| 48 | } |
| 49 | |
| 50 | char * |
| 51 | Py_GetProgramFullPath() |
| 52 | { |
| 53 | if (!module_search_path) |
| 54 | calculate_path(); |
| 55 | return progpath; |
| 56 | } |