static BOOL get_gs_string_product(int gs_revision, const char *name, char *ptr, int len, const char *gs_productfamily) { /* If using Win32, look in the registry for a value with * the given name. The registry value will be under the key * HKEY_CURRENT_USER\Software\AFPL Ghostscript\N.NN * or if that fails under the key * HKEY_LOCAL_MACHINE\Software\AFPL Ghostscript\N.NN * where "AFPL Ghostscript" is actually gs_productfamily * and N.NN is obtained from gs_revision. */ int code; char key[256]; char dotversion[16]; int length; DWORD version = GetVersion(); if (((HIWORD(version) & 0x8000) != 0) && ((HIWORD(version) & 0x4000) == 0)) { /* Win32s */ return FALSE; } if (gs_revision % 100 == 0) wsprintf(dotversion, "%d.0", (int)(gs_revision/100)); else wsprintf(dotversion, "%d.%02d", (int)(gs_revision / 100), (int)(gs_revision % 100)); wsprintf(key, "Software\\%s\\%s", gs_productfamily, dotversion); length = len; code = gp_getenv_registry(HKEY_CURRENT_USER, key, name, ptr, &length); if ( code == 0 ) return TRUE; /* found it */ length = len; code = gp_getenv_registry(HKEY_LOCAL_MACHINE, key, name, ptr, &length); if ( code == 0 ) return TRUE; /* found it */ return FALSE; }
/* Get the value of an environment variable. See gp.h for details. */ int gp_getenv(const char *name, char *ptr, int *plen) { const char *str = getenv(name); if (str) { int len = strlen(str); if (len < *plen) { /* string fits */ strcpy(ptr, str); *plen = len + 1; return 0; } /* string doesn't fit */ *plen = len + 1; return -1; } /* environment variable was not found */ #ifdef __WIN32__ { /* If using Win32, look in the registry for a value with * the given name. The registry value will be under the key * HKEY_CURRENT_USER\Software\GPL Ghostscript\N.NN * or if that fails under the key * HKEY_LOCAL_MACHINE\Software\GPL Ghostscript\N.NN * where "GPL Ghostscript" is actually gs_productfamily * and N.NN is obtained from gs_revision. */ DWORD version = GetVersion(); if (!(((HIWORD(version) & 0x8000) != 0) && ((HIWORD(version) & 0x4000) == 0))) { /* not Win32s */ int code; #ifdef WINDOWS_NO_UNICODE char key[256]; char dotversion[16]; sprintf(dotversion, "%d.%02d", (int)(gs_revision / 100), (int)(gs_revision % 100)); sprintf(key, "Software\\%s\\%s", gs_productfamily, dotversion); #else wchar_t key[256]; wchar_t dotversion[16]; wsprintfW(dotversion, L"%d.%02d", (int)(gs_revision / 100), (int)(gs_revision % 100)); wsprintfW(key, L"Software\\%hs\\%s", gs_productfamily, dotversion); #endif code = gp_getenv_registry(HKEY_CURRENT_USER, key, name, ptr, plen); if ( code <= 0 ) return code; /* found it */ code = gp_getenv_registry(HKEY_LOCAL_MACHINE, key, name, ptr, plen); if ( code <= 0 ) return code; /* found it */ } } #endif /* nothing found at all */ if (*plen > 0) *ptr = 0; *plen = 1; return 1; }