Skip to content

Commit

Permalink
Add macros to check true/false
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha0552 authored Aug 18, 2024
1 parent c5a700e commit 10364e8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,41 +122,31 @@ 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(argv[++i], &iterations_before_switch)) {
goto usage;
}
IS_TRUE(parse_uint(argv[++i], &iterations_before_switch), usage);
}

// 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(argv[++i], &performance_state_high)) {
goto usage;
}
IS_TRUE(parse_uint(argv[++i], &performance_state_high), usage);
}

// 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(argv[++i], &performance_state_low)) {
goto usage;
}
IS_TRUE(parse_uint(argv[++i], &performance_state_low), usage);
}

// 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(argv[++i], &sleep_interval)) {
goto usage;
}
IS_TRUE(parse_uint(argv[++i], &sleep_interval), usage);
}

// Check if the option is "-tt" or "--temperature-threshold" and if there is a next argument
if ((IS_OPTION("-tt") || IS_OPTION("--temperature-threshold")) && HAS_NEXT_ARG) {
// Parse the integer option and store it in sleep_interval
if (!parse_uint(argv[++i], &temperature_threshold)) {
goto usage;
}
// Parse the integer option and store it in temperature_threshold
IS_TRUE(parse_uint(argv[++i], &temperature_threshold), usage);
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
// Macro to check if there is a next argument
#define HAS_NEXT_ARG (i + 1 < argc)

// Macro to check if a condition is true and jump to a label if it is not
#define IS_TRUE(call, label) do { \
/* Evaluate the condition */ \
int result = (call); \
\
/* Check if the condition is false */ \
if (!result) { \
/* Jump to the specified label */ \
goto label; \
} \
} while(0);

// Macro to check if a condition is false and jump to a label if it is not
#define IS_FALSE(call, label) do { \
/* Evaluate the condition */ \
int result = (call); \
\
/* Check if the condition is true */ \
if (result) { \
/* Jump to the specified label */ \
goto label; \
} \
} while(0);

// Macro to simplify NVAPI function calls and handle errors
#define NVAPI_CALL(call, label) do { \
/* Evaluate the NVAPI function call and store the result */ \
Expand Down

0 comments on commit 10364e8

Please sign in to comment.