bug-global
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GLOBAL 4.8, djgpp & MinGW


From: Jason Hood
Subject: GLOBAL 4.8, djgpp & MinGW
Date: Sat, 11 Sep 2004 02:28:21 +1000

I finally got around to updating the latest GLOBAL version to djgpp.
While I was there, I also got it working with MinGW (and MSYS). In
addition to fixing earlier djgpp bugs and just getting things working
in MinGW, the attached patch does the following:

gozilla:
* removed the Win32 version of sendbrowser, using a direct call to
  ShellExecute (since the browser probably isn't on the path, and
  -remote doesn't seem to work on Windows).

htags:
* try TMP if TMPDIR doesn't exist.

Unfortunately, I haven't thoroughly tested it, but as I'm going away
for a week, I wanted to get it out there.

Jason.
diff -ur global-4.8.orig/gozilla/gozilla.c global-4.8/gozilla/gozilla.c
--- global-4.8.orig/gozilla/gozilla.c   Thu Aug 26 12:45:12 2004
+++ global-4.8/gozilla/gozilla.c        Fri Sep 10 21:54:52 2004
@@ -25,7 +25,9 @@
 #include <string.h>
 #include <ctype.h>
 #ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+#include <shellapi.h>
 #endif
 
 #include "global.h"
@@ -47,12 +49,9 @@
 int isprotocol(char *);
 int issource(char *);
 int convertpath(char *, char *, char *, STRBUF *);
-#ifndef __DJGPP__
+#if !defined(_WIN32) && !defined(__DJGPP__)
 void sendbrowser(char *, char *);
 #endif
-#ifndef _WIN32
-int sendcommand(char *);
-#endif
 
 #ifndef isblank
 #define isblank(c)     ((c) == ' ' || (c) == '\t')
@@ -240,6 +239,10 @@
                        fprintf(stdout, "using browser '%s'.\n", browser);
                exit(0);
        }
+#ifdef _WIN32
+       if (ShellExecute(NULL, NULL, browser, strbuf_value(URL), NULL, 
SW_SHOWNORMAL) <= (HINSTANCE)32)
+               die("Cannot load %s (error = 0x%04x).", browser, 
GetLastError());
+#else
 #ifndef __DJGPP__
        /*
         * send a command to browser.
@@ -264,7 +267,14 @@
                 * assume a Windows browser if it's not on the path.
                 */
                if (!(path = usable(browser)))
-                       snprintf(com, sizeof(com), "start %s \"%s\"", browser, 
strbuf_value(URL));
+               {
+                       /*
+                        * START is an internal command in XP, external in 9X.
+                        */
+                       if (!(path = usable("start")))
+                               path = "cmd /c start";
+                       snprintf(com, sizeof(com), "%s %s \"%s\"", path, 
browser, strbuf_value(URL));
+               }
                else
                        snprintf(com, sizeof(com), "%s \"%s\"", path, 
strbuf_value(URL));
 #else
@@ -272,6 +282,7 @@
 #endif /* !__DJGPP__ */
                system(com);
        }
+#endif /* _WIN32 */
        exit(0);
 }
 
@@ -557,7 +568,7 @@
        }
        return -1;
 }
-#ifndef __DJGPP__
+#if !defined(_WIN32) && !defined(__DJGPP__)
 /*
  * sendbrowser: send message to mozilla.
  *
@@ -565,28 +576,6 @@
  *     i)      url     URL
  *
  */
-#ifdef _WIN32
-void
-sendbrowser(browser, url)
-       char *browser;
-       char *url;
-{
-       char com[1024], *path;
-       STARTUPINFO si;
-       PROCESS_INFORMATION pi;
-
-       if (!(path = usable(browser)))
-               die("%s not found in your path.", browser);
-       ZeroMemory(&si, sizeof(STARTUPINFO));
-       ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
-       si.cb = sizeof(STARTUPINFO);
-       si.dwFlags = STARTF_USESHOWWINDOW;
-       si.wShowWindow = SW_SHOWNORMAL;
-       snprintf(com, sizeof(com), "%s -remote \"openURL(%s)\"", browser, url);
-       if (!CreateProcess(path, com, NULL, NULL, FALSE, 0, NULL, NULL, &si, 
&pi))
-               die("Cannot load %s.(error = 0x%04x)\n", browser, 
GetLastError());
-}
-#else
 void
 sendbrowser(browser, url)
        char *browser;
@@ -606,5 +595,4 @@
                die("cannot load %s (execlp).", browser);
        }
 }
-#endif /* !_WIN32 */
-#endif /* !__DJGPP__ */
+#endif /* !_WIN32 and !__DJGPP__ */
diff -ur global-4.8.orig/htags/dupindex.c global-4.8/htags/dupindex.c
--- global-4.8.orig/htags/dupindex.c    Thu Aug 26 12:45:12 2004
+++ global-4.8/htags/dupindex.c Fri Sep 10 23:04:22 2004
@@ -110,7 +110,7 @@
                        continue;
                prev[0] = 0;
                first_line[0] = 0;
-               snprintf(command, sizeof(command), "global -xn%s%s '.*' | gtags 
--sort", dynamic ? "n" : "", option);
+               snprintf(command, sizeof(command), "global -xn%s%s \".*\" | 
gtags --sort", dynamic ? "n" : "", option);
                if ((ip = popen(command, "r")) == NULL)
                        die("cannot execute command '%s'.", command);
                while ((_ = strbuf_fgets(sb, ip, STRBUF_NOCRLF)) != NULL) {
diff -ur global-4.8.orig/htags/htags.c global-4.8/htags/htags.c
--- global-4.8.orig/htags/htags.c       Thu Aug 26 12:45:12 2004
+++ global-4.8/htags/htags.c    Fri Sep 10 22:48:34 2004
@@ -50,6 +50,11 @@
 int makedefineindex(char *, int, STRBUF *);
 int makefileindex(char *, STRBUF *);
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define mkdir(path,mode) mkdir(path)
+#define link(one,two) (-1)
+#endif
+
 /*
  * Global data.
  */
@@ -867,7 +872,9 @@
        /*
         * Temporary directory.
         */
-       if ((p = getenv("TMPDIR")) != NULL && test("d", p))
+       if ((p = getenv("TMPDIR")) == NULL)
+               p = getenv("TMP");
+       if (p != NULL && test("d", p))
                tmpdir = p;
 }
 /*
diff -ur global-4.8.orig/htags/src2html.c global-4.8/htags/src2html.c
--- global-4.8.orig/htags/src2html.c    Thu Aug 26 12:45:12 2004
+++ global-4.8/htags/src2html.c Fri Sep 10 19:37:22 2004
@@ -107,7 +107,11 @@
  * reverse of atoi
  */
 static char *
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
+my_itoa(n)
+#else
 itoa(n)
+#endif
        int n;
 {
        static char buf[32];
@@ -115,6 +119,9 @@
        snprintf(buf, sizeof(buf), "%d", n);
        return buf;
 }
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
+#define itoa my_itoa
+#endif
 void
 echoc(int c)
 {
diff -ur global-4.8.orig/libdb/bt_open.c global-4.8/libdb/bt_open.c
--- global-4.8.orig/libdb/bt_open.c     Thu Aug 26 12:45:12 2004
+++ global-4.8/libdb/bt_open.c  Fri Sep 10 19:17:06 2004
@@ -70,6 +70,10 @@
 #include <unistd.h>
 #endif
 
+#if (defined(_WIN32) && !defined(__CYGWIN__))
+#define mkstemp(p) open(_mktemp(p), _O_CREAT | _O_SHORT_LIVED | _O_EXCL)
+#endif
+
 #include "db.h"
 #include "btree.h"
 
diff -ur global-4.8.orig/libdb/compat.h global-4.8/libdb/compat.h
--- global-4.8.orig/libdb/compat.h      Thu Aug 26 12:45:14 2004
+++ global-4.8/libdb/compat.h   Fri Sep 10 18:22:42 2004
@@ -36,12 +36,12 @@
 
 #include <sys/types.h>
 
-#ifdef __DJGPP__
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
 typedef unsigned char  u_char;
 typedef unsigned int   u_int;
 typedef unsigned long  u_long;
 typedef unsigned short u_short;
-#endif /* __DJGPP__ */
+#endif /* _WIN32 || __DJGPP__ */
 
 #ifdef NO_POSIX_SIGNALS
 #define        sigemptyset(set)        (*(set) = 0)
diff -ur global-4.8.orig/libdb/mpool.c global-4.8/libdb/mpool.c
--- global-4.8.orig/libdb/mpool.c       Thu Aug 26 12:45:14 2004
+++ global-4.8/libdb/mpool.c    Fri Sep 10 19:17:20 2004
@@ -54,6 +54,10 @@
 #include <unistd.h>
 #endif
 
+#if (defined(_WIN32) && !defined(__CYGWIN__))
+#define fsync _commit
+#endif
+
 #include "queue.h"
 #include "db.h"
 
diff -ur global-4.8.orig/libutil/find.c global-4.8/libutil/find.c
--- global-4.8.orig/libutil/find.c      Thu Aug 26 12:45:14 2004
+++ global-4.8/libutil/find.c   Fri Sep 10 20:21:34 2004
@@ -572,6 +572,9 @@
 char   *
 find_read(void)
 {
+#if defined(_WIN32) && !defined(__CYGWIN__)
+       static int back = 1;
+#endif
        static char val[MAXPATHLEN+2];
        char *path = &val[1];
        char *p;
@@ -585,6 +588,20 @@
                if (*p != '\n')
                        die("output of find(1) is wrong (find_read).");
                *p = 0;
+#if defined(_WIN32) && !defined(__CYGWIN__)
+               /*
+                * depending on the port of find used, backslashes may
+                * be used - translate to slashes.
+                */
+               if (back)
+               {
+                       for (p = path; *p; ++p)
+                               if (*p == '\\')
+                                       *p = '/', back = 2;
+                       if (back == 1)
+                               back = 0;
+               }
+#endif
                if (skipthisfile(path))
                        continue;
                if (regexec(suff, path, 0, 0, 0) != 0) {
diff -ur global-4.8.orig/libutil/is_unixy.c global-4.8/libutil/is_unixy.c
--- global-4.8.orig/libutil/is_unixy.c  Thu Aug 26 12:45:14 2004
+++ global-4.8/libutil/is_unixy.c       Fri Sep 10 20:11:28 2004
@@ -23,10 +23,12 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
-#ifdef __DJGPP__
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
 #include <stdlib.h>
+#ifdef __DJGPP__
 #include <sys/system.h>
 #endif
+#endif
 
 #include "is_unixy.h"
 
@@ -38,13 +40,17 @@
 int
 is_unixy(void)
 {
-#ifdef __DJGPP__
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
        static int unix_shell = -1;
 
        if (unix_shell == -1) {
                char *s = getenv("SHELL");
+#ifdef __DJGPP__
                /* Assume if SHELL isn't defined, COMSPEC is DOS. */
                unix_shell = (s == NULL) ? 0 : _is_unixy_shell(s);
+#else
+               unix_shell = (s != 0);
+#endif
        }
        return unix_shell;
 #else
diff -ur global-4.8.orig/libutil/path.c global-4.8/libutil/path.c
--- global-4.8.orig/libutil/path.c      Thu Aug 26 12:45:14 2004
+++ global-4.8/libutil/path.c   Fri Sep 10 19:19:42 2004
@@ -32,7 +32,6 @@
 #endif
 
 #ifdef __DJGPP__
-#include <dos.h>                       /* for intdos() */
 #include <fcntl.h>                     /* for _USE_LFN */
 #endif
 
@@ -77,34 +76,47 @@
        char *p;
 
        if (_USE_LFN) {
-               /* Ensure we're using a complete long name, not a mixture
+               char name[260], sfn[13];
+               char *base;
+
+               /*
+                * Ensure we're using a complete long name, not a mixture
                 * of long and short.
                 */
-               union REGS regs;
-               regs.x.ax = 0x7160;
-               regs.x.cx = 0x8002;
-               regs.x.si = (unsigned)path;
-               regs.x.di = (unsigned)path;
-               intdos( &regs, &regs );
+               _truename(path, path);
+               /*
+                * _truename will successfully convert the path of a non-
+                * existant file, but it's probably still a mixture of long and
+                * short components - convert the path separately.
+                */
+               if (access(path, F_OK) != 0) {
+                       base = basename(path);
+                       strcpy(name, base);
+                       *base = '\0';
+                       _truename(path, path);
+                       strcat(path, name);
+               }
                /*
-                * A non-existant file returns error code 3; get the path,
-                * strip the filename, LFN the path and put the filename back.
+                * Convert the case of 8.3 names, as other djgpp functions do.
                 */
-               if (regs.x.cflag && regs.h.al == 3) {
-                       char filename[261];
-                       regs.x.ax = 0x7160;
-                       regs.h.cl = 0;
-                       intdos(&regs, &regs);
-                       p = basename(path);
-                       strlimcpy(filename, p, sizeof(filename));
-                       *p = 0;
-                       regs.x.ax = 0x7160;
-                       regs.h.cl = 2;
-                       intdos( &regs, &regs );
-                       strcat(path, filename);
+               if (!_preserve_fncase()) {
+                       for (p = path+3, base = p-1; *base; p++) {
+                               if (*p == '\\' || *p == '\0') {
+                                       memcpy(name, base+1, p-base-1);
+                                       name[p-base-1] = '\0';
+                                       if (!strcmp(_lfn_gen_short_fname(name, 
sfn), name)) {
+                                               while (++base < p)
+                                                       if (*base >= 'A' && 
*base <= 'Z')
+                                                               *base += 'a' - 
'A';
+                                       } else
+                                          base = p;
+                               }
+                       }
                }
        }
-       /* Lowercase the drive letter and convert to slashes. */
+       /*
+        * Lowercase the drive letter and convert to slashes.
+        */
        path[0] = tolower(path[0]);
        for (p = path+2; *p; ++p)
                if (*p == '\\')
@@ -137,7 +149,7 @@
        return path;
 }
 
-#ifdef __DJGPP__
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
 /*
  * realpath: get the complete path
  */
@@ -146,6 +158,7 @@
        char *in_path;
        char *out_path;
 {
+#ifdef __DJGPP__
        /*
         * I don't use _fixpath or _truename in LFN because neither guarantee
         * a complete long name. This is mainly DOS's fault, since the cwd can
@@ -156,6 +169,10 @@
                canonpath(out_path);
        } else
                _fixpath(in_path, out_path);
+#else
+       _fullpath(out_path, in_path, MAXPATHLEN);
+       canonpath(out_path);
+#endif
        return out_path;
 }
 #endif
diff -ur global-4.8.orig/libutil/path.h global-4.8/libutil/path.h
--- global-4.8.orig/libutil/path.h      Thu Aug 26 12:45:14 2004
+++ global-4.8/libutil/path.h   Fri Sep 10 18:29:30 2004
@@ -39,7 +39,7 @@
 
 int isabspath(char *);
 char *canonpath(char *);
-#ifdef __DJGPP__
+#if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
 char *realpath(char *, char *);
 #endif
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]