From: "Mark Hammond" <MHammond@skippinet.com.au>
Date: Fri, 4 Oct 1996 09:08:19 +1000
A couple of things. As I mentioned a while back, I have made the
changes to the registry support, in getpath_nt.c. To recap, there can be:
...\pythonpath = default core Pythonpath
...\pythonpath\Pythonwin = c:\somewhere
etc.
The code simply appends them all. The order can not be guaranteed
(registry limitation) but the "default" is always at the end.
The main reasons for change were the length of the path, but mainly
so an uninstaller can do the right thing.
diff --git a/PC/getpath_nt.c b/PC/getpath_nt.c
index 99e8b06..30dd601 100644
--- a/PC/getpath_nt.c
+++ b/PC/getpath_nt.c
@@ -59,27 +59,46 @@
RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL,
&numEntries, &nameSize, &dataSize, NULL, NULL );
}
- if (numEntries==0) {
- if (newKey)
- CloseHandle(newKey);
- if ((rc=RegOpenKey(keyBase, "Software\\Python\\PythonPath",
- &newKey))==ERROR_SUCCESS) {
- RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL,
- &numEntries, &nameSize, &dataSize, NULL, NULL );
- }
- }
if (bWin32s && numEntries==0 && dataSize==0) { /* must hardcode for Win32s */
numEntries = 1;
dataSize = 511;
}
if (numEntries) {
- dataBuf = malloc(dataSize);
- // on NT, datasize is unicode - ie, 2xstrlen,
- // even when ascii string returned.
- // presumably will be 1xstrlen on 95/win3.1
- // Additionally, win32s doesnt work as expected, so
- // the specific strlen() is required for 3.1.
- rc = RegQueryValue(newKey, "", dataBuf, &dataSize);
+ /* Loop over all subkeys. */
+ /* Win32s doesnt know how many subkeys, so we do
+ it twice */
+ char keyBuf[MAX_PATH+1];
+ int index = 0;
+ int off = 0;
+ for(index=0;;index++) {
+ long reqdSize = 0;
+ DWORD rc = RegEnumKey(newKey, index, keyBuf,MAX_PATH+1);
+ if (rc) break;
+ rc = RegQueryValue(newKey, keyBuf, NULL, &reqdSize);
+ if (rc) break;
+ if (bWin32s && reqdSize==0) reqdSize = 512;
+ dataSize += reqdSize + 1; /* 1 for the ";" */
+ }
+ dataBuf = malloc(dataSize+1);
+ if (dataBuf==NULL) return NULL; /* pretty serious? Raise error? */
+ /* Now loop over, grabbing the paths. Subkeys before main library */
+ for(index=0;;index++) {
+ int adjust;
+ long reqdSize = dataSize;
+ DWORD rc = RegEnumKey(newKey, index, keyBuf,MAX_PATH+1);
+ if (rc) break;
+ rc = RegQueryValue(newKey, keyBuf, dataBuf+off, &reqdSize);
+ if (rc) break;
+ adjust = strlen(dataBuf+off);
+ dataSize -= adjust;
+ off += adjust;
+ dataBuf[off++] = ';';
+ dataBuf[off] = '\0';
+ dataSize--;
+ }
+ /* Additionally, win32s doesnt work as expected, so
+ the specific strlen() is required for 3.1. */
+ rc = RegQueryValue(newKey, "", dataBuf+off, &dataSize);
if (rc==ERROR_SUCCESS) {
if (strlen(dataBuf)==0)
free(dataBuf);