summaryrefslogtreecommitdiff
path: root/Build/source/libs/libgsw32
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2006-01-16 00:09:26 +0000
committerKarl Berry <karl@freefriends.org>2006-01-16 00:09:26 +0000
commit6c0eafbb1395d426a72a74538e0b2a95e8344ca6 (patch)
tree2a5f80b80fc76086a2602b812c2a182d00f961b7 /Build/source/libs/libgsw32
parent70f7efeb5c9965a63a4143ad1c1f473585dc364c (diff)
libs 1
git-svn-id: svn://tug.org/texlive/trunk@1483 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/libgsw32')
-rw-r--r--Build/source/libs/libgsw32/depend.mak11
-rw-r--r--Build/source/libs/libgsw32/ghostscr.c227
-rw-r--r--Build/source/libs/libgsw32/gs32lib.h52
-rw-r--r--Build/source/libs/libgsw32/gsdll.h132
-rw-r--r--Build/source/libs/libgsw32/gvwgsver.c297
-rw-r--r--Build/source/libs/libgsw32/gvwgsver.h22
-rw-r--r--Build/source/libs/libgsw32/win32.mak68
7 files changed, 809 insertions, 0 deletions
diff --git a/Build/source/libs/libgsw32/depend.mak b/Build/source/libs/libgsw32/depend.mak
new file mode 100644
index 00000000000..30c1dc8b43d
--- /dev/null
+++ b/Build/source/libs/libgsw32/depend.mak
@@ -0,0 +1,11 @@
+$(objdir)/gvwgsver.obj: \
+ gvwgsver.h
+
+$(objdir)/ghostscr.obj: \
+ $(gnuw32dir)/win32lib.h \
+ gs32lib.h \
+ ../../gstools/ghostscript/src/gsdll.h \
+ ../../gstools/ghostscript/src/iapi.h \
+ ../../gstools/ghostscript/src/errors.h \
+ gvwgsver.h
+
diff --git a/Build/source/libs/libgsw32/ghostscr.c b/Build/source/libs/libgsw32/ghostscr.c
new file mode 100644
index 00000000000..77bd2d6c6f8
--- /dev/null
+++ b/Build/source/libs/libgsw32/ghostscr.c
@@ -0,0 +1,227 @@
+/*
+
+Ghostscript initialization for fpTeX.
+
+Copyright (C) 1998, 99 Free Software Foundation, Inc.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/*
+ This function returns the directory name where GS is installed
+ and tries to make sure that either gswin32c.exe or gsdll32.dll
+ will run as expected, by checking GS_LIB.
+
+ Location of .exe or .dll :
+ - look into the PATH for the dll, if found this will be the directory
+ - look into the registry, warn user if a different version is found
+ - check for GS_LIB in the environment
+ - check for GS_LIB in the registry
+ - else build a GS_LIB from rule of thumb.
+*/
+
+#include <string.h>
+#include <win32lib.h>
+#include <gs32lib.h>
+
+#include "gvwgsver.h"
+
+extern char *xstrdup(const char *);
+
+#define GSDLL "gsdll32.dll"
+
+/* GSW32DLL char *gs_dir = NULL; */
+GSW32DLL char *gs_dll = NULL;
+GSW32DLL char *gs_lib = NULL;
+GSW32DLL char *gs_revision = NULL;
+/* GSW32DLL char *gs_product_values[] = { "AFPL Ghostscript", "Aladdin Ghostscript", "GNU Ghostscript" }; */
+/* GSW32DLL char *gs_product = NULL; */
+/* int gs_product_index; */
+
+#define NB_ITEMS(x) (sizeof(x)/sizeof(x[0]))
+
+/*
+ * Load the ghostscript dll gswin32.dll.
+ * See the dll.txt file in the ghostscript source distribution.
+ * We will try to make gs draw directly onto the screen/printer
+ * device, as it is using SetDIBitsToDevice(), and it may use
+ * more colors than the mem device has.
+ * This may not be the more efficient, and we will have to see
+ * how it adapts to printing. But there may be some overhead
+ * at getting the whole dib at scale 1.
+ */
+GSW32DLL PFN_gsdll_init pgsdll_init;
+GSW32DLL PFN_gsdll_execute_begin pgsdll_execute_begin;
+GSW32DLL PFN_gsdll_execute_cont pgsdll_execute_cont;
+GSW32DLL PFN_gsdll_execute_end pgsdll_execute_end;
+GSW32DLL PFN_gsdll_exit pgsdll_exit;
+GSW32DLL PFN_gsdll_draw pgsdll_draw;
+GSW32DLL PFN_gsdll_get_bitmap_row pgsdll_get_bitmap_row;
+GSW32DLL PFN_gsdll_lock_device pgsdll_lock_device;
+
+GSW32DLL HANDLE hGsDll = 0;
+
+const char *gslocpath[] = { "fonts", "..\\fonts", "..\\..\\fonts",
+ "lib", "..\\lib" };
+
+
+int
+gs_version_cmp(const char *sv1, const char *sv2)
+{
+ /*
+ Assuming version numbers of the form : xx.yy
+ */
+
+ int nv1x, nv1y, nv2x, nv2y;
+ if (sscanf(sv1, "%d.%d", &nv1x, &nv1y) == 2
+ && sscanf(sv2, "%d.%d", &nv2x, &nv2y) == 2) {
+ if (nv1x == nv2x) {
+ return nv1y - nv2y;
+ }
+ else {
+ return nv1x - nv2x;
+ }
+ }
+ else {
+ return -1;
+ }
+}
+
+// Set the latest Ghostscript EXE or DLL from the registry
+BOOL
+gs_registry_locate()
+{
+ int count;
+ int *ver;
+ int gsver;
+ char buf[256];
+ char *p;
+ int i;
+
+ DWORD version = GetVersion();
+ if ( ((HIWORD(version) & 0x8000)!=0) && ((HIWORD(version) & 0x4000)==0) )
+ return FALSE; // win32s
+
+ count = 1;
+ get_gs_versions(&count);
+ if (count < 1)
+ return FALSE;
+ ver = (int *)malloc((count+1)*sizeof(int));
+ if (ver == (int *)NULL)
+ return FALSE;
+ ver[0] = count+1;
+ if (!get_gs_versions(ver)) {
+ free(ver);
+ return FALSE;
+ }
+ gsver = 0;
+ for (i=1; i<=ver[0]; i++) {
+ if (ver[i] > gsver)
+ gsver = ver[i];
+ }
+ free(ver);
+
+ gs_revision = xmalloc(sizeof("99.99"));
+ gs_revision[0] = (int)(gsver / 100) + 48;
+ gs_revision[1] = '.';
+ gs_revision[2] = (int)((gsver / 10) % 10) + 48;
+ gs_revision[3] = (int)(gsver % 10) + 48;
+ gs_revision[4] = '\0';
+
+ if (!get_gs_string(gsver, "GS_DLL", buf, sizeof(buf)))
+ return FALSE;
+ // just to make sure
+ for(p = buf; p && *p; p++)
+ *p = (*p == '/' ? '\\' : *p);
+
+ gs_dll = xstrdup(buf);
+
+ if (!get_gs_string(gsver, "GS_LIB", buf, sizeof(buf)))
+ return FALSE;
+
+ gs_lib = xstrdup(buf);
+
+ return TRUE;
+}
+
+char * gs_locate()
+{
+ char data[MAXPATHLEN];
+ DWORD data_len;
+ char *fp;
+
+ /* FIXME : Should also try to open and read
+ gsview32.ini !
+ FIXME : What policy should we use ?
+ What if gs_dll is found in the registry and
+ in the PATH ?
+ Currently, it the PATH points to some gs version, then this
+ is the one that will be used. But in this case, GS_LIB must
+ be set too, else the registry will be looked for.
+ */
+
+ if (gs_registry_locate() == FALSE) {
+ gs_revision = xstrdup("(unknown)");
+ if (SearchPath(NULL, GSDLL, NULL, sizeof(data), data, &fp) != 0) {
+ gs_dll = xstrdup(data);
+ }
+ if (gs_lib = getenv("GS_LIB"))
+ gs_lib = xstrdup(gs_lib);
+ }
+
+ return gs_dll;
+}
+
+BOOL gs_dll_initialize()
+{
+
+ if (!gs_dll || !*gs_dll) {
+ fprintf(stderr, "gs not initialized, dll not found.\n");
+ return FALSE;
+ }
+
+ if ((hGsDll = LoadLibrary(gs_dll)) == NULL) {
+ fprintf(stderr, "LoadLibrary: Can't load gs dll.");
+ hGsDll = 0;
+ return FALSE;
+ }
+
+ pgsdll_init = (PFN_gsdll_init)GetProcAddress(hGsDll, "gsdll_init");
+ pgsdll_execute_begin = (PFN_gsdll_execute_begin)GetProcAddress(hGsDll, "gsdll_execute_begin");
+ pgsdll_execute_cont = (PFN_gsdll_execute_cont)GetProcAddress(hGsDll, "gsdll_execute_cont");
+ pgsdll_execute_end = (PFN_gsdll_execute_end)GetProcAddress(hGsDll, "gsdll_execute_end");
+ pgsdll_exit = (PFN_gsdll_exit)GetProcAddress(hGsDll, "gsdll_exit");
+ pgsdll_draw = (PFN_gsdll_draw)GetProcAddress(hGsDll, "gsdll_draw");
+ pgsdll_get_bitmap_row = (PFN_gsdll_get_bitmap_row)GetProcAddress(hGsDll, "gsdll_get_bitmap_row");
+ pgsdll_lock_device = (PFN_gsdll_lock_device)GetProcAddress(hGsDll, "gsdll_lock_device");
+ if (!pgsdll_init || !pgsdll_execute_begin || !pgsdll_execute_cont
+ || !pgsdll_execute_end || !pgsdll_exit || !pgsdll_draw
+ || !pgsdll_get_bitmap_row || !pgsdll_lock_device) {
+ fprintf(stderr, "Not all functions found in gs dll.\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+BOOL gs_dll_release()
+{
+ if (hGsDll) {
+ FreeLibrary(hGsDll);
+ hGsDll = 0;
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/Build/source/libs/libgsw32/gs32lib.h b/Build/source/libs/libgsw32/gs32lib.h
new file mode 100644
index 00000000000..e30d868d854
--- /dev/null
+++ b/Build/source/libs/libgsw32/gs32lib.h
@@ -0,0 +1,52 @@
+#ifndef _GS32LIB_H_
+#define _GS32LIB_H_
+
+#pragma warning( disable : 4007 4096 4018 4244 )
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <gsdll.h>
+
+#if defined(WIN32)
+# if defined(GSW32_DLL)
+# if defined(MAKE_GSW32_DLL)
+# define GSW32DLL __declspec( dllexport)
+# else
+# define GSW32DLL __declspec( dllimport)
+# endif
+# else
+# define GSW32DLL
+# endif
+#else /* ! WIN32 */
+# define GSW32DLL
+#endif
+
+/* Functions from ghostscr.c */
+extern GSW32DLL char *gs_locate();
+extern GSW32DLL int gs_version_cmp(const char *, const char *);
+extern GSW32DLL BOOL gs_dll_initialize();
+extern GSW32DLL BOOL gs_dll_release();
+extern GSW32DLL char *gs_dir;
+extern GSW32DLL char *gs_dll;
+extern GSW32DLL char *gs_lib;
+extern GSW32DLL char *gs_revision;
+extern GSW32DLL char *gs_product;
+
+extern GSW32DLL PFN_gsdll_init pgsdll_init;
+extern GSW32DLL PFN_gsdll_execute_begin pgsdll_execute_begin;
+extern GSW32DLL PFN_gsdll_execute_cont pgsdll_execute_cont;
+extern GSW32DLL PFN_gsdll_execute_end pgsdll_execute_end;
+extern GSW32DLL PFN_gsdll_exit pgsdll_exit;
+extern GSW32DLL PFN_gsdll_draw pgsdll_draw;
+extern GSW32DLL PFN_gsdll_get_bitmap_row pgsdll_get_bitmap_row;
+extern GSW32DLL PFN_gsdll_lock_device pgsdll_lock_device;
+
+extern GSW32DLL HANDLE hGsDll;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GS32LIB_H_ */
diff --git a/Build/source/libs/libgsw32/gsdll.h b/Build/source/libs/libgsw32/gsdll.h
new file mode 100644
index 00000000000..c155be4d75e
--- /dev/null
+++ b/Build/source/libs/libgsw32/gsdll.h
@@ -0,0 +1,132 @@
+/* Copyright (C) 1994-1996, Russell Lang. All rights reserved.
+
+ This file is part of Aladdin Ghostscript.
+
+ Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author
+ or distributor accepts any responsibility for the consequences of using it,
+ or for whether it serves any particular purpose or works at all, unless he
+ or she says so in writing. Refer to the Aladdin Ghostscript Free Public
+ License (the "License") for full details.
+
+ Every copy of Aladdin Ghostscript must include a copy of the License,
+ normally in a plain ASCII text file named PUBLIC. The License grants you
+ the right to copy, modify and redistribute Aladdin Ghostscript, but only
+ under certain conditions described in the License. Among other things, the
+ License requires that the copyright notice and this notice be preserved on
+ all copies.
+*/
+
+
+/* gsdll.h */
+
+#ifndef _GSDLL_H
+#define _GSDLL_H
+
+#ifndef GSDLLEXPORT
+#define GSDLLEXPORT
+#endif
+
+#ifdef __WINDOWS__
+#define _Windows
+#endif
+
+#ifdef WIN32
+#define _Windows
+#endif
+
+/* type of exported functions */
+#ifdef _Windows
+#ifdef _WATCOM_
+#define GSDLLAPI GSDLLEXPORT
+#else
+#define GSDLLAPI CALLBACK GSDLLEXPORT
+#endif
+#else
+#ifdef __IBMC__
+#define GSDLLAPI _System
+#else
+#define GSDLLAPI
+#endif
+#endif
+
+#ifdef _Windows
+#define GSDLLCALLLINK
+#define GSFAR FAR
+#else
+#ifdef __IBMC__
+#define GSDLLCALLLINK _System
+#else
+#define GSDLLCALLLINK
+#endif
+#define GSFAR
+#endif
+
+/* global pointer to callback */
+typedef int (__cdecl *GSDLLCALLLINK GSDLL_CALLBACK)(int, char GSFAR *, unsigned long);
+extern GSDLL_CALLBACK pgsdll_callback;
+
+/* message values for callback */
+#define GSDLL_STDIN 1 /* get count characters to str from stdin */
+ /* return number of characters read */
+#define GSDLL_STDOUT 2 /* put count characters from str to stdout*/
+ /* return number of characters written */
+#define GSDLL_DEVICE 3 /* device = str has been opened if count=1 */
+ /* or closed if count=0 */
+#define GSDLL_SYNC 4 /* sync_output for device str */
+#define GSDLL_PAGE 5 /* output_page for device str */
+#define GSDLL_SIZE 6 /* resize for device str */
+ /* LOWORD(count) is new xsize */
+ /* HIWORD(count) is new ysize */
+#define GSDLL_POLL 7 /* Called from gp_check_interrupt */
+ /* Can be used by caller to poll the message queue */
+ /* Normally returns 0 */
+ /* To abort gsdll_execute_cont(), return a */
+ /* non zero error code until gsdll_execute_cont() */
+ /* returns */
+
+/* return values from gsdll_init() */
+#define GSDLL_INIT_IN_USE 100 /* DLL is in use */
+#define GSDLL_INIT_QUIT 101 /* quit or EOF during init */
+ /* This is not an error. */
+ /* gsdll_exit() must not be called */
+
+
+/* DLL exported functions */
+/* for load time dynamic linking */
+int GSDLLAPI gsdll_revision(char GSFAR * GSFAR *product, char GSFAR * GSFAR *copyright, long GSFAR *gs_revision, long GSFAR *gs_revisiondate);
+int GSDLLAPI gsdll_init(GSDLL_CALLBACK callback, HWND hwnd, int argc, char GSFAR * GSFAR *argv);
+int GSDLLAPI gsdll_execute_begin(void);
+int GSDLLAPI gsdll_execute_cont(const char GSFAR *str, int len);
+int GSDLLAPI gsdll_execute_end(void);
+int GSDLLAPI gsdll_exit(void);
+int GSDLLAPI gsdll_lock_device(unsigned char *device, int flag);
+#ifdef _Windows
+HGLOBAL GSDLLAPI gsdll_copy_dib(unsigned char GSFAR *device);
+HPALETTE GSDLLAPI gsdll_copy_palette(unsigned char GSFAR *device);
+void GSDLLAPI gsdll_draw(unsigned char GSFAR *device, HDC hdc, LPRECT dest, LPRECT src);
+int GSDLLAPI gsdll_get_bitmap_row(unsigned char *device, LPBITMAPINFOHEADER pbmih,
+ LPRGBQUAD prgbquad, LPBYTE *ppbyte, unsigned int row);
+#else
+unsigned long gsdll_get_bitmap(unsigned char *device, unsigned char **pbitmap);
+#endif
+
+/* Function pointer typedefs */
+/* for run time dynamic linking */
+typedef int (GSDLLAPI *PFN_gsdll_revision)(char GSFAR * GSFAR *, char GSFAR * GSFAR *, long GSFAR *, long GSFAR *);
+typedef int (GSDLLAPI *PFN_gsdll_init)(GSDLL_CALLBACK, HWND, int argc, char GSFAR * GSFAR *argv);
+typedef int (GSDLLAPI *PFN_gsdll_execute_begin)(void);
+typedef int (GSDLLAPI *PFN_gsdll_execute_cont)(const char GSFAR *str, int len);
+typedef int (GSDLLAPI *PFN_gsdll_execute_end)(void);
+typedef int (GSDLLAPI *PFN_gsdll_exit)(void);
+typedef int (GSDLLAPI *PFN_gsdll_lock_device)(unsigned char GSFAR *, int);
+#ifdef _Windows
+typedef HGLOBAL (GSDLLAPI *PFN_gsdll_copy_dib)(unsigned char GSFAR *);
+typedef HPALETTE (GSDLLAPI *PFN_gsdll_copy_palette)(unsigned char GSFAR *);
+typedef void (GSDLLAPI *PFN_gsdll_draw)(unsigned char GSFAR *, HDC, LPRECT, LPRECT);
+typedef int (GSDLLAPI *PFN_gsdll_get_bitmap_row)(unsigned char *device, LPBITMAPINFOHEADER pbmih,
+ LPRGBQUAD prgbquad, LPBYTE *ppbyte, unsigned int row);
+#else
+typedef long (*GSDLLAPI PFN_gsdll_get_bitmap)(unsigned char *, unsigned char **);
+#endif
+
+#endif
diff --git a/Build/source/libs/libgsw32/gvwgsver.c b/Build/source/libs/libgsw32/gvwgsver.c
new file mode 100644
index 00000000000..c5bd417bbe3
--- /dev/null
+++ b/Build/source/libs/libgsw32/gvwgsver.c
@@ -0,0 +1,297 @@
+/* Copyright (C) 2000, Ghostgum Software Pty Ltd. All rights reserved.
+
+ This file is part of GSview.
+
+ This program is distributed with NO WARRANTY OF ANY KIND. No author
+ or distributor accepts any responsibility for the consequences of using it,
+ or for whether it serves any particular purpose or works at all, unless he
+ or she says so in writing. Refer to the GSview Free Public Licence
+ (the "Licence") for full details.
+
+ Every copy of GSview must include a copy of the Licence, normally in a
+ plain ASCII text file named LICENCE. The Licence grants you the right
+ to copy, modify and redistribute GSview, but only under certain conditions
+ described in the Licence. Among other things, the Licence requires that
+ the copyright notice and this notice be preserved on all copies.
+*/
+
+/* gvwgsver.c */
+
+#ifdef DUMP_GSVER
+#include <windows.h>
+#include <stdio.h>
+#else
+#include <windows.h>
+#endif
+#include <stdlib.h>
+#include "gvwgsver.h"
+
+#define GS_PRODUCT_AFPL "AFPL Ghostscript"
+#define GS_PRODUCT_ALADDIN "Aladdin Ghostscript"
+#define GS_PRODUCT_GNU "GNU Ghostscript"
+
+// Get Ghostscript versions for given product.
+// Store results starting at pver + 1 + offset.
+// Returns total number of versions in pver.
+static int get_gs_versions_product(int *pver, int offset,
+ const char *gs_productfamily)
+{
+ // First find out how many versions of Ghostscript are available.
+ HKEY hkey;
+ DWORD cbData;
+ HKEY hkeyroot;
+ TCHAR key[256];
+ int ver;
+ TCHAR *p;
+ int n = 0;
+
+ wsprintf(key, TEXT("Software\\%s"), gs_productfamily);
+ hkeyroot = HKEY_LOCAL_MACHINE;
+ if (RegOpenKeyEx(hkeyroot, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS) {
+ // Now enumerate the keys
+ cbData = sizeof(key) / sizeof(TCHAR);
+ while (RegEnumKey(hkey, n, key, cbData) == ERROR_SUCCESS) {
+ n++;
+ ver = 0;
+ p = key;
+ while (*p && (*p!='.')) {
+ ver = (ver * 10) + (*p - '0')*100;
+ p++;
+ }
+ if (*p == '.')
+ p++;
+ if (*p) {
+ ver += (*p - '0') * 10;
+ p++;
+ }
+ if (*p)
+ ver += (*p - '0');
+ if (n + offset < pver[0])
+ pver[n+offset] = ver;
+ }
+ }
+ return n+offset;
+}
+
+// Query registry to find which versions of Ghostscript are installed.
+// Return version numbers in an integer array.
+// On entry, the first element in the array must be the array size
+// in elements.
+// If all is well, TRUE is returned.
+// On exit, the first element is set to the number of Ghostscript
+// versions installed, and subsequent elements to the version
+// numbers of Ghostscript.
+// e.g. on entry {5, 0, 0, 0, 0}, on exit {3, 550, 600, 596, 0}
+// Returned version numbers may not be sorted.
+//
+// If Ghostscript is not installed at all, return FALSE
+// and set pver[0] to 0.
+// If the array is not large enough, return FALSE
+// and set pver[0] to the number of Ghostscript versions installed.
+BOOL get_gs_versions(int *pver)
+{
+ // First find out how many versions of Ghostscript are available.
+ int n;
+ if (pver == (int *)NULL)
+ return FALSE;
+
+ n = get_gs_versions_product(pver, 0, GS_PRODUCT_AFPL);
+ n = get_gs_versions_product(pver, n, GS_PRODUCT_ALADDIN);
+ n = get_gs_versions_product(pver, n, GS_PRODUCT_GNU);
+
+ if (n >= pver[0]) {
+ pver[0] = n;
+ return FALSE; // too small
+ }
+
+ if (n == 0) {
+ pver[0] = 0;
+ return FALSE; // not installed
+ }
+ pver[0] = n;
+ return TRUE;
+}
+
+
+/*
+ * Get a named registry value.
+ * Key = hkeyroot\\key, named value = name.
+ * name, ptr, plen and return values are the same as in gp_getenv();
+ */
+
+int
+gp_getenv_registry(HKEY hkeyroot, const char *key, const char *name,
+ char *ptr, int *plen)
+{
+ HKEY hkey;
+ DWORD cbData, keytype;
+ BYTE b;
+ LONG rc;
+ BYTE *bptr = (BYTE *)ptr;
+
+ if (RegOpenKeyEx(hkeyroot, key, 0, KEY_READ, &hkey)
+ == ERROR_SUCCESS) {
+ keytype = REG_SZ;
+ cbData = *plen;
+ if (bptr == (BYTE *)NULL)
+ bptr = &b; /* Registry API won't return ERROR_MORE_DATA */
+ /* if ptr is NULL */
+ rc = RegQueryValueEx(hkey, (char *)name, 0, &keytype, bptr, &cbData);
+ RegCloseKey(hkey);
+ if (rc == ERROR_SUCCESS) {
+ *plen = cbData;
+ return 0; /* found environment variable and copied it */
+ } else if (rc == ERROR_MORE_DATA) {
+ /* buffer wasn't large enough */
+ *plen = cbData;
+ return -1;
+ }
+ }
+ return 1; /* not found */
+}
+
+
+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;
+}
+
+BOOL get_gs_string(int gs_revision, const char *name, char *ptr, int len)
+{
+ if (get_gs_string_product(gs_revision, name, ptr, len, GS_PRODUCT_AFPL))
+ return TRUE;
+ if (get_gs_string_product(gs_revision, name, ptr, len, GS_PRODUCT_ALADDIN))
+ return TRUE;
+ if (get_gs_string_product(gs_revision, name, ptr, len, GS_PRODUCT_GNU))
+ return TRUE;
+ return FALSE;
+}
+
+
+
+// Set the latest Ghostscript EXE or DLL from the registry
+BOOL
+find_gs(char *gspath, int len, int minver, BOOL bDLL)
+{
+ int count;
+ int *ver;
+ int gsver;
+ char buf[256];
+ char *p;
+ int i;
+
+ DWORD version = GetVersion();
+ if ( ((HIWORD(version) & 0x8000)!=0) && ((HIWORD(version) & 0x4000)==0) )
+ return FALSE; // win32s
+
+ count = 1;
+ get_gs_versions(&count);
+ if (count < 1)
+ return FALSE;
+ ver = (int *)malloc((count+1)*sizeof(int));
+ if (ver == (int *)NULL)
+ return FALSE;
+ ver[0] = count+1;
+ if (!get_gs_versions(ver)) {
+ free(ver);
+ return FALSE;
+ }
+ gsver = 0;
+ for (i=1; i<=ver[0]; i++) {
+ if (ver[i] > gsver)
+ gsver = ver[i];
+ }
+ free(ver);
+ if (gsver < minver) // minimum version (e.g. for gsprint)
+ return FALSE;
+
+ if (!get_gs_string(gsver, "GS_DLL", buf, sizeof(buf)))
+ return FALSE;
+
+ if (bDLL) {
+ strncpy(gspath, buf, len-1);
+ return TRUE;
+ }
+
+ p = strrchr(buf, '\\');
+ if (p) {
+ p++;
+ *p = 0;
+ strncpy(p, "gswin32c.exe", sizeof(buf)-1-strlen(buf));
+ strncpy(gspath, buf, len-1);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+#ifdef DUMP_GSVER
+int main(int argc, char *argv[])
+{
+ BOOL flag;
+ int n;
+ int ver[6];
+ int i;
+ char buf[256];
+
+ ver[0] = sizeof(ver) / sizeof(int);
+ flag = get_gs_versions(ver);
+ printf("Versions: %d\n", ver[0]);
+
+ if (flag == FALSE) {
+ printf("get_gs_versions failed, need %d\n", ver[0]);
+ return 1;
+ }
+
+ for (i=1; i <= ver[0]; i++) {
+ printf(" %d\n", ver[i]);
+ if (get_gs_string(ver[i], "GS_DLL", buf, sizeof(buf)))
+ printf(" GS_DLL=%s\n", buf);
+ if (get_gs_string(ver[i], "GS_LIB", buf, sizeof(buf)))
+ printf(" GS_LIB=%s\n", buf);
+ }
+ return 0;
+}
+#endif
diff --git a/Build/source/libs/libgsw32/gvwgsver.h b/Build/source/libs/libgsw32/gvwgsver.h
new file mode 100644
index 00000000000..96289f7ff5b
--- /dev/null
+++ b/Build/source/libs/libgsw32/gvwgsver.h
@@ -0,0 +1,22 @@
+/* Copyright (C) 2001, Ghostgum Software Pty Ltd. All rights reserved.
+
+ This file is part of GSview.
+
+ This program is distributed with NO WARRANTY OF ANY KIND. No author
+ or distributor accepts any responsibility for the consequences of using it,
+ or for whether it serves any particular purpose or works at all, unless he
+ or she says so in writing. Refer to the GSview Free Public Licence
+ (the "Licence") for full details.
+
+ Every copy of GSview must include a copy of the Licence, normally in a
+ plain ASCII text file named LICENCE. The Licence grants you the right
+ to copy, modify and redistribute GSview, but only under certain conditions
+ described in the Licence. Among other things, the Licence requires that
+ the copyright notice and this notice be preserved on all copies.
+*/
+
+/* gvgsver.h */
+/* Functions for finding Ghostscript versions */
+BOOL get_gs_versions(int *pver);
+BOOL get_gs_string(int gs_revision, const char *name, char *ptr, int len);
+BOOL find_gs(char *gspath, int len, int minver, BOOL bDLL);
diff --git a/Build/source/libs/libgsw32/win32.mak b/Build/source/libs/libgsw32/win32.mak
new file mode 100644
index 00000000000..9b9178b5067
--- /dev/null
+++ b/Build/source/libs/libgsw32/win32.mak
@@ -0,0 +1,68 @@
+################################################################################
+#
+# Makefile : Gs Win32
+# Author : Fabrice Popineau <Fabrice.Popineau@supelec.fr>
+# Platform : Win32, Microsoft VC++ 6.0, depends upon fpTeX 0.5 sources
+# Time-stamp: <03/09/15 12:11:00 popineau>
+#
+################################################################################
+root_srcdir=..\..
+!ifdef DEVELOPMENT
+INCLUDE=$(INCLUDE);$(root_srcdir)\texk.development
+!else
+INCLUDE=$(INCLUDE);$(root_srcdir)\texk
+!endif
+
+!include <msvc/common.mak>
+
+USE_GNUW32 = 1
+USE_GSW32 = 1
+MAKE_GSW32 = 1
+USE_ADVAPI = 1
+USE_KPATHSEA = 1
+
+!include <msvc/common.mak>
+
+objects = \
+ $(objdir)\gvwgsver.obj \
+ $(objdir)\ghostscr.obj
+
+programs = $(gsw32dll)
+libfiles = $(gsw32lib)
+includefiles =
+
+DEFS = $(DEFS) -I..\..\gstools\ghostscript\src
+
+default: all
+
+all: $(objdir) $(gsw32)
+
+lib: $(objdir) $(gsw32lib)
+
+!ifdef GSW32_DLL
+DEFS= $(DEFS) -DMAKE_GSW32_DLL
+
+$(gsw32lib): $(objdir) $(objects)
+ $(archive) /DEF $(objects)
+
+$(gsw32dll): $(objects) $(objdir)\libgsw32.lib $(objdir)\libgsw32.res
+ $(link_dll) $(**) $(gsw32lib:.lib=.exp) $(conlibs)
+!else
+$(gsw32lib): $(objdir) $(objects)
+ $(archive) $(objects)
+!endif
+
+
+!include <msvc/config.mak>
+!include <msvc/install.mak>
+
+install:: install-exec install-lib install-include
+
+!include <msvc/clean.mak>
+!include <msvc/rdepend.mak>
+!include "./depend.mak"
+
+#
+# Local Variables:
+# mode: makefile
+# End: \ No newline at end of file