sl: Support continued line inputs for heredocs
This will allow kadmin to support heredocs, which will speed up testing.
This commit is contained in:
35
lib/sl/sl.c
35
lib/sl/sl.c
@@ -311,13 +311,40 @@ int
|
||||
sl_command_loop(SL_cmd *cmds, const char *prompt, void **data)
|
||||
{
|
||||
int ret = 0;
|
||||
char *buf;
|
||||
char *buf = NULL;
|
||||
int argc;
|
||||
char **argv;
|
||||
int continued = 0;
|
||||
|
||||
buf = sl_readline(prompt);
|
||||
if(buf == NULL)
|
||||
return -2;
|
||||
do {
|
||||
char *buf2;
|
||||
size_t len;
|
||||
|
||||
buf2 = sl_readline(buf == NULL ? prompt : "> ");
|
||||
if (buf2 == NULL)
|
||||
return -2;
|
||||
|
||||
if (buf) {
|
||||
char *tmp = NULL;
|
||||
|
||||
if (asprintf(&tmp, "%s %s", buf, buf2) == -1 || tmp == NULL) {
|
||||
fprintf(stderr, "sl_loop: out of memory\n");
|
||||
free(buf2);
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
free(buf2);
|
||||
free(buf);
|
||||
buf = tmp;
|
||||
} else {
|
||||
buf = buf2;
|
||||
}
|
||||
|
||||
len = strlen(buf);
|
||||
continued = (len > 0 && buf[len - 1] == '\\');
|
||||
if (continued)
|
||||
buf[len - 1] = '\0';
|
||||
} while (continued);
|
||||
|
||||
if(*buf)
|
||||
add_history(buf);
|
||||
|
Reference in New Issue
Block a user