annotate PC/getpath_nt.c @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 0294a67bfbdb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4087
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #include "Python.h"
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 #include "osdefs.h"
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #include <windows.h>
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 /* PREFIX and EXEC_PREFIX are meaningless on Windows */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #ifndef PREFIX
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 #define PREFIX ""
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #endif
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #ifndef EXEC_PREFIX
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #define EXEC_PREFIX ""
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 #endif
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 /*
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 This is a special Win32 version of getpath.
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 * There is no default path. There is nothing even remotely resembling
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 a standard location. Maybe later "Program Files/Python", but not yet.
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 * The Registry is used as the primary store for the Python path.
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 * The environment variable PYTHONPATH _overrides_ the registry. This should
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 allow a "standard" Python environment, but allow you to manually setup
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 another (eg, a beta version).
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 BOOL PyWin_IsWin32s()
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 static BOOL bIsWin32s = -1; // flag as "not yet looked"
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 if (bIsWin32s==-1) {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 OSVERSIONINFO ver;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 ver.dwOSVersionInfoSize = sizeof(ver);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 GetVersionEx(&ver);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 bIsWin32s = ver.dwPlatformId == VER_PLATFORM_WIN32s;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 return bIsWin32s;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 /* Load a PYTHONPATH value from the registry
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 Load from either HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 Returns NULL, or a pointer that should be free'd.
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 static char *
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 getpythonregpath(HKEY keyBase, BOOL bWin32s)
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 HKEY newKey = 0;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 DWORD nameSize = 0;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 DWORD dataSize = 0;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 DWORD numEntries = 0;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 LONG rc;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 char *retval = NULL;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 char *dataBuf;
4127
a7a9d83505c4 Use MS_DLL_ID and similar changes
Guido van Rossum <guido@python.org>
parents: 4105
diff changeset
57 if ((rc=RegOpenKey(keyBase, "Software\\Python\\PythonCore\\" MS_DLL_ID "\\PythonPath",
4087
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 &newKey))==ERROR_SUCCESS) {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL,
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 &numEntries, &nameSize, &dataSize, NULL, NULL );
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 if (bWin32s && numEntries==0 && dataSize==0) { /* must hardcode for Win32s */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 numEntries = 1;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 dataSize = 511;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 if (numEntries) {
4419
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
67 /* Loop over all subkeys. */
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
68 /* Win32s doesnt know how many subkeys, so we do
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
69 it twice */
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
70 char keyBuf[MAX_PATH+1];
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
71 int index = 0;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
72 int off = 0;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
73 for(index=0;;index++) {
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
74 long reqdSize = 0;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
75 DWORD rc = RegEnumKey(newKey, index, keyBuf,MAX_PATH+1);
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
76 if (rc) break;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
77 rc = RegQueryValue(newKey, keyBuf, NULL, &reqdSize);
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
78 if (rc) break;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
79 if (bWin32s && reqdSize==0) reqdSize = 512;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
80 dataSize += reqdSize + 1; /* 1 for the ";" */
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
81 }
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
82 dataBuf = malloc(dataSize+1);
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
83 if (dataBuf==NULL) return NULL; /* pretty serious? Raise error? */
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
84 /* Now loop over, grabbing the paths. Subkeys before main library */
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
85 for(index=0;;index++) {
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
86 int adjust;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
87 long reqdSize = dataSize;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
88 DWORD rc = RegEnumKey(newKey, index, keyBuf,MAX_PATH+1);
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
89 if (rc) break;
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
90 rc = RegQueryValue(newKey, keyBuf, dataBuf+off, &reqdSize);
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
91 if (rc) break;
4939
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
92 if (reqdSize>1) { // If Nothing, or only '\0' copied.
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
93 adjust = strlen(dataBuf+off);
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
94 dataSize -= adjust;
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
95 off += adjust;
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
96 dataBuf[off++] = ';';
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
97 dataBuf[off] = '\0';
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
98 dataSize--;
217cfb6199be Skip empty paths read from the registry.
Guido van Rossum <guido@python.org>
parents: 4419
diff changeset
99 }
4419
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
100 }
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
101 /* Additionally, win32s doesnt work as expected, so
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
102 the specific strlen() is required for 3.1. */
2eacd2c8eabf From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents: 4127
diff changeset
103 rc = RegQueryValue(newKey, "", dataBuf+off, &dataSize);
4087
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 if (rc==ERROR_SUCCESS) {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 if (strlen(dataBuf)==0)
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 free(dataBuf);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 else
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 retval = dataBuf; // caller will free
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 else
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 free(dataBuf);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 if (newKey)
5411
6717073de586 CloseHandle should be RegCloseKey.
Guido van Rossum <guido@python.org>
parents: 4939
diff changeset
115 RegCloseKey(newKey);
4087
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 return retval;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 /* Return the initial python search path. This is called once from
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 initsys() to initialize sys.path. The environment variable
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 PYTHONPATH is fetched and the default path appended. The default
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 path may be passed to the preprocessor; if not, a system-dependent
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 default is used. */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 char *
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 Py_GetPath()
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 char *path = getenv("PYTHONPATH");
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 char *defpath = PYTHONPATH;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 static char *buf = NULL;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 char *p;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 int n;
5411
6717073de586 CloseHandle should be RegCloseKey.
Guido van Rossum <guido@python.org>
parents: 4939
diff changeset
132 extern char *Py_GetProgramName();
4087
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
133
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 if (buf != NULL) {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 free(buf);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 buf = NULL;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 if (path == NULL) {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 char *machinePath, *userPath;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 int machineLen, userLen;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 /* lookup the registry */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 BOOL bWin32s = PyWin_IsWin32s();
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 if (bWin32s) { /* are we running under Windows 3.1 Win32s */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 /* only CLASSES_ROOT is supported */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 machinePath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 userPath = NULL;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 } else {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 machinePath = getpythonregpath(HKEY_LOCAL_MACHINE, FALSE);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 userPath = getpythonregpath(HKEY_CURRENT_USER, FALSE);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 if (machinePath==NULL && userPath==NULL) return defpath;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 machineLen = machinePath ? strlen(machinePath) : 0;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 userLen = userPath ? strlen(userPath) : 0;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 n = machineLen + userLen + 1;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 // this is a memory leak, as Python never frees it. Only ever called once, so big deal!
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 buf = malloc(n);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 if (buf == NULL)
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 Py_FatalError("not enough memory to copy module search path");
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 p = buf;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 *p = '\0';
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 if (machineLen) {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 strcpy(p, machinePath);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 p += machineLen;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 if (userLen) {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 if (machineLen)
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 *p++ = DELIM;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 strcpy(p, userPath);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 if (userPath) free(userPath);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 if (machinePath) free(machinePath);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 } else {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
175
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 buf = malloc(strlen(path)+1);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 if (buf == NULL)
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 Py_FatalError("not enough memory to copy module search path");
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 strcpy(buf, path);
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 return buf;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 /* Similar for Makefile variables $prefix and $exec_prefix */
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
185
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 char *
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
187 Py_GetPrefix()
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 return PREFIX;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 }
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
191
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 char *
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 Py_GetExecPrefix()
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 {
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 return EXEC_PREFIX;
740def697d8b NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 }
5602
0294a67bfbdb Added Py_GetProgramFullPath (same as GetProgramName)
Guido van Rossum <guido@python.org>
parents: 5411
diff changeset
197
0294a67bfbdb Added Py_GetProgramFullPath (same as GetProgramName)
Guido van Rossum <guido@python.org>
parents: 5411
diff changeset
198 char *
0294a67bfbdb Added Py_GetProgramFullPath (same as GetProgramName)
Guido van Rossum <guido@python.org>
parents: 5411
diff changeset
199 Py_GetProgramFullPath()
0294a67bfbdb Added Py_GetProgramFullPath (same as GetProgramName)
Guido van Rossum <guido@python.org>
parents: 5411
diff changeset
200 {
0294a67bfbdb Added Py_GetProgramFullPath (same as GetProgramName)
Guido van Rossum <guido@python.org>
parents: 5411
diff changeset
201 extern char *Py_GetProgramName();
0294a67bfbdb Added Py_GetProgramFullPath (same as GetProgramName)
Guido van Rossum <guido@python.org>
parents: 5411
diff changeset
202 return Py_GetProgramName();
0294a67bfbdb Added Py_GetProgramFullPath (same as GetProgramName)
Guido van Rossum <guido@python.org>
parents: 5411
diff changeset
203 }