14 puts("Dodge the rocks until you die.");
16 puts(" -f, --full-screen");
17 puts(" -s, --silent No explosion sounds or music");
18 puts(" -V, --version Print program version");
19 puts(" -?, --help Give this help list");
21 puts("Mandatory or optional arguments to long options are also mandatory or optional");
22 puts("for any corresponding short options.");
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", VERSION);
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" };
54 static char short_opts[] = { 'f', 's', 'V', 'h' };
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);
76 parse_opts(int argc, char *argv[])
82 for(i=1; i<argc; i++) {
84 s = argv[i]; if(!*s) continue;
86 fputs("not an option\n\n", stderr);
92 for(r=s; *r; r++) if(*r == '=') { *r = 0; arg = r+1; break; }
93 if(!arg && (i+1 < argc)) arg = argv[i+1];
96 if(!parse_long_opt(s+1, arg)) { show_help(); return 0; }
98 if(!parse_short_opts(s, arg)) { show_help(); return 0; }