summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2004-11-07 20:04:10 +1100
committerDarren Tucker <dtucker@zip.com.au>2004-11-07 20:04:10 +1100
commit2d963d87210c6a0c5eadfa5f02c808f6d983b47e (patch)
treefff7171e61cc32b2b1bb47c212d8e6e759f8ffb7
parent08d04faf2457e80b65b798f46bc71ac5a81b6d27 (diff)
- 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
-rw-r--r--ChangeLog9
-rw-r--r--sftp.c65
2 files changed, 64 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 009470049..871187478 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
120041107
2 - (dtucker) OpenBSD CVS Sync
3 - djm@cvs.openbsd.org 2004/11/05 12:19:56
4 [sftp.c]
5 command editing and history support via libedit; ok markus@
6 thanks to hshoexer@ and many testers on tech@ too
7
120041105 820041105
2 - (dtucker) OpenBSD CVS Sync 9 - (dtucker) OpenBSD CVS Sync
3 - markus@cvs.openbsd.org 2004/08/30 09:18:08 10 - markus@cvs.openbsd.org 2004/08/30 09:18:08
@@ -1841,4 +1848,4 @@
1841 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 1848 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
1842 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 1849 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
1843 1850
1844$Id: ChangeLog,v 1.3578 2004/11/05 09:42:28 dtucker Exp $ 1851$Id: ChangeLog,v 1.3579 2004/11/07 09:04:10 dtucker Exp $
diff --git a/sftp.c b/sftp.c
index f01c9194c..2db394e23 100644
--- a/sftp.c
+++ b/sftp.c
@@ -16,7 +16,13 @@
16 16
17#include "includes.h" 17#include "includes.h"
18 18
19RCSID("$OpenBSD: sftp.c,v 1.56 2004/07/11 17:48:47 deraadt Exp $"); 19RCSID("$OpenBSD: sftp.c,v 1.57 2004/11/05 12:19:56 djm Exp $");
20
21#ifdef USE_LIBEDIT
22#include <histedit.h>
23#else
24typedef void EditLine;
25#endif
20 26
21#include "buffer.h" 27#include "buffer.h"
22#include "xmalloc.h" 28#include "xmalloc.h"
@@ -1206,6 +1212,14 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
1206 return (0); 1212 return (0);
1207} 1213}
1208 1214
1215#ifdef USE_LIBEDIT
1216static char *
1217prompt(EditLine *el)
1218{
1219 return ("sftp> ");
1220}
1221#endif
1222
1209int 1223int
1210interactive_loop(int fd_in, int fd_out, char *file1, char *file2) 1224interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1211{ 1225{
@@ -1214,6 +1228,27 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1214 char cmd[2048]; 1228 char cmd[2048];
1215 struct sftp_conn *conn; 1229 struct sftp_conn *conn;
1216 int err; 1230 int err;
1231 EditLine *el = NULL;
1232#ifdef USE_LIBEDIT
1233 History *hl = NULL;
1234 HistEvent hev;
1235 extern char *__progname;
1236
1237 if (!batchmode && isatty(STDIN_FILENO)) {
1238 if ((el = el_init(__progname, stdin, stdout, stderr)) == NULL)
1239 fatal("Couldn't initialise editline");
1240 if ((hl = history_init()) == NULL)
1241 fatal("Couldn't initialise editline history");
1242 history(hl, &hev, H_SETSIZE, 100);
1243 el_set(el, EL_HIST, history, hl);
1244
1245 el_set(el, EL_PROMPT, prompt);
1246 el_set(el, EL_EDITOR, "emacs");
1247 el_set(el, EL_TERMINAL, NULL);
1248 el_set(el, EL_SIGNAL, 1);
1249 el_source(el, NULL);
1250 }
1251#endif /* USE_LIBEDIT */
1217 1252
1218 conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests); 1253 conn = do_init(fd_in, fd_out, copy_buffer_len, num_requests);
1219 if (conn == NULL) 1254 if (conn == NULL)
@@ -1261,17 +1296,29 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1261 1296
1262 signal(SIGINT, SIG_IGN); 1297 signal(SIGINT, SIG_IGN);
1263 1298
1264 printf("sftp> "); 1299 if (el == NULL) {
1300 printf("sftp> ");
1301 if (fgets(cmd, sizeof(cmd), infile) == NULL) {
1302 printf("\n");
1303 break;
1304 }
1305 if (batchmode) /* Echo command */
1306 printf("%s", cmd);
1307 } else {
1308#ifdef USE_LIBEDIT
1309 const char *line;
1310 int count = 0;
1265 1311
1266 /* XXX: use libedit */ 1312 if ((line = el_gets(el, &count)) == NULL || count <= 0)
1267 if (fgets(cmd, sizeof(cmd), infile) == NULL) { 1313 break;
1268 printf("\n"); 1314 history(hl, &hev, H_ENTER, line);
1269 break; 1315 if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) {
1316 fprintf(stderr, "Error: input line too long\n");
1317 continue;
1318 }
1319#endif /* USE_LIBEDIT */
1270 } 1320 }
1271 1321
1272 if (batchmode) /* Echo command */
1273 printf("%s", cmd);
1274
1275 cp = strrchr(cmd, '\n'); 1322 cp = strrchr(cmd, '\n');
1276 if (cp) 1323 if (cp)
1277 *cp = '\0'; 1324 *cp = '\0';