- djm@cvs.openbsd.org 2004/11/05 12:19:56
[sftp.c] command editing and history support via libedit; ok markus@ thanks to hshoexer@ and many testers on tech@ too
This commit is contained in:
parent
08d04faf24
commit
2d963d8721
|
@ -1,3 +1,10 @@
|
||||||
|
20041107
|
||||||
|
- (dtucker) OpenBSD CVS Sync
|
||||||
|
- djm@cvs.openbsd.org 2004/11/05 12:19:56
|
||||||
|
[sftp.c]
|
||||||
|
command editing and history support via libedit; ok markus@
|
||||||
|
thanks to hshoexer@ and many testers on tech@ too
|
||||||
|
|
||||||
20041105
|
20041105
|
||||||
- (dtucker) OpenBSD CVS Sync
|
- (dtucker) OpenBSD CVS Sync
|
||||||
- markus@cvs.openbsd.org 2004/08/30 09:18:08
|
- markus@cvs.openbsd.org 2004/08/30 09:18:08
|
||||||
|
@ -1841,4 +1848,4 @@
|
||||||
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
|
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
|
||||||
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
|
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
|
||||||
|
|
||||||
$Id: ChangeLog,v 1.3578 2004/11/05 09:42:28 dtucker Exp $
|
$Id: ChangeLog,v 1.3579 2004/11/07 09:04:10 dtucker Exp $
|
||||||
|
|
55
sftp.c
55
sftp.c
|
@ -16,7 +16,13 @@
|
||||||
|
|
||||||
#include "includes.h"
|
#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 $");
|
||||||
|
|
||||||
|
#ifdef USE_LIBEDIT
|
||||||
|
#include <histedit.h>
|
||||||
|
#else
|
||||||
|
typedef void EditLine;
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
@ -1206,6 +1212,14 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_LIBEDIT
|
||||||
|
static char *
|
||||||
|
prompt(EditLine *el)
|
||||||
|
{
|
||||||
|
return ("sftp> ");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
|
interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
|
||||||
{
|
{
|
||||||
|
@ -1214,6 +1228,27 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
|
||||||
char cmd[2048];
|
char cmd[2048];
|
||||||
struct sftp_conn *conn;
|
struct sftp_conn *conn;
|
||||||
int err;
|
int err;
|
||||||
|
EditLine *el = NULL;
|
||||||
|
#ifdef USE_LIBEDIT
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
#endif /* USE_LIBEDIT */
|
||||||
|
|
||||||
conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests);
|
conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests);
|
||||||
if (conn == NULL)
|
if (conn == NULL)
|
||||||
|
@ -1261,16 +1296,28 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
|
||||||
|
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
|
|
||||||
|
if (el == NULL) {
|
||||||
printf("sftp> ");
|
printf("sftp> ");
|
||||||
|
|
||||||
/* XXX: use libedit */
|
|
||||||
if (fgets(cmd, sizeof(cmd), infile) == NULL) {
|
if (fgets(cmd, sizeof(cmd), infile) == NULL) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (batchmode) /* Echo command */
|
if (batchmode) /* Echo command */
|
||||||
printf("%s", cmd);
|
printf("%s", cmd);
|
||||||
|
} else {
|
||||||
|
#ifdef USE_LIBEDIT
|
||||||
|
const char *line;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
#endif /* USE_LIBEDIT */
|
||||||
|
}
|
||||||
|
|
||||||
cp = strrchr(cmd, '\n');
|
cp = strrchr(cmd, '\n');
|
||||||
if (cp)
|
if (cp)
|
||||||
|
|
Loading…
Reference in New Issue