Use readline compatible i/o.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1044 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
29
lib/sl/sl.c
29
lib/sl/sl.c
@@ -91,10 +91,30 @@ sl_help (SL_cmd *cmds, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef HAVE_READLINE
|
||||
|
||||
static char *
|
||||
readline(char *prompt)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
printf ("%s", prompt);
|
||||
fflush (stdout);
|
||||
if(fgets(buf, sizeof(buf), stdin) == NULL)
|
||||
return NULL;
|
||||
return strdup(buf);
|
||||
}
|
||||
|
||||
static void
|
||||
add_history(char *p)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
sl_loop (SL_cmd *cmds, char *prompt)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
char *buf;
|
||||
int count;
|
||||
char *ptr[17];
|
||||
int i;
|
||||
@@ -104,15 +124,15 @@ sl_loop (SL_cmd *cmds, char *prompt)
|
||||
char **a = ptr;
|
||||
SL_cmd *c;
|
||||
|
||||
printf ("%s", prompt);
|
||||
fflush (stdout);
|
||||
if(fgets (buf, sizeof(buf), stdin) == NULL)
|
||||
buf = readline(prompt);
|
||||
if(buf == NULL)
|
||||
break;
|
||||
|
||||
if (buf[strlen(buf) - 1] == '\n')
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
p = buf;
|
||||
count = 0;
|
||||
add_history(buf);
|
||||
for (;;) {
|
||||
while (*p == ' ' || *p == '\t')
|
||||
p++;
|
||||
@@ -131,6 +151,7 @@ sl_loop (SL_cmd *cmds, char *prompt)
|
||||
(*c->func)(count, ptr);
|
||||
else
|
||||
printf ("Unrecognized command: %s\n", ptr[0]);
|
||||
free(buf);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user