"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "othersrc/gsdllinc/wgsver.c" between
pstoedit-3.77.tar.gz and pstoedit-3.78.tar.gz

About: pstoedit translates PostScript and PDF graphics into other vector formats.

wgsver.c  (pstoedit-3.77):wgsver.c  (pstoedit-3.78)
skipping to change at line 60 skipping to change at line 60
/* #define GS_PRODUCT_GNU */ "GNU Ghostscript", /* #define GS_PRODUCT_GNU */ "GNU Ghostscript",
0}; 0};
/* Get Ghostscript versions for given product. /* Get Ghostscript versions for given product.
* Store results starting at pver + 1 + offset. * Store results starting at pver + 1 + offset.
* Returns total number of versions in pver. * Returns total number of versions in pver.
*/ */
static int get_gs_versions_product(int *pver, int offset, static int get_gs_versions_product(int *pver, int offset,
HKEY hkeyroot, REGSAM regopenflags, HKEY hkeyroot, REGSAM regopenflags,
const char *gs_productfamily, const char *gsregbase, const char *gs_productfamily, const char *gsregbase,
bool verbose) int verbose, const char * const debug_info)
{ {
HKEY hkey; HKEY hkey;
DWORD cbData; DWORD cbData;
char key[256]; char key[256];
int ver; int ver;
char *p; char *p;
int n = 0; int n = 0;
if (strlen(gsregbase)) if (strlen(gsregbase))
sprintf_s(TARGETWITHLEN(key,256) , "Software\\%s\\%s", gsregbase, gs_pr sprintf_s(TARGETWITHLEN(key,256) , "Software\\%s\\%s", gsregbase, gs_prod
oductfamily); uctfamily);
else else
sprintf_s(TARGETWITHLEN(key,256) ,"Software\\%s", gs_productfamily); sprintf_s(TARGETWITHLEN(key,256) , "Software\\%s", gs_productfamily);
#ifdef OS_WIN32_WCE #ifdef OS_WIN32_WCE
const long regtestresult = RegOpenKeyEx(hkeyroot, LPSTRtoLPWSTR(key).c_st r(), 0, KEY_READ|regopenflags , &hkey); const long regtestresult = RegOpenKeyEx(hkeyroot, LPSTRtoLPWSTR(key).c_str(), 0, KEY_READ|regopenflags , &hkey);
#else #else
const long regtestresult = RegOpenKeyExA(hkeyroot, key, 0, KEY_READ|regop enflags , &hkey); const long regtestresult = RegOpenKeyExA(hkeyroot, key, 0, KEY_READ|regopenfla gs , &hkey);
#endif #endif
if (regtestresult == ERROR_SUCCESS) { if (verbose) fprintf(stdout, " return code for \"%s\" %s is %d\n", key, debug_
info, regtestresult);
if (regtestresult == ERROR_SUCCESS) {
/* Now enumerate the keys */ /* Now enumerate the keys */
if (verbose) fprintf(stdout," return code for \"%s\" is %d\n", key, re cbData = sizeof(key) / sizeof(char);
gtestresult);
cbData = sizeof(key) / sizeof(char);
#ifdef OS_WIN32_WCE #ifdef OS_WIN32_WCE
while (RegEnumKeyEx(hkey, n, (LPWSTR)LPSTRtoLPWSTR(key).c_str(), &cbData, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { while (RegEnumKeyEx(hkey, n, (LPWSTR)LPSTRtoLPWSTR(key).c_str(), &cbData, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
#else #else
while (RegEnumKeyA(hkey, n, key, cbData) == ERROR_SUCCESS) { while (RegEnumKeyA(hkey, n, key, cbData) == ERROR_SUCCESS)
#endif #endif
if (verbose) fprintf(stdout, " enumerate gs versions: \"%s\" is number %d {
", key, n+offset); if (verbose) fprintf(stdout, " enumerate gs versions: \"%s\" is number
n++; %d ", key, n+offset);
ver = 0; n++;
p = key; ver = 0;
int major = 0; p = key;
while (*p && (*p!='.')) { int major = 0;
while (*p && (*p!='.')) {
major *= 10; major *= 10;
major += (*p - '0'); major += (*p - '0');
p++; p++;
} }
if (*p == '.') { if (*p == '.') {
int minor = 0; int minor = 0;
p++; p++;
while (*p && (*p != '.')) { while (*p && (*p != '.')) {
minor *= 10; minor *= 10;
minor += (*p - '0'); minor += (*p - '0');
p++; p++;
} }
int pl = 0; int pl = 0;
if (*p == '.') { if (*p == '.') {
// new scheme nn.nn.PL // new scheme nn.nn.PL
p++; p++;
while (*p) { while (*p) {
pl *= 10; pl *= 10;
pl += (*p - '0'); pl += (*p - '0');
p++; p++;
} }
} }
ver = major * 10000 + minor * 100 + pl; ver = major * 10000 + minor * 100 + pl;
} else { } else {
// not expected, but ... // not expected, but ...
ver = major * 10000; ver = major * 10000;
} }
if (n + offset < pver[0]) { /* the pver[0] item contains the lenght if (n + offset < pver[0]) { /* the pver[0] item contains the lenght of
of the pver vector */ the pver vector */
/* this func /* this functi
tion is called also just for counting purposes */ on is called also just for counting purposes */
pver[n+offset] = ver; pver[n+offset] = ver;
} }
if (verbose) fprintf(stdout, "mapped to %d\n", ver); if (verbose) fprintf(stdout, "mapped to %d\n", ver);
}
} else {
/*
fprintf(stdout," return code for \"%s\" is %d\n", key, regtestres
ult);
*/
} }
return n+offset; }
return n+offset;
} }
/* Query registry to find which versions of Ghostscript are installed. /* Query registry to find which versions of Ghostscript are installed.
* Return version numbers in an integer array. * Return version numbers in an integer array.
* On entry, the first element in the array must be the array size * On entry, the first element in the array must be the array size
* in elements. * in elements.
* If all is well, TRUE is returned. * If all is well, TRUE is returned.
* On exit, the first element is set to the number of Ghostscript * On exit, the first element is set to the number of Ghostscript
* versions installed, and subsequent elements to the version * versions installed, and subsequent elements to the version
* numbers of Ghostscript. * numbers of Ghostscript.
skipping to change at line 156 skipping to change at line 153
* Returned version numbers may not be sorted. * Returned version numbers may not be sorted.
* *
* If Ghostscript is not installed at all, return FALSE * If Ghostscript is not installed at all, return FALSE
* and set pver[0] to 0. * and set pver[0] to 0.
* If the array is not large enough, return FALSE * If the array is not large enough, return FALSE
* and set pver[0] to the number of Ghostscript versions installed. * and set pver[0] to the number of Ghostscript versions installed.
*/ */
BOOL get_gs_versions(int *pver, const char *gsregbase, int verbose) BOOL get_gs_versions(int *pver, const char *gsregbase, int verbose)
{ {
int n=0; int n=0;
if (pver == (int *)NULL) if (pver == nullptr)
return FALSE; return FALSE;
const char * const * productptr = &gs_products[0]; const char * const * productptr = &gs_products[0];
while (productptr && *productptr) { while (productptr && *productptr) {
n = get_gs_versions_product(pver, n, HKEY_LOCAL_MACHINE, 0, n = get_gs_versions_product(pver, n, HKEY_LOCAL_MACHINE, 0,
*productptr, gsregbase, verbose); *productptr, gsregbase, verbose,"HKEY_LOCAL_MACHINE, 0");
n = get_gs_versions_product(pver, n, HKEY_CURRENT_USER, 0, n = get_gs_versions_product(pver, n, HKEY_CURRENT_USER, 0,
*productptr, gsregbase, verbose); *productptr, gsregbase, verbose,"HKEY_CURRENT_USE
n = get_gs_versions_product(pver, n, HKEY_LOCAL_MACHINE, KEY_WOW6 R, 0");
4_64KEY, *productptr, gsregbase, verbose); n = get_gs_versions_product(pver, n, HKEY_LOCAL_MACHINE, KEY_WOW6
n = get_gs_versions_product(pver, n, HKEY_CURRENT_USER, KEY_WOW6 4_64KEY, *productptr, gsregbase, verbose,"HKEY_LOCAL_MACHINE, KEY_WOW64_64
4_64KEY, *productptr, gsregbase, verbose); KEY");
n = get_gs_versions_product(pver, n, HKEY_CURRENT_USER, KEY_WOW6
4_64KEY, *productptr, gsregbase, verbose,"HKEY_CURRENT_USER, KEY_WOW64_64
KEY");
productptr++; productptr++;
} }
if (n >= pver[0]) { if (n >= pver[0]) {
pver[0] = n; pver[0] = n;
return FALSE; /* too small */ return FALSE; /* too small */
} }
if (n == 0) { if (n == 0) {
pver[0] = 0; pver[0] = 0;
skipping to change at line 188 skipping to change at line 185
} }
/* /*
* Get a named registry value. * Get a named registry value.
* Key = hkeyroot\\key, named value = name. * Key = hkeyroot\\key, named value = name.
* name, ptr, plen and return values are the same as in gp_getenv(); * name, ptr, plen and return values are the same as in gp_getenv();
*/ */
static int static int
gp_getenv_registry(HKEY hkeyroot, REGSAM regopenflags, const char *key, const ch ar *name, gp_getenv_registry(HKEY hkeyroot, REGSAM regopenflags, const char *key, const ch ar *name,
char *ptr, int *plen) char *ptr, int len, int verbose, const char * debug_info)
{ {
HKEY hkey; HKEY hkey;
DWORD cbData, keytype; DWORD cbData, keytype;
BYTE b; BYTE b;
LONG rc; LONG rc;
BYTE *bptr = (BYTE *)ptr; BYTE *bptr = (BYTE *)ptr;
/* int rsl = 1; /* not found */;
fprintf(stdout,"checking key %s %s\n",key,name);
*/
#ifdef OS_WIN32_WCE #ifdef OS_WIN32_WCE
if (RegOpenKeyEx(hkeyroot, LPSTRtoLPWSTR(key).c_str(), 0, KEY_READ | reg openflags , &hkey) == ERROR_SUCCESS) { if (RegOpenKeyEx(hkeyroot, LPSTRtoLPWSTR(key).c_str(), 0, KEY_READ | regopenf lags , &hkey) == ERROR_SUCCESS)
#else #else
if (RegOpenKeyExA(hkeyroot, key, 0, KEY_READ | regopenflags , &hkey) = = ERROR_SUCCESS) { if (RegOpenKeyExA(hkeyroot, key, 0, KEY_READ | regopenflags , &hkey) = = ERROR_SUCCESS)
#endif #endif
{
keytype = REG_SZ; keytype = REG_SZ;
cbData = *plen; cbData = len;
if (bptr == (BYTE *)NULL) if (bptr == (BYTE *)NULL)
bptr = &b; /* Registry API won't return ERROR_MORE_DATA */ bptr = &b; /* Registry API won't return ERROR_MORE_DATA */
/* if ptr is NULL */ /* if ptr is NULL */
#ifdef OS_WIN32_WCE #ifdef OS_WIN32_WCE
rc = RegQueryValueEx(hkey, LPSTRtoLPWSTR((char *)name).c_str(), 0, &keyty pe, bptr, &cbData); rc = RegQueryValueEx(hkey, LPSTRtoLPWSTR((char *)name).c_str(), 0, &keyty pe, bptr, &cbData);
#else #else
rc = RegQueryValueExA(hkey, (char *)name, 0, &keytype, bptr, &cbData); rc = RegQueryValueExA(hkey, (char *)name, 0, &keytype, bptr, &cbData);
#endif #endif
(void)RegCloseKey(hkey); (void)RegCloseKey(hkey);
if (rc == ERROR_SUCCESS) { if (rc == ERROR_SUCCESS) {
*plen = cbData; // *plen = cbData;
return 0; /* found environment variable and copied it */ rsl = 0; /* found environment variable and copied it */
} else if (rc == ERROR_MORE_DATA) { } else if (rc == ERROR_MORE_DATA) {
/* buffer wasn't large enough */ /* buffer wasn't large enough */
*plen = cbData; // *plen = cbData;
return -1; rsl = -1;
} }
} }
return 1; /* not found */ if (verbose) {
fprintf(stdout, "checking key %s %s (%s) -> %d\n", key, name, debug_info,
rsl);
}
return rsl;
} }
static BOOL get_gs_string_product(int gs_revision, const char *name, static BOOL get_gs_string_product(int gs_revision, const char *name,
char *ptr, int len, const char *gs_productfamily, const char *gsregbase) char *ptr, int len, const char *gs_productfamily, const char *gsregbase, int verbose)
{ {
/* If using Win32, look in the registry for a value with /* If using Win32, look in the registry for a value with
* the given name. The registry value will be under the key * the given name. The registry value will be under the key
* HKEY_CURRENT_USER\Software\AFPL Ghostscript\N.NN * HKEY_CURRENT_USER\Software\AFPL Ghostscript\N.NN
* or if that fails under the key * or if that fails under the key
* HKEY_LOCAL_MACHINE\Software\AFPL Ghostscript\N.NN * HKEY_LOCAL_MACHINE\Software\AFPL Ghostscript\N.NN
* where "AFPL Ghostscript" is actually gs_productfamily * where "AFPL Ghostscript" is actually gs_productfamily
* and N.NN is obtained from gs_revision. * and N.NN is obtained from gs_revision.
*/ */
/* new since Rel 9.93.0: We have also a PL /* new since Rel 9.93.0: We have also a PL
hence all gs_revision is 99300 in this case hence all gs_revision is 99300 in this case
for older relases we use then 99200 for older relases we use then 99200
*/ */
int code;
char key[256]; char key[256];
char dotversion[16]; char dotversion[16];
int length;
#if 0 #if 0
const DWORD version = GetVersion(); const DWORD version = GetVersion();
// hope we do not need this anymore // hope we do not need this anymore
if (((HIWORD(version) & 0x8000) != 0) if (((HIWORD(version) & 0x8000) != 0)
&& ((HIWORD(version) & 0x4000) == 0)) { && ((HIWORD(version) & 0x4000) == 0)) {
/* Win32s */ /* Win32s */
return FALSE; return FALSE;
} }
#endif #endif
if (gs_revision < 95300) { if (gs_revision < 95300) {
sprintf_s(TARGETWITHLEN(dotversion, 16), "%d.%02d", sprintf_s(TARGETWITHLEN(dotversion, 16), "%d.%02d",
(int)(gs_revision / 10000), (int)(gs_revision / 10000),
(int)(gs_revision % 10000)); (int)(gs_revision % 10000)/100);
} else { } else {
const int major = gs_revision / 10000; const int major = gs_revision / 10000;
const int minor = (gs_revision - major * 10000) / 100; const int minor = (gs_revision - major * 10000) / 100;
const int pl = (gs_revision - major * 10000) % 100; const int pl = (gs_revision - major * 10000) % 100;
sprintf_s(TARGETWITHLEN(dotversion, 16), "%d.%02d.%d", sprintf_s(TARGETWITHLEN(dotversion, 16), "%d.%02d.%d",
major, major,
minor, minor,
pl pl
); );
} }
//fprintf(stdout, "DOT: %s\n", dotversion); if (verbose) fprintf(stdout, "DOT: %s\n", dotversion);
if (strlen(gsregbase)) if (strlen(gsregbase))
sprintf_s(TARGETWITHLEN(key,256), "Software\\%s\\%s\\%s", gsregbase, gs _productfamily, dotversion); sprintf_s(TARGETWITHLEN(key,256), "Software\\%s\\%s\\%s", gsregbase, gs _productfamily, dotversion);
else else
sprintf_s(TARGETWITHLEN(key,256), "Software\\%s\\%s", gs_productfamily, dotversion); sprintf_s(TARGETWITHLEN(key,256), "Software\\%s\\%s", gs_productfamily, dotversion);
length = len; if (
code = gp_getenv_registry(HKEY_CURRENT_USER, 0, key, name, ptr, &length); (gp_getenv_registry(HKEY_CURRENT_USER, 0, key, nam
if ( code == 0 ) return TRUE; /* found it */ e, ptr, len, verbose, "HKEY_CURRENT_USER, 0") == 0) ||
(gp_getenv_registry(HKEY_LOCAL_MACHINE, 0, key, nam
length = len; e, ptr, len, verbose, "HKEY_LOCAL_MACHINE, 0") == 0) ||
code = gp_getenv_registry(HKEY_LOCAL_MACHINE, 0, key, name, ptr, &length); (gp_getenv_registry(HKEY_CURRENT_USER, KEY_WOW64_64KEY, key, nam
if ( code == 0 ) return TRUE; /* found it */ e, ptr, len, verbose, "HKEY_CURRENT_USER, KEY_WOW64_64KEY") == 0) ||
(gp_getenv_registry(HKEY_LOCAL_MACHINE, KEY_WOW64_64KEY, key, nam
length = len; e, ptr, len, verbose, "HKEY_LOCAL_MACHINE, KEY_WOW64_64KEY") == 0)
code = gp_getenv_registry(HKEY_CURRENT_USER, KEY_WOW64_64KEY, key, name, ptr ) {
, &length); return true;
if ( code == 0 ) return TRUE; /* found it */ } else {
return false;
length = len; }
code = gp_getenv_registry(HKEY_LOCAL_MACHINE, KEY_WOW64_64KEY, key, name, pt
r, &length);
if ( code == 0 ) return TRUE; /* found it */
return FALSE;
} }
BOOL get_gs_string(int gs_revision, const char *name, char *ptr, int len, BOOL get_gs_string(int gs_revision, const char *name, char *ptr, int len,
const char *gsregbase) const char *gsregbase, int verbose)
{ {
const char * const * productptr = &gs_products[0]; const char * const * productptr = &gs_products[0];
while (productptr && *productptr) { while (productptr && *productptr) {
if (get_gs_string_product(gs_revision, name, ptr, len, *productpt r, gsregbase)) if (get_gs_string_product(gs_revision, name, ptr, len, *productpt r, gsregbase, verbose))
return TRUE; return TRUE;
productptr++; productptr++;
} }
return FALSE; return FALSE;
} }
/* Set the latest Ghostscript EXE or DLL from the registry */ /* Set the latest Ghostscript EXE or DLL from the registry */
BOOL BOOL
find_gs(char *gspath, int len, int minver, BOOL bDLL, const char *gsregbase, int verbose) find_gs(char *gspath, int len, int minver, BOOL bDLL, const char *gsregbase, int verbose)
{ {
#if 0 #if 0
// win32s no longer supported // win32s no longer supported
const DWORD version = GetVersion(); const DWORD version = GetVersion();
if (((HIWORD(version) & 0x8000) != 0) && ((HIWORD(version) & 0x4000) == 0 )) { if (((HIWORD(version) & 0x8000) != 0) && ((HIWORD(version) & 0x4000) == 0 )) {
return FALSE; // win32s return FALSE; // win32s
} }
#endif #endif
//if (verbose) fprintf(stdout, "find_gs - counting\n");
int count = 1; int count = 1;
(void)get_gs_versions(&count, gsregbase, verbose); (void)get_gs_versions(&count, gsregbase, false /* verbose */); // first cal l for counting
if (count < 1) { if (count < 1) {
return FALSE; return FALSE;
} }
int* ver = new int[count + 1]; // (int *)malloc((count + 1) * sizeof(int) ); int* ver = new int[count + 1];
if (!ver) { if (!ver) {
return FALSE; return FALSE;
} }
//if (verbose) fprintf(stdout, "find_gs - collecting\n");
ver[0] = count+1; ver[0] = count+1;
if (!get_gs_versions(ver, gsregbase, verbose)) { if (!get_gs_versions(ver, gsregbase, verbose)) {
delete[] ver; // free(ver); delete[] ver; // free(ver);
return FALSE; return FALSE;
} }
int maxversion = 10000000; int maxversion = 10000000;
const char * gsvmax = getenv("GS_V_MAX"); const char * gsvmax = getenv("GS_V_MAX");
if (gsvmax) { if (gsvmax) {
maxversion = atoi(gsvmax); maxversion = atoi(gsvmax);
skipping to change at line 356 skipping to change at line 350
if ((ver[i] > gsver) && (ver[i] <= maxversion)) { if ((ver[i] > gsver) && (ver[i] <= maxversion)) {
gsver = ver[i]; gsver = ver[i];
} }
} }
delete[] ver; // free(ver); delete[] ver; // free(ver);
if (gsver < minver) { // minimum version (e.g. for gsprint) if (gsver < minver) { // minimum version (e.g. for gsprint)
return FALSE; return FALSE;
} }
char buf[1000]; char buf[1000];
if (!get_gs_string(gsver, "GS_DLL", buf, sizeof(buf), gsregbase)) { if (!get_gs_string(gsver, "GS_DLL", buf, sizeof(buf), gsregbase, verbose) ) {
return FALSE; return FALSE;
} }
if (bDLL) { if (bDLL) {
strncpy_s(gspath, len, buf, len-1); strncpy_s(gspath, len, buf, len-1);
return TRUE; return TRUE;
} else { } else {
char * p = strrchr(buf, '\\'); char * p = strrchr(buf, '\\');
if (p) { if (p) {
p++; p++;
skipping to change at line 411 skipping to change at line 405
const BOOL flag = get_gs_versions(ver, gsregbase, verbose); const BOOL flag = get_gs_versions(ver, gsregbase, verbose);
fprintf(stderr,"Versions: %d\n", ver[0]); fprintf(stderr,"Versions: %d\n", ver[0]);
if (flag == FALSE) { if (flag == FALSE) {
fprintf(stderr,"get_gs_versions failed, need %d\n", ver[0]); fprintf(stderr,"get_gs_versions failed, need %d\n", ver[0]);
return 1; return 1;
} }
for (int i=1; i <= ver[0]; i++) { for (int i=1; i <= ver[0]; i++) {
fprintf(stderr," %d\n", ver[i]); fprintf(stderr," %d\n", ver[i]);
if (get_gs_string(ver[i], "GS_DLL", buf, sizeof(buf), gsregbase)) { if (get_gs_string(ver[i], "GS_DLL", buf, sizeof(buf), gsregbase, verbos e)) {
fprintf(stderr," GS_DLL=%s\n", buf); fprintf(stderr," GS_DLL=%s\n", buf);
} }
if (get_gs_string(ver[i], "GS_LIB", buf, sizeof(buf), gsregbase)) { if (get_gs_string(ver[i], "GS_LIB", buf, sizeof(buf), gsregbase, verbos e)) {
fprintf(stderr," GS_LIB=%s\n", buf); fprintf(stderr," GS_LIB=%s\n", buf);
} }
} }
return 0; return 0;
} }
 End of changes. 42 change blocks. 
106 lines changed or deleted 105 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)