20 puts("Dodge the rocks until you die.");
22 puts(" Gameplay Variations:");
23 puts(" -b, --bounciness=N% Keep N% of speed when hitting edges (default 50%)");
24 puts(" -g, --game-speed=N% 50-200% (default 100%)");
26 puts(" Look and Feel:");
27 puts(" -f, --full-screen");
28 puts(" -m, --music Enable music");
29 puts(" -s, --silent No explosion sounds or music");
31 puts(" Informational:");
32 puts(" -?, --help Give this help list");
33 puts(" -V, --version Print program version");
35 puts("Mandatory or optional arguments to long options are also mandatory or optional");
36 puts("for any corresponding short options.");
38 puts("Report bugs to <josh@qualdan.com>.");
42 short_opt(char c, char *arg)
47 case 'b': if(!arg || sscanf(arg, "%d%%", &i) != 1 || i < 0 || i > 100) {
48 fprintf(stderr, "bad --bounciness (-b) value (should be 0-100%%)\n\n");
51 opt_bounciness = (float)i / 100;
54 case 'f': opt_fullscreen = 1; break;
55 case 'g': if(!arg || sscanf(arg, "%d%%", &i) != 1 || i < 50 || i > 200) {
56 fprintf(stderr, "bad --game-speed (-g) value (should be 50-200%%)\n\n");
59 opt_gamespeed = (float)i / 100;
62 case 'l': if(sscanf(arg, "%f", &opt_max_lead) != 1) {
63 fprintf(stderr, "bad --max-lead (-l) value (must be a number)\n\n");
66 opt_max_lead *= XSIZE;
69 case 'm': opt_music = 1; break;
70 case 's': opt_sound = 0; opt_music = 0; break;
72 printf("Variations on Rockdodger %s\n", VERSION);
77 fprintf(stderr, "unknown option -%c\n\n", c);
84 parse_short_opts(const char *s, char *arg)
86 while(s[1]) if(!short_opt(*s++, NULL)) return 0;
87 return short_opt(*s, arg);
90 static char *long_opts[] = {
91 "bounciness", "game-speed",
92 "full-screen", "music", "silent",
96 static char short_opts[] = {
103 parse_long_opt(const char *s, char *arg)
106 for(i=0; i<sizeof(short_opts); i++) {
107 if(strcmp(s, long_opts[i]) == 0)
108 return short_opt(short_opts[i], arg);
110 fprintf(stderr, "unknown long option --%s\n\n", s);
117 // Gameplay Variations
118 opt_bounciness = 0.50; // lose 50% when you hit the screen edge.
119 opt_gamespeed = 1.00; // Run game at full speed.
120 opt_max_lead = 1.00*XSIZE; // you can get 1 screen ahead.
129 parse_opts(int argc, char *argv[])
135 for(i=1; i<argc; i++) {
137 s = argv[i]; if(!*s) continue;
139 fputs("not an option\n\n", stderr);
145 for(r=s; *r; r++) if(*r == '=') { *r = 0; arg = r+1; break; }
146 if(!arg && (i+1 < argc)) arg = argv[i+1];
149 if(!parse_long_opt(s+1, arg)) { show_help(); return 0; }
151 if(!parse_short_opts(s, arg)) { show_help(); return 0; }