summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/sftp.c b/sftp.c
index 9d2360743..0f1aa4b54 100644
--- a/sftp.c
+++ b/sftp.c
@@ -16,7 +16,7 @@
16 16
17#include "includes.h" 17#include "includes.h"
18 18
19RCSID("$OpenBSD: sftp.c,v 1.65 2005/07/17 07:17:55 djm Exp $"); 19RCSID("$OpenBSD: sftp.c,v 1.66 2005/08/08 13:22:48 jaredy Exp $");
20 20
21#ifdef USE_LIBEDIT 21#ifdef USE_LIBEDIT
22#include <histedit.h> 22#include <histedit.h>
@@ -1237,7 +1237,7 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1237 char *dir = NULL; 1237 char *dir = NULL;
1238 char cmd[2048]; 1238 char cmd[2048];
1239 struct sftp_conn *conn; 1239 struct sftp_conn *conn;
1240 int err; 1240 int err, interactive;
1241 EditLine *el = NULL; 1241 EditLine *el = NULL;
1242#ifdef USE_LIBEDIT 1242#ifdef USE_LIBEDIT
1243 History *hl = NULL; 1243 History *hl = NULL;
@@ -1303,6 +1303,7 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1303 setlinebuf(infile); 1303 setlinebuf(infile);
1304#endif 1304#endif
1305 1305
1306 interactive = !batchmode && isatty(STDIN_FILENO);
1306 err = 0; 1307 err = 0;
1307 for (;;) { 1308 for (;;) {
1308 char *cp; 1309 char *cp;
@@ -1310,20 +1311,28 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1310 signal(SIGINT, SIG_IGN); 1311 signal(SIGINT, SIG_IGN);
1311 1312
1312 if (el == NULL) { 1313 if (el == NULL) {
1313 printf("sftp> "); 1314 if (interactive)
1315 printf("sftp> ");
1314 if (fgets(cmd, sizeof(cmd), infile) == NULL) { 1316 if (fgets(cmd, sizeof(cmd), infile) == NULL) {
1315 printf("\n"); 1317 if (interactive)
1318 printf("\n");
1316 break; 1319 break;
1317 } 1320 }
1318 if (batchmode) /* Echo command */ 1321 if (!interactive) { /* Echo command */
1319 printf("%s", cmd); 1322 printf("sftp> %s", cmd);
1323 if (strlen(cmd) > 0 &&
1324 cmd[strlen(cmd) - 1] != '\n')
1325 printf("\n");
1326 }
1320 } else { 1327 } else {
1321#ifdef USE_LIBEDIT 1328#ifdef USE_LIBEDIT
1322 const char *line; 1329 const char *line;
1323 int count = 0; 1330 int count = 0;
1324 1331
1325 if ((line = el_gets(el, &count)) == NULL || count <= 0) 1332 if ((line = el_gets(el, &count)) == NULL || count <= 0) {
1326 break; 1333 printf("\n");
1334 break;
1335 }
1327 history(hl, &hev, H_ENTER, line); 1336 history(hl, &hev, H_ENTER, line);
1328 if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) { 1337 if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) {
1329 fprintf(stderr, "Error: input line too long\n"); 1338 fprintf(stderr, "Error: input line too long\n");
@@ -1346,6 +1355,9 @@ interactive_loop(int fd_in, int fd_out, char *file1, char *file2)
1346 } 1355 }
1347 xfree(pwd); 1356 xfree(pwd);
1348 1357
1358 if (el != NULL)
1359 el_end(el);
1360
1349 /* err == 1 signifies normal "quit" exit */ 1361 /* err == 1 signifies normal "quit" exit */
1350 return (err >= 0 ? 0 : -1); 1362 return (err >= 0 ? 0 : -1);
1351} 1363}