16 puts("Dodge the rocks until you die.");
18 puts(" -f, --full-screen");
19 puts(" -s, --silent No explosion sounds or music");
20 puts(" -V, --version Print program version");
21 puts(" -?, --help Give this help list");
23 puts("Mandatory or optional arguments to long options are also mandatory or optional");
24 puts("for any corresponding short options.");
26 puts("Report bugs at http://jasonwoof.com/contact.html");
30 short_opt(char c, char *arg)
33 case 'f': opt_fullscreen = 1; break;
34 case 's': opt_sound = 0; break;
36 printf("Variations on Rockdodger %s\n", VERSION);
40 case 'a': opt_autopilot = 1; break;
42 fprintf(stderr, "unknown option -%c\n\n", c);
49 parse_short_opts(const char *s, char *arg)
51 while(s[1]) if(!short_opt(*s++, NULL)) return 0;
52 return short_opt(*s, arg);
55 static char *long_opts[] = { "full-screen", "silent", "version", "help", "autopilot" };
57 static char short_opts[] = { 'f', 's', 'V', 'h', 'a' };
60 parse_long_opt(const char *s, char *arg)
63 for(i=0; i<sizeof(short_opts); i++) {
64 if(strcmp(s, long_opts[i]) == 0)
65 return short_opt(short_opts[i], arg);
67 fprintf(stderr, "unknown long option --%s\n\n", s);
80 parse_opts(int argc, char *argv[])
86 for(i=1; i<argc; i++) {
88 s = argv[i]; if(!*s) continue;
90 fputs("not an option\n\n", stderr);
96 for(r=s; *r; r++) if(*r == '=') { *r = 0; arg = r+1; break; }
97 if(!arg && (i+1 < argc)) arg = argv[i+1];
100 if(!parse_long_opt(s+1, arg)) { show_help(); return 0; }
102 if(!parse_short_opts(s, arg)) { show_help(); return 0; }