X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=win32.c;h=201d8da54ae527c7c15622e37fc7cd229c4087aa;hp=2252dc1fe5322260e67169573c6006229391753e;hb=36bed44da8971c4b75627ec86cc41163bfde81ae;hpb=c75584ebcc79f939fb4ec9c8f842cef6692640c7 diff --git a/win32.c b/win32.c index 2252dc1f..201d8da5 100644 --- a/win32.c +++ b/win32.c @@ -1,17 +1,16 @@ -const char win32_rcs[] = "$Id: win32.c,v 1.1 2001/05/13 21:57:07 administrator 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 * - * Copyright : Written by and Copyright (C) 2001 the SourceForge - * IJBSWA team. http://ijbswa.sourceforge.net + * Copyright : Written by and Copyright (C) 2001-2002 members of + * the Privoxy team. https://www.privoxy.org/ * * Written by and Copyright (C) 1999 Adam Lock * * - * This program is free software; you can redistribute it + * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software * Foundation; either version 2 of the License, or (at @@ -29,11 +28,8 @@ const char win32_rcs[] = "$Id: win32.c,v 1.1 2001/05/13 21:57:07 administrator E * or write to the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * Revisions : - * $Log: win32.c,v $ - * *********************************************************************/ - + #include "config.h" @@ -43,44 +39,66 @@ 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 */ +#ifndef STRICT +#define STRICT +#endif #include #include #include -#include "win32.h" +#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) +/* Visual C++ Heap debugging */ +#include +#endif /* defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) */ -const char win32_h_rcs[] = WIN32_H_VERSION; +#include "win32.h" +/** + * A short introductory text about Privoxy. Used for the "About" box + * or the console startup message. + */ const char win32_blurb[] = -"Internet Junkbuster Proxy(TM) Version " VERSION " for Windows is Copyright (C) 1997-8\n" -"by Junkbusters Corp. This is free software; it may be used and copied under\n" -"the GNU General Public License: http://www.gnu.org/copyleft/gpl.html .\n" -"This program comes with ABSOLUTELY NO WARRANTY OF ANY KIND.\n" -"\n" -"For information about how to to configure the proxy and your browser, see\n" -" " REDIRECT_URL "win\n" -"\n" -"The Internet Junkbuster Proxy(TM) is running and ready to serve!\n" -""; +"Privoxy version " VERSION " for Windows\n" +"Copyright (C) 2000-2019 the Privoxy Team (" HOME_PAGE_URL ")\n" +"Based on the Internet Junkbuster by Junkbusters Corp.\n" +"This is free software; it may be used and copied under the\n" +"GNU General Public License, version 2: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\n" +"This program comes with ABSOLUTELY NO WARRANTY OF ANY KIND.\n"; #ifdef _WIN_CONSOLE +/** + * Hide the console. If set, the program will disconnect from the + * console and run in the background. This allows the command-prompt + * window to close. + */ int hideConsole = 0; -#else +#else /* ndef _WIN_CONSOLE */ + + +/** + * The application instance handle. + */ HINSTANCE g_hInstance; + + +/** + * The command to show the window that was specified at startup. + */ int g_nCmdShow; static void __cdecl UserInterfaceThread(void *); -#endif +#endif /* ndef _WIN_CONSOLE */ /********************************************************************* * @@ -89,12 +107,12 @@ static void __cdecl UserInterfaceThread(void *); * Description : M$ Windows "main" routine: * parse the `lpCmdLine' param into main's argc and argv variables, * start the user interface thread (for the systray window), and - * call main (i.e. patch execution into normal IJB startup). + * call main (i.e. patch execution into normal startup). * * Parameters : - * 1 : hInstance = instance handle of this IJB execution - * 2 : hPrevInstance = instance handle of previous IJB execution - * 3 : lpCmdLine = command line string which started IJB + * 1 : hInstance = instance handle of this execution + * 2 : hPrevInstance = instance handle of previous execution + * 3 : lpCmdLine = command line string which started us * 4 : nCmdShow = window show value (MIN, MAX, NORMAL, etc...) * * Returns : `main' never returns, so WinMain will also never return. @@ -102,56 +120,79 @@ static void __cdecl UserInterfaceThread(void *); *********************************************************************/ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - int argc = 0; +#if 0 /* See comment about __argc & __argv below */ int i; - int res; - char **argv = NULL; - char *pszArgs = NULL; - char *pszLastTok; + int argc = 1; + const char *argv[3]; char szModule[MAX_PATH+1]; +#endif + + int res; #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); +#if defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) +#if 0 + /* Visual C++ Heap debugging */ - /* Count number of spaces */ - argc = 1; - if (strlen(pszArgs) > 0) - { - pszLastTok = pszArgs; - do - { - argc++; - pszLastTok = strchr(pszLastTok+1, ' '); - } while (pszLastTok); - } + /* Get current flag*/ + int tmpFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); - /* Allocate array of strings */ - argv = (char **)malloc(sizeof(char *) * argc); + /* Turn on leak-checking bit */ + tmpFlag |= _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_CHECK_ALWAYS_DF; - /* step through command line replacing spaces with zeros, initialise array */ - argv[0] = szModule; - i = 1; - pszLastTok = pszArgs; - do + /* Turn off CRT block checking bit */ + tmpFlag &= ~(_CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF); + + /* Set flag to the new value */ + _CrtSetDbgFlag(tmpFlag); +#endif +#endif /* defined(_WIN32) && defined(_MSC_VER) && defined(_DEBUG) */ + + +/************ + * I couldn't figure out why the command line was being sorta parsed here + * instead of using the __argc & __argv globals usually defined in stdlib.h + * + * From what I can tell by looking at the MinWG source, it supports these + * globals, so i'd hope that the other compilers do so as well. + * Obviously, if i'm wrong i'll find out soon enough! :) + ************/ +#if 0 + /* + * Cheat in parsing the command line. We only ever have at most one + * parameter, which may optionally be specified inside double quotes. + */ + + if (lpCmdLine != NULL) + { + /* Make writable copy */ + lpCmdLine = strdup(lpCmdLine); + } + 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); +#endif /* -END- 0 */ + #ifndef _WIN_CONSOLE /* Create a user-interface thread and wait for it to initialise */ @@ -160,19 +201,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine g_nCmdShow = nCmdShow; _beginthread(UserInterfaceThread, 0, &hInitCompleteEvent); WaitForSingleObject(hInitCompleteEvent, INFINITE); - DeleteObject(hInitCompleteEvent); + CloseHandle(hInitCompleteEvent); #endif #ifdef __MINGW32__ - res = _main( argc, argv ); + res = real_main(__argc, __argv); #else - res = main( argc, argv ); + res = main(__argc, __argv); #endif - /* Cleanup */ - free(argv); - free(pszArgs); - return res; } @@ -206,8 +243,8 @@ void InitWin32(void) if (WSAStartup(wVersionRequested, &wsaData) != 0) { #ifndef _WIN_CONSOLE - MessageBox(NULL, "Cannot initialize WinSock library", "Internet JunkBuster Error", - MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST); + MessageBox(NULL, "Cannot initialize WinSock library", "Privoxy Error", + MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_SETFOREGROUND | MB_TOPMOST); #endif exit(1); } @@ -230,7 +267,7 @@ void InitWin32(void) * Description : User interface thread. WinMain will wait for us to set * the hInitCompleteEvent before patching over to `main'. * This ensures the systray window is active before beginning - * IJB operations. + * operations. * * Parameters : * 1 : pData = pointer to `hInitCompleteEvent'. @@ -258,12 +295,12 @@ static void __cdecl UserInterfaceThread(void *pData) TermLogWindow(); /* Time to die... */ - raise(SIGINT); + exit(0); } -#endif +#endif /* ndef _WIN_CONSOLE */ /*