#include "includes.h"
-RCSID("$OpenBSD: sftp.c,v 1.63 2005/03/10 22:01:05 deraadt Exp $");
+RCSID("$OpenBSD: sftp.c,v 1.66 2005/08/08 13:22:48 jaredy Exp $");
#ifdef USE_LIBEDIT
#include <histedit.h>
{
const char *cp = *cpp, *end;
char quot;
- int i, j;
+ u_int i, j;
cp += strspn(cp, WHITESPACE);
if (!*cp) {
static int
do_ls_dir(struct sftp_conn *conn, char *path, char *strip_path, int lflag)
{
- int n, c = 1, colspace = 0, columns = 1;
+ int n;
+ u_int c = 1, colspace = 0, columns = 1;
SFTP_DIRENT **d;
if ((n = do_readdir(conn, path, &d)) != 0)
return (n);
if (!(lflag & LS_SHORT_VIEW)) {
- int m = 0, width = 80;
+ u_int m = 0, width = 80;
struct winsize ws;
char *tmp;
int lflag)
{
glob_t g;
- int i, c = 1, colspace = 0, columns = 1;
+ u_int i, c = 1, colspace = 0, columns = 1;
Attrib *a = NULL;
memset(&g, 0, sizeof(g));
}
if (!(lflag & LS_SHORT_VIEW)) {
- int m = 0, width = 80;
+ u_int m = 0, width = 80;
struct winsize ws;
/* Count entries for sort and find longest filename */
char *dir = NULL;
char cmd[2048];
struct sftp_conn *conn;
- int err;
+ int err, interactive;
EditLine *el = NULL;
#ifdef USE_LIBEDIT
History *hl = NULL;
setvbuf(stdout, NULL, _IOLBF, 0);
setvbuf(infile, NULL, _IOLBF, 0);
#else
- setlinebuf(stdout);
- setlinebuf(infile);
+ setlinebuf(stdout);
+ setlinebuf(infile);
#endif
+ interactive = !batchmode && isatty(STDIN_FILENO);
err = 0;
for (;;) {
char *cp;
signal(SIGINT, SIG_IGN);
if (el == NULL) {
- printf("sftp> ");
+ if (interactive)
+ printf("sftp> ");
if (fgets(cmd, sizeof(cmd), infile) == NULL) {
- printf("\n");
+ if (interactive)
+ printf("\n");
break;
}
- if (batchmode) /* Echo command */
- printf("%s", cmd);
+ if (!interactive) { /* Echo command */
+ printf("sftp> %s", cmd);
+ if (strlen(cmd) > 0 &&
+ cmd[strlen(cmd) - 1] != '\n')
+ printf("\n");
+ }
} else {
#ifdef USE_LIBEDIT
const char *line;
int count = 0;
- if ((line = el_gets(el, &count)) == NULL || count <= 0)
- break;
+ if ((line = el_gets(el, &count)) == NULL || count <= 0) {
+ printf("\n");
+ break;
+ }
history(hl, &hev, H_ENTER, line);
if (strlcpy(cmd, line, sizeof(cmd)) >= sizeof(cmd)) {
fprintf(stderr, "Error: input line too long\n");
}
xfree(pwd);
+#ifdef USE_LIBEDIT
+ if (el != NULL)
+ el_end(el);
+#endif /* USE_LIBEDIT */
+
/* err == 1 signifies normal "quit" exit */
return (err >= 0 ? 0 : -1);
}
/* Allow "-" as stdin */
if (strcmp(optarg, "-") != 0 &&
- (infile = fopen(optarg, "r")) == NULL)
+ (infile = fopen(optarg, "r")) == NULL)
fatal("%s (%s).", strerror(errno), optarg);
showprogress = 0;
batchmode = 1;
err = interactive_loop(in, out, file1, file2);
#if !defined(USE_PIPES)
- shutdown(in, SHUT_RDWR);
- shutdown(out, SHUT_RDWR);
+ shutdown(in, SHUT_RDWR);
+ shutdown(out, SHUT_RDWR);
#endif
close(in);