Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

clanapp.cpp

Go to the documentation of this file.
00001 /*
00002         ------------------------------------------------------------------------
00003         ClanLib, the platform independent game SDK.
00004 
00005         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00006         version 2. See COPYING for details.
00007 
00008         For a total list of contributers see CREDITS.
00009 
00010         ------------------------------------------------------------------------
00011 */
00012 
00013 #include <windows.h>
00014 #include <vector>
00015 #include "API/Core/System/setupcore.h"
00016 #include "API/Application/clanapp.h"
00017 
00018 static void calc_commandline(int *argc, char ***argv);
00019 
00021 // WinMain:
00022 
00023 int WINAPI WinMain(
00024         HINSTANCE hInstance,
00025         HINSTANCE hPrevInstance,
00026         LPSTR lpCmdLine,
00027         int nCmdShow)
00028 {
00029         int retval;
00030         int argc;
00031         char **argv;
00032 
00033         // Did the game developer remember to create one global application
00034         // interface?
00035         if (CL_ClanApplication::app == NULL)
00036         {
00037                 MessageBox(NULL, "No program instance found", "ClanLib/Win32", 32);
00038                 return 0;
00039         }
00040 
00041         // Get commandline arguments.
00042         calc_commandline(&argc, &argv);
00043 
00044         // Initialize clanlib and call clanapp main:
00045         CL_SetupCore::set_instance(hInstance);
00046         CL_SetupCore::init();
00047         retval = CL_ClanApplication::app->main(argc, argv);
00048         CL_SetupCore::deinit();
00049 
00050         // calc_commandline() doesn't clean up after itself. tsk tsk:
00051         delete[] argv;
00052 
00053         return retval;
00054 }
00055 
00057 // calc_commandline:
00058 
00059 static void calc_commandline(int *argc, char ***argv)
00060 {
00061         char *command_line = GetCommandLine();
00062         static std::vector<char *> pos;
00063         bool state_gaaseoejne = false;
00064         bool new_arg = true;
00065 
00066         for (;*command_line;command_line++) 
00067         {
00068                 if (*command_line == '"')
00069                 {
00070                         new_arg = true;
00071                         command_line++;
00072                         char *start_arg = command_line;
00073                         for (;*command_line && *command_line!='"';command_line++)
00074                         {
00075                                 if (!isspace(*command_line)) new_arg = false;
00076                         }
00077                         if (new_arg == false) pos.push_back(start_arg);
00078                         if (*command_line == '"') *command_line = 0;
00079                         else if (*command_line == 0) break;
00080                         command_line++;
00081                         if (*command_line == 0) break;
00082                         new_arg = true;
00083                 }
00084                 
00085                 if (new_arg && !isspace(*command_line))
00086                 {
00087                         new_arg = false;
00088                         pos.push_back(command_line);
00089                 }
00090                 else if (!new_arg && isspace(*command_line))
00091                 {
00092                         new_arg = true;
00093                         *command_line = 0;
00094                 }
00095         }
00096         int num_words = pos.size();
00097 
00098         char **words = new char*[num_words];
00099 
00100         int i;
00101         for (i=0; i<num_words; i++)
00102         {
00103                 words[i] = pos[i];
00104         }
00105 
00106         *argc = num_words;
00107         *argv = words;
00108 }
00109 
00111 // CL_ClanApplication:
00112 
00113 CL_ClanApplication *CL_ClanApplication::app = NULL;
00114 
00115 CL_ClanApplication::CL_ClanApplication()
00116 {
00117         CL_ClanApplication::app = this;
00118 }
00119 
00120 CL_ClanApplication::~CL_ClanApplication()
00121 {
00122         CL_ClanApplication::app = NULL;
00123 }

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001