6 Commits

Author SHA1 Message Date
a7c0bc1620 fix comment 2024-07-12 12:05:43 +01:00
25692a9f35 increase input buffer size
when resetting buffer, clear only bits written to
2024-07-12 12:04:03 +01:00
a05b029e9d specify enum type 2024-07-11 18:45:35 +01:00
68c2022ad7 return quickcommands + i 2024-07-10 23:57:19 +01:00
ff2970f4c5 move quickcommands into parse_command() 2024-07-10 23:37:49 +01:00
f60fc231b0 add note about quick commands to README 2024-07-10 18:20:58 +01:00
6 changed files with 39 additions and 22 deletions

4
.gitignore vendored
View File

@@ -51,4 +51,6 @@ Module.symvers
Mkfile.old Mkfile.old
dkms.conf dkms.conf
.vscode/ .vscode/
test*

View File

@@ -48,6 +48,18 @@ Launch banana GUI, set log level to DEBUG, set Strip 0 label to podmic then prin
.\vmrcli.exe -kbanana -D1 strip[0].label=podmic strip[2].label .\vmrcli.exe -kbanana -D1 strip[0].label=podmic strip[2].label
``` ```
#### `Quick Commands`
A short list of quick commands are available:
- `lock`: command.lock=1
- `unlock`: command.lock=0
- `show`: command.show=1
- `hide`: command.show=0
- `restart`: command.restart=1
They may be used in direct or interactive mode.
## `Interactive Mode` ## `Interactive Mode`
Running the following command in Powershell: Running the following command in Powershell:

View File

@@ -18,6 +18,6 @@ void remove_last_part_of_path(char *fullpath);
char *kind_as_string(char *s, int kind, int n); char *kind_as_string(char *s, int kind, int n);
char *version_as_string(char *s, long v, int n); char *version_as_string(char *s, long v, int n);
bool is_comment(char *s); 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__ */ #endif /* __UTIL_H__ */

View File

@@ -11,7 +11,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "voicemeeterRemote.h" #include "voicemeeterRemote.h"
enum kind enum kind : int
{ {
UNKNOWN = -1, UNKNOWN = -1,
BASIC = 1, BASIC = 1,

View File

@@ -93,13 +93,13 @@ bool is_comment(char *s)
* @return struct quickcommand* Pointer to the found quickcommand * @return struct quickcommand* Pointer to the found quickcommand
* May return NULL if quickcommand not found. * 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++) for (int i = 0; i < n; i++)
{ {
if (strncmp(command_key, quickcommands[i].name, strlen(command_key)) == 0) if (strcmp(command_key, quickcommands[i].name) == 0)
{ {
return &quickcommands[i]; return (struct quickcommand *)(quickcommands + i);
} }
} }
return NULL; return NULL;

View File

@@ -32,13 +32,15 @@
"\tm: Launch the MacroButtons application\n" \ "\tm: Launch the MacroButtons application\n" \
"\ts: Launch the StreamerView application" "\ts: Launch the StreamerView application"
#define OPTSTR ":hk:msc:iID:v" #define OPTSTR ":hk:msc:iID:v"
#define MAX_LINE 512 #define MAX_LINE 4096 /* Size of the input buffer */
#define RES_SZ 512 /* Size of the buffer passed to VBVMR_GetParameterStringW */
#define COUNT_OF(x) (sizeof(x) / sizeof(x[0])) #define COUNT_OF(x) (sizeof(x) / sizeof(x[0]))
#define DELIMITERS " \t;,"
/** /**
* @enum The kind of values a get call may return. * @enum The kind of values a get call may return.
*/ */
enum enum restype : int
{ {
FLOAT_T, FLOAT_T,
STRING_T, STRING_T,
@@ -49,24 +51,17 @@ enum
*/ */
struct result struct result
{ {
int type; enum restype type;
union val union val
{ {
float f; float f;
wchar_t s[MAX_LINE]; wchar_t s[RES_SZ];
} val; } 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 bool vflag = false;
static void usage(void); static void usage();
enum kind set_kind(char *kval); enum kind set_kind(char *kval);
void interactive(PT_VMR vmr, bool with_prompt); void interactive(PT_VMR vmr, bool with_prompt);
void parse_input(PT_VMR vmr, char *input); void parse_input(PT_VMR vmr, char *input);
@@ -246,18 +241,19 @@ enum kind set_kind(char *kval)
void interactive(PT_VMR vmr, bool with_prompt) void interactive(PT_VMR vmr, bool with_prompt)
{ {
char input[MAX_LINE]; char input[MAX_LINE];
size_t len;
if (with_prompt) if (with_prompt)
printf(">> "); printf(">> ");
while (fgets(input, MAX_LINE, stdin) != NULL) while (fgets(input, MAX_LINE, stdin) != NULL)
{ {
input[strcspn(input, "\n")] = 0; input[strcspn(input, "\n")] = 0;
if (strlen(input) == 1 && toupper(input[0]) == 'Q') if ((len = strlen(input)) == 1 && toupper(input[0]) == 'Q')
break; break;
parse_input(vmr, input); parse_input(vmr, input);
memset(input, 0, len); /* reset input buffer */
memset(input, 0, MAX_LINE); /* reset input buffer */
if (with_prompt) if (with_prompt)
printf(">> "); printf(">> ");
} }
@@ -278,11 +274,11 @@ void parse_input(PT_VMR vmr, char *input)
char *token, *p; char *token, *p;
token = strtok_r(input, " \t;,", &p); token = strtok_r(input, DELIMITERS, &p);
while (token != NULL) while (token != NULL)
{ {
parse_command(vmr, token); parse_command(vmr, token);
token = strtok_r(NULL, " \t;,", &p); token = strtok_r(NULL, DELIMITERS, &p);
} }
} }
@@ -298,6 +294,13 @@ void parse_command(PT_VMR vmr, char *command)
{ {
log_debug("Parsing %s", 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)); struct quickcommand *qc_ptr = command_in_quickcommands(command, quickcommands, (int)COUNT_OF(quickcommands));
if (qc_ptr != NULL) if (qc_ptr != NULL)
{ {