Find attached the patch to make the plug-in parser work with Windows.
It adds "-no-undefined" to the *_la_LDFLAGS options, necessary to
create the DLLs. It also changes "@{libdir}" to "@{prefix}/lib" and
does the opposite change in gtags.conf.in, changing "@prefix@/lib" to
"@libdir@". This is necessary so I can "configure --prefix=c:/usr
--libdir=/usr/lib", preventing the drive colon from interfering with
the config. I also ignore libtool, so the actual path in the config
doesn't matter (although it will be used if it's valid).
--
Jason.
diff -pur global-6.3/gtags.conf.in global-6-3/gtags.conf.in
--- global-6.3/gtags.conf.in 2014-06-09 10:46:06 +1000
+++ global-6-3/gtags.conf.in 2014-06-13 16:19:58 +1000
@@ -51,7 +51,7 @@ builtin-parser:\
user-custom|User custom plugin parser:\
:tc=common:\
:langmap=c\:.c.h:\
- :gtags_parser=c\:@prefix@/lib/gtags/user-custom.la:
+ :gtags_parser=c\:@libdir@/gtags/user-custom.la:
#
# Plug-in parser to use Exuberant Ctags.
#
@@ -96,45 +96,45 @@ exuberant-ctags|plugin-example|setting t
:langmap=VHDL\:.vhdl.vhd:\
:langmap=Vim\:.vim:\
:langmap=YACC\:.y:\
- :gtags_parser=Asm\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Asp\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Awk\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Basic\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=BETA\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=C\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=C++\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=C#\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Cobol\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=DosBatch\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Eiffel\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Erlang\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Flex\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Fortran\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=HTML\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Java\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=JavaScript\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Lisp\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Lua\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=MatLab\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=OCaml\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Pascal\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Perl\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=PHP\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Python\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=REXX\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Ruby\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Scheme\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Sh\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=SLang\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=SML\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=SQL\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Tcl\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Tex\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Vera\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Verilog\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=VHDL\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=Vim\:@prefix@/lib/gtags/exuberant-ctags.la:\
- :gtags_parser=YACC\:@prefix@/lib/gtags/exuberant-ctags.la:
+ :gtags_parser=Asm\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Asp\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Awk\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Basic\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=BETA\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=C\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=C++\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=C#\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Cobol\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=DosBatch\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Eiffel\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Erlang\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Flex\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Fortran\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=HTML\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Java\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=JavaScript\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Lisp\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Lua\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=MatLab\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=OCaml\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Pascal\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Perl\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=PHP\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Python\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=REXX\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Ruby\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Scheme\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Sh\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=SLang\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=SML\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=SQL\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Tcl\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Tex\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Vera\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Verilog\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=VHDL\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=Vim\:@libdir@/gtags/exuberant-ctags.la:\
+ :gtags_parser=YACC\:@libdir@/gtags/exuberant-ctags.la:
#
# Drupal configuration.
#
diff -pur global-6.3/libparser/parser.c global-6-3/libparser/parser.c
--- global-6.3/libparser/parser.c 2014-06-09 10:46:06 +1000
+++ global-6-3/libparser/parser.c 2014-06-13 16:19:58 +1000
@@ -31,6 +31,11 @@
#include <strings.h>
#endif
#include <ltdl.h>
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#undef SLIST_ENTRY
+#endif
#include "parser.h"
#include "internal.h"
@@ -171,6 +176,11 @@ load_plugin_parser(const char *pluginspe
if (p != NULL)
*p++ = '\0';
q = strchr(lt_dl_name, ':');
+#ifdef _WIN32
+ /* Assume a single-character name is a drive letter. */
+ if (q == lt_dl_name + 1)
+ q = strchr(q + 1, ':');
+#endif
if (q == NULL) {
parser_name = "parser";
} else {
@@ -179,11 +189,37 @@ load_plugin_parser(const char *pluginspe
die_with_code(2, "syntax error in pluginspec
'%s'.", pluginspec);
parser_name = q;
}
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ /* Bypass libtool and load the DLL directly, relative to us. */
+ pent->handle = (lt_dlhandle)LoadLibrary(lt_dl_name);
+ if (pent->handle == NULL) {
+ q = strrchr(lt_dl_name, '/');
+ if (q == NULL)
+ q = strrchr(lt_dl_name, '\\');
+ if (q != NULL)
+ lt_dl_name = q + 1;
+ q = strrchr(lt_dl_name, '.');
+ if (q != NULL && strcmp(q, ".la") == 0)
+ *q = '\0';
+ pent->handle = (lt_dlhandle)LoadLibrary(lt_dl_name);
+ if (pent->handle == NULL) {
+ char dll[MAX_PATH];
+ q = strrchr(_pgmptr, '\\');
+ _snprintf(dll, MAX_PATH,
"%.*s\\..\\lib\\gtags\\%s", q - _pgmptr, _pgmptr, lt_dl_name);
+ pent->handle = (lt_dlhandle)LoadLibrary(dll);
+ }
+ }
+ if (pent->handle == NULL)
+ die_with_code(2, "cannot open shared object '%s'.",
lt_dl_name);
+ pent->entry.lt_dl_name = lt_dl_name;
+ pent->entry.parser =
(PVOID)GetProcAddress((HINSTANCE)pent->handle, parser_name);
+#else
pent->handle = lt_dlopen(lt_dl_name);
if (pent->handle == NULL)
die_with_code(2, "cannot open shared object '%s'.",
lt_dl_name);
pent->entry.lt_dl_name = lt_dl_name;
pent->entry.parser = lt_dlsym(pent->handle, parser_name);
+#endif
if (pent->entry.parser == NULL)
die_with_code(2, "cannot find symbol '%s' in '%s'.",
parser_name, lt_dl_name);
pent->entry.parser_name = parser_name;
@@ -205,7 +241,11 @@ unload_plugin_parser(void)
return;
while (!STAILQ_EMPTY(&plugin_list)) {
pent = STAILQ_FIRST(&plugin_list);
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ FreeLibrary((HINSTANCE)pent->handle);
+#else
lt_dlclose(pent->handle);
+#endif
STAILQ_REMOVE_HEAD(&plugin_list, next);
free(pent);
}
diff -pur global-6.3/plugin-factory/exuberant-ctags.c
global-6-3/plugin-factory/exuberant-ctags.c
--- global-6.3/plugin-factory/exuberant-ctags.c 2014-06-09 10:46:06 +1000
+++ global-6-3/plugin-factory/exuberant-ctags.c 2014-06-13 16:19:58 +1000
@@ -22,9 +22,6 @@
#include <config.h>
#endif
#include <sys/types.h>
-#if !defined(_WIN32) || defined(__CYGWIN__)
-#include <sys/wait.h>
-#endif
#include <assert.h>
#include <ctype.h>
#include <errno.h>
@@ -51,24 +48,15 @@
#define LANGMAP_OPTION "--langmap="
#define INITIAL_BUFSIZE 1024
-static char *argv[] = {
- EXUBERANT_CTAGS,
- NULL,
-#ifdef USE_TYPE_STRING
- "--gtags",
-#endif
- "-xu",
- "--filter",
- "--filter-terminator=" TERMINATOR "\n",
- "--format=1",
- NULL
-};
-static pid_t pid;
static FILE *ip, *op;
static char *linebuf;
static size_t bufsize;
static char *ctagsnotfound = "Exuberant Ctags not found. Please see
./configure --help.";
+#ifdef __GNUC__
+static void terminate_ctags(void) __attribute__((destructor));
+#endif
+
static void
copy_langmap_converting_cpp(char *dst, const char *src)
{
@@ -89,6 +77,84 @@ copy_langmap_converting_cpp(char *dst, c
strcpy(dst, src);
}
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <fcntl.h>
+static HANDLE pid;
+static char argv[] = "ctags "
+ "--gtags "
+ "-xu --filter --filter-terminator=" TERMINATOR "\n "
+ "--format=1 " LANGMAP_OPTION;
+static void
+start_ctags(const struct parser_param *param)
+{
+ HANDLE opipe[2], ipipe[2];
+ SECURITY_ATTRIBUTES sa;
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ char* arg;
+
+ arg = malloc(sizeof(argv) + strlen(param->langmap));
+ if (arg == NULL)
+ param->die("short of memory.");
+ strcpy(arg, argv);
+ copy_langmap_converting_cpp(arg + sizeof(argv) - 1, param->langmap);
+
+ sa.nLength = sizeof(sa);
+ sa.bInheritHandle = TRUE;
+ sa.lpSecurityDescriptor = NULL;
+ if (!CreatePipe(&opipe[0], &opipe[1], &sa, 0) ||
+ !CreatePipe(&ipipe[0], &ipipe[1], &sa, 0))
+ param->die("CreatePipe failed.");
+ SetHandleInformation(opipe[1], HANDLE_FLAG_INHERIT, 0);
+ SetHandleInformation(ipipe[0], HANDLE_FLAG_INHERIT, 0);
+ ZeroMemory(&si, sizeof(si));
+ si.cb = sizeof(si);
+ si.hStdInput = opipe[0];
+ si.hStdOutput = ipipe[1];
+ si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
+ si.dwFlags = STARTF_USESTDHANDLES;
+ CreateProcess(NULL, arg, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
+ CloseHandle(opipe[0]);
+ CloseHandle(ipipe[1]);
+ CloseHandle(pi.hThread);
+ pid = pi.hProcess;
+ op = fdopen(_open_osfhandle((long)opipe[1], _O_WRONLY), "w");
+ ip = fdopen(_open_osfhandle((long)ipipe[0], _O_RDONLY), "r");
+ if (ip == NULL || op == NULL)
+ param->die("fdopen failed.");
+
+ bufsize = INITIAL_BUFSIZE;
+ linebuf = malloc(bufsize);
+ if (linebuf == NULL)
+ param->die("short of memory.");
+}
+static void
+terminate_ctags(void) {
+ if (op == NULL)
+ return;
+ free(linebuf);
+ fclose(op);
+ fclose(ip);
+ WaitForSingleObject(pid, INFINITE);
+ CloseHandle(pid);
+}
+#else
+#include <sys/wait.h>
+static pid_t pid;
+static char *argv[] = {
+ EXUBERANT_CTAGS,
+ NULL,
+#ifdef USE_TYPE_STRING
+ "--gtags",
+#endif
+ "-xu",
+ "--filter",
+ "--filter-terminator=" TERMINATOR "\n",
+ "--format=1",
+ NULL
+};
static void
start_ctags(const struct parser_param *param)
{
@@ -134,10 +200,6 @@ start_ctags(const struct parser_param *p
param->die("short of memory.");
}
-#ifdef __GNUC__
-static void terminate_ctags(void) __attribute__((destructor));
-#endif
-
static void
terminate_ctags(void)
{
@@ -149,6 +211,7 @@ terminate_ctags(void)
while (waitpid(pid, NULL, 0) < 0 && errno == EINTR)
;
}
+#endif
static char *
get_line(const struct parser_param *param)
diff -pur global-6.3/plugin-factory/Makefile.am
global-6-3/plugin-factory/Makefile.am
--- global-6.3/plugin-factory/Makefile.am 2014-06-09 10:46:06 +1000
+++ global-6-3/plugin-factory/Makefile.am 2014-06-13 16:19:57 +1000
@@ -10,15 +10,15 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
-plugindir = ${libdir}/gtags
+plugindir = ${prefix}/lib/gtags
plugin_LTLIBRARIES = exuberant-ctags.la user-custom.la
exuberant_ctags_la_SOURCES = exuberant-ctags.c
-exuberant_ctags_la_LDFLAGS = -module -avoid-version
+exuberant_ctags_la_LDFLAGS = -module -avoid-version -no-undefined
# skeleton
user_custom_la_SOURCES = user-custom.c
-user_custom_la_LDFLAGS = -module -avoid-version
+user_custom_la_LDFLAGS = -module -avoid-version -no-undefined
gtagsdir = ${datadir}/gtags
gtags_DATA = PLUGIN_HOWTO
diff -pur global-6.3/plugin-factory/Makefile.in
global-6-3/plugin-factory/Makefile.in
--- global-6.3/plugin-factory/Makefile.in 2014-06-09 10:46:16 +1000
+++ global-6-3/plugin-factory/Makefile.in 2014-06-13 16:19:58 +1000
@@ -359,14 +359,14 @@ top_srcdir = @top_srcdir@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
-plugindir = ${libdir}/gtags
+plugindir = ${prefix}/lib/gtags
plugin_LTLIBRARIES = exuberant-ctags.la user-custom.la
exuberant_ctags_la_SOURCES = exuberant-ctags.c
-exuberant_ctags_la_LDFLAGS = -module -avoid-version
+exuberant_ctags_la_LDFLAGS = -module -avoid-version -no-undefined
# skeleton
user_custom_la_SOURCES = user-custom.c
-user_custom_la_LDFLAGS = -module -avoid-version
+user_custom_la_LDFLAGS = -module -avoid-version -no-undefined
gtagsdir = ${datadir}/gtags
gtags_DATA = PLUGIN_HOWTO
EXTRA_DIST = $(gtags_DATA)
_______________________________________________
Bug-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-global