On 18/03/2026 17:48, Shigio YAMAGUCHI wrote:
> [libutil/getdbpath.c]
> 133             setupvariables(verbose);                <===

Why is this not already present?  gtagsexist has it, why not this?
Even so, it ends up being ignored in global, since it gets called
with 0 (before options are processed).

> [global/global.c]
> 
> 954                     putenv("GTAGSLIBPATH=");        <===

Not sure why that's necessary, my old MinGW has unsetenv.

>> having to use GNU Global on windows on my work computer and I noticed that 
>> GTAGSOBJDIRPREFIX does not work for windows.
I took a slightly different approach, converting back2slash from
global.c into a function in path.c (and moving STRCMP to path.h
as PATHCMP).  I duplicate the variables and convert them once (and
use "c:/usr/obj" as default).  Rather than stripping a colon I
assume the drive is present and generate a new path without it
(D:/path -> /D/path).

-- 
Jason.
diff -ur global-6.6-14/global/global.c global-6.6.14/global/global.c
--- global-6.6-14/global/global.c       2024-12-11 16:44:34 +1000
+++ global-6.6.14/global/global.c       2026-03-19 17:21:20 +1000
@@ -55,22 +55,6 @@
 #include "convert.h"
 
 /*
- * ensure GTAGSLIBPATH compares correctly
- */
-#if defined(_WIN32) || defined(__DJGPP__)
-#define STRCMP stricmp
-#define back2slash(sb) do {            \
-       char *p = strbuf_value(sb);     \
-       for (; *p; p++)                 \
-               if (*p == '\\')         \
-                       *p = '/';       \
-} while (0)
-#else
-#define STRCMP strcmp
-#define back2slash(sb)
-#endif
-
-/*
  * enable [set] globbing, if available
  */
 #ifdef __CRT_GLOB_BRACKET_GROUPS__
@@ -367,13 +351,13 @@
 
                sb = strbuf_open(0);
                strbuf_puts(sb, getenv("GTAGSLIBPATH"));
-               back2slash(sb);
+               back2slash(strbuf_value(sb));
                for (libdir = strbuf_value(sb); db != GTAGS && libdir; libdir = 
nextp) {
                        if ((nextp = locatestring(libdir, PATHSEP, 
MATCH_FIRST)) != NULL)
                                *nextp++ = 0;
                        if (!gtagsexist(libdir, libdbpath, sizeof(libdbpath), 
0))
                                continue;
-                       if (!STRCMP(dbpath, libdbpath))
+                       if (!PATHCMP(dbpath, libdbpath))
                                continue;
                        gtop = gtags_open(libdbpath, root, GTAGS, GTAGS_READ, 
0);
                        if ((gtp = gtags_first(gtop, tag, flags)) != NULL)
@@ -1068,7 +1053,7 @@
                char *libdir, *nextp = NULL;
 
                strbuf_puts(sb, getenv("GTAGSLIBPATH"));
-               back2slash(sb);
+               back2slash(strbuf_value(sb));
                /*
                 * search for each tree in the library path.
                 */
@@ -1077,7 +1062,7 @@
                                *nextp++ = 0;
                        if (!gtagsexist(libdir, libdbpath, sizeof(libdbpath), 
0))
                                continue;
-                       if (!STRCMP(dbpath, libdbpath))
+                       if (!PATHCMP(dbpath, libdbpath))
                                continue;
                        if (!test("f", makepath(libdbpath, dbname(db), NULL)))
                                continue;
@@ -1971,7 +1956,7 @@
                char *libdir, *nextp = NULL;
 
                strbuf_puts(sb, getenv("GTAGSLIBPATH"));
-               back2slash(sb);
+               back2slash(strbuf_value(sb));
                /*
                 * search for each tree in the library path.
                 */
@@ -1980,7 +1965,7 @@
                                *nextp++ = 0;
                        if (!gtagsexist(libdir, libdbpath, sizeof(libdbpath), 
0))
                                continue;
-                       if (!STRCMP(dbpath, libdbpath))
+                       if (!PATHCMP(dbpath, libdbpath))
                                continue;
                        if (!test("f", makepath(libdbpath, dbname(db), NULL)))
                                continue;
diff -ur global-6.6-14/libutil/getdbpath.c global-6.6.14/libutil/getdbpath.c
--- global-6.6-14/libutil/getdbpath.c   2024-12-11 16:44:34 +1000
+++ global-6.6.14/libutil/getdbpath.c   2026-03-19 17:43:16 +1000
@@ -51,6 +51,7 @@
  */
 #if defined(_WIN32) || defined(__DJGPP__)
 #define ROOT 2
+#include "checkalloc.h"
 #else
 #define ROOT 0
 #endif
@@ -70,15 +71,27 @@
        if ((p = getenv("GTAGSOBJDIRPREFIX")) != NULL ||
            (p = getenv("MAKEOBJDIRPREFIX")) != NULL)
        {
+#if defined(_WIN32) || defined(__DJGPP__)
+               p = check_strdup(p);
+               back2slash((char *)p);
+#endif
                gtagsobjdirprefix = p;
                if (verbose)
                        fprintf(stderr, "GTAGSOBJDIRPREFIX is set to '%s'.\n", 
p);
        } else {
+#if defined(_WIN32) || defined(__DJGPP__)
+               gtagsobjdirprefix = "c:/usr/obj";
+#else
                gtagsobjdirprefix = "/usr/obj";
+#endif
        }
        if ((p = getenv("GTAGSOBJDIR")) != NULL ||
            (p = getenv("MAKEOBJDIR")) != NULL)
        {
+#if defined(_WIN32) || defined(__DJGPP__)
+               p = check_strdup(p);
+               back2slash((char *)p);
+#endif
                gtagsobjdir = p;
                if (verbose)
                        fprintf(stderr, "GTAGSOBJDIR is set to '%s'.\n", p);
@@ -97,12 +110,15 @@
 getobjdir(const char *candidate, int verbose)
 {
        static char path[MAXPATHLEN];
+#if defined(_WIN32) || defined(__DJGPP__)
+       char driveless[MAXPATHLEN];
+#endif
 
        /*
         * setup gtagsobjdir and gtagsobjdirprefix (only first time).
         */
        if (gtagsobjdir == NULL)
-               setupvariables(0);
+               setupvariables(verbose);
        snprintf(path, sizeof(path), "%s/%s", candidate, gtagsobjdir);
        if (test("d", path)) {
                if (!test("drw", path))
@@ -111,7 +127,13 @@
                        fprintf(stderr, "Using objdir '%s'.\n", path);
                return path;
        }
-#if !defined(_WIN32) && !defined(__DJGPP__)
+#if defined(_WIN32) || defined(__DJGPP__)
+       /*
+        * D:/path -> /D/path
+        */
+       snprintf(driveless, sizeof(driveless), "/%c%s", *candidate, candidate + 
2);
+       candidate = driveless;
+#endif
        if (test("d", gtagsobjdirprefix)) {
                snprintf(path, sizeof(path), "%s%s", gtagsobjdirprefix, 
candidate);
                if (test("d", path)) {
@@ -127,7 +149,6 @@
                        fprintf(stderr, "Using objdir '%s'.\n", path);
                return path;
        }
-#endif
        return NULL;
 }
 /**
@@ -148,6 +169,9 @@
 {
        char path[MAXPATHLEN];
        const char *candidate_without_slash;
+#if defined(_WIN32) || defined(__DJGPP__)
+       char driveless[MAXPATHLEN];
+#endif
 
        /*
         * setup gtagsobjdir and gtagsobjdirprefix (only first time).
@@ -178,7 +202,10 @@
                snprintf(dbpath, size, "%s/%s", candidate_without_slash, 
gtagsobjdir);
                return 1;
        }
-#if !defined(_WIN32) && !defined(__DJGPP__)
+#if defined(_WIN32) || defined(__DJGPP__)
+       snprintf(driveless, sizeof(driveless), "/%c%s", *candidate, candidate + 
2);
+       candidate_without_slash = driveless;
+#endif
        snprintf(path, sizeof(path),
                "%s%s/%s", gtagsobjdirprefix, candidate_without_slash, 
dbname(GTAGS));
        if (verbose)
@@ -189,7 +216,6 @@
                snprintf(dbpath, size, "%s%s", gtagsobjdirprefix, 
candidate_without_slash);
                return 1;
        }
-#endif
        return 0;
 }
 static char dbpath[MAXPATHLEN];
@@ -356,7 +382,7 @@
 int
 in_the_project(const char *path)
 {
-       if (!strcmp(path, root) || locatestring(path, root_with_slash, 
MATCH_AT_FIRST))
+       if (!PATHCMP(path, root) || locatestring(path, root_with_slash, 
MATCH_AT_FIRST))
                return 1;
        return 0;
 }
diff -ur global-6.6-14/libutil/path.c global-6.6.14/libutil/path.c
--- global-6.6-14/libutil/path.c        2024-12-11 16:44:34 +1000
+++ global-6.6.14/libutil/path.c        2026-03-19 17:19:12 +1000
@@ -195,6 +195,18 @@
 }
 #endif
 
+#if defined(_WIN32) || defined(__DJGPP__)
+char *
+back2slash(char *path)
+{
+       char *p;
+       for (p = path; *p; p++)
+               if (*p == '\\')
+                       *p = '/';
+       return path;
+}
+#endif
+
 #define SEP '/'
 
 /**
diff -ur global-6.6-14/libutil/path.h global-6.6.14/libutil/path.h
--- global-6.6-14/libutil/path.h        2024-12-11 16:44:34 +1000
+++ global-6.6.14/libutil/path.h        2026-03-19 17:20:05 +1000
@@ -43,6 +43,13 @@
 #if (defined(_WIN32) && !defined(__CYGWIN__)) || defined(__DJGPP__)
 char *realpath(const char *, char *);
 #endif
+#if defined(_WIN32) || defined(__DJGPP__)
+char *back2slash(char *);
+#define PATHCMP stricmp
+#else
+#define back2slash(path) path
+#define PATHCMP strcmp
+#endif
 int makedirectories(const char *, const char *, int);
 const char *trimpath(const char *);
 char *vgetcwd(char *, size_t);

Reply via email to