Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nwmain.h
Go to the documentation of this file.
1 /**********************************************************************
2 * File: nwmain.h
3 * Description: Tool to declare main, making windows invisible.
4 * Author: Ray Smith
5 * Created: Fri Sep 07 13:27:50 MDT 1995
6 *
7 * (C) Copyright 1995, Hewlett-Packard Co.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #ifndef RUNMAIN_H
21 #define RUNMAIN_H
22
23 #include "host.h"
24 #include "params.h"
25 #include "notdll.h" //must be last include
26
27 #define DECLARE_MAIN(ARGC,ARGV)\
28 STRING_VAR(init_config_file,"config","Config file to read on startup");\
29 REALLY_DECLARE_MAIN(ARGC,ARGV)
30
31 #define DECLARE_MAIN_CONFIG(ARGC,ARGV,NAME)\
32 STRING_VAR(init_config_file,NAME,"Config file to read on startup");\
33 REALLY_DECLARE_MAIN(ARGC,ARGV)
34
35 #ifndef __UNIX__
36
37 #define REALLY_DECLARE_MAIN(ARGC,ARGV)\
38 \
39 /**********************************************************************\
40 * parse_args\
41 *\
42 * Turn a list of args into a new list of args with each separate\
43 * whitespace spaced string being an arg.\
44 **********************************************************************/\
45 \
46 inT32 parse_args( /*refine arg list*/\
47 inT32 argc, /*no of input args*/\
48 char *argv[], /*input args*/\
49 char *arglist[] /*output args*/\
50 )\
51 {\
52 inT32 argcount; /*converted argc*/\
53 char *testchar; /*char in option string*/\
54 inT32 arg; /*current argument*/\
55 \
56 argcount=0; /*no of options*/\
57 for (arg=0;arg<argc;arg++)\
58 {\
59 testchar=argv[arg]; /*start of arg*/\
60 do\
61 {\
62 while (*testchar\
63 && (*testchar==' ' || *testchar=='"' || *testchar=='\n' || *testchar=='\t'))\
64 testchar++; /*skip white space*/\
65 if (*testchar)\
66 {\
67 arglist[argcount++]=testchar; /*new arg*/\
68 do\
69 {\
70 for (testchar++;*testchar\
71 && *testchar!=' ' && *testchar!='"' && *testchar!='\n' && *testchar!='\t';\
72 testchar++); /*skip to white space*/\
73 }\
74 while (*testchar=='"' && testchar[1]!=' ' && testchar[1]!='\0' && testchar[1]!='\n' && testchar[1]!='\t');\
75 if (*testchar)\
76 *testchar++='\0'; /*turn to separate args*/\
77 }\
78 }\
79 while (*testchar);\
80 }\
81 return argcount; /*new number of args*/\
82 }\
83 \
84 inT32 global_exit_code;\
85 inT32 real_main(inT32,const char**);\
86 \
87 inT32 run_main( /*the main thread*/\
88 CWinApp* theapp /*arguments*/\
89 )\
90 {\
91 char **argv;\
92 char *argsin[2];\
93 inT32 argc;\
94 inT32 exit_code;\
95 \
96 argsin[0]=strdup(theapp->m_pszExeName);\
97 argsin[1]=strdup(theapp->m_lpCmdLine);\
98 /*allocate memory for the args. There can never be more than half*/\
99 /*the total number of characters in the arguments.*/\
100 argv=(char**)malloc(((strlen(argsin[0])+strlen(argsin[1]))/2+1)*sizeof(char*));\
101 \
102 /*now construct argv as it should be for C.*/\
103 argc=parse_args(2,argsin,argv);\
104 \
105 /*call main(argc,argv) here*/\
106 exit_code=real_main(argc,(const char **)argv);\
107 \
108 \
109 /*now get rid of the main app window*/\
110 if (theapp!=NULL && theapp->m_pMainWnd!=NULL)\
111 PostMessage(theapp->m_pMainWnd->m_hWnd,WM_QUIT,0,0);\
112 free(argsin[0]);\
113 free(argsin[1]);\
114 free(argv);\
115 global_exit_code=exit_code;\
116 return exit_code;\
117 }\
118 \
119 inT32 real_main(inT32 ARGC,const char* ARGV[])\
120
121 #else
122
123 #define REALLY_DECLARE_MAIN(ARGC,ARGV)\
124 \
125 /**********************************************************************\
126 * parse_args\
127 *\
128 * Turn a list of args into a new list of args with each separate\
129 * whitespace spaced string being an arg.\
130 **********************************************************************/\
131 \
132 inT32 parse_args( /*refine arg list*/\
133 inT32 argc, /*no of input args*/\
134 char *argv[], /*input args*/\
135 char *arglist[] /*output args*/\
136 )\
137 {\
138 inT32 argcount; /*converted argc*/\
139 char *testchar; /*char in option string*/\
140 inT32 arg; /*current argument*/\
141 \
142 argcount=0; /*no of options*/\
143 for (arg=0;arg<argc;arg++)\
144 {\
145 testchar=argv[arg]; /*start of arg*/\
146 do\
147 {\
148 while (*testchar\
149 && (*testchar==' ' || *testchar=='"' || *testchar=='\n' || *testchar=='\t'))\
150 testchar++; /*skip white space*/\
151 if (*testchar)\
152 {\
153 arglist[argcount++]=testchar; /*new arg*/\
154 do\
155 {\
156 for (testchar++;*testchar\
157 && *testchar!=' ' && *testchar!='"' && *testchar!='\n' && *testchar!='\t';\
158 testchar++); /*skip to white space*/\
159 }\
160 while (*testchar=='"' && testchar[1]!=' ' && testchar[1]!='\0' && testchar[1]!='\n' && testchar[1]!='\t');\
161 if (*testchar)\
162 *testchar++='\0'; /*turn to separate args*/\
163 }\
164 }\
165 while (*testchar);\
166 }\
167 return argcount; /*new number of args*/\
168 }\
169 \
170 inT32 main(inT32 ARGC,const char* ARGV[])\
171
172 #endif
173
174 #else
175 #error "NOT allowed to include nwmain.h or runmain.h twice!!"
176 #endif