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:
Assar Westerlund
1996-11-18 23:45:33 +00:00
parent 0d06afde69
commit d92314772e

View File

@@ -101,6 +101,8 @@ readline(char *prompt)
fflush (stdout); fflush (stdout);
if(fgets(buf, sizeof(buf), stdin) == NULL) if(fgets(buf, sizeof(buf), stdin) == NULL)
return NULL; return NULL;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
return strdup(buf); return strdup(buf);
} }
@@ -128,11 +130,10 @@ sl_loop (SL_cmd *cmds, char *prompt)
if(buf == NULL) if(buf == NULL)
break; break;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
p = buf; p = buf;
count = 0; count = 0;
add_history(buf); if(*buf)
add_history(buf);
for (;;) { for (;;) {
while (*p == ' ' || *p == '\t') while (*p == ' ' || *p == '\t')
p++; p++;
@@ -146,11 +147,13 @@ sl_loop (SL_cmd *cmds, char *prompt)
break; break;
*p++ = '\0'; *p++ = '\0';
} }
c = sl_match (cmds, ptr[0], 0); if (count > 0) {
if (c) c = sl_match (cmds, ptr[0], 0);
(*c->func)(count, ptr); if (c)
else (*c->func)(count, ptr);
printf ("Unrecognized command: %s\n", ptr[0]); else
printf ("Unrecognized command: %s\n", ptr[0]);
}
free(buf); free(buf);
} }
return 0; return 0;