Mercurial > hg > forks > yadex
comparison src/yadex.cc @ 80:2f1ecc1c5f72
Huge cleanup -- move some global variables into a struct.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Sep 2011 17:39:49 +0300 |
parents | 626678d4ecf3 |
children | 154714f3ab2e |
comparison
equal
deleted
inserted
replaced
79:0602d9bf474a | 80:2f1ecc1c5f72 |
---|---|
58 #ifdef Y_READLINE | 58 #ifdef Y_READLINE |
59 #include <readline/readline.h> | 59 #include <readline/readline.h> |
60 #include <readline/history.h> | 60 #include <readline/history.h> |
61 #endif | 61 #endif |
62 | 62 |
63 /* | 63 const char *const yadex_log_filename = "yadex.log"; |
64 * Constants (declared in yadex.h) | |
65 */ | |
66 const char *const log_file = "yadex.log"; | |
67 const char *const msg_unexpected = "unexpected error"; | |
68 const char *const msg_nomem = "Not enough memory"; | |
69 | |
70 | |
71 /* | |
72 * Not real variables -- just unique pointer values | |
73 * used by functions that return pointers to | |
74 */ | |
75 char error_non_unique[1]; // Found more than one | |
76 char error_none[1]; // Found none | |
77 char error_invalid[1]; // Invalid parameter | |
78 | 64 |
79 | 65 |
80 /* | 66 /* |
81 * Global variables | 67 * Global variables |
82 */ | 68 */ |
83 const char *install_dir = 0; // Where Yadex is installed | 69 Wad_res wad_res(&cfg.MasterDir); |
84 FILE *logfile = NULL; // Filepointer to the error log | 70 YadexConfig cfg; |
85 bool Registered = false; // Registered or shareware game? | 71 |
86 int screen_lines = 24; // Lines that our TTY can display | 72 void InitializeConfig() |
87 int remind_to_build_nodes = 0; // Remind user to build nodes | 73 { |
88 Wad_res wad_res(&MasterDir); | 74 cfg.install_dir = NULL, // Where Yadex is installed |
89 | 75 cfg.logfile = NULL, // Filepointer to the error log |
90 // Set from command line and/or config file | 76 cfg.Registered = false, // Registered or shareware game? |
91 bool autoscroll = 0; | 77 cfg.screen_lines = 24, // Lines that our TTY can display |
92 unsigned long autoscroll_amp = 10; | 78 cfg.remind_to_build_nodes = false, // Remind user to build nodes |
93 unsigned long autoscroll_edge = 30; | 79 cfg.config_file = NULL; |
94 const char *config_file = NULL; | 80 cfg.Debug = false; |
95 int copy_linedef_reuse_sidedefs = 0; | 81 |
96 int cpu_big_endian = 0; | 82 // Set from command line and/or config file |
97 bool Debug = false; | 83 cfg.autoscroll = false; |
98 int default_ceiling_height = 128; | 84 cfg.autoscroll_amp = 10; |
99 char default_ceiling_texture[WAD_FLAT_NAME + 1] = "CEIL3_5"; | 85 cfg.autoscroll_edge = 30; |
100 int default_floor_height = 0; | 86 cfg.copy_linedef_reuse_sidedefs = false; |
101 char default_floor_texture[WAD_FLAT_NAME + 1] = "FLOOR4_8"; | 87 cfg.cpu_big_endian = false; |
102 int default_light_level = 144; | 88 |
103 char default_lower_texture[WAD_TEX_NAME + 1] = "STARTAN3"; | 89 cfg.def.ceiling_height = 128; |
104 char default_middle_texture[WAD_TEX_NAME + 1] = "STARTAN3"; | 90 strcpy(cfg.def.ceiling_texture, "CEIL3_5"); |
105 char default_upper_texture[WAD_TEX_NAME + 1] = "STARTAN3"; | 91 cfg.def.floor_height = 0; |
106 int default_thing = 3004; | 92 strcpy(cfg.def.floor_texture, "FLOOR4_8"); |
107 int double_click_timeout = 200; | 93 cfg.def.light_level = 144; |
108 bool Expert = false; | 94 strcpy(cfg.def.lower_texture, "STARTAN3"); |
109 const char *Game = NULL; | 95 strcpy(cfg.def.middle_texture, "STARTAN3"); |
110 int grid_pixels_min = 10; | 96 strcpy(cfg.def.upper_texture, "STARTAN3"); |
111 int GridMin = 2; | 97 cfg.def.thing = 3004; |
112 int GridMax = 128; | 98 cfg.double_click_timeout = 200; |
113 int idle_sleep_ms = 50; | 99 cfg.Expert = false; |
114 bool InfoShown = true; | 100 cfg.Game = NULL; |
115 int zoom_default = 0; // 0 means fit | 101 |
116 int zoom_step = 0; // 0 means sqrt(2) | 102 cfg.PatchWads = NULL; |
117 int digit_zoom_base = 100; | 103 cfg.Quiet = false; |
118 int digit_zoom_step = 0; // 0 means sqrt(2) | 104 cfg.Quieter = false; |
119 confirm_t insert_vertex_split_linedef = YC_ASK_ONCE; | 105 cfg.scroll_less = 10; |
120 confirm_t insert_vertex_merge_vertices = YC_ASK_ONCE; | 106 cfg.scroll_more = 90; |
121 bool blindly_swap_sidedefs = false; | 107 cfg.Select0 = false; |
122 const char *Iwad1 = NULL; | 108 cfg.show_help = false; |
123 const char *Iwad2 = NULL; | 109 cfg.sprite_scale = 100; |
124 const char *Iwad3 = NULL; | 110 cfg.SwapButtons = false; |
125 const char *Iwad4 = NULL; | 111 cfg.verbose = 0; |
126 const char *Iwad5 = NULL; | 112 cfg.welcome_message = 1; |
127 const char *Iwad6 = NULL; | 113 cfg.bench = NULL; |
128 const char *Iwad7 = NULL; | 114 |
129 const char *Iwad8 = NULL; | 115 memset(cfg.Iwad, 0, sizeof(cfg.Iwad)); |
130 const char *Iwad9 = NULL; | 116 cfg.MainWad = NULL; |
131 const char *Iwad10 = NULL; | 117 |
132 const char *MainWad = NULL; | 118 |
119 cfg.grid_pixels_min = 10; | |
120 cfg.GridMin = 2; | |
121 cfg.GridMax = 128; | |
122 cfg.idle_sleep_ms = 50; | |
123 cfg.InfoShown = true; | |
124 cfg.zoom_default = 0; // 0 means fit | |
125 cfg.zoom_step = 0; // 0 means sqrt(2) | |
126 cfg.digit_zoom_base = 100; | |
127 cfg.digit_zoom_step = 0; // 0 means sqrt(2) | |
128 | |
133 #ifdef AYM_MOUSE_HACKS | 129 #ifdef AYM_MOUSE_HACKS |
134 int MouseMickeysH = 5; | 130 cfg.MouseMickeysH = 5; |
135 int MouseMickeysV = 5; | 131 cfg.MouseMickeysV = 5; |
136 #endif | 132 #endif |
137 char **PatchWads = NULL; | 133 |
138 bool Quiet = false; | 134 cfg.insert_vertex_split_linedef = YC_ASK_ONCE; |
139 bool Quieter = false; | 135 cfg.insert_vertex_merge_vertices = YC_ASK_ONCE; |
140 unsigned long scroll_less = 10; | 136 cfg.blindly_swap_sidedefs = false; |
141 unsigned long scroll_more = 90; | 137 } |
142 bool Select0 = false; | 138 |
143 int show_help = 0; | |
144 int sprite_scale = 100; | |
145 bool SwapButtons = false; | |
146 int verbose = 0; | |
147 int welcome_message = 1; | |
148 const char *bench = 0; | |
149 | 139 |
150 // Global variables declared in game.h | 140 // Global variables declared in game.h |
151 yglf_t yg_level_format = YGLF__; | 141 yglf_t yg_level_format = YGLF__; |
152 ygln_t yg_level_name = YGLN__; | 142 ygln_t yg_level_name = YGLN__; |
153 ygpf_t yg_picture_format = YGPF_NORMAL; | 143 ygpf_t yg_picture_format = YGPF_NORMAL; |
162 | 152 |
163 | 153 |
164 /* | 154 /* |
165 * Prototypes of private functions | 155 * Prototypes of private functions |
166 */ | 156 */ |
167 static int parse_environment_vars(); | |
168 static void MainLoop(); | 157 static void MainLoop(); |
169 static void print_error_message(const char *fmt, va_list args); | |
170 static void add_base_colours(); | 158 static void add_base_colours(); |
171 static const Wad_file *wad_by_name(const char *pathname); | 159 static const Wad_file *wad_by_name(const char *pathname); |
172 static bool wad_already_loaded(const char *pathname); | 160 static bool wad_already_loaded(const char *pathname); |
173 | 161 |
174 typedef struct | 162 typedef struct |
175 { | 163 { |
176 const char *game, *wadname; | 164 const char *game, *wadname; |
177 const char **pwadloc; | |
178 } GameInfo; | 165 } GameInfo; |
179 | 166 |
180 GameInfo gameList[] = { | 167 GameInfo gameList[IWAD_LAST] = { |
181 {"doom", "doom.wad", &Iwad1}, | 168 {"doom", "doom.wad"}, |
182 {"doom2", "doom2.wad", &Iwad2}, | 169 {"doom2", "doom2.wad"}, |
183 {"heretic", "heretic.wad", &Iwad3}, | 170 {"heretic", "heretic.wad"}, |
184 {"hexen", "hexen.wad", &Iwad4}, | 171 {"hexen", "hexen.wad"}, |
185 {"strife", "strife1.wad", &Iwad5}, | 172 {"strife", "strife1.wad"}, |
186 {"doom02", "Doom alpha 0.2 IWAD", &Iwad6}, | 173 {"doom02", "Doom alpha 0.2 IWAD"}, |
187 {"doom04", "Doom alpha 0.4 IWAD", &Iwad7}, | 174 {"doom04", "Doom alpha 0.4 IWAD"}, |
188 {"doom05", "Doom alpha 0.5 IWAD", &Iwad8}, | 175 {"doom05", "Doom alpha 0.5 IWAD"}, |
189 {"doompr", "Doom Press Release IWAD", &Iwad9}, | 176 {"doompr", "Doom Press Release IWAD"}, |
190 {"strife10", "strife1.wad", &Iwad10} | 177 {"strife10", "strife1.wad"} |
191 }; | 178 }; |
192 | 179 |
193 const int ngameList = sizeof(gameList) / sizeof(gameList[0]); | 180 |
181 /* | |
182 * parse_environment_vars | |
183 * Check certain environment variables. | |
184 */ | |
185 static void parse_environment_vars(void) | |
186 { | |
187 char *value; | |
188 | |
189 if ((value = getenv("YADEX_GAME")) != NULL) | |
190 cfg.Game = value; | |
191 | |
192 if ((value = getenv("LINES")) != NULL) | |
193 cfg.screen_lines = atoi(value); | |
194 else | |
195 cfg.screen_lines = 0; | |
196 | |
197 if (cfg.screen_lines == 0) | |
198 cfg.screen_lines = 24; | |
199 } | |
194 | 200 |
195 | 201 |
196 /* | 202 /* |
197 * main | 203 * main |
198 * Guess what. | 204 * Guess what. |
199 */ | 205 */ |
200 int main(int argc, char *argv[]) | 206 int main(int argc, char *argv[]) |
201 { | 207 { |
202 int r; | 208 int r; |
203 | 209 |
204 // Set <screen_lines> | 210 InitializeConfig(); |
205 if (getenv("LINES") != NULL) | 211 parse_environment_vars(); |
206 screen_lines = atoi(getenv("LINES")); | 212 |
207 else | |
208 screen_lines = 0; | |
209 if (screen_lines == 0) | |
210 screen_lines = 24; | |
211 | |
212 // First detect manually --help and --version | |
213 // because parse_command_line_options() cannot. | |
214 if (argc == 2 && strcmp(argv[1], "--help") == 0) | 213 if (argc == 2 && strcmp(argv[1], "--help") == 0) |
215 { | 214 { |
216 print_usage(stdout); | 215 print_usage(stdout); |
217 if (fflush(stdout) != 0) | |
218 fatal_error("stdout: %s", strerror(errno)); | |
219 exit(0); | 216 exit(0); |
220 } | 217 } |
221 if (argc == 2 && strcmp(argv[1], "--version") == 0) | 218 if (argc == 2 && strcmp(argv[1], "--version") == 0) |
222 { | 219 { |
223 puts(what()); | 220 puts(what()); |
224 puts(config_file_magic); | 221 puts(config_file_magic); |
225 puts(ygd_file_magic); | 222 puts(ygd_file_magic); |
226 if (fflush(stdout) != 0) | |
227 fatal_error("stdout: %s", strerror(errno)); | |
228 exit(0); | 223 exit(0); |
229 } | 224 } |
230 | 225 |
231 // Second a quick pass through the command line | 226 // Second a quick pass through the command line |
232 // arguments to detect -?, -f and -help. | 227 // arguments to detect -?, -f and -help. |
233 r = parse_command_line_options(argc - 1, argv + 1, 1); | 228 r = parse_command_line_options(argc - 1, argv + 1, 1); |
234 if (r) | 229 if (r) |
235 goto syntax_error; | 230 goto syntax_error; |
236 | 231 |
237 if (show_help) | 232 if (cfg.show_help) |
238 { | 233 { |
239 print_usage(stdout); | 234 print_usage(stdout); |
240 exit(1); | 235 exit(1); |
241 } | 236 } |
242 | 237 |
243 printf("%s\n", what()); | 238 printf("%s\n", what()); |
244 | 239 |
245 // Where am I installed ? (the config file might be there) | 240 // Where am I installed ? (the config file might be there) |
246 #if defined Y_DOS | 241 #if defined Y_DOS |
247 install_dir = spec_path(argv[0]); | 242 install_dir = spec_path(argv[0]); |
248 #endif | 243 #endif |
249 | 244 |
250 // The config file provides some values. | 245 // The config file provides some values. |
251 if (config_file != NULL) | 246 if (cfg.config_file != NULL) |
252 r = parse_config_file_user(config_file); | 247 r = parse_config_file_user(cfg.config_file); |
253 else | 248 else |
254 r = parse_config_file_default(); | 249 r = parse_config_file_default(); |
250 | |
255 if (r == 0) | 251 if (r == 0) |
256 { | 252 { |
257 // Environment variables can override them. | 253 // Environment variables can override them. |
258 r = parse_environment_vars(); | 254 parse_environment_vars(); |
259 if (r == 0) | 255 r = parse_command_line_options(argc - 1, argv + 1, 2); |
260 { | 256 } |
261 // And the command line argument can override both. | 257 |
262 r = parse_command_line_options(argc - 1, argv + 1, 2); | |
263 } | |
264 } | |
265 if (r != 0) | 258 if (r != 0) |
266 { | 259 { |
267 syntax_error: | 260 syntax_error: |
268 fprintf(stderr, "Try \"yadex --help\" or \"man yadex\".\n"); | 261 fprintf(stderr, "Try \"yadex --help\" or \"man yadex\".\n"); |
269 exit(1); | 262 exit(1); |
270 } | 263 } |
271 | 264 |
272 if (Game != NULL) | 265 if (cfg.Game != NULL) |
273 { | 266 { |
274 int n; | 267 int n; |
275 for (n = 0; n < ngameList; n++) | 268 for (n = 0; n < IWAD_LAST; n++) |
276 { | 269 { |
277 GameInfo *info = &gameList[n]; | 270 GameInfo *info = &gameList[n]; |
278 if (strcmp(Game, info->game) == 0) | 271 if (strcmp(cfg.Game, info->game) == 0) |
279 { | 272 { |
280 if (*(info->pwadloc) == NULL) | 273 if (cfg.Iwad[n] == NULL) |
281 { | 274 { |
282 err("You have to tell me where %s is.", info->wadname); | 275 err("You have to tell me where %s is.", info->wadname); |
283 fprintf(stderr, | 276 fprintf(stderr, |
284 "Use \"-i%d <file>\" or put \"iwad%d=<file>\" in yadex.cfg\n", | 277 "Use \"-i%d <file>\" or put \"iwad%d=<file>\" in yadex.cfg\n", |
285 n + 1, n + 1); | 278 n + 1, n + 1); |
286 exit(1); | 279 exit(1); |
287 } | 280 } |
288 MainWad = *(info->pwadloc); | 281 cfg.MainWad = cfg.Iwad[n]; |
289 } | 282 } |
290 } | 283 } |
291 } | 284 } |
292 | 285 |
293 if (MainWad == NULL) | 286 if (cfg.MainWad == NULL) |
294 { | 287 { |
295 int n; | 288 int n; |
296 if (Game == NULL) | 289 if (cfg.Game == NULL) |
297 err("You didn't say for which game you want to edit."); | 290 err("You didn't say for which game you want to edit."); |
298 else | 291 else |
299 err("Unknown game \"%s\"", Game); | 292 err("Unknown game \"%s\"", cfg.Game); |
293 | |
300 fprintf(stderr, | 294 fprintf(stderr, |
301 "Use \"-g <game>\" on the command line or put \"game=<game>\" in yadex.cfg\n" | 295 "Use \"-g <game>\" on the command line or put \"game=<game>\" in yadex.cfg\n" |
302 "where <game> is one of: "); | 296 "where <game> is one of: "); |
303 for (n = 0; n < ngameList; n++) | 297 |
298 for (n = 0; n < IWAD_LAST; n++) | |
304 { | 299 { |
305 fprintf(stderr, "%s\"%s\"", n > 0 ? ", " : "", gameList[n].game); | 300 fprintf(stderr, "%s\"%s\"", n > 0 ? ", " : "", gameList[n].game); |
306 } | 301 } |
307 fprintf(stderr, ".\n"); | 302 fprintf(stderr, ".\n"); |
308 exit(1); | 303 exit(1); |
309 } | 304 } |
310 if (Debug) | 305 |
311 { | 306 if (cfg.Debug) |
312 logfile = fopen(log_file, "a"); | 307 { |
313 if (logfile == NULL) | 308 cfg.logfile = fopen(yadex_log_filename, "a"); |
314 warn("can't open log file \"%s\" (%s)", log_file, | 309 if (cfg.logfile == NULL) |
310 { | |
311 warn("Can't open log file \"%s\" (%s)", yadex_log_filename, | |
315 strerror(errno)); | 312 strerror(errno)); |
313 } | |
314 | |
315 LogMessage(": Main IWAD = '%s'\n", cfg.MainWad); | |
316 LogMessage(": Welcome to Yadex!\n"); | 316 LogMessage(": Welcome to Yadex!\n"); |
317 } | 317 } |
318 if (Quieter) | 318 |
319 Quiet = true; | 319 if (cfg.Quieter) |
320 | 320 cfg.Quiet = true; |
321 // Sanity checks (useful when porting). | 321 |
322 // Sanity checks (useful when porting). | |
322 check_types(); | 323 check_types(); |
323 check_charset(); | 324 check_charset(); |
324 | 325 |
325 // Misc. things done only once. | 326 // Misc. things done only once. |
326 cpu_big_endian = native_endianness(); | 327 cfg.cpu_big_endian = native_endianness(); |
327 add_base_colours(); | 328 add_base_colours(); |
328 | 329 |
329 // Load game definitions (*.ygd). | 330 // Load game definitions (*.ygd). |
330 InitGameDefs(); | 331 InitGameDefs(); |
331 LoadGameDefs(Game); | 332 LoadGameDefs(cfg.Game); |
332 | 333 |
333 // Load the iwad and the pwads. | 334 // Load the iwad and the pwads. |
334 if (OpenMainWad(MainWad)) | 335 if (OpenMainWad(cfg.MainWad)) |
335 fatal_error("If you don't give me an iwad, I'll quit. I'm serious."); | 336 fatal_error("If you don't give me an iwad, I'll quit. I'm serious."); |
336 if (PatchWads) | 337 |
338 if (cfg.PatchWads) | |
337 { | 339 { |
338 const char *const *pwad_name; | 340 const char *const *pwad_name; |
339 for (pwad_name = PatchWads; *pwad_name; pwad_name++) | 341 for (pwad_name = cfg.PatchWads; *pwad_name; pwad_name++) |
340 OpenPatchWad(*pwad_name); | 342 OpenPatchWad(*pwad_name); |
341 } | 343 } |
342 /* sanity check */ | 344 |
345 /* sanity check */ | |
343 CloseUnusedWadFiles(); | 346 CloseUnusedWadFiles(); |
344 | 347 |
345 // BRANCH 1 : benchmarking (-b) | 348 // BRANCH 1 : benchmarking (-b) |
346 if (bench != 0) | 349 if (cfg.bench != NULL) |
347 { | 350 { |
348 benchmark(bench); | 351 benchmark(cfg.bench); |
349 return 0; // Exit successfully | 352 return 0; // Exit successfully |
350 } | 353 } |
351 | 354 |
352 // BRANCH 2 : normal use ("yadex:" prompt) | 355 // BRANCH 2 : normal use ("yadex:" prompt) |
353 else | 356 else |
354 { | 357 { |
355 if (welcome_message) | 358 if (cfg.welcome_message) |
356 print_welcome(stdout); | 359 print_welcome(stdout); |
357 | 360 |
358 if (strcmp(Game, "hexen") == 0) | 361 if (strcmp(cfg.Game, "hexen") == 0) |
359 printf | 362 printf |
360 ("WARNING: Hexen mode is experimental. Don't expect to be able to do any\n" | 363 ("WARNING: Hexen mode is experimental. Don't expect to be able to do any\n" |
361 "real Hexen editing with it. You can edit levels but you can't save them.\n" | 364 "real Hexen editing with it. You can edit levels but you can't save them.\n" |
362 "And there might be other bugs... BE CAREFUL !\n\n"); | 365 "And there might be other bugs... BE CAREFUL !\n\n"); |
363 | 366 |
364 if (strcmp(Game, "strife") == 0) | 367 if (strcmp(cfg.Game, "strife") == 0) |
365 printf | 368 printf |
366 ("WARNING: Strife mode is experimental. Many thing types, linedef types,\n" | 369 ("WARNING: Strife mode is experimental. Many thing types, linedef types,\n" |
367 "etc. are missing or wrong. And be careful, there might be bugs.\n\n"); | 370 "etc. are missing or wrong. And be careful, there might be bugs.\n\n"); |
368 | 371 |
369 /* all systems go! */ | 372 /* all systems go! */ |
372 | 375 |
373 /* that's all, folks! */ | 376 /* that's all, folks! */ |
374 CloseWadFiles(); | 377 CloseWadFiles(); |
375 FreeGameDefs(); | 378 FreeGameDefs(); |
376 LogMessage(": The end!\n\n\n"); | 379 LogMessage(": The end!\n\n\n"); |
377 if (logfile != NULL) | 380 |
378 fclose(logfile); | 381 if (cfg.logfile != NULL) |
379 if (remind_to_build_nodes) | 382 fclose(cfg.logfile); |
383 | |
384 if (cfg.remind_to_build_nodes) | |
380 printf("\n" | 385 printf("\n" |
381 "** You have made changes to one or more wads. Don't forget to pass\n" | 386 "** You have made changes to one or more wads. Don't forget to pass\n" |
382 "** them through a nodes builder (E.G. BSP) before running them.\n" | 387 "** them through a nodes builder (E.G. BSP) before running them.\n" |
383 "** Like this: \"ybsp foo.wad -o tmp.wad; doom -file tmp.wad\"\n\n"); | 388 "** Like this: \"ybsp foo.wad -o tmp.wad; doom -file tmp.wad\"\n\n"); |
384 return 0; | 389 return 0; |
385 } | 390 } |
386 | 391 |
387 | 392 |
388 /* | 393 /* |
389 * parse_environment_vars | |
390 * Check certain environment variables. | |
391 * Returns 0 on success, <>0 on error. | |
392 */ | |
393 static int parse_environment_vars() | |
394 { | |
395 char *value; | |
396 | |
397 value = getenv("YADEX_GAME"); | |
398 if (value != NULL) | |
399 Game = value; | |
400 return 0; | |
401 } | |
402 | |
403 | |
404 /* | |
405 play a fascinating tune | 394 play a fascinating tune |
406 */ | 395 */ |
407 | 396 |
408 void Beep() | 397 void Beep() |
409 { | 398 { |
428 freq = msec; // To prevent a warning about unused variables | 417 freq = msec; // To prevent a warning about unused variables |
429 return; | 418 return; |
430 #endif | 419 #endif |
431 } | 420 } |
432 | 421 |
422 | |
423 | |
424 /* | |
425 * print_error_message | |
426 * Print an error message to stderr. | |
427 */ | |
428 static void print_error_message(const char *fmt, va_list args) | |
429 { | |
430 fflush(stdout); | |
431 fputs("Error: ", stderr); | |
432 vfprintf(stderr, fmt, args); | |
433 fputc('\n', stderr); | |
434 fflush(stderr); | |
435 | |
436 if (cfg.Debug && cfg.logfile != NULL) | |
437 { | |
438 fputs("Error: ", cfg.logfile); | |
439 vfprintf(cfg.logfile, fmt, args); | |
440 fputc('\n', cfg.logfile); | |
441 fflush(cfg.logfile); | |
442 } | |
443 } | |
433 | 444 |
434 | 445 |
435 /* | 446 /* |
436 * fatal_error | 447 * fatal_error |
437 * Print an error message and terminate the program with code 2. | 448 * Print an error message and terminate the program with code 2. |
469 print_error_message(fmt, args); | 480 print_error_message(fmt, args); |
470 } | 481 } |
471 | 482 |
472 | 483 |
473 /* | 484 /* |
474 * print_error_message | |
475 * Print an error message to stderr. | |
476 */ | |
477 static void print_error_message(const char *fmt, va_list args) | |
478 { | |
479 fflush(stdout); | |
480 fputs("Error: ", stderr); | |
481 vfprintf(stderr, fmt, args); | |
482 fputc('\n', stderr); | |
483 fflush(stderr); | |
484 if (Debug && logfile != NULL) | |
485 { | |
486 fputs("Error: ", logfile); | |
487 vfprintf(logfile, fmt, args); | |
488 fputc('\n', logfile); | |
489 fflush(logfile); | |
490 } | |
491 } | |
492 | |
493 | |
494 /* | |
495 * nf_bug | 485 * nf_bug |
496 * Report about a non-fatal bug to stderr. The message | 486 * Report about a non-fatal bug to stderr. The message |
497 * should not expand to more than 80 characters. | 487 * should not expand to more than 80 characters. |
498 */ | 488 */ |
499 void nf_bug(const char *fmt, ...) | 489 void nf_bug(const char *fmt, ...) |
549 { | 539 { |
550 va_list args; | 540 va_list args; |
551 time_t tval; | 541 time_t tval; |
552 char *tstr; | 542 char *tstr; |
553 | 543 |
554 if (Debug && logfile != NULL) | 544 if (cfg.Debug && cfg.logfile != NULL) |
555 { | 545 { |
556 va_start(args, logstr); | 546 va_start(args, logstr); |
557 /* if the message begins with ":", output the current date & time first */ | 547 /* if the message begins with ":", output the current date & time first */ |
558 if (logstr[0] == ':') | 548 if (logstr[0] == ':') |
559 { | 549 { |
560 time(&tval); | 550 time(&tval); |
561 tstr = ctime(&tval); | 551 tstr = ctime(&tval); |
562 tstr[strlen(tstr) - 1] = '\0'; | 552 tstr[strlen(tstr) - 1] = '\0'; |
563 fprintf(logfile, "%s", tstr); | 553 fprintf(cfg.logfile, "%s", tstr); |
564 } | 554 } |
565 vfprintf(logfile, logstr, args); | 555 vfprintf(cfg.logfile, logstr, args); |
566 fflush(logfile); /* AYM 19971031 */ | 556 fflush(cfg.logfile); /* AYM 19971031 */ |
567 } | 557 } |
568 } | 558 } |
569 | 559 |
570 | 560 |
571 void PrintHelp() | 561 void PrintHelp() |
682 } | 672 } |
683 | 673 |
684 /* user asked to quit */ | 674 /* user asked to quit */ |
685 else if (!strcmp(com, "quit") || !strcmp(com, "q")) | 675 else if (!strcmp(com, "quit") || !strcmp(com, "q")) |
686 { | 676 { |
687 if (!Registered) | 677 if (!cfg.Registered) |
688 printf("Remember to register your copy of the game !\n"); | 678 printf("Remember to register your copy of the game !\n"); |
689 break; | 679 break; |
690 } | 680 } |
691 | 681 |
692 /* user asked to edit a level */ | 682 /* user asked to edit a level */ |
705 continue; | 695 continue; |
706 } | 696 } |
707 } | 697 } |
708 else | 698 else |
709 { | 699 { |
710 MDirPtr entry = FindMasterDir(MasterDir, com); | 700 MDirPtr entry = FindMasterDir(cfg.MasterDir, com); |
711 if (entry != NULL) | 701 if (entry != NULL) |
712 { | 702 { |
713 level_name = strdup(entry->dir.name); | 703 level_name = strdup(entry->dir.name); |
714 } | 704 } |
715 else | 705 else |
717 printf("Level '%s' not found.", com); | 707 printf("Level '%s' not found.", com); |
718 | 708 |
719 // Hint absent-minded users | 709 // Hint absent-minded users |
720 if ((tolower(*com) == 'e' && yg_level_name == YGLN_MAP01) || | 710 if ((tolower(*com) == 'e' && yg_level_name == YGLN_MAP01) || |
721 (tolower(*com) == 'm' && yg_level_name == YGLN_E1M1)) | 711 (tolower(*com) == 'm' && yg_level_name == YGLN_E1M1)) |
722 printf(" You are in %s mode.", Game); | 712 printf(" You are in %s mode.", cfg.Game); |
723 else | 713 else |
724 | 714 |
725 if (tolower(*com) == 'e' && com[1] > '1' && !Registered) | 715 if (tolower(*com) == 'e' && com[1] > '1' && !cfg.Registered) |
726 printf(" You have the shareware IWAD."); | 716 printf(" You have the shareware IWAD."); |
727 | 717 |
728 printf("\n"); | 718 printf("\n"); |
729 continue; | 719 continue; |
730 } | 720 } |
995 do | 985 do |
996 get_input_status(); | 986 get_input_status(); |
997 while (is.key != YE_EXPOSE); | 987 while (is.key != YE_EXPOSE); |
998 com = strtok(NULL, " "); | 988 com = strtok(NULL, " "); |
999 force_window_not_pixmap(); // FIXME quick hack | 989 force_window_not_pixmap(); // FIXME quick hack |
1000 patch_dir.refresh(MasterDir); | 990 patch_dir.refresh(cfg.MasterDir); |
1001 { | 991 { |
1002 char buf[WAD_NAME + 1]; | 992 char buf[WAD_NAME + 1]; |
1003 *buf = '\0'; | 993 *buf = '\0'; |
1004 if (com != 0) | 994 if (com != 0) |
1005 strncat(buf, com, sizeof buf - 1); | 995 strncat(buf, com, sizeof buf - 1); |
1023 do | 1013 do |
1024 get_input_status(); | 1014 get_input_status(); |
1025 while (is.key != YE_EXPOSE); | 1015 while (is.key != YE_EXPOSE); |
1026 com = strtok(NULL, " "); | 1016 com = strtok(NULL, " "); |
1027 force_window_not_pixmap(); // FIXME quick hack | 1017 force_window_not_pixmap(); // FIXME quick hack |
1028 patch_dir.refresh(MasterDir); | 1018 patch_dir.refresh(cfg.MasterDir); |
1029 { | 1019 { |
1030 char buf[WAD_TEX_NAME + 1]; | 1020 char buf[WAD_TEX_NAME + 1]; |
1031 *buf = '\0'; | 1021 *buf = '\0'; |
1032 if (com != 0) | 1022 if (com != 0) |
1033 strncat(buf, com, sizeof buf - 1); | 1023 strncat(buf, com, sizeof buf - 1); |