=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/sftp.c,v retrieving revision 1.56 retrieving revision 1.57 diff -u -r1.56 -r1.57 --- src/usr.bin/ssh/sftp.c 2004/07/11 17:48:47 1.56 +++ src/usr.bin/ssh/sftp.c 2004/11/05 12:19:56 1.57 @@ -16,9 +16,10 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.56 2004/07/11 17:48:47 deraadt Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.57 2004/11/05 12:19:56 djm Exp $"); #include +#include #include "buffer.h" #include "xmalloc.h" @@ -1206,6 +1207,12 @@ return (0); } +static char * +prompt(EditLine *el) +{ + return ("sftp> "); +} + int interactive_loop(int fd_in, int fd_out, char *file1, char *file2) { @@ -1214,7 +1221,26 @@ char cmd[2048]; struct sftp_conn *conn; int err; + EditLine *el = NULL; + History *hl = NULL; + HistEvent hev; + extern char *__progname; + if (!batchmode && isatty(STDIN_FILENO)) { + if ((el = el_init(__progname, stdin, stdout, stderr)) == NULL) + fatal("Couldn't initialise editline"); + if ((hl = history_init()) == NULL) + fatal("Couldn't initialise editline history"); + history(hl, &hev, H_SETSIZE, 100); + el_set(el, EL_HIST, history, hl); + + el_set(el, EL_PROMPT, prompt); + el_set(el, EL_EDITOR, "emacs"); + el_set(el, EL_TERMINAL, NULL); + el_set(el, EL_SIGNAL, 1); + el_source(el, NULL); + } + conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests); if (conn == NULL) fatal("Couldn't initialise connection to server"); @@ -1253,19 +1279,28 @@ err = 0; for (;;) { char *cp; + const char *line; + int count = 0; signal(SIGINT, SIG_IGN); - printf("sftp> "); - - /* XXX: use libedit */ - if (fgets(cmd, sizeof(cmd), infile) == NULL) { - printf("\n"); - break; + if (el == NULL) { + printf("sftp> "); + if (fgets(cmd, sizeof(cmd), infile) == NULL) { + printf("\n"); + break; + } + if (batchmode) /* Echo command */ + printf("%s", cmd); + } else { + if ((line = el_gets(el, &count)) == NULL || count <= 0) + break; + history(hl, &hev, H_ENTER, line); + if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { + fprintf(stderr, "Error: input line too long\n"); + continue; + } } - - if (batchmode) /* Echo command */ - printf("%s", cmd); cp = strrchr(cmd, '\n'); if (cp)