summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-09-29 19:59:55 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-09-29 19:59:55 +0200
commit09813128f55c009faeb2300d4aa9933ca957f613 (patch)
treec2027f630c372a53bf96e177f8c4ce3b28000e58
parent64ac8cc14003a31ae21d28e7f37a7d9c8ed638fe (diff)
downloadcmumble-09813128f55c009faeb2300d4aa9933ca957f613.tar.gz
cmumble-09813128f55c009faeb2300d4aa9933ca957f613.tar.bz2
cmumble-09813128f55c009faeb2300d4aa9933ca957f613.zip
Support delimiter in cmdline arguments
Delimiters are " and '.
-rw-r--r--src/io.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/io.c b/src/io.c
index 2a981b1..473ce30 100644
--- a/src/io.c
+++ b/src/io.c
@@ -75,29 +75,58 @@ skip_whitespace(char *text)
return &text[i];
}
+static gboolean
+is_escaped(char *text, int index, char escape)
+{
+ if (index <= 0)
+ return FALSE;
+
+ if (text[index-1] == escape)
+ return !is_escaped(text, index-1, escape);
+
+ return FALSE;
+}
+
static char *
-skip_non_whitespace(char *text)
+skip_non_whitespace(char *text, char delimiter)
{
int i;
for (i = 0; text[i] != '\0'; ++i) {
- if (text[i] == ' ')
+ if (text[i] == delimiter && !is_escaped(text, i, '\\'))
return &text[i];
}
return &text[i];
}
+static char *
+skip_delimiter(char *text, char *delimiter)
+{
+ *delimiter = ' ';
+
+ if (text[0] == '"' || text[0] == '\'') {
+ *delimiter = text[0];
+ text = &text[1];
+ }
+
+ return text;
+}
+
static int
command_split(char *cmd, char ***argv)
{
static char *av[16];
int i;
+ char delimiter;
for (i = 0; i < 15; ++i) {
cmd = skip_whitespace(cmd);
+ if (strlen(cmd) == 0)
+ break;
+ cmd = skip_delimiter(cmd, &delimiter);
av[i] = cmd;
- cmd = skip_non_whitespace(cmd);
+ cmd = skip_non_whitespace(cmd, delimiter);
if (cmd[0] == '\0') {
++i;
break;
@@ -123,7 +152,6 @@ process_line(char *line)
g_assert(global_rl_user_data);
-
rl_reset_line_state();
if (line == NULL) {