Skip to content

Commit

Permalink
Fix option parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha0552 authored Aug 7, 2024
1 parent 59021b4 commit fbdece5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ int main(int argc, char *argv[]) {
// Check if the option is "-psh" or "--performance-state-high" and if there is a next argument
if ((IS_OPTION("-psh") || IS_OPTION("--performance-state-high")) && HAS_NEXT_ARG) {
// Parse the integer option and store it in performance_state_high
if (!parse_uint_option(argv[i++], &performance_state_high)) {
goto errored;
if (!parse_uint_option(argv[++i], &performance_state_high)) {
goto usage;
}

// Continue to the next argument
Expand All @@ -128,8 +128,8 @@ int main(int argc, char *argv[]) {
// Check if the option is "-ibs" or "--iterations-before-switch" and if there is a next argument
if ((IS_OPTION("-ibs") || IS_OPTION("--iterations-before-switch")) && HAS_NEXT_ARG) {
// Parse the integer option and store it in iterations_before_switch
if (!parse_uint_option(argv[i++], &iterations_before_switch)) {
goto errored;
if (!parse_uint_option(argv[++i], &iterations_before_switch)) {
goto usage;
}

// Continue to the next argument
Expand All @@ -139,8 +139,8 @@ int main(int argc, char *argv[]) {
// Check if the option is "-psl" or "--performance-state-low" and if there is a next argument
if ((IS_OPTION("-psl") || IS_OPTION("--performance-state-low")) && HAS_NEXT_ARG) {
// Parse the integer option and store it in performance_state_low
if (!parse_uint_option(argv[i++], &performance_state_low)) {
goto errored;
if (!parse_uint_option(argv[++i], &performance_state_low)) {
goto usage;
}

// Continue to the next argument
Expand All @@ -150,14 +150,17 @@ int main(int argc, char *argv[]) {
// Check if the option is "-si" or "--sleep-interval" and if there is a next argument
if ((IS_OPTION("-si") || IS_OPTION("--sleep-interval")) && HAS_NEXT_ARG) {
// Parse the integer option and store it in sleep_interval
if (!parse_uint_option(argv[i++], &sleep_interval)) {
goto errored;
if (!parse_uint_option(argv[++i], &sleep_interval)) {
goto usage;
}

// Continue to the next argument
continue;
}

// If an invalid option is encountered, print the usage instructions
usage:

// If an invalid option is provided, print the usage instructions
printf("Usage: %s [options]\n", argv[0]);
printf("\n");
Expand All @@ -167,7 +170,7 @@ int main(int argc, char *argv[]) {
printf(" -psl, --performance-state-low <value> Set the low performance state for the GPU (default: %d)\n", PERFORMANCE_STATE_LOW);
printf(" -si, --sleep-interval <value> Set the sleep interval in milliseconds between utilization checks (default: %d)\n", SLEEP_INTERVAL);

// If an invalid option is encountered, jump to the errored label
// Jump to the error handling code
goto errored;
}
}
Expand Down

0 comments on commit fbdece5

Please sign in to comment.