|
Lines 1268-1274
makeargv(const char *arg, int *argcp, int sloppy, char *lastquote,
Link Here
|
| 1268 |
} |
1268 |
} |
| 1269 |
|
1269 |
|
| 1270 |
static int |
1270 |
static int |
| 1271 |
parse_args(const char **cpp, int *ignore_errors, int *aflag, |
1271 |
parse_args(const char **cpp, int *ignore_errors, int *disable_echo, int *aflag, |
| 1272 |
int *fflag, int *hflag, int *iflag, int *lflag, int *pflag, |
1272 |
int *fflag, int *hflag, int *iflag, int *lflag, int *pflag, |
| 1273 |
int *rflag, int *sflag, |
1273 |
int *rflag, int *sflag, |
| 1274 |
unsigned long *n_arg, char **path1, char **path2) |
1274 |
unsigned long *n_arg, char **path1, char **path2) |
|
Lines 1282-1294
parse_args(const char **cpp, int *ignore_errors, int *aflag,
Link Here
|
| 1282 |
/* Skip leading whitespace */ |
1282 |
/* Skip leading whitespace */ |
| 1283 |
cp = cp + strspn(cp, WHITESPACE); |
1283 |
cp = cp + strspn(cp, WHITESPACE); |
| 1284 |
|
1284 |
|
| 1285 |
/* Check for leading '-' (disable error processing) */ |
1285 |
/* |
|
|
1286 |
* Check for leading '-' (disable error processing) and '@' (suppress |
| 1287 |
* command echo) |
| 1288 |
*/ |
| 1286 |
*ignore_errors = 0; |
1289 |
*ignore_errors = 0; |
| 1287 |
if (*cp == '-') { |
1290 |
*disable_echo = 0; |
| 1288 |
*ignore_errors = 1; |
1291 |
for (;*cp != '\0'; cp++) { |
| 1289 |
cp++; |
1292 |
if (*cp == '-') { |
| 1290 |
cp = cp + strspn(cp, WHITESPACE); |
1293 |
*ignore_errors = 1; |
|
|
1294 |
} else if (*cp == '@') { |
| 1295 |
*disable_echo = 1; |
| 1296 |
} else { |
| 1297 |
/* all other characters terminate prefix processing */ |
| 1298 |
break; |
| 1299 |
} |
| 1291 |
} |
1300 |
} |
|
|
1301 |
cp = cp + strspn(cp, WHITESPACE); |
| 1292 |
|
1302 |
|
| 1293 |
/* Ignore blank lines and lines which begin with comment '#' char */ |
1303 |
/* Ignore blank lines and lines which begin with comment '#' char */ |
| 1294 |
if (*cp == '\0' || *cp == '#') |
1304 |
if (*cp == '\0' || *cp == '#') |
|
Lines 1463-1473
parse_args(const char **cpp, int *ignore_errors, int *aflag,
Link Here
|
| 1463 |
|
1473 |
|
| 1464 |
static int |
1474 |
static int |
| 1465 |
parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, |
1475 |
parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, |
| 1466 |
const char *startdir, int err_abort) |
1476 |
const char *startdir, int err_abort, int echo_command) |
| 1467 |
{ |
1477 |
{ |
|
|
1478 |
const char *ocmd = cmd; |
| 1468 |
char *path1, *path2, *tmp; |
1479 |
char *path1, *path2, *tmp; |
| 1469 |
int ignore_errors = 0, aflag = 0, fflag = 0, hflag = 0, |
1480 |
int ignore_errors = 0, disable_echo = 1; |
| 1470 |
iflag = 0; |
1481 |
int aflag = 0, fflag = 0, hflag = 0, iflag = 0; |
| 1471 |
int lflag = 0, pflag = 0, rflag = 0, sflag = 0; |
1482 |
int lflag = 0, pflag = 0, rflag = 0, sflag = 0; |
| 1472 |
int cmdnum, i; |
1483 |
int cmdnum, i; |
| 1473 |
unsigned long n_arg = 0; |
1484 |
unsigned long n_arg = 0; |
|
Lines 1477-1487
parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
Link Here
|
| 1477 |
glob_t g; |
1488 |
glob_t g; |
| 1478 |
|
1489 |
|
| 1479 |
path1 = path2 = NULL; |
1490 |
path1 = path2 = NULL; |
| 1480 |
cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag, |
1491 |
cmdnum = parse_args(&cmd, &ignore_errors, &disable_echo, &aflag, &fflag, |
| 1481 |
&iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, &path1, &path2); |
1492 |
&hflag, &iflag, &lflag, &pflag, &rflag, &sflag, &n_arg, |
|
|
1493 |
&path1, &path2); |
| 1482 |
if (ignore_errors != 0) |
1494 |
if (ignore_errors != 0) |
| 1483 |
err_abort = 0; |
1495 |
err_abort = 0; |
| 1484 |
|
1496 |
|
|
|
1497 |
if (echo_command && !disable_echo) |
| 1498 |
mprintf("sftp> %s\n", ocmd); |
| 1499 |
|
| 1485 |
memset(&g, 0, sizeof(g)); |
1500 |
memset(&g, 0, sizeof(g)); |
| 1486 |
|
1501 |
|
| 1487 |
/* Perform command */ |
1502 |
/* Perform command */ |
|
Lines 2137-2143
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
Link Here
|
| 2137 |
mprintf("Changing to: %s\n", dir); |
2152 |
mprintf("Changing to: %s\n", dir); |
| 2138 |
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); |
2153 |
snprintf(cmd, sizeof cmd, "cd \"%s\"", dir); |
| 2139 |
if (parse_dispatch_command(conn, cmd, |
2154 |
if (parse_dispatch_command(conn, cmd, |
| 2140 |
&remote_path, startdir, 1) != 0) { |
2155 |
&remote_path, startdir, 1, 0) != 0) { |
| 2141 |
free(dir); |
2156 |
free(dir); |
| 2142 |
free(startdir); |
2157 |
free(startdir); |
| 2143 |
free(remote_path); |
2158 |
free(remote_path); |
|
Lines 2151-2157
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
Link Here
|
| 2151 |
file2 == NULL ? "" : " ", |
2166 |
file2 == NULL ? "" : " ", |
| 2152 |
file2 == NULL ? "" : file2); |
2167 |
file2 == NULL ? "" : file2); |
| 2153 |
err = parse_dispatch_command(conn, cmd, |
2168 |
err = parse_dispatch_command(conn, cmd, |
| 2154 |
&remote_path, startdir, 1); |
2169 |
&remote_path, startdir, 1, 0); |
| 2155 |
free(dir); |
2170 |
free(dir); |
| 2156 |
free(startdir); |
2171 |
free(startdir); |
| 2157 |
free(remote_path); |
2172 |
free(remote_path); |
|
Lines 2167-2173
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
Link Here
|
| 2167 |
interactive = !batchmode && isatty(STDIN_FILENO); |
2182 |
interactive = !batchmode && isatty(STDIN_FILENO); |
| 2168 |
err = 0; |
2183 |
err = 0; |
| 2169 |
for (;;) { |
2184 |
for (;;) { |
| 2170 |
char *cp; |
|
|
| 2171 |
const char *line; |
2185 |
const char *line; |
| 2172 |
int count = 0; |
2186 |
int count = 0; |
| 2173 |
|
2187 |
|
|
Lines 2181-2192
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
Link Here
|
| 2181 |
printf("\n"); |
2195 |
printf("\n"); |
| 2182 |
break; |
2196 |
break; |
| 2183 |
} |
2197 |
} |
| 2184 |
if (!interactive) { /* Echo command */ |
|
|
| 2185 |
mprintf("sftp> %s", cmd); |
| 2186 |
if (strlen(cmd) > 0 && |
| 2187 |
cmd[strlen(cmd) - 1] != '\n') |
| 2188 |
printf("\n"); |
| 2189 |
} |
| 2190 |
} else { |
2198 |
} else { |
| 2191 |
if ((line = el_gets(el, &count)) == NULL || |
2199 |
if ((line = el_gets(el, &count)) == NULL || |
| 2192 |
count <= 0) { |
2200 |
count <= 0) { |
|
Lines 2200-2215
interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
Link Here
|
| 2200 |
} |
2208 |
} |
| 2201 |
} |
2209 |
} |
| 2202 |
|
2210 |
|
| 2203 |
cp = strrchr(cmd, '\n'); |
2211 |
cmd[strcspn(cmd, "\n")] = '\0'; |
| 2204 |
if (cp) |
|
|
| 2205 |
*cp = '\0'; |
| 2206 |
|
2212 |
|
| 2207 |
/* Handle user interrupts gracefully during commands */ |
2213 |
/* Handle user interrupts gracefully during commands */ |
| 2208 |
interrupted = 0; |
2214 |
interrupted = 0; |
| 2209 |
signal(SIGINT, cmd_interrupt); |
2215 |
signal(SIGINT, cmd_interrupt); |
| 2210 |
|
2216 |
|
| 2211 |
err = parse_dispatch_command(conn, cmd, &remote_path, |
2217 |
err = parse_dispatch_command(conn, cmd, &remote_path, |
| 2212 |
startdir, batchmode); |
2218 |
startdir, batchmode, !interactive && el == NULL); |
| 2213 |
if (err != 0) |
2219 |
if (err != 0) |
| 2214 |
break; |
2220 |
break; |
| 2215 |
} |
2221 |
} |