diff --git a/include/util.h b/include/util.h index 305d7d8..5840ae0 100644 --- a/include/util.h +++ b/include/util.h @@ -18,6 +18,6 @@ void remove_last_part_of_path(char *fullpath); char *kind_as_string(char *s, int kind, int n); char *version_as_string(char *s, long v, int n); bool is_comment(char *s); -struct quickcommand *command_in_quickcommands(const char *command, struct quickcommand *quickcommands, int n); +struct quickcommand *command_in_quickcommands(const char *command, const struct quickcommand *quickcommands, int n); #endif /* __UTIL_H__ */ \ No newline at end of file diff --git a/src/util.c b/src/util.c index 19322c4..fa68b82 100644 --- a/src/util.c +++ b/src/util.c @@ -93,13 +93,13 @@ bool is_comment(char *s) * @return struct quickcommand* Pointer to the found quickcommand * May return NULL if quickcommand not found. */ -struct quickcommand *command_in_quickcommands(const char *command_key, struct quickcommand *quickcommands, int n) +struct quickcommand *command_in_quickcommands(const char *command_key, const struct quickcommand *quickcommands, int n) { for (int i = 0; i < n; i++) { if (strncmp(command_key, quickcommands[i].name, strlen(command_key)) == 0) { - return &quickcommands[i]; + return (struct quickcommand *)&quickcommands[i]; } } return NULL; diff --git a/src/vmrcli.c b/src/vmrcli.c index 006f688..a957496 100644 --- a/src/vmrcli.c +++ b/src/vmrcli.c @@ -34,6 +34,7 @@ #define OPTSTR ":hk:msc:iID:v" #define MAX_LINE 512 #define COUNT_OF(x) (sizeof(x) / sizeof(x[0])) +#define DELIMITERS " \t;," /** * @enum The kind of values a get call may return. @@ -57,13 +58,6 @@ struct result } val; }; -struct quickcommand quickcommands[] = { - {.name = "lock", .fullcommand = "command.lock=1"}, - {.name = "unlock", .fullcommand = "command.lock=0"}, - {.name = "show", .fullcommand = "command.show=1"}, - {.name = "hide", .fullcommand = "command.show=0"}, - {.name = "restart", .fullcommand = "command.restart=1"}}; - static bool vflag = false; static void usage(void); @@ -278,11 +272,11 @@ void parse_input(PT_VMR vmr, char *input) char *token, *p; - token = strtok_r(input, " \t;,", &p); + token = strtok_r(input, DELIMITERS, &p); while (token != NULL) { parse_command(vmr, token); - token = strtok_r(NULL, " \t;,", &p); + token = strtok_r(NULL, DELIMITERS, &p); } } @@ -298,6 +292,13 @@ void parse_command(PT_VMR vmr, char *command) { log_debug("Parsing %s", command); + static const struct quickcommand quickcommands[] = { + {.name = "lock", .fullcommand = "command.lock=1"}, + {.name = "unlock", .fullcommand = "command.lock=0"}, + {.name = "show", .fullcommand = "command.show=1"}, + {.name = "hide", .fullcommand = "command.show=0"}, + {.name = "restart", .fullcommand = "command.restart=1"}}; + struct quickcommand *qc_ptr = command_in_quickcommands(command, quickcommands, (int)COUNT_OF(quickcommands)); if (qc_ptr != NULL) {