Add some basic readline support.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1071 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -188,62 +188,92 @@ tail(filename)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#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;
|
||||||
|
if (buf[strlen(buf) - 1] == '\n')
|
||||||
|
buf[strlen(buf) - 1] = '\0';
|
||||||
|
return strdup(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
add_history(char *p)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Command parser.
|
* Command parser.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cmdscanner(int top)
|
cmdscanner(int top)
|
||||||
{
|
{
|
||||||
struct cmd *c;
|
struct cmd *c;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
if (!top)
|
if (!top)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (fromatty) {
|
if (fromatty) {
|
||||||
printf("ftp> ");
|
char *p;
|
||||||
fflush(stdout);
|
p = readline("ftp> ");
|
||||||
}
|
if(p == NULL)
|
||||||
if (fgets(line, sizeof line, stdin) == NULL)
|
quit(0, 0);
|
||||||
quit(0, 0);
|
strncpy(line, p, sizeof(line));
|
||||||
l = strlen(line);
|
line[sizeof(line) - 1] = 0;
|
||||||
if (l == 0)
|
add_history(p);
|
||||||
break;
|
free(p);
|
||||||
if (line[--l] == '\n') {
|
} else{
|
||||||
if (l == 0)
|
if (fgets(line, sizeof line, stdin) == NULL)
|
||||||
break;
|
quit(0, 0);
|
||||||
line[l] = '\0';
|
|
||||||
} else if (l == sizeof(line) - 2) {
|
|
||||||
printf("sorry, input line too long\n");
|
|
||||||
while ((l = getchar()) != '\n' && l != EOF)
|
|
||||||
/* void */;
|
|
||||||
break;
|
|
||||||
} /* else it was a line without a newline */
|
|
||||||
makeargv();
|
|
||||||
if (margc == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
c = getcmd(margv[0]);
|
|
||||||
if (c == (struct cmd *)-1) {
|
|
||||||
printf("?Ambiguous command\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c == 0) {
|
|
||||||
printf("?Invalid command\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (c->c_conn && !connected) {
|
|
||||||
printf("Not connected.\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
(*c->c_handler)(margc, margv);
|
|
||||||
if (bell && c->c_bell)
|
|
||||||
putchar('\007');
|
|
||||||
if (c->c_handler != help)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
signal(SIGINT, intr);
|
/* XXX will break on long lines */
|
||||||
signal(SIGPIPE, lostpeer);
|
l = strlen(line);
|
||||||
|
if (l == 0)
|
||||||
|
break;
|
||||||
|
if (line[--l] == '\n') {
|
||||||
|
if (l == 0)
|
||||||
|
break;
|
||||||
|
line[l] = '\0';
|
||||||
|
} else if (l == sizeof(line) - 2) {
|
||||||
|
printf("sorry, input line too long\n");
|
||||||
|
while ((l = getchar()) != '\n' && l != EOF)
|
||||||
|
/* void */;
|
||||||
|
break;
|
||||||
|
} /* else it was a line without a newline */
|
||||||
|
makeargv();
|
||||||
|
if (margc == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
c = getcmd(margv[0]);
|
||||||
|
if (c == (struct cmd *)-1) {
|
||||||
|
printf("?Ambiguous command\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c == 0) {
|
||||||
|
printf("?Invalid command\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c->c_conn && !connected) {
|
||||||
|
printf("Not connected.\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
(*c->c_handler)(margc, margv);
|
||||||
|
if (bell && c->c_bell)
|
||||||
|
putchar('\007');
|
||||||
|
if (c->c_handler != help)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
signal(SIGINT, intr);
|
||||||
|
signal(SIGPIPE, lostpeer);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd *
|
struct cmd *
|
||||||
|
Reference in New Issue
Block a user