17 puts("Dodge the rocks until you die.");
19 puts(" -f, --full-screen");
20 puts(" -s, --silent No explosion sounds or music");
21 puts(" -V, --version Print program version");
22 puts(" -?, --help Give this help list");
24 puts("Report bugs at http://jasonwoof.com/contact.html");
28 short_opt(char c, char *arg)
31 case 'f': opt_fullscreen = 1; break;
32 case 's': opt_sound = 0; break;
34 printf("Variations on Rockdodger %s\n", PACKAGE_VERSION);
38 case 'a': opt_autopilot = 1; break;
40 fprintf(stderr, "unknown option -%c\n\n", c);
47 parse_short_opts(const char *s, char *arg)
49 while(s[1]) if(!short_opt(*s++, NULL)) return 0;
50 return short_opt(*s, arg);
53 static char *long_opts[] = { "full-screen", "silent", "version", "help", "autopilot" };
55 static char short_opts[] = { 'f', 's', 'V', 'h', 'a' };
58 parse_long_opt(const char *s, char *arg)
61 for(i=0; i<sizeof(short_opts); i++) {
62 if(strcmp(s, long_opts[i]) == 0)
63 return short_opt(short_opts[i], arg);
65 fprintf(stderr, "unknown long option --%s\n\n", s);
78 parse_opts(int argc, char *argv[])
84 for(i=1; i<argc; i++) {
86 s = argv[i]; if(!*s) continue;
88 fputs("not an option\n\n", stderr);
94 for(r=s; *r; r++) if(*r == '=') { *r = 0; arg = r+1; break; }
95 if(!arg && (i+1 < argc)) arg = argv[i+1];
98 if(!parse_long_opt(s+1, arg)) { show_help(); return 0; }
100 if(!parse_short_opts(s, arg)) { show_help(); return 0; }