X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=args.c;h=519833adc2685d0d25361dd0244afd82ba3affd7;hp=5ee9c356fed393fb08cc475dec93b2f6c25024a8;hb=1d9107a3d43b3f57087edee14f1eaf7c1f3db54e;hpb=4461dfec6f8f09b43ec9719523d14978d82bd124 diff --git a/args.c b/args.c index 5ee9c35..519833a 100644 --- a/args.c +++ b/args.c @@ -1,68 +1,155 @@ +#include +#include +#include #include "args.h" #include "config.h" +// Gameplay Variations +float opt_bounciness; +float opt_gamespeed; +float opt_max_lead; + +// Look and Feel int opt_fullscreen; int opt_music; int opt_sound; -float opt_bounciness; -float opt_gamespeed; -int opt_tail_engine; -int opt_friction; -error_t parse_opt(int, char*, struct argp_state *); +static void +show_help(void) +{ + puts("Dodge the rocks until you die."); + putchar('\n'); + puts(" Gameplay Variations:"); + puts(" -b, --bounciness=N% Keep N% of speed when hitting edges (default 50%)"); + puts(" -g, --game-speed=N% 50-200% (default 100%)"); + putchar('\n'); + puts(" Look and Feel:"); + puts(" -f, --full-screen"); + puts(" -m, --music Enable music"); + puts(" -s, --silent No explosion sounds or music"); + putchar('\n'); + puts(" Informational:"); + puts(" -?, --help Give this help list"); + puts(" -V, --version Print program version"); + putchar('\n'); + puts("Mandatory or optional arguments to long options are also mandatory or optional"); + puts("for any corresponding short options."); + putchar('\n'); + puts("Report bugs to ."); +} + +int +short_opt(char c, char *arg) +{ + int i; + + switch(c) { + case 'b': if(!arg || sscanf(arg, "%d%%", &i) != 1 || i < 0 || i > 100) { + fprintf(stderr, "bad --bounciness (-b) value (should be 0-100%%)\n\n"); + return 0; + } + opt_bounciness = (float)i / 100; + *arg = 0; + break; + case 'f': opt_fullscreen = 1; break; + case 'g': if(!arg || sscanf(arg, "%d%%", &i) != 1 || i < 50 || i > 200) { + fprintf(stderr, "bad --game-speed (-g) value (should be 50-200%%)\n\n"); + return 0; + } + opt_gamespeed = (float)i / 100; + *arg = 0; + break; + case 'l': if(sscanf(arg, "%f", &opt_max_lead) != 1) { + fprintf(stderr, "bad --max-lead (-l) value (must be a number)\n\n"); + return 0; + } + opt_max_lead *= XSIZE; + *arg = 0; + break; + case 'm': opt_music = 1; break; + case 's': opt_sound = 0; opt_music = 0; break; + case 'V': + printf("Variations on Rockdodger %s\n", VERSION); + exit(0); + case '?': + case 'h': return 0; + default: + fprintf(stderr, "unknown option -%c\n\n", c); + return 0; + } + return 1; +} + +int +parse_short_opts(const char *s, char *arg) +{ + while(s[1]) if(!short_opt(*s++, NULL)) return 0; + return short_opt(*s, arg); +} + +static char *long_opts[] = { + "bounciness", "game-speed", + "full-screen", "music", "silent", + "help", "version" +}; -const char *argp_program_version = "Variations on Rockdodger " VERSION; -const char *argp_program_bug_address = ""; -static char doc[] = "Dodge the rocks until you die."; -static struct argp_option opts[] = { - {0, 0, 0, 0, "Gameplay Variations:"}, - {"bounciness", 'b', "N%", 0, "keep N% of speed when hitting edges (default 50%)"}, - {"game-speed", 'g', "N%", 0, "50-100% (default 100%)"}, - {"bad-physics", 'p', 0, 0, "bad physics (i.e. friction)"}, - {0, 0, 0, 0, "Look and Feel:"}, - {"engine", 'e', 0, 0, "Display large tail plume"}, - {"full-screen", 'f', 0, 0, ""}, - {"music", 'm', 0, 0, "Enable music"}, - {"silent", 's', 0, 0, "Turn off explosion sounds"}, - {0, 0, 0, 0, "Informational:", -1}, - {0} +static char short_opts[] = { + 'b', 'g', + 'f', 'm', 's', + 'h', 'V' }; -struct argp argp = { opts, &parse_opt, 0, doc }; +int +parse_long_opt(const char *s, char *arg) +{ + int i; + for(i=0; i 100) i = 100; - opt_bounciness = (float)i / 100; - break; - case 'g': i = 0; sscanf(arg, "%d%%", &i); - if(i < 0) i = 0; else if(i > 100) i = 100; - opt_gamespeed = (float)i / 100; - break; - case 'e': opt_tail_engine = 1; break; - case 'p': opt_friction = 1; break; - default: break; + init_opts(); + for(i=1; i