mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-03-02 15:31:52 +00:00
Use glib utility function for shell parsing - fixes ticket #44
This commit is contained in:
parent
d8aad67d8d
commit
fa73a202af
1 changed files with 10 additions and 19 deletions
|
@ -18,6 +18,8 @@
|
||||||
* 02111-1307, USA
|
* 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#include "fluidsynth_priv.h"
|
#include "fluidsynth_priv.h"
|
||||||
#include "fluid_cmd.h"
|
#include "fluid_cmd.h"
|
||||||
#include "fluid_synth.h"
|
#include "fluid_synth.h"
|
||||||
|
@ -189,33 +191,22 @@ fluid_cmd_t fluid_commands[] = {
|
||||||
int
|
int
|
||||||
fluid_command(fluid_cmd_handler_t* handler, const char *cmd, fluid_ostream_t out)
|
fluid_command(fluid_cmd_handler_t* handler, const char *cmd, fluid_ostream_t out)
|
||||||
{
|
{
|
||||||
char* token[MAX_TOKENS];
|
int result, num_tokens = 0;
|
||||||
char buf[MAX_COMMAND_LEN+1];
|
char** tokens = NULL;
|
||||||
char *strtok, *tok;
|
|
||||||
int num_tokens = 0;
|
|
||||||
|
|
||||||
if (cmd[0] == '#') {
|
if (cmd[0] == '#' || cmd[0] == '\0') {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen (cmd) > MAX_COMMAND_LEN)
|
if (!g_shell_parse_argv(cmd, &num_tokens, &tokens, NULL)) {
|
||||||
{
|
fluid_ostream_printf(out, "Error parsing command\n");
|
||||||
fluid_ostream_printf(out, "Command exceeded max length of %d chars\n",
|
|
||||||
MAX_COMMAND_LEN);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FLUID_STRCPY(buf, cmd); /* copy - since fluid_strtok thrashes it */
|
result = fluid_cmd_handler_handle(handler, num_tokens, &tokens[0], out);
|
||||||
strtok = buf;
|
g_strfreev(tokens);
|
||||||
|
|
||||||
/* tokenize the input line */
|
return result;
|
||||||
while ((tok = fluid_strtok (&strtok, " \t\n\r")))
|
|
||||||
token[num_tokens++] = tok;
|
|
||||||
|
|
||||||
if (num_tokens == 0) return 1;
|
|
||||||
|
|
||||||
/* handle the command */
|
|
||||||
return fluid_cmd_handler_handle(handler, num_tokens, &token[0], out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue