From 2f2e503ae35f3b7447d95dbac0d387dea44748fe Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 10 Jul 2024 18:15:11 +0100 Subject: [PATCH] implements a short list of quickcommands --- include/util.h | 7 +++++++ src/util.c | 24 +++++++++++++++++++++++- src/vmrcli.c | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/include/util.h b/include/util.h index 19c2655..305d7d8 100644 --- a/include/util.h +++ b/include/util.h @@ -8,9 +8,16 @@ #ifndef __UTIL_H__ #define __UTIL_H__ +struct quickcommand +{ + char *name; + char *fullcommand; +}; + 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); #endif /* __UTIL_H__ */ \ No newline at end of file diff --git a/src/util.c b/src/util.c index 4b961bb..805b13a 100644 --- a/src/util.c +++ b/src/util.c @@ -81,4 +81,26 @@ char *version_as_string(char *s, long v, int n) bool is_comment(char *s) { return s[0] == '#'; -} \ No newline at end of file +} + +/** + * @brief Searches the quickcommands array for a quickcommand + * corresponding to the command_key. + * + * @param command_key The key used to search for the quickcommand + * @param quickcommands Pointer to an array of quickcommands + * @param n The number of quickcommands + * @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) +{ + for (int i = 0; i < n; i++) + { + if (strncmp(command_key, quickcommands[i].name, strlen(command_key)) == 0) + { + return &quickcommands[i]; + } + } + return NULL; +} diff --git a/src/vmrcli.c b/src/vmrcli.c index bbeb621..a02873d 100644 --- a/src/vmrcli.c +++ b/src/vmrcli.c @@ -33,6 +33,7 @@ "\ts: Launch the StreamerView application" #define OPTSTR ":hk:msc:iID:v" #define MAX_LINE 512 +#define COUNT_OF(x) (sizeof(x) / sizeof(x[0])) /** * @enum The kind of values a get call may return. @@ -56,6 +57,13 @@ 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); @@ -290,6 +298,17 @@ void parse_command(PT_VMR vmr, char *command) { log_debug("Parsing %s", command); + struct quickcommand *qc_ptr = command_in_quickcommands(command, quickcommands, (int)COUNT_OF(quickcommands)); + if (qc_ptr != NULL) + { + set_parameters(vmr, qc_ptr->fullcommand); + if (vflag) + { + printf("Setting %s\n", qc_ptr->fullcommand); + } + return; + } + if (command[0] == '!') /* toggle */ { command++;