diff options
author | antirez <antirez@gmail.com> | 2010-08-05 11:36:39 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2010-08-05 11:36:39 +0200 |
commit | cbce5171451eb53f1370aacc30decd74512347ac (patch) | |
tree | e63e5efce72c10a2ba29f117ee7545988e7b8785 /src/redis-cli.c | |
parent | 1fb4e8def723ac836ba96e5369f22a0bf463578d (diff) | |
download | redis-cbce5171451eb53f1370aacc30decd74512347ac.tar.gz |
redis cli argument splitting is general and is now moved into the sds.c lib
Diffstat (limited to 'src/redis-cli.c')
-rw-r--r-- | src/redis-cli.c | 70 |
1 files changed, 3 insertions, 67 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c index dac828625..b4a108904 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -366,79 +366,15 @@ static char **convertToSds(int count, char** args) { return sds; } -static char **splitArguments(char *line, int *argc) { - char *p = line; - char *current = NULL; - char **vector = NULL; - - *argc = 0; - while(1) { - /* skip blanks */ - while(*p && isspace(*p)) p++; - if (*p) { - /* get a token */ - int inq=0; /* set to 1 if we are in "quotes" */ - int done = 0; - - if (current == NULL) current = sdsempty(); - while(!done) { - if (inq) { - if (*p == '\\' && *(p+1)) { - char c; - - p++; - switch(*p) { - case 'n': c = '\n'; break; - case 'r': c = '\r'; break; - case 't': c = '\t'; break; - case 'b': c = '\b'; break; - case 'a': c = '\a'; break; - default: c = *p; break; - } - current = sdscatlen(current,&c,1); - } else if (*p == '"') { - done = 1; - } else { - current = sdscatlen(current,p,1); - } - } else { - switch(*p) { - case ' ': - case '\n': - case '\r': - case '\t': - case '\0': - done=1; - break; - case '"': - inq=1; - break; - default: - current = sdscatlen(current,p,1); - break; - } - } - if (*p) p++; - } - /* add the token to the vector */ - vector = zrealloc(vector,((*argc)+1)*sizeof(char*)); - vector[*argc] = current; - (*argc)++; - current = NULL; - } else { - return vector; - } - } -} - #define LINE_BUFLEN 4096 static void repl() { int argc, j; - char *line, **argv; + char *line; + sds *argv; while((line = linenoise("redis> ")) != NULL) { if (line[0] != '\0') { - argv = splitArguments(line,&argc); + argv = sdssplitargs(line,&argc); linenoiseHistoryAdd(line); if (config.historyfile) linenoiseHistorySave(config.historyfile); if (argc > 0) { |