win_crash_logger.cpp

Go to the documentation of this file.
00001 
00032 // win_crash_logger.cpp : Defines the entry point for the application.
00033 //
00034 
00035 // Must be first include, precompiled headers.
00036 #include "stdafx.h"
00037 
00038 #include <stdlib.h>
00039 
00040 #include "llcrashloggerwindows.h"
00041 
00042 
00043 
00044 //
00045 // Implementation
00046 //
00047 
00048 int APIENTRY WinMain(HINSTANCE hInstance,
00049                      HINSTANCE hPrevInstance,
00050                      LPSTR     lpCmdLine,
00051                      int       nCmdShow)
00052 {
00053         llinfos << "Starting crash reporter" << llendl;
00054 
00055         // In Win32, we need to generate argc and argv ourselves...
00056         // Note: GetCommandLine() returns a  potentially return a LPTSTR
00057         // which can resolve to a LPWSTR (unicode string).
00058         // (That's why it's different from lpCmdLine which is a LPSTR.)
00059         // We don't currently do unicode, so call the non-unicode version
00060         // directly.
00061         llinfos << "Processing command line" << llendl;
00062         LPSTR cmd_line_including_exe_name = GetCommandLineA();
00063 
00064         const S32       MAX_ARGS = 100;
00065         int argc = 0;
00066         char *argv[MAX_ARGS];           
00067 
00068         char *token = NULL;
00069         if( cmd_line_including_exe_name[0] == '\"' )
00070         {
00071                 // Exe name is enclosed in quotes
00072                 token = strtok( cmd_line_including_exe_name, "\"" );
00073                 argv[argc++] = token;
00074                 token = strtok( NULL, " \t," );
00075         }
00076         else
00077         {
00078                 // Exe name is not enclosed in quotes
00079                 token = strtok( cmd_line_including_exe_name, " \t," );
00080         }
00081 
00082         while( (token != NULL) && (argc < MAX_ARGS) )
00083         {
00084                 argv[argc++] = token;
00085                 /* Get next token: */
00086                 if (*(token + strlen(token) + 1) == '\"')               
00087                 {
00088                         token = strtok( NULL, "\"");
00089                 }
00090                 else
00091                 {
00092                         token = strtok( NULL, " \t," );
00093                 }
00094         }
00095 
00096         LLCrashLoggerWindows app;
00097         bool ok = app.parseCommandOptions(argc, argv);
00098         if(!ok)
00099         {
00100                 llwarns << "Unable to parse command line." << llendl;
00101         }
00102         
00103         app.setHandle(hInstance);
00104         ok = app.init();
00105         if(!ok)
00106         {
00107                 llwarns << "Unable to initialize application." << llendl;
00108                 return -1;
00109         }
00110 
00111                 // Run the application main loop
00112         if(!LLApp::isQuitting()) app.mainLoop();
00113 
00114         if (!app.isError())
00115         {
00116                 //
00117                 // We don't want to do cleanup here if the error handler got called -
00118                 // the assumption is that the error handler is responsible for doing
00119                 // app cleanup if there was a problem.
00120                 //
00121                 app.cleanup();
00122         }
00123         return 0;
00124 }

Generated on Fri May 16 08:34:33 2008 for SecondLife by  doxygen 1.5.5