From: jongfoster Date: Mon, 4 Mar 2002 23:47:30 +0000 (+0000) Subject: - Rewritten, simpler command-line pre-parser X-Git-Tag: v_2_9_12~193 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=ec44326330e5207515e33af19707ef838a37ec30 - Rewritten, simpler command-line pre-parser - not using raise(SIGINT) any more --- diff --git a/win32.c b/win32.c index fc08d610..40722e73 100644 --- a/win32.c +++ b/win32.c @@ -1,4 +1,4 @@ -const char win32_rcs[] = "$Id: win32.c,v 1.3 2001/11/16 00:46:31 jongfoster Exp $"; +const char win32_rcs[] = "$Id: win32.c,v 1.4 2001/11/30 21:29:33 jongfoster Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/win32.c,v $ @@ -31,6 +31,9 @@ const char win32_rcs[] = "$Id: win32.c,v 1.3 2001/11/16 00:46:31 jongfoster Exp * * Revisions : * $Log: win32.c,v $ + * Revision 1.4 2001/11/30 21:29:33 jongfoster + * Fixing a warning + * * Revision 1.3 2001/11/16 00:46:31 jongfoster * Fixing compiler warnings * @@ -52,6 +55,7 @@ const char win32_rcs[] = "$Id: win32.c,v 1.3 2001/11/16 00:46:31 jongfoster Exp #include "project.h" #include "jcc.h" +#include "miscutil.h" /* Uncomment this if you want to build Win32 as a console app */ /* #define _WIN_CONSOLE */ @@ -111,56 +115,45 @@ static void __cdecl UserInterfaceThread(void *); *********************************************************************/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - int argc = 0; int i; int res; - const char **argv = NULL; - char *pszArgs = NULL; - char *pszLastTok; + int argc = 1; + const char *argv[3]; char szModule[MAX_PATH+1]; #ifndef _WIN_CONSOLE HANDLE hInitCompleteEvent = NULL; #endif - /* Split command line into arguments */ - pszArgs = (char *)malloc(strlen(lpCmdLine) + 1); - strcpy(pszArgs, lpCmdLine); - - GetModuleFileName(hInstance, szModule, MAX_PATH); + /* + * Cheat in parsing the command line. We only ever have at most one + * paramater, which may optionally be specified inside double quotes. + */ - /* Count number of spaces */ - argc = 1; - if (strlen(pszArgs) > 0) + if (lpCmdLine != NULL) { - pszLastTok = pszArgs; - do - { - argc++; - pszLastTok = strchr(pszLastTok+1, ' '); - } while (pszLastTok); + /* Make writable copy */ + lpCmdLine = strdup(lpCmdLine); } - - /* Allocate array of strings */ - argv = (const char **)malloc(sizeof(const char *) * argc); - - /* step through command line replacing spaces with zeros, initialise array */ - argv[0] = szModule; - i = 1; - pszLastTok = pszArgs; - do + if (lpCmdLine != NULL) { - argv[i] = pszLastTok; - pszLastTok = strchr(pszLastTok+1, ' '); - if (pszLastTok) + chomp(lpCmdLine); + i = strlen(lpCmdLine); + if ((i >= 2) && (lpCmdLine[0] == '\"') && (lpCmdLine[i - 1] == '\"')) { - while (*pszLastTok != '\0' && *pszLastTok == ' ') - { - *pszLastTok = '\0'; - pszLastTok++; - } + lpCmdLine[i - 1] = '\0'; + lpCmdLine++; } - i++; - } while (pszLastTok && *pszLastTok != '\0'); + if (lpCmdLine[0] == '\0') + { + lpCmdLine = NULL; + } + } + + GetModuleFileName(hInstance, szModule, MAX_PATH); + argv[0] = szModule; + argv[1] = lpCmdLine; + argv[2] = NULL; + argc = ((lpCmdLine != NULL) ? 2 : 1); #ifndef _WIN_CONSOLE /* Create a user-interface thread and wait for it to initialise */ @@ -178,10 +171,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine res = main( argc, argv ); #endif - /* Cleanup */ - free((void *)argv); - free(pszArgs); - return res; } @@ -267,7 +256,7 @@ static void __cdecl UserInterfaceThread(void *pData) TermLogWindow(); /* Time to die... */ - raise(SIGINT); + exit(0); }