rev |
line source |
nuclear@1
|
1 #include <stdio.h>
|
nuclear@1
|
2 #include <stdlib.h>
|
nuclear@1
|
3 #include <string.h>
|
nuclear@7
|
4 #include <signal.h>
|
nuclear@14
|
5 #include <errno.h>
|
nuclear@14
|
6 #include <direct.h>
|
nuclear@1
|
7 #include "inttypes.h"
|
nuclear@1
|
8 #include "gfx.h"
|
nuclear@1
|
9 #include "keyb.h"
|
nuclear@1
|
10 #include "mouse.h"
|
nuclear@1
|
11 #include "logger.h"
|
nuclear@6
|
12 #include "scene.h"
|
nuclear@9
|
13 #include "rayzor.h"
|
nuclear@9
|
14 #include "screen.h"
|
nuclear@9
|
15 #include "modeller.h"
|
nuclear@9
|
16 #include "renderer.h"
|
nuclear@9
|
17 #include "scrman.h"
|
nuclear@10
|
18 #include "timer.h"
|
nuclear@10
|
19
|
nuclear@10
|
20 #ifdef __DOS__
|
nuclear@10
|
21 #undef USE_ASM_SWAPBUF
|
nuclear@10
|
22 #endif
|
nuclear@10
|
23
|
nuclear@10
|
24 #ifdef USE_ASM_SWAPBUF
|
nuclear@10
|
25 // defined in swapbuf.asm
|
nuclear@10
|
26 extern "C" void swap_buffers_asm(void *dest, void *src, int xsz, int ysz, int bpp);
|
nuclear@10
|
27 #endif
|
nuclear@1
|
28
|
nuclear@6
|
29 static bool init();
|
nuclear@6
|
30 static void cleanup();
|
nuclear@1
|
31 static void display();
|
nuclear@1
|
32 static void swap_buffers();
|
nuclear@9
|
33 static void draw_cursor(uint32_t *buf, int mx, int my);
|
nuclear@14
|
34 static void screenshot();
|
nuclear@1
|
35 static void handle_keyboard();
|
nuclear@1
|
36 static void handle_mouse();
|
nuclear@1
|
37 static bool parse_args(int argc, char **argv);
|
nuclear@7
|
38 static void sig(int s);
|
nuclear@1
|
39
|
nuclear@9
|
40 uint32_t *fb_pixels;
|
nuclear@9
|
41 int fb_width = 640;
|
nuclear@9
|
42 int fb_height = 480;
|
nuclear@9
|
43 int fb_bpp = 32;
|
nuclear@9
|
44 Scene *scene;
|
nuclear@9
|
45
|
nuclear@6
|
46 static bool novideo;
|
nuclear@9
|
47 static void *fb;
|
nuclear@1
|
48 static int rbits, gbits, bbits;
|
nuclear@1
|
49 static int rshift, gshift, bshift;
|
nuclear@1
|
50 static unsigned int rmask, gmask, bmask;
|
nuclear@1
|
51
|
nuclear@10
|
52 static bool use_asm_swap = true;
|
nuclear@7
|
53 static bool use_mouse;
|
nuclear@9
|
54 static int mouse_x, mouse_y;
|
nuclear@1
|
55 static bool quit;
|
nuclear@14
|
56 static bool cap_shot;
|
nuclear@1
|
57
|
nuclear@1
|
58 int main(int argc, char **argv)
|
nuclear@1
|
59 {
|
nuclear@10
|
60 unsigned long start_msec, msec;
|
nuclear@10
|
61 unsigned long nframes = 0;
|
nuclear@10
|
62
|
nuclear@1
|
63 if(!parse_args(argc, argv)) {
|
nuclear@1
|
64 return 1;
|
nuclear@1
|
65 }
|
nuclear@6
|
66 if(!init()) {
|
nuclear@1
|
67 return 1;
|
nuclear@1
|
68 }
|
nuclear@1
|
69
|
nuclear@10
|
70 start_msec = get_msec();
|
nuclear@10
|
71
|
nuclear@1
|
72 // main loop
|
nuclear@1
|
73 for(;;) {
|
nuclear@1
|
74 handle_keyboard();
|
nuclear@1
|
75 handle_mouse();
|
nuclear@1
|
76 if(quit) break;
|
nuclear@1
|
77
|
nuclear@1
|
78 display();
|
nuclear@10
|
79 ++nframes;
|
nuclear@6
|
80
|
nuclear@6
|
81 if(novideo) break;
|
nuclear@1
|
82 }
|
nuclear@1
|
83
|
nuclear@10
|
84 msec = get_msec() - start_msec;
|
nuclear@10
|
85
|
nuclear@6
|
86 cleanup();
|
nuclear@10
|
87
|
nuclear@10
|
88 printf("Average framerate: %g\n", (float)nframes / ((float)msec / 1000.0f));
|
nuclear@1
|
89 printf("Thank you for using Rayzor!\n");
|
nuclear@1
|
90 return 0;
|
nuclear@1
|
91 }
|
nuclear@1
|
92
|
nuclear@9
|
93 void quit_app()
|
nuclear@9
|
94 {
|
nuclear@9
|
95 quit = true;
|
nuclear@9
|
96 }
|
nuclear@9
|
97
|
nuclear@6
|
98 static bool init()
|
nuclear@6
|
99 {
|
nuclear@7
|
100 signal(SIGINT, sig);
|
nuclear@7
|
101 signal(SIGSEGV, sig);
|
nuclear@7
|
102 signal(SIGILL, sig);
|
nuclear@7
|
103 signal(SIGFPE, sig);
|
nuclear@7
|
104
|
nuclear@10
|
105 init_timer(128);
|
nuclear@10
|
106
|
nuclear@6
|
107 if(!novideo) {
|
nuclear@6
|
108 if(kb_init(32) == -1) {
|
nuclear@6
|
109 fprintf(stderr, "failed to initialize keyboard driver\n");
|
nuclear@6
|
110 return false;
|
nuclear@6
|
111 }
|
nuclear@6
|
112
|
nuclear@9
|
113 if(!(fb = set_video_mode(fb_width, fb_height, fb_bpp))) {
|
nuclear@6
|
114 set_text_mode();
|
nuclear@9
|
115 fprintf(stderr, "failed to set video mode: %dx%d %dbpp\n", fb_width, fb_height, fb_bpp);
|
nuclear@6
|
116 return false;
|
nuclear@6
|
117 }
|
nuclear@9
|
118 fb_bpp = get_color_depth();
|
nuclear@6
|
119 get_color_bits(&rbits, &gbits, &bbits);
|
nuclear@6
|
120 get_color_shift(&rshift, &gshift, &bshift);
|
nuclear@6
|
121 get_color_mask(&rmask, &gmask, &bmask);
|
nuclear@6
|
122
|
nuclear@10
|
123 printlog("video resolution: %dx%d\n", fb_width, fb_height);
|
nuclear@9
|
124 printlog("bpp: %d (%d %d %d)\n", fb_bpp, rbits, gbits, bbits);
|
nuclear@6
|
125 printlog("shift: %d %d %d\n", rshift, gshift, bshift);
|
nuclear@6
|
126 printlog("mask: %x %x %x\n", rmask, gmask, bmask);
|
nuclear@7
|
127
|
nuclear@7
|
128 if(have_mouse()) {
|
nuclear@7
|
129 use_mouse = true;
|
nuclear@9
|
130 set_mouse_limits(0, 0, fb_width - 1, fb_height - 1);
|
nuclear@7
|
131 }
|
nuclear@6
|
132 } else {
|
nuclear@6
|
133 logger_output(stdout);
|
nuclear@6
|
134 printlog("novideo (debug) mode\n");
|
nuclear@10
|
135 fb_bpp = 24;
|
nuclear@6
|
136 rbits = gbits = bbits = 8;
|
nuclear@6
|
137 }
|
nuclear@6
|
138
|
nuclear@9
|
139 fb_pixels = new uint32_t[fb_width * fb_height * 4];
|
nuclear@9
|
140 if(!fb_pixels) {
|
nuclear@6
|
141 return false;
|
nuclear@6
|
142 }
|
nuclear@6
|
143
|
nuclear@9
|
144 scene = new Scene;
|
nuclear@6
|
145
|
nuclear@6
|
146 Sphere *sph = new Sphere;
|
nuclear@12
|
147 scene->add(sph);
|
nuclear@12
|
148
|
nuclear@12
|
149 Box *box = new Box;
|
nuclear@12
|
150 scene->add(box);
|
nuclear@12
|
151 box->set_scaling(Vector3(2, 0.25, 2));
|
nuclear@6
|
152
|
nuclear@9
|
153 Modeller *modeller = new Modeller;
|
nuclear@9
|
154 if(!modeller->init()) {
|
nuclear@9
|
155 return false;
|
nuclear@9
|
156 }
|
nuclear@9
|
157 add_screen(modeller);
|
nuclear@9
|
158
|
nuclear@9
|
159 Renderer *renderer = new Renderer;
|
nuclear@9
|
160 if(!renderer->init()) {
|
nuclear@9
|
161 return false;
|
nuclear@9
|
162 }
|
nuclear@9
|
163 add_screen(renderer);
|
nuclear@9
|
164
|
nuclear@9
|
165 activate_screen(modeller); // start the modeller screen
|
nuclear@6
|
166 return true;
|
nuclear@6
|
167 }
|
nuclear@6
|
168
|
nuclear@6
|
169 static void cleanup()
|
nuclear@6
|
170 {
|
nuclear@9
|
171 delete scene;
|
nuclear@9
|
172 delete [] fb_pixels;
|
nuclear@6
|
173
|
nuclear@9
|
174 destroy_screens();
|
nuclear@6
|
175
|
nuclear@6
|
176 if(!novideo) {
|
nuclear@6
|
177 set_text_mode();
|
nuclear@6
|
178 kb_shutdown();
|
nuclear@6
|
179 }
|
nuclear@6
|
180 }
|
nuclear@6
|
181
|
nuclear@1
|
182 static void display()
|
nuclear@1
|
183 {
|
nuclear@9
|
184 Screen *scr = active_screen();
|
nuclear@9
|
185 if(scr) {
|
nuclear@9
|
186 scr->update();
|
nuclear@9
|
187 scr->draw();
|
nuclear@9
|
188 }
|
nuclear@6
|
189
|
nuclear@7
|
190 // draw the mouse cursor
|
nuclear@7
|
191 if(use_mouse) {
|
nuclear@9
|
192 draw_cursor(fb_pixels, mouse_x, mouse_y);
|
nuclear@7
|
193 }
|
nuclear@7
|
194
|
nuclear@14
|
195 if(cap_shot) {
|
nuclear@14
|
196 screenshot();
|
nuclear@14
|
197 cap_shot = false;
|
nuclear@14
|
198 }
|
nuclear@14
|
199
|
nuclear@6
|
200 if(!novideo) {
|
nuclear@10
|
201 wait_vsync();
|
nuclear@10
|
202 #ifdef USE_ASM_SWAPBUF
|
nuclear@10
|
203 swap_buffers_asm(fb, fb_pixels, fb_width, fb_height, fb_bpp);
|
nuclear@10
|
204 #else
|
nuclear@6
|
205 swap_buffers();
|
nuclear@10
|
206 #endif
|
nuclear@1
|
207 }
|
nuclear@1
|
208 }
|
nuclear@1
|
209
|
nuclear@1
|
210 #define PACK_RGB(r, g, b) \
|
nuclear@1
|
211 ((((r) << rshift) & rmask) | \
|
nuclear@1
|
212 (((g) << gshift) & gmask) | \
|
nuclear@1
|
213 (((b) << bshift) & bmask))
|
nuclear@1
|
214
|
nuclear@11
|
215 #define UNPACK_RED(c) (((c) >> 16) & 0xff)
|
nuclear@9
|
216 #define UNPACK_GREEN(c) (((c) >> 8) & 0xff)
|
nuclear@11
|
217 #define UNPACK_BLUE(c) ((c) & 0xff)
|
nuclear@9
|
218
|
nuclear@1
|
219 static void swap_buffers()
|
nuclear@1
|
220 {
|
nuclear@9
|
221 uint32_t *src = fb_pixels;
|
nuclear@9
|
222 int num_pixels = fb_width * fb_height;
|
nuclear@1
|
223
|
nuclear@9
|
224 switch(fb_bpp) {
|
nuclear@1
|
225 case 32:
|
nuclear@9
|
226 memcpy(fb, fb_pixels, num_pixels * 4);
|
nuclear@1
|
227 break;
|
nuclear@1
|
228
|
nuclear@1
|
229 case 24:
|
nuclear@9
|
230 {
|
nuclear@9
|
231 unsigned char *dest = (unsigned char*)fb;
|
nuclear@10
|
232 for(int i=0; i<num_pixels-1; i++) {
|
nuclear@10
|
233 *((uint32_t*)dest) = *src++;
|
nuclear@10
|
234 dest += 3;
|
nuclear@9
|
235 }
|
nuclear@10
|
236 *dest++ = UNPACK_RED(*src);
|
nuclear@10
|
237 *dest++ = UNPACK_GREEN(*src);
|
nuclear@10
|
238 *dest++ = UNPACK_BLUE(*src);
|
nuclear@9
|
239 }
|
nuclear@1
|
240 break;
|
nuclear@1
|
241
|
nuclear@1
|
242 case 16:
|
nuclear@1
|
243 {
|
nuclear@1
|
244 uint16_t *dest = (uint16_t*)fb;
|
nuclear@1
|
245 for(int i=0; i<num_pixels; i++) {
|
nuclear@9
|
246 uint32_t c = *src++;
|
nuclear@9
|
247 unsigned char r = UNPACK_RED(c);
|
nuclear@9
|
248 unsigned char g = UNPACK_GREEN(c);
|
nuclear@9
|
249 unsigned char b = UNPACK_BLUE(c);
|
nuclear@9
|
250
|
nuclear@11
|
251 *dest++ = (((r) << 8) & 0xf800) |
|
nuclear@11
|
252 (((g) << 3) & 0x7e0) |
|
nuclear@11
|
253 (((b) >> 3) & 0x1f);
|
nuclear@1
|
254 }
|
nuclear@1
|
255 }
|
nuclear@1
|
256 break;
|
nuclear@1
|
257
|
nuclear@1
|
258 default:
|
nuclear@1
|
259 break;
|
nuclear@1
|
260 }
|
nuclear@1
|
261 }
|
nuclear@1
|
262
|
nuclear@9
|
263 static void draw_cursor(uint32_t *buf, int mx, int my)
|
nuclear@7
|
264 {
|
nuclear@9
|
265 uint32_t *cptr = buf + my * fb_width + mx;
|
nuclear@7
|
266 int i, cw[2] = {4, 4}, ch[2] = {4, 4};
|
nuclear@7
|
267
|
nuclear@7
|
268 if(mx < cw[0]) cw[0] = mx;
|
nuclear@7
|
269 if(my < ch[0]) ch[0] = my;
|
nuclear@9
|
270 if(fb_width - mx < cw[1]) cw[1] = fb_width - mx - 1;
|
nuclear@9
|
271 if(fb_height - my < ch[1]) ch[1] = fb_height - my - 1;
|
nuclear@7
|
272
|
nuclear@7
|
273 for(i=1; i<cw[0]; i++) {
|
nuclear@9
|
274 int idx = -i;
|
nuclear@9
|
275 cptr[idx] = 0xffffff;
|
nuclear@7
|
276 }
|
nuclear@7
|
277 for(i=1; i<cw[1]; i++) {
|
nuclear@9
|
278 int idx = i;
|
nuclear@9
|
279 cptr[idx] = 0xffffff;
|
nuclear@7
|
280 }
|
nuclear@7
|
281 for(i=1; i<ch[0]; i++) {
|
nuclear@9
|
282 int idx = -i * fb_width;
|
nuclear@9
|
283 cptr[idx] = 0xffffff;
|
nuclear@7
|
284 }
|
nuclear@7
|
285 for(i=1; i<ch[1]; i++) {
|
nuclear@9
|
286 int idx = i * fb_width;
|
nuclear@9
|
287 cptr[idx] = 0xffffff;
|
nuclear@7
|
288 }
|
nuclear@7
|
289 }
|
nuclear@7
|
290
|
nuclear@14
|
291 #define PPM_COMMENT "screenshot saved by the rayzor modeller/renderer"
|
nuclear@14
|
292 static void screenshot()
|
nuclear@14
|
293 {
|
nuclear@14
|
294 static int shotidx = -1;
|
nuclear@14
|
295 FILE *fp;
|
nuclear@14
|
296 char fname[PATH_MAX];
|
nuclear@14
|
297
|
nuclear@14
|
298 if(shotidx == -1) {
|
nuclear@14
|
299 DIR *dir;
|
nuclear@14
|
300 struct dirent *dent;
|
nuclear@14
|
301
|
nuclear@14
|
302 shotidx = 0;
|
nuclear@14
|
303 if((dir = opendir("."))) {
|
nuclear@14
|
304 while((dent = readdir(dir))) {
|
nuclear@14
|
305 int i, num;
|
nuclear@14
|
306 for(i=0; dent->d_name[i]; i++) {
|
nuclear@14
|
307 fname[i] = tolower(dent->d_name[i]);
|
nuclear@14
|
308 }
|
nuclear@14
|
309 fname[i] = 0;
|
nuclear@14
|
310
|
nuclear@14
|
311 if(sscanf(fname, "shot%d.ppm", &num) == 1 && num > shotidx) {
|
nuclear@14
|
312 shotidx = num;
|
nuclear@14
|
313 }
|
nuclear@14
|
314 }
|
nuclear@14
|
315 closedir(dir);
|
nuclear@14
|
316 }
|
nuclear@14
|
317 }
|
nuclear@14
|
318
|
nuclear@14
|
319 sprintf(fname, "shot%04d.ppm", ++shotidx);
|
nuclear@14
|
320 if(!(fp = fopen(fname, "wb"))) {
|
nuclear@14
|
321 printlog("failed to save screenshot %s: %s\n", fname, strerror(errno));
|
nuclear@14
|
322 return;
|
nuclear@14
|
323 }
|
nuclear@14
|
324
|
nuclear@14
|
325 fprintf(fp, "P6\n" PPM_COMMENT "\n%d %d\n255\n", fb_width, fb_height);
|
nuclear@14
|
326 for(int i=0; i<fb_width * fb_height; i++) {
|
nuclear@14
|
327 uint32_t c = fb_pixels[i];
|
nuclear@14
|
328 fputc(UNPACK_RED(c), fp);
|
nuclear@14
|
329 fputc(UNPACK_GREEN(c), fp);
|
nuclear@14
|
330 fputc(UNPACK_BLUE(c), fp);
|
nuclear@14
|
331 }
|
nuclear@14
|
332
|
nuclear@14
|
333 fclose(fp);
|
nuclear@14
|
334 }
|
nuclear@14
|
335
|
nuclear@1
|
336 static void handle_keyboard()
|
nuclear@1
|
337 {
|
nuclear@5
|
338 int key;
|
nuclear@9
|
339 Screen *scr = active_screen();
|
nuclear@1
|
340
|
nuclear@6
|
341 if(novideo) return;
|
nuclear@6
|
342
|
nuclear@5
|
343 while((key = kb_getkey()) != -1) {
|
nuclear@10
|
344 switch(key) {
|
nuclear@10
|
345 case '`':
|
nuclear@10
|
346 use_asm_swap = !use_asm_swap;
|
nuclear@10
|
347 break;
|
nuclear@10
|
348
|
nuclear@12
|
349 case 'q':
|
nuclear@12
|
350 case 'x':
|
nuclear@12
|
351 if(kb_isdown(KB_ALT)) {
|
nuclear@12
|
352 quit_app();
|
nuclear@12
|
353 }
|
nuclear@12
|
354 break;
|
nuclear@12
|
355
|
nuclear@14
|
356 case KB_SYSRQ:
|
nuclear@14
|
357 case KB_F12:
|
nuclear@14
|
358 cap_shot = true;
|
nuclear@14
|
359 break;
|
nuclear@14
|
360
|
nuclear@10
|
361 default:
|
nuclear@10
|
362 break;
|
nuclear@10
|
363 }
|
nuclear@9
|
364 scr->handle_keyboard(key, true); // TODO also generate release events...
|
nuclear@1
|
365 }
|
nuclear@1
|
366 }
|
nuclear@1
|
367
|
nuclear@1
|
368 static void handle_mouse()
|
nuclear@1
|
369 {
|
nuclear@9
|
370 static int prev_mx, prev_my, prev_bnmask, bndiff;
|
nuclear@9
|
371 int mx, my, bnmask;
|
nuclear@9
|
372 Screen *scr = active_screen();
|
nuclear@7
|
373
|
nuclear@7
|
374 if(!use_mouse || novideo) return;
|
nuclear@7
|
375
|
nuclear@7
|
376 bnmask = read_mouse(&mx, &my);
|
nuclear@9
|
377 if(scr && (bndiff = bnmask ^ prev_bnmask)) {
|
nuclear@9
|
378 for(int i=0; i<8; i++) {
|
nuclear@9
|
379 int bit = 1 << i;
|
nuclear@9
|
380 if(bndiff & bit) {
|
nuclear@9
|
381 scr->handle_mbutton(i, bnmask & bit, mx, my);
|
nuclear@9
|
382 }
|
nuclear@9
|
383 }
|
nuclear@7
|
384 }
|
nuclear@9
|
385 prev_bnmask = bnmask;
|
nuclear@9
|
386
|
nuclear@9
|
387 if(scr && (mx != prev_mx || my != prev_my)) {
|
nuclear@9
|
388 scr->handle_mmotion(mx, my);
|
nuclear@7
|
389 }
|
nuclear@9
|
390 prev_mx = mx;
|
nuclear@9
|
391 prev_my = my;
|
nuclear@10
|
392
|
nuclear@10
|
393 mouse_x = mx;
|
nuclear@10
|
394 mouse_y = my;
|
nuclear@7
|
395 }
|
nuclear@7
|
396
|
nuclear@1
|
397
|
nuclear@1
|
398 static struct {
|
nuclear@1
|
399 int opt;
|
nuclear@1
|
400 const char *lopt;
|
nuclear@1
|
401 const char *desc;
|
nuclear@1
|
402 } options[] = {
|
nuclear@1
|
403 {'s', "size", "resolution <xres>x<yres>[:bpp]"},
|
nuclear@6
|
404 {'n', "novid", "don't switch video mode (for debugging)"},
|
nuclear@1
|
405 {'h', "help", "print usage information and exit"},
|
nuclear@1
|
406 {-1, 0, 0}
|
nuclear@1
|
407 };
|
nuclear@1
|
408
|
nuclear@1
|
409 static void print_usage(const char *argv0)
|
nuclear@1
|
410 {
|
nuclear@1
|
411 printf("%s usage\n", argv0);
|
nuclear@1
|
412 for(int i=0; options[i].opt != -1; i++) {
|
nuclear@1
|
413 printf(" -%c, -%s: %s\n", options[i].opt, options[i].lopt, options[i].desc);
|
nuclear@1
|
414 }
|
nuclear@1
|
415 exit(0);
|
nuclear@1
|
416 }
|
nuclear@1
|
417
|
nuclear@1
|
418 static bool parse_args(int argc, char **argv)
|
nuclear@1
|
419 {
|
nuclear@1
|
420 for(int i=1; i<argc; i++) {
|
nuclear@1
|
421 if(argv[i][0] == '-') {
|
nuclear@1
|
422 int opt = -1;
|
nuclear@1
|
423
|
nuclear@1
|
424 for(int j=0; options[j].opt != -1; j++) {
|
nuclear@1
|
425 if(argv[i][2] == 0) {
|
nuclear@1
|
426 if(argv[i][1] == options[j].opt) {
|
nuclear@1
|
427 opt = options[j].opt;
|
nuclear@1
|
428 break;
|
nuclear@1
|
429 }
|
nuclear@1
|
430 } else {
|
nuclear@1
|
431 if(strcmp(argv[i] + 1, options[j].lopt) == 0) {
|
nuclear@1
|
432 opt = options[j].opt;
|
nuclear@1
|
433 break;
|
nuclear@1
|
434 }
|
nuclear@1
|
435 }
|
nuclear@1
|
436 }
|
nuclear@1
|
437
|
nuclear@1
|
438 switch(opt) {
|
nuclear@1
|
439 case 's':
|
nuclear@9
|
440 if(sscanf(argv[++i], "%dx%d:%d", &fb_width, &fb_height, &fb_bpp) < 2) {
|
nuclear@1
|
441 fprintf(stderr, "%s must be followed by a resolution: WxH\n", argv[i - 1]);
|
nuclear@1
|
442 return false;
|
nuclear@1
|
443 }
|
nuclear@1
|
444 break;
|
nuclear@1
|
445
|
nuclear@6
|
446 case 'n':
|
nuclear@6
|
447 novideo = true;
|
nuclear@6
|
448 break;
|
nuclear@6
|
449
|
nuclear@1
|
450 case 'h':
|
nuclear@1
|
451 print_usage(argv[0]); // doesn't return
|
nuclear@1
|
452 break;
|
nuclear@1
|
453
|
nuclear@1
|
454 default:
|
nuclear@1
|
455 fprintf(stderr, "unknown option: %s\n", argv[i]);
|
nuclear@1
|
456 return false;
|
nuclear@1
|
457 }
|
nuclear@1
|
458 } else {
|
nuclear@1
|
459 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
|
nuclear@1
|
460 return false;
|
nuclear@1
|
461 }
|
nuclear@1
|
462 }
|
nuclear@1
|
463 return true;
|
nuclear@1
|
464 }
|
nuclear@7
|
465
|
nuclear@7
|
466 static void sig(int s)
|
nuclear@7
|
467 {
|
nuclear@7
|
468 cleanup();
|
nuclear@7
|
469 fprintf(stderr, "signal caught: %d\n", s);
|
nuclear@9
|
470 exit(1);
|
nuclear@7
|
471 }
|