Language-Haskell
view release on metacpan or search on metacpan
hugs98-Nov2003/src/machdep.c view on Meta::CPAN
return setValue(HKEY_CURRENT_USER, hugsRegRoot, var,
REG_SZ, (LPBYTE)realVal, lstrlen(realVal)+1);
}
#if HUGS_FOR_WINDOWS
Bool writeRegInt(var,val) /* write String to registry */
String var;
Int val; {
return setValue(HKEY_CURRENT_USER, hugsRegRoot, var,
REG_DWORD, (LPBYTE)&val, sizeof(val));
}
Int readRegInt(var, def) /* read Int from registry */
String var;
Int def; {
DWORD buf;
DWORD type;
if (queryValue(HKEY_CURRENT_USER, hugsRegRoot, var, &type,
(LPBYTE)&buf, sizeof(buf))
&& type == REG_DWORD) {
return (Int)buf;
} else if (queryValue(HKEY_LOCAL_MACHINE, hugsRegRoot, var, &type,
(LPBYTE)&buf, sizeof(buf))
&& type == REG_DWORD) {
return (Int)buf;
} else {
return def;
}
}
#endif
/* concatenate together all strings from registry of the form regPath\\*\\var,
* seperated by character sep.
*/
String readRegChildStrings(HKEY key, String regPath, String var, String def)
{
HKEY baseKey;
ULONG ulResult;
int done = 0;
DWORD dwIndex = 0;
char subKeyName[256];
DWORD subKeyLen;
BOOL addedPath = FALSE;
char* resPath = NULL; /* result path, returned to caller */
unsigned int strIncrement = 512; /* min length 'resPath' is extended by. */
unsigned int resRoom = 0; /* Number of chars left in 'resPath'. */
unsigned int resLength = 0; /* resPath length */
unsigned int maxLen = 0;
unsigned int strLength = 0; /* length of component */
String component;
FILETIME ft; /* just to satisfy RegEnumKeyEx() */
char sepString[2];
sepString[0] = PATHSEP;
sepString[1] = '\0';
/* Macro which appends a NUL terminated string to 'resPath', taking
* care of (re)allocating the string buffer, so that it'll fit.
*/
#define APPEND_STRING__(x) \
if (x) {\
if ( (strLength = strlen(x)) > resRoom || (resRoom == 0 && (x) != NULL) ) { \
maxLen = max(strLength, strIncrement); \
if (resPath == NULL) { \
if ( (resPath = (String)malloc(sizeof(char) * maxLen)) == NULL) { \
return NULL; \
} \
resPath[0] = '\0'; \
resLength = maxLen; \
resRoom = maxLen; \
} else { \
String tmpPtr; \
if ( (tmpPtr = (String)realloc(resPath,sizeof(char) * (resLength + maxLen))) == NULL) { \
/* The assumption is that the string is well-formed at the point we exhaust the allocator. */ \
return resPath; \
} \
resPath = tmpPtr; \
resLength += maxLen; \
resRoom = maxLen; \
} \
} \
strcat(resPath, x); \
resRoom -= strLength;}
ulResult = RegOpenKeyEx(key, regPath, 0, KEY_READ, &baseKey);
if (ulResult != ERROR_SUCCESS) {
APPEND_STRING__(def);
return resPath;
}
APPEND_STRING__(def);
while (!done) {
subKeyLen = sizeof(subKeyName);
ulResult = RegEnumKeyEx(baseKey, dwIndex, subKeyName, &subKeyLen,
NULL, NULL, NULL, &ft);
if (ulResult == ERROR_SUCCESS) {
/* read next component of path */
component = readRegString(baseKey, subKeyName, var, "");
if (addedPath) {
APPEND_STRING__(sepString);
}
addedPath = TRUE;
APPEND_STRING__(component);
free(component); /* readRegString() dynamically allocated it, so let go. */
} else {
if (ulResult == ERROR_NO_MORE_ITEMS) {
done = 1;
}
}
dwIndex++;
}
RegCloseKey(baseKey);
return resPath;
( run in 1.142 second using v1.01-cache-2.11-cpan-39bf76dae61 )