Let `readline' to the \n-removal.
Handle empty lines. Don't store empty lines in the history. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1045 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
19
lib/sl/sl.c
19
lib/sl/sl.c
@@ -101,6 +101,8 @@ readline(char *prompt)
|
||||
fflush (stdout);
|
||||
if(fgets(buf, sizeof(buf), stdin) == NULL)
|
||||
return NULL;
|
||||
if (buf[strlen(buf) - 1] == '\n')
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
return strdup(buf);
|
||||
}
|
||||
|
||||
@@ -128,11 +130,10 @@ sl_loop (SL_cmd *cmds, char *prompt)
|
||||
if(buf == NULL)
|
||||
break;
|
||||
|
||||
if (buf[strlen(buf) - 1] == '\n')
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
p = buf;
|
||||
count = 0;
|
||||
add_history(buf);
|
||||
if(*buf)
|
||||
add_history(buf);
|
||||
for (;;) {
|
||||
while (*p == ' ' || *p == '\t')
|
||||
p++;
|
||||
@@ -146,11 +147,13 @@ sl_loop (SL_cmd *cmds, char *prompt)
|
||||
break;
|
||||
*p++ = '\0';
|
||||
}
|
||||
c = sl_match (cmds, ptr[0], 0);
|
||||
if (c)
|
||||
(*c->func)(count, ptr);
|
||||
else
|
||||
printf ("Unrecognized command: %s\n", ptr[0]);
|
||||
if (count > 0) {
|
||||
c = sl_match (cmds, ptr[0], 0);
|
||||
if (c)
|
||||
(*c->func)(count, ptr);
|
||||
else
|
||||
printf ("Unrecognized command: %s\n", ptr[0]);
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user