Missed patch. Attached.

On Fri, Apr 18, 2014 at 2:53 PM, Suresh Kumar <[email protected]>wrote:

> Hi
>
> On Thu, Apr 17, 2014 at 8:55 PM, Jason Hood <[email protected]> wrote:
>
>> On 17/04/2014 0:25, Suresh Kumar wrote:
>> > But when I try to use it for C# code (by setting GTAGSLABEL=ctags), I
>> > run into a problem where it is not able to find gtags parser library
>> > (I get something like "gtags: cannot open shared object
>> > '/usr/local/lib/gtags/exuberant-ctags.la'"). I am wondering if
>> > anybody using similar setup and can share some details.
>>
>> That's the default path for Unix; for Windows, I configure with
>> --prefix=c:/usr (where I've installed various GNU utilities).  However,
>> there's another problem, since gtags.conf doesn't escape the colon; not
>> sure where I should handle that - atm you'll have to DIY.  You also need
>> a patch, so it will compile and build a DLL (Windows needs the
>> -no-undefined
>> option, not sure how that affects Unix).  BTW, shouldn't terminate_ctags
>> free argv[1]?
>>
>>
> I did have the /usr copied at c:\usr. Since I was running msys from d:
> drive,
> it was prefixing d: into the path. Once I moved it into d:\usr things
> worked.
> I did some modifications to get it working, it looks similar to the patch
> you shared.
> Attached.
>
> Some changes:
>
>    - For some reason, _pgmptr was null. I had to use "GetModuleFileNameA()"
>      to make it work. (I am on Windows 7)
>
>    - Had trouble getting the "filter-terminator" arg passed to ctags
> properly. ctags was getting
>      "\n" escaped (\\n) due to which gtags was waiting infinitely.
> Temporarily I have modified
>      ctags to output \n along terminator string. Not sure who is doing the
> escape.
>
>    - I load ctags.exe from the same location as gtags.exe (something like
> what we do for
>      sort.exe)
>
> Any chance you can include ctags support in your next release?
>
>
>
>> > Also, can someone share their ./configure option for compiling global
>> > under Windows? --with-exuberant-ctags=/c/bin/ctags.exe
>>
>> No, that won't work, as you're building a native tool, so you need a
>> native path - "c:" instead of "/c" is what you want.  And as mentioned
>> above, you probably want something for --prefix (which is the only option
>> I use, but I build with stock MinGW).
>>
>> --
>> Jason.
>>
>>
>> _______________________________________________
>> Bug-global mailing list
>> [email protected]
>> https://lists.gnu.org/mailman/listinfo/bug-global
>>
>>
> Thanks,
> Suresh
>
--- D:\source\global-6.2-11.org\libutil\dbop.c
+++ D:\source\global-6.2-11\libutil\dbop.c
@@ -121,8 +121,10 @@
 	 * force using sort in the same directory as the program, to avoid
 	 * using the Windows one
 	 */
-	path = strrchr(_pgmptr, '\\');
-	sprintf(sort, "%.*s\\sort.exe", path - _pgmptr, _pgmptr);
+	char pBuf[MAX_PATH];
+	int bytes = GetModuleFileNameA(NULL, pBuf, MAX_PATH);
+	path = strrchr(pBuf, '\\');
+	sprintf(sort, "%.*s\\sort.exe", path - pBuf, pBuf);
 	if (!test("fx", sort)) {
 		warning(sortnotfound);
 		informed = 1;

--- D:\source\global-6.2-11.org\plugin-factory\exuberant-ctags.c	2014-03-12 12:49:34 +0530
+++ D:\source\global-6.2-11\plugin-factory\exuberant-ctags.c	2014-04-18 11:57:17 +0530
@@ -51,19 +51,6 @@
 #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;
@@ -89,6 +76,141 @@
 	strcpy(dst, src);
 }
 
+#if defined(_WIN32) && !defined(__CYGWIN__)
+typedef void* HANDLE;
+static HANDLE pid;
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <fcntl.h>
+#include "env.h"
+
+void
+set_env(const char *var, const char *val)
+{
+#ifdef HAVE_PUTENV
+	int len = strlen(var) + 1 + strlen(val) + 1;
+	char *str = malloc(len);
+	sprintf(str, "%s=%s", var, val);
+	putenv(str);
+	/* Don't free memory. putenv(3) require it. */
+#else
+	setenv(var, val, 1);
+#endif
+}
+
+static char argv[] = " --gtags -xu --filter --filter-terminator=###terminator###\\n --format=1";
+
+static void
+start_ctags(const struct parser_param *param)
+{
+	STARTUPINFO si;
+	PROCESS_INFORMATION pi;
+	const char* lc_all;
+	SECURITY_ATTRIBUTES sa;
+	HANDLE opipe[2], ipipe[2];
+	char *langmap;
+	int argvsize = 0;
+	char *argv_updated;
+	char* path;
+	char ctags[MAX_PATH];
+
+	if (strlen(EXUBERANT_CTAGS) == 0 || !strcmp(EXUBERANT_CTAGS, "no"))
+		param->die(ctagsnotfound);
+
+	langmap = malloc(sizeof(LANGMAP_OPTION) + strlen(param->langmap));
+	if (langmap == NULL)
+		param->die("short of memory.");
+	memcpy(langmap, LANGMAP_OPTION, sizeof(LANGMAP_OPTION) - 1);
+	copy_langmap_converting_cpp(langmap + sizeof(LANGMAP_OPTION) - 1, param->langmap);
+
+	/*
+	 * force using ctags.exe in the same directory as the program
+	 * to avoid looking for the ctags.exe at wrong locations
+	 * (i.e., not the one used during ./configure)
+	 */
+	char pBuf[MAX_PATH];
+	int bytes = GetModuleFileNameA(NULL, pBuf, MAX_PATH);
+	path = strrchr(pBuf, '\\');
+	sprintf(ctags, "%.*s\\ctags.exe ", path - pBuf, pBuf);
+	/* if (!test("fx", path)) { */
+	/* 	sprintf(ctags, "%s ", EXUBERANT_CTAGS); */
+	/* } */
+
+	argvsize = strlen(ctags) + strlen(argv) + strlen(langmap) + 2;
+	argv_updated = malloc(argvsize);
+	if (argv_updated == NULL)
+		param->die("short of memory.");
+	memset(argv_updated, 0, argvsize);
+	strcat(argv_updated, ctags);
+	strcat(argv_updated, langmap);
+	strcat(argv_updated, argv);
+
+	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;
+	lc_all = getenv("LC_ALL");
+	if (lc_all == NULL)
+		lc_all = "";
+	set_env("LC_ALL", "C");
+	CreateProcess(ctags, argv_updated, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
+	set_env("LC_ALL", lc_all);
+	CloseHandle(opipe[0]);
+	CloseHandle(ipipe[1]);
+	CloseHandle(pi.hThread);
+	pid = pi.hProcess;
+	ip = fdopen(_open_osfhandle((long)ipipe[0], _O_WRONLY), "r");
+	op = fdopen(_open_osfhandle((long)opipe[1], _O_RDONLY), "w");
+	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
+
+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)
 {
@@ -150,6 +272,8 @@
 		;
 }
 
+#endif
+
 static char *
 get_line(const struct parser_param *param)
 {
@@ -265,7 +389,7 @@
 		ctags_x = get_line(param);
 		if (ctags_x == NULL)
 			param->die("unexpected EOF.");
-		if (strcmp(ctags_x, TERMINATOR) == 0)
+		if (strstr(ctags_x, TERMINATOR))
 			break;
 		put_line(ctags_x, param);
 	}
_______________________________________________
Bug-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-global

Reply via email to