From b35a29396b176fe0ad13d18ac0fd860d818a5a3a Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 10 Jul 2024 10:51:53 +0100 Subject: [PATCH] add `-I` flag for disabling `>>` on the interactive prompt return early from parse_input() if input is a comment add comments to example_commands.txt upd README. minor ver bump --- README.md | 9 ++++++--- example_commands.txt | 9 +++++++++ include/util.h | 1 + src/ivmr.c | 2 +- src/util.c | 14 +++++++++++++- src/vmrcli.c | 46 +++++++++++++++++++++++++++----------------- src/wrapper.c | 2 +- 7 files changed, 59 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9c8eadc..0587f08 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,14 @@ ## `Use` ```powershell -.\vmrcli.exe [-h] [-i] [-k] [-D] [-v] [-c] [-m] [-s] +.\vmrcli.exe [-h] [-i|-I] [-k] [-D] [-v] [-c] [-m] [-s] ``` Where: - `h`: Prints the help message. -- `i`: Enable interactive mode. If set, any api commands passed on the command line will be ignored. +- `i`: Enable interactive mode, use (-I) to disable the '>>' prompt. + - If set, any api commands passed on the command line will be ignored. - `k`: The kind of Voicemeeter (basic, banana or potato). Use this to launch the GUI. - `D`: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL - `v`: Enable extra console output (toggle, set messages) @@ -75,11 +76,13 @@ Scripts can be loaded from text files, for example in Powershell: You may also pipe a scripts contents to the CLI: ```powershell -$(Get-Content .\example_commands.txt) | .\vmrcli.exe -D1 -i +$(Get-Content .\example_commands.txt) | .\vmrcli.exe -D1 -I ``` Multiple API commands can be in a single line, they may be separated by space, `;` or `,`. +Lines starting with `#` will be interpreted as comments. + ## `Build` Run the included `makefile` with [GNU Make](https://www.gnu.org/software/make/). diff --git a/example_commands.txt b/example_commands.txt index df98f29..7636402 100644 --- a/example_commands.txt +++ b/example_commands.txt @@ -1,5 +1,14 @@ +# Strip 0 strip[0].mute !strip[0].mute strip[0].mute strip[0].gain strip[0].label=podmic strip[0].label + +# Strip 1 strip[1].mute=1 strip[1].mute strip[1].limit-=8 + +# Strip 2 strip[2].gain-=5 strip[2].comp+=4.8 + +# Bus 0 bus[0].label + +# Bus 1 bus[1].gain-=5.8 \ No newline at end of file diff --git a/include/util.h b/include/util.h index fe54f98..19c2655 100644 --- a/include/util.h +++ b/include/util.h @@ -11,5 +11,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); #endif /* __UTIL_H__ */ \ No newline at end of file diff --git a/src/ivmr.c b/src/ivmr.c index 0a10bb3..3daf97a 100644 --- a/src/ivmr.c +++ b/src/ivmr.c @@ -3,7 +3,7 @@ * @author Vincent Burel, Onyx and Iris (code@onyxandiris.online) * @brief Functions for initializing the iVMR interface. * Defines a single public function that returns a pointer to the interface. - * @version 0.7.0 + * @version 0.8.0 * @date 2024-07-06 * * @copyright Vincent Burel(c)2015-2021 All Rights Reserved diff --git a/src/util.c b/src/util.c index 3bbecd3..4b961bb 100644 --- a/src/util.c +++ b/src/util.c @@ -2,7 +2,7 @@ * @file util.c * @author Onyx and Iris (code@onyxandiris.online) * @brief Utility functions. - * @version 0.7.0 + * @version 0.8.0 * @date 2024-07-06 * * @copyright Copyright (c) 2024 @@ -69,4 +69,16 @@ char *version_as_string(char *s, long v, int n) v4 = (v & 0x000000FF); snprintf(s, n, "%i.%i.%i.%i", (int)v1, (int)v2, (int)v3, (int)v4); return s; +} + +/** + * @brief Is the current input a comment + * + * @param s Pointer to the current input + * @return true + * @return false + */ +bool is_comment(char *s) +{ + return s[0] == '#'; } \ No newline at end of file diff --git a/src/vmrcli.c b/src/vmrcli.c index e3a467c..bbeb621 100644 --- a/src/vmrcli.c +++ b/src/vmrcli.c @@ -2,7 +2,7 @@ * @file vmrcli.c * @author Onyx and Iris (code@onyxandiris.online) * @brief A Voicemeeter Remote Command Line Interface - * @version 0.7.0 + * @version 0.8.0 * @date 2024-07-06 * * @copyright Copyright (c) 2024 @@ -21,17 +21,17 @@ #include "log.h" #include "util.h" -#define USAGE "Usage: .\\vmrcli.exe [-h] [-i] [-k] [-D] [-v] [-c] [-m] [-s] \n" \ - "Where: \n" \ - "\th: Prints the help message\n" \ - "\ti: Enable interactive mode\n" \ - "\tk: The kind of Voicemeeter (basic, banana, potato)\n" \ - "\tD: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL\n" \ - "\tv: Enable extra console output (toggle, set messages)\n" \ - "\tc: Load a user configuration (give the full file path)\n" \ - "\tm: Launch the MacroButtons application\n" \ +#define USAGE "Usage: .\\vmrcli.exe [-h] [-i|-I] [-k] [-D] [-v] [-c] [-m] [-s] \n" \ + "Where: \n" \ + "\th: Prints the help message\n" \ + "\ti: Enable interactive mode, use (-I) to disable the '>>' prompt\n" \ + "\tk: The kind of Voicemeeter (basic, banana, potato)\n" \ + "\tD: Set log level 0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR, 5=FATAL\n" \ + "\tv: Enable extra console output (toggle, set messages)\n" \ + "\tc: Load a user configuration (give the full file path)\n" \ + "\tm: Launch the MacroButtons application\n" \ "\ts: Launch the StreamerView application" -#define OPTSTR ":hk:msc:iD:v" +#define OPTSTR ":hk:msc:iID:v" #define MAX_LINE 512 /** @@ -60,7 +60,7 @@ static bool vflag = false; static void usage(void); enum kind set_kind(char *kval); -void interactive(PT_VMR vmr); +void interactive(PT_VMR vmr, bool with_prompt); void parse_input(PT_VMR vmr, char *input); void parse_command(PT_VMR vmr, char *command); void get(PT_VMR vmr, char *command, struct result *res); @@ -70,7 +70,8 @@ int main(int argc, char *argv[]) bool iflag = false, mflag = false, sflag = false, - cflag = false; + cflag = false, + with_prompt = true; int opt; int dvalue; char *cvalue; @@ -106,6 +107,9 @@ int main(int argc, char *argv[]) cflag = true; cvalue = optarg; break; + case 'I': + with_prompt = false; + [[fallthrough]]; case 'i': iflag = true; break; @@ -174,7 +178,7 @@ int main(int argc, char *argv[]) if (iflag) { puts("Interactive mode enabled. Enter 'Q' to exit."); - interactive(vmr); + interactive(vmr, with_prompt); } else { @@ -231,11 +235,12 @@ enum kind set_kind(char *kval) * * @param vmr Pointer to the iVMR interface */ -void interactive(PT_VMR vmr) +void interactive(PT_VMR vmr, bool with_prompt) { char input[MAX_LINE]; - printf(">> "); + if (with_prompt) + printf(">> "); while (fgets(input, MAX_LINE, stdin) != NULL) { input[strcspn(input, "\n")] = 0; @@ -245,12 +250,14 @@ void interactive(PT_VMR vmr) parse_input(vmr, input); memset(input, 0, MAX_LINE); /* reset input buffer */ - printf(">> "); + if (with_prompt) + printf(">> "); } } /** - * @brief Walks through each line split by " \t;," delimiters. + * @brief Returns early if input is a comment + * Walks through each line split by " \t;," delimiters. * Each token is passed to parse_command() * * @param vmr Pointer to the iVMR interface @@ -258,6 +265,9 @@ void interactive(PT_VMR vmr) */ void parse_input(PT_VMR vmr, char *input) { + if (is_comment(input)) + return; + char *token, *p; token = strtok_r(input, " \t;,", &p); diff --git a/src/wrapper.c b/src/wrapper.c index 184cfbb..002c4b2 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -2,7 +2,7 @@ * @file wrapper.c * @author Onyx and Iris (code@onyxandiris.online) * @brief Provides public functions that wrap the iVMR calls - * @version 0.7.0 + * @version 0.8.0 * @date 2024-07-06 * * @copyright Copyright (c) 2024