diff --git a/Src/main.c b/Src/main.c index 8897ffd..f441520 100644 --- a/Src/main.c +++ b/Src/main.c @@ -753,54 +753,52 @@ optimizations(int nr) case '1': dataflow = 1 - dataflow; /* dataflow */ if (verbose&32) - printf("spin: dataflow optimizations turned %s\n", - dataflow?"on":"off"); - break; - case '2': + printf("spin: dataflow optimizations turned %s\n", + dataflow?"on":"off"); + break; + case '2': /* dead variable elimination */ deadvar = 1 - deadvar; if (verbose&32) - printf("spin: dead variable elimination turned %s\n", - deadvar?"on":"off"); - break; + printf("spin: dead variable elimination turned %s\n", + deadvar?"on":"off"); + break; case '3': /* statement merging */ merger = 1 - merger; if (verbose&32) printf("spin: statement merging turned %s\n", merger?"on":"off"); - break; - + break; case '4': /* rv optimization */ rvopt = 1 - rvopt; if (verbose&32) printf("spin: rendezvous optimization turned %s\n", rvopt?"on":"off"); - break; + break; case '5': /* case caching */ ccache = 1 - ccache; if (verbose&32) - printf("spin: case caching turned %s\n", - ccache?"on":"off"); - break; + printf("spin: case caching turned %s\n", + ccache?"on":"off"); + break; case '6': old_priority_rules = 1; if (verbose&32) - printf("spin: using old priority rules (pre version 6.2)\n"); - return 0; /* no break */ + printf("spin: using old priority rules (pre version 6.2)\n"); + return 0; /* no break */ case '7': implied_semis = 0; if (verbose&32) - printf("spin: no implied semi-colons (pre version 6.3)\n"); - return 0; /* no break */ + printf("spin: no implied semi-colons (pre version 6.3)\n"); + return 0; /* no break */ default: - printf("spin: bad or missing parameter on -o\n"); - // usage(); - break; + return -1; // TODO: Improve the failure mode for argument parsing } - return 1; + + return 0; } static void @@ -1004,7 +1002,14 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { } case 'n': args->T = atoi(arg); tl_terse = 1; break; case 'O': old_scope_rules = 1; break; - case 'o': args->usedopts += optimizations(atoi(arg)); break; + case 'o': { + args->usedopts += optimizations(arg[0]); + if (args->usedopts == -1) { + argp_failure(state, 0, 1, "bad or missing parameter on -o: %d", atoi(arg)); + return EINVAL; + } + break; + } case 'P': { assert(strlen(arg) < sizeof(PreProc)); strcpy(PreProc, arg);