1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/*
* File: main.h
* ------------
* This file renames the <code>main</code> method in the client's
* program to <code>Main</code>, thereby allowing a custom
* <code>main</code> method in the libraries to take control
* before passing control back to the client program. The main macro
* also defines a function getMainFlags that returns an int whose bits
* indicate which of the various interfaces have been loaded by this
* definition of main.
*
* Note: This file can be loaded more than once and must therefore
* check to see what has already been defined.
*/
#ifdef main
# undef main
# undef CONSOLE_FLAG
# undef GRAPHICS_FLAG
#else
# define MAIN_USES_CONSOLE (1<<0)
# define MAIN_USES_GRAPHICS (1<<1)
#endif
#ifdef _console_h
# define CONSOLE_FLAG MAIN_USES_CONSOLE
#else
# define CONSOLE_FLAG 0
#endif
#ifdef _gwindow_h
# define GRAPHICS_FLAG MAIN_USES_GRAPHICS
#else
# define GRAPHICS_FLAG 0
#endif
#if CONSOLE_FLAG | GRAPHICS_FLAG
#define main main(int argc, char **argv) { \
extern int _mainFlags; \
_mainFlags = GRAPHICS_FLAG + CONSOLE_FLAG; \
try { \
return startupMain(argc, argv); \
} catch (const std::exception& ex) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** An exception occurred during program execution: \n"; \
msg += " *** "; \
msg += ex.what(); \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw ex; \
} catch (std::string str) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A string exception occurred during program execution: \n"; \
msg += " *** \""; \
msg += str; \
msg += "\"\n ***\n"; \
std::cerr << msg; \
throw str; \
} catch (char const* str) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A string exception occurred during program execution: \n"; \
msg += " *** \""; \
msg += str; \
msg += "\"\n ***\n"; \
std::cerr << msg; \
throw str; \
} catch (int n) { \
char buf[128]; \
snprintf(buf, 128, "%d", n); \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** An int exception occurred during program execution: \n"; \
msg += " *** "; \
msg += buf; \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw n; \
} catch (long l) { \
char buf[128]; \
snprintf(buf, 128, "%ld", l); \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A long exception occurred during program execution: \n"; \
msg += " *** "; \
msg += buf; \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw l; \
} catch (char c) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A char exception occurred during program execution: \n"; \
msg += " *** '"; \
msg += c; \
msg += "'\n ***\n"; \
std::cerr << msg; \
throw c; \
} catch (bool b) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A bool exception occurred during program execution: \n"; \
msg += " *** "; \
msg += (b ? "true" : "false"); \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw b; \
} catch (double d) { \
char buf[128]; \
snprintf(buf, 128, "%lf", d); \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A double exception occurred during program execution: \n"; \
msg += " *** "; \
msg += buf; \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw d; \
} \
} \
int Main
extern int startupMain(int argc, char **argv);
#else
#define main main(int argc, char **argv) { \
extern int _mainFlags; \
_mainFlags = GRAPHICS_FLAG + CONSOLE_FLAG; \
try { \
return mainWrapper(argc, argv); } \
} catch (const std::exception& ex) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** An exception occurred during program execution: \n"; \
msg += " *** "; \
msg += ex.what(); \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw ex; \
} catch (std::string str) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A string exception occurred during program execution: \n"; \
msg += " *** \""; \
msg += str; \
msg += "\"\n ***\n"; \
std::cerr << msg; \
throw str; \
} catch (char const* str) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A string exception occurred during program execution: \n"; \
msg += " *** \""; \
msg += str; \
msg += "\"\n ***\n"; \
std::cerr << msg; \
throw str; \
} catch (int n) { \
char buf[128]; \
snprintf(buf, 128, "%d", n); \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** An int exception occurred during program execution: \n"; \
msg += " *** "; \
msg += buf; \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw n; \
} catch (long l) { \
char buf[128]; \
snprintf(buf, 128, "%ld", l); \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A long exception occurred during program execution: \n"; \
msg += " *** "; \
msg += buf; \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw l; \
} catch (char c) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A char exception occurred during program execution: \n"; \
msg += " *** '"; \
msg += c; \
msg += "'\n ***\n"; \
std::cerr << msg; \
throw c; \
} catch (bool b) { \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A bool exception occurred during program execution: \n"; \
msg += " *** "; \
msg += (b ? "true" : "false"); \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw b; \
} catch (double d) { \
char buf[128]; \
snprintf(buf, 128, "%lf", d); \
string msg = "\n ***\n"; \
msg += " *** STANFORD C++ LIBRARY \n"; \
msg += " *** A double exception occurred during program execution: \n"; \
msg += " *** "; \
msg += buf; \
msg += "\n ***\n\n"; \
std::cerr << msg; \
throw d; \
} \
int Main
extern int mainWrapper(int argc, char **argv);
#endif
|