Find attached the patch for the DOS & Windows ports of
GLOBAL 5.9. The Windows version uses API functions to
emulate the fork/exec for sorting; DOS simply ignores it.
--
Jason.
diff -ur global-5.9-o/libutil/dbop.c global-5.9/libutil/dbop.c
--- global-5.9-o/libutil/dbop.c 2010-06-08 14:07:46 +1000
+++ global-5.9/libutil/dbop.c 2010-06-10 00:02:46 +1000
@@ -69,12 +69,21 @@
* than 'sort -k 1,1'. But we should use '-k 1,1' here not to rely on
* a specific command.
*/
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+/*
+ * sort is included with the binary distribution
+ */
+static char argv[] = "sort -k 1,1";
+#else
static char *argv[] = {
POSIX_SORT,
"-k",
"1,1",
NULL
};
+#endif
static void start_sort_process(DBOP *);
static void terminate_sort_process(DBOP *);
@@ -86,6 +95,59 @@
*/
static void
start_sort_process(DBOP *dbop) {
+#if defined(__DJGPP__)
+ return;
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE opipe[2], ipipe[2];
+ SECURITY_ATTRIBUTES sa;
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ const char* lc_all;
+ char sort[MAX_PATH];
+ char* path;
+ static int informed;
+
+ if (informed)
+ return;
+ /*
+ * 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);
+ if (!test("fx", sort)) {
+ warning("POSIX sort program not found. If available, the
program will be speed up.");
+ informed = 1;
+ return;
+ }
+
+ 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))
+ die("cannot create pipe.");
+ 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(sort, argv, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
+ set_env("LC_ALL", lc_all);
+ CloseHandle(opipe[0]);
+ CloseHandle(ipipe[1]);
+ CloseHandle(pi.hThread);
+ dbop->pid = pi.hProcess;
+ dbop->sortout = fdopen(_open_osfhandle((long)opipe[1], _O_WRONLY), "w");
+ dbop->sortin = fdopen(_open_osfhandle((long)ipipe[0], _O_RDONLY), "r");
+#else
int opipe[2], ipipe[2];
if (!test("fx", POSIX_SORT)) {
@@ -131,6 +193,7 @@
fcntl(opipe[1], F_SETFD, FD_CLOEXEC);
dbop->sortout = fdopen(opipe[1], "w");
dbop->sortin = fdopen(ipipe[0], "r");
+#endif
if (dbop->sortout == NULL || dbop->sortin == NULL)
die("fdopen failed.");
}
@@ -141,8 +204,15 @@
*/
static void
terminate_sort_process(DBOP *dbop) {
+#if defined(__DJGPP__)
+ return;
+#elif defined(_WIN32) && !defined(__CYGWIN__)
+ WaitForSingleObject(dbop->pid, INFINITE);
+ CloseHandle(dbop->pid);
+#else
while (waitpid(dbop->pid, NULL, 0) < 0 && errno == EINTR)
;
+#endif
}
/*
diff -ur global-5.9-o/libutil/dbop.h global-5.9/libutil/dbop.h
--- global-5.9-o/libutil/dbop.h 2010-06-08 14:07:46 +1000
+++ global-5.9/libutil/dbop.h 2010-06-09 15:56:10 +1000
@@ -30,6 +30,10 @@
#include "regex.h"
#include "strbuf.h"
+#if defined(_WIN32) && !defined(__CYGWIN__)
+typedef void* HANDLE;
+#endif
+
#define DBOP_PAGESIZE 8192
#define VERSIONKEY " __.VERSION"
@@ -61,7 +65,11 @@
*/
FILE *sortout; /* write to sort command */
FILE *sortin; /* read from sort command */
+#if defined(_WIN32) && !defined(__CYGWIN__)
+ HANDLE pid;
+#else
int pid; /* sort process id */
+#endif
} DBOP;
/*
_______________________________________________
Bug-global mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-global