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("Report bugs at http://jasonwoof.com/contact.html");
27 short_opt(char c, char *arg)
30 case 'f': opt_fullscreen = 1; break;
31 case 's': opt_sound = 0; break;
33 printf("Variations on Rockdodger %s\n", VERSION);
37 case 'a': opt_autopilot = 1; break;
39 fprintf(stderr, "unknown option -%c\n\n", c);
46 parse_short_opts(const char *s, char *arg)
48 while(s[1]) if(!short_opt(*s++, NULL)) return 0;
49 return short_opt(*s, arg);
52 static char *long_opts[] = { "full-screen", "silent", "version", "help", "autopilot" };
54 static char short_opts[] = { 'f', 's', 'V', 'h', 'a' };
57 parse_long_opt(const char *s, char *arg)
60 for(i=0; i<sizeof(short_opts); i++) {
61 if(strcmp(s, long_opts[i]) == 0)
62 return short_opt(short_opts[i], arg);
64 fprintf(stderr, "unknown long option --%s\n\n", s);
77 parse_opts(int argc, char *argv[])
83 for(i=1; i<argc; i++) {
85 s = argv[i]; if(!*s) continue;
87 fputs("not an option\n\n", stderr);
93 for(r=s; *r; r++) if(*r == '=') { *r = 0; arg = r+1; break; }
94 if(!arg && (i+1 < argc)) arg = argv[i+1];
97 if(!parse_long_opt(s+1, arg)) { show_help(); return 0; }
99 if(!parse_short_opts(s, arg)) { show_help(); return 0; }