int shutdown;
int monitor_mode;
int pubsub_mode;
- int raw_output;
+ int raw_output; /* output mode per command */
char *auth;
char *historyfile;
} config;
reply = zmalloc(bulklen);
anetRead(fd,reply,bulklen);
anetRead(fd,crlf,2);
- if (config.raw_output || !isatty(fileno(stdout))) {
+ if (config.raw_output || !config.interactive) {
if (bulklen && fwrite(reply,bulklen,1,stdout) == 0) {
zfree(reply);
return 1;
if (*p) {
/* get a token */
int inq=0; /* set to 1 if we are in "quotes" */
- int done = 0;
+ int done=0;
if (current == NULL) current = sdsempty();
while(!done) {
}
current = sdscatlen(current,&c,1);
} else if (*p == '"') {
- done = 1;
+ /* closing quote must be followed by a space */
+ if (*(p+1) && !isspace(*(p+1))) goto err;
+ done=1;
+ } else if (!*p) {
+ /* unterminated quotes */
+ goto err;
} else {
current = sdscatlen(current,p,1);
}
return vector;
}
}
+
+err:
+ while(*argc--)
+ sdsfree(vector[*argc]);
+ zfree(vector);
+ if (current) sdsfree(current);
+ return NULL;
}
#define LINE_BUFLEN 4096
argv = splitArguments(line,&argc);
linenoiseHistoryAdd(line);
if (config.historyfile) linenoiseHistorySave(config.historyfile);
- if (argc > 0) {
+ if (argv == NULL) {
+ printf("Invalid argument(s)\n");
+ continue;
+ } else if (argc > 0) {
if (strcasecmp(argv[0],"quit") == 0 ||
strcasecmp(argv[0],"exit") == 0)
exit(0);
cliSendCommand(2, convertToSds(2, authargv), 1);
}
- if (argc == 0 || config.interactive == 1) repl();
+ if (argc == 0 || config.interactive == 1) {
+ config.interactive = 1;
+ repl();
+ }
argvcopy = convertToSds(argc+1, argv);
if (config.argn_from_stdin) {