--- 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 +#include +#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); }