X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=args.c;h=5056239aed206fcc5fb828474d74c28486f63678;hp=3a40acd69c71fe9ff14af04ae075bdb7bb061172;hb=HEAD;hpb=30498ebe775df3854f28946b1373da948bd190a3 diff --git a/args.c b/args.c index 3a40acd..81a9b16 100644 --- a/args.c +++ b/args.c @@ -1,89 +1,104 @@ -#include +#include +#include +#include #include "args.h" -#include "config.h" - -// Gameplay Variations -float opt_bounciness; -float opt_gamespeed; -float opt_max_lead; -int opt_friction; +#include +#include "vorconfig.h" // Look and Feel int opt_fullscreen; -int opt_music; int opt_sound; -int opt_tail_engine; -error_t parse_opt(int, char*, struct argp_state *); +int opt_autopilot; + +static void +show_help(void) +{ + puts("Dodge the rocks until you die."); + putchar('\n'); + puts(" -f, --full-screen"); + puts(" -s, --silent No explosion sounds or music"); + puts(" -V, --version Print program version"); + puts(" -?, --help Give this help list"); + putchar('\n'); + puts("Report bugs at https://jasonwoof.com/contact"); +} + +int +short_opt(char c, char *arg) +{ + switch(c) { + case 'f': opt_fullscreen = 1; break; + case 's': opt_sound = 0; break; + case 'V': + printf("Variations on Rockdodger %s\n", PACKAGE_VERSION); + exit(0); + case '?': + case 'h': return 0; + case 'a': opt_autopilot = 1; break; + 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); +} -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%)"}, - {"max-lead", 'l', "#SCREENS", 0, "Max dist. ahead you can get (default 1 screen)\n(negative value means no limit)"}, - {"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, "No explosion sounds or music"}, - {0, 0, 0, 0, "Informational:", -1}, - {0} -}; +static char *long_opts[] = { "full-screen", "silent", "version", "help", "autopilot" }; -struct argp argp = { opts, &parse_opt, 0, doc }; +static char short_opts[] = { 'f', 's', 'V', 'h', 'a' }; + +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 'e': opt_tail_engine = 1; break; - case 'f': opt_fullscreen = 1; break; - case 'g': if(!sscanf(arg, "%d%%", &i)) { - argp_error(state, "bad --gamespeed (-g) value (should be 50-100%%)"); - return EINVAL; - } - if(i < 0) i = 0; else if(i > 100) i = 100; - opt_gamespeed = (float)i / 100; - break; - case 'l': if(!sscanf(arg, "%f", &opt_max_lead)) { - argp_error(state, "bad --max-limit (-l) value (must be a number)"); - return EINVAL; - } - opt_max_lead *= XSIZE; - break; - case 'm': opt_music = 1; break; - case 'p': opt_friction = 1; break; - case 's': opt_sound = 0; opt_music = 0; break; - default: break; + init_opts(); + for(i=1; i