From: erg Date: Thu, 3 May 2007 23:19:43 +0000 (+0000) Subject: Modify library code to work on Windows X-Git-Tag: LAST_LIBGRAPH~32^2~5589 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf10af395d085fbef8ad347eda97c2234349ed7b;p=graphviz Modify library code to work on Windows --- diff --git a/lib/expr/exeval.c b/lib/expr/exeval.c index 22f05260e..2d8072f26 100644 --- a/lib/expr/exeval.c +++ b/lib/expr/exeval.c @@ -29,6 +29,12 @@ #include "exop.h" #include #include +#ifdef WIN32 +#include +#define srand48 srand +#define drand48 rand +#endif + static Extype_t eval(Expr_t *, Exnode_t *, void *); diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index e033cba1e..07c776766 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -22,10 +22,25 @@ #ifdef ENABLE_LTDL #include -#include +#ifdef WIN32 +#include +typedef struct { + int gl_pathc; /* count of total paths so far */ + int gl_matchc; /* count of paths matching pattern */ + int gl_offs; /* reserved at beginning of gl_pathv */ + int gl_flags; /* returned flags */ + char **gl_pathv; /* list of paths matching pattern */ +} glob_t; +static void globfree (glob_t* pglob); +static int glob (char*, int, int (*errfunc)(const char *, int), glob_t*); +#else +#include +#include +#endif #include +#ifdef HAVE_UNISTD_H #include -#include +#endif #endif #include "memory.h" @@ -242,6 +257,12 @@ char * gvconfig_libdir(void) if (!libdir) { +#ifdef WIN32 + /* this code has to be modified to read value from + * registry or argg[0] -- +/lib etc method. FIX + */ + libdir="C:/unix/local/lib/Graphviz"; +#else /* this only works on linux, other systems will get GVLIBDIR only */ libdir = GVLIBDIR; f = fopen ("/proc/self/maps", "r"); @@ -268,6 +289,7 @@ char * gvconfig_libdir(void) } fclose (f); } +#endif } return libdir; } @@ -530,3 +552,68 @@ void gvconfig(GVC_t * gvc, boolean rescan) #endif gvtextlayout_select(gvc); /* choose best available textlayout plugin immediately */ } + +#ifdef ENABLE_LTDL +#ifdef WIN32 +#include +#define GLOB_NOSPACE 1 /* Ran out of memory. */ +#define GLOB_ABORTED 2 /* Read error. */ +#define GLOB_NOMATCH 3 /* No matches found. */ +#define GLOB_NOSORT 4 +#define DMKEY "Software\\Microsoft" //key to look for library dir + +/* Emulating windows glob */ + +/* glob: + * Assumes only GLOB_NOSORT flag given. That is, there is no offset, + * and no previous call to glob. + */ +char * gvconfig_libdir(void); + +static int +glob (char* pattern, int flags, int (*errfunc)(const char *, int), + glob_t *pglob) +{ + char* libdir; + WIN32_FIND_DATA wfd; + HANDLE h; + char** str=0; + int arrsize=0; + int cnt = 0; + h = FindFirstFile (pattern, &wfd); + if (h == INVALID_HANDLE_VALUE) return GLOB_NOMATCH; + libdir = gvconfig_libdir(); + do { + if (cnt >= arrsize-1) { + arrsize += 512; + if (str) str = (char**)realloc (str, arrsize*sizeof(char*)); + else str = (char**)malloc (arrsize*sizeof(char*)); + if (!str) return GLOB_NOSPACE; + } + str[cnt] = (char*)malloc (strlen(libdir)+1+strlen(wfd.cFileName)+1); + if (!str[cnt]) return GLOB_NOSPACE; + (str[cnt])[0]="/0"; + + strcpy(str[cnt],libdir); + strcat(str[cnt],"/"); + strcat(str[cnt],wfd.cFileName); + cnt++; + } while (FindNextFile (h, &wfd)); + str[cnt] = 0; + + pglob->gl_pathc = cnt; + pglob->gl_pathv = (char**)realloc(str, (cnt+1)*sizeof(char*)); + + return 0; +} + +static void +globfree (glob_t* pglob) +{ + int i; + for (i = 0; i < pglob->gl_pathc; i++) + free (pglob->gl_pathv[i]); + free (pglob->gl_pathv); +} +#endif +#endif diff --git a/lib/vmalloc/vmbest.c b/lib/vmalloc/vmbest.c index ad5028dc7..f345b6902 100644 --- a/lib/vmalloc/vmbest.c +++ b/lib/vmalloc/vmbest.c @@ -1147,10 +1147,6 @@ size_t align; return (Void_t *) data; } -#if defined(_WIN32) -#include -#endif /*_WIN32*/ - /* A discipline to get memory using sbrk() or VirtualAlloc on win32 */ #if __STD_C static Void_t *sbrkmem(Vmalloc_t * vm, Void_t * caddr, diff --git a/lib/vmalloc/vmhdr.h b/lib/vmalloc/vmhdr.h index ca36da0fc..790a9376e 100644 --- a/lib/vmalloc/vmhdr.h +++ b/lib/vmalloc/vmhdr.h @@ -23,6 +23,9 @@ extern "C" { #ifndef _BLD_vmalloc #define _BLD_vmalloc 1 #endif +#ifdef WIN32 +#include +#endif /* Common types, and macros for vmalloc functions. ** @@ -437,8 +440,13 @@ extern "C" { #if !_PACKAGE_ast extern size_t getpagesize _ARG_((void)); + +#ifdef WIN32 +typedef unsigned int ssize_t; +#else extern void abort _ARG_((void)); extern ssize_t write _ARG_((int, const void *, size_t)); +#endif #if !__STDC__ && !_hdr_stdlib extern size_t strlen _ARG_((const char *)); @@ -458,13 +466,17 @@ extern "C" { #endif /* for malloc.c */ +#ifndef WIN32 extern int creat _ARG_((const char *, int)); extern int close _ARG_((int)); +#endif extern int getpid _ARG_((void)); /* for vmexit.c */ +#ifndef WIN32 extern int onexit _ARG_((void (*)(void))); extern void _exit _ARG_((int)); +#endif extern void _cleanup _ARG_((void)); #endif /*!PACKAGE_ast */