allow interactive mode to parse multiple api calls in one go

This commit is contained in:
onyx-and-iris 2024-06-26 05:54:13 +01:00
parent 69d28822dd
commit 3e9b0e91f7

View File

@ -155,18 +155,33 @@ int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind)
void interactive(T_VBVMR_INTERFACE *vmr) void interactive(T_VBVMR_INTERFACE *vmr)
{ {
char input[MAX_LINE]; char input[MAX_LINE];
char *p = input;
while (fgets(input, MAX_LINE, stdin) != NULL) while (fgets(input, MAX_LINE, stdin) != NULL)
{ {
if (strlen(input) == 2 && (strncmp(input, "Q", 1) == 0 || strncmp(input, "q", 1) == 0)) if (strlen(input) == 2 && (strncmp(input, "Q", 1) == 0 || strncmp(input, "q", 1) == 0))
break; break;
parse_command(vmr, input); while (*p)
{
char command[MAX_LINE];
int i = 0;
while (!isspace(*p))
command[i++] = *p++;
command[i] = '\0';
p++; /* shift to next char */
parse_command(vmr, command);
}
p = input; /* reset pointer */
} }
} }
void parse_command(T_VBVMR_INTERFACE *vmr, char *command) void parse_command(T_VBVMR_INTERFACE *vmr, char *command)
{ {
printf("Parsing %s\n", command);
if (command[0] == '!') /* toggle */ if (command[0] == '!') /* toggle */
{ {
command++; command++;
@ -210,7 +225,11 @@ struct result *get(T_VBVMR_INTERFACE *vmr, char *command, struct result *res)
if (get_parameter_float(vmr, command, &res->val.f) != 0) if (get_parameter_float(vmr, command, &res->val.f) != 0)
{ {
res->type = STRING_T; res->type = STRING_T;
get_parameter_string(vmr, command, res->val.s); if (get_parameter_string(vmr, command, res->val.s) != 0)
{
res->val.s[0] = 0;
fputs("Unknown parameter", stderr);
}
} }
return res; return res;