X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=win32.c;h=40722e73c4f6ea17d0d43a0ca706692fa881d969;hp=2252dc1fe5322260e67169573c6006229391753e;hb=150268ba0b827da8e10bfea91a6484b824eede7c;hpb=c75584ebcc79f939fb4ec9c8f842cef6692640c7 diff --git a/win32.c b/win32.c index 2252dc1f..40722e73 100644 --- a/win32.c +++ b/win32.c @@ -1,7 +1,7 @@ -const char win32_rcs[] = "$Id: win32.c,v 1.1 2001/05/13 21:57:07 administrator Exp $"; +const char win32_rcs[] = "$Id: win32.c,v 1.4 2001/11/30 21:29:33 jongfoster Exp $"; /********************************************************************* * - * File : $Source: /home/administrator/cvs/ijb/win32.c,v $ + * File : $Source: /cvsroot/ijbswa/current/win32.c,v $ * * Purpose : Win32 User Interface initialization and message loop * @@ -31,6 +31,18 @@ const char win32_rcs[] = "$Id: win32.c,v 1.1 2001/05/13 21:57:07 administrator E * * 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 + * + * Revision 1.2 2001/07/29 19:32:00 jongfoster + * Renaming _main() [mingw32 only] to real_main(), for ANSI compliance. + * + * Revision 1.1.1.1 2001/05/15 13:59:08 oes + * Initial import of version 2.9.3 source tree + * * *********************************************************************/ @@ -43,6 +55,7 @@ const char win32_rcs[] = "$Id: win32.c,v 1.1 2001/05/13 21:57:07 administrator E #include "project.h" #include "jcc.h" +#include "miscutil.h" /* Uncomment this if you want to build Win32 as a console app */ /* #define _WIN_CONSOLE */ @@ -102,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; - 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); + /* + * Cheat in parsing the command line. We only ever have at most one + * paramater, which may optionally be specified inside double quotes. + */ - GetModuleFileName(hInstance, szModule, MAX_PATH); - - /* 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 = (char **)malloc(sizeof(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] == '\"')) + { + lpCmdLine[i - 1] = '\0'; + lpCmdLine++; + } + if (lpCmdLine[0] == '\0') { - while (*pszLastTok != '\0' && *pszLastTok == ' ') - { - *pszLastTok = '\0'; - pszLastTok++; - } + lpCmdLine = NULL; } - i++; - } while (pszLastTok && *pszLastTok != '\0'); + } + + 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 */ @@ -164,15 +166,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine #endif #ifdef __MINGW32__ - res = _main( argc, argv ); + res = real_main( argc, argv ); #else res = main( argc, argv ); #endif - /* Cleanup */ - free(argv); - free(pszArgs); - return res; } @@ -258,7 +256,7 @@ static void __cdecl UserInterfaceThread(void *pData) TermLogWindow(); /* Time to die... */ - raise(SIGINT); + exit(0); }