+ // read x axis
+ if(parse_next_int(&arg, &opt_joystick_x_axis)) {
+ puts(bad_arg);
+ return 0;
+ }
+
+ // skip comma
+ if(*arg != ',') {
+ puts(bad_arg);
+ return 0;
+ }
+ arg += 1;
+
+ // read y axis
+ if(parse_next_int(&arg, &opt_joystick_y_axis)) {
+ puts(bad_arg);
+ return 0;
+ }
+
+ // optionally joystick number
+ if(*arg == ',') {
+ arg += 1; // skip comma
+ if(parse_next_int(&arg, &opt_joystick_number)) {
+ puts(bad_arg);
+ return 0;
+ }
+ opt_joystick_enabled = 1;
+ }
+
+ // end with a comma or end of string
+ if(*arg != 0 && *arg != ',') {
+ puts(bad_arg);
+ return 0;
+ }
+
+ // mark arg as consumed (so it won't be parsed as a commandline switch)
+ arg_was[0] = 0;
+
+ // return success
+ return 1;
+}
+int
+short_opt(char c, char *arg)
+{
+ switch(c) {
+ case 'f': opt_fullscreen = 1; break;
+ case 's': opt_sound = 0; break;
+ case 'j':
+ return parse_joystick_opts(arg);
+ 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);
+}
+
+static char *long_opts[] = { "full-screen", "silent", "joystick", "version", "help", "autopilot" };
+
+static char short_opts[] = { 'f', 's', 'j', 'V', 'h', 'a' };
+
+int
+parse_long_opt(const char *s, char *arg)
+{
+ int i;
+ for(i=0; i<sizeof(short_opts); i++) {
+ if(strcmp(s, long_opts[i]) == 0)
+ return short_opt(short_opts[i], arg);
+ }
+ fprintf(stderr, "unknown long option --%s\n\n", s);
+ return 0;
+}