From d92314772e1af30024b167e21e64ce73e0dd16f9 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Mon, 18 Nov 1996 23:45:33 +0000 Subject: [PATCH] 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 --- lib/sl/sl.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/sl/sl.c b/lib/sl/sl.c index 8f1e9ec7b..53e98c875 100644 --- a/lib/sl/sl.c +++ b/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;