00001
00020 #ifndef RUNMAIN_H
00021 #define RUNMAIN_H
00022
00023 #include "host.h"
00024 #include "varable.h"
00025 #include "notdll.h"
00026
00027 #define DECLARE_MAIN(ARGC,ARGV)\
00028 STRING_VAR(init_config_file,"config","Config file to read on startup");\
00029 REALLY_DECLARE_MAIN(ARGC,ARGV)
00030
00031 #define DECLARE_MAIN_CONFIG(ARGC,ARGV,NAME)\
00032 STRING_VAR(init_config_file,NAME,"Config file to read on startup");\
00033 REALLY_DECLARE_MAIN(ARGC,ARGV)
00034
00035 #ifndef __UNIX__
00036
00037 #define REALLY_DECLARE_MAIN(ARGC,ARGV)\
00038 \
00039
00040
00041
00042
00043
00044 \
00045 \
00046 INT32 parse_args( \
00047 INT32 argc, \
00048 char *argv[], \
00049 char *arglist[] \
00050 )\
00051 {\
00052 INT32 argcount; \
00053 char *testchar; \
00054 INT32 arg; \
00055 \
00056 argcount=0; \
00057 for (arg=0;arg<argc;arg++)\
00058 {\
00059 testchar=argv[arg]; \
00060 do\
00061 {\
00062 while (*testchar\
00063 && (*testchar==' ' || *testchar=='"' || *testchar=='\n' || *testchar=='\t'))\
00064 testchar++; \
00065 if (*testchar)\
00066 {\
00067 arglist[argcount++]=testchar; \
00068 do\
00069 {\
00070 for (testchar++;*testchar\
00071 && *testchar!=' ' && *testchar!='"' && *testchar!='\n' && *testchar!='\t';\
00072 testchar++); \
00073 }\
00074 while (*testchar=='"' && testchar[1]!=' ' && testchar[1]!='\0' && testchar[1]!='\n' && testchar[1]!='\t');\
00075 if (*testchar)\
00076 *testchar++='\0'; \
00077 }\
00078 }\
00079 while (*testchar);\
00080 }\
00081 return argcount; \
00082 }\
00083 \
00084 INT32 global_exit_code;\
00085 INT32 real_main(INT32,const char**);\
00086 \
00087 INT32 run_main( \
00088 CWinApp* theapp \
00089 )\
00090 {\
00091 char **argv;\
00092 char *argsin[2];\
00093 INT32 argc;\
00094 INT32 exit_code;\
00095 \
00096 argsin[0]=strdup(theapp->m_pszExeName);\
00097 argsin[1]=strdup(theapp->m_lpCmdLine);\
00098 \
00099 \
00100 argv=(char**)malloc(((strlen(argsin[0])+strlen(argsin[1]))/2+1)*sizeof(char*));\
00101 \
00102 \
00103 argc=parse_args(2,argsin,argv);\
00104 \
00105 \
00106 exit_code=real_main(argc,(const char **)argv);\
00107 \
00108 \
00109 \
00110 if (theapp!=NULL && theapp->m_pMainWnd!=NULL)\
00111 PostMessage(theapp->m_pMainWnd->m_hWnd,WM_QUIT,0,0);\
00112 free(argsin[0]);\
00113 free(argsin[1]);\
00114 free(argv);\
00115 global_exit_code=exit_code;\
00116 return exit_code;\
00117 }\
00118 \
00119 INT32 real_main(INT32 ARGC,const char* ARGV[])\
00120
00121 #else
00122
00123 #define REALLY_DECLARE_MAIN(ARGC,ARGV)\
00124 \
00125
00126
00127
00128
00129
00130 \
00131 \
00132 INT32 parse_args( \
00133 INT32 argc, \
00134 char *argv[], \
00135 char *arglist[] \
00136 )\
00137 {\
00138 INT32 argcount; \
00139 char *testchar; \
00140 INT32 arg; \
00141 \
00142 argcount=0; \
00143 for (arg=0;arg<argc;arg++)\
00144 {\
00145 testchar=argv[arg]; \
00146 do\
00147 {\
00148 while (*testchar\
00149 && (*testchar==' ' || *testchar=='"' || *testchar=='\n' || *testchar=='\t'))\
00150 testchar++; \
00151 if (*testchar)\
00152 {\
00153 arglist[argcount++]=testchar; \
00154 do\
00155 {\
00156 for (testchar++;*testchar\
00157 && *testchar!=' ' && *testchar!='"' && *testchar!='\n' && *testchar!='\t';\
00158 testchar++); \
00159 }\
00160 while (*testchar=='"' && testchar[1]!=' ' && testchar[1]!='\0' && testchar[1]!='\n' && testchar[1]!='\t');\
00161 if (*testchar)\
00162 *testchar++='\0'; \
00163 }\
00164 }\
00165 while (*testchar);\
00166 }\
00167 return argcount; \
00168 }\
00169 \
00170 INT32 main(INT32 ARGC,const char* ARGV[])\
00171
00172 #endif
00173
00174 #else
00175 #error "NOT allowed to include nwmain.h or runmain.h twice!!"
00176 #endif