From 3394416cef1cce33c820cc00cbec2fc050bf189b Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 16 Dec 2004 17:45:29 +0000 Subject: [PATCH] Wildcards in `ls'. I think that completes `psftp-multi'. Woo! git-svn-id: svn://svn.tartarus.org/sgt/putty@4992 cda61777-01e9-0310-a592-d414129be87e --- doc/psftp.but | 6 ++++++ psftp.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/doc/psftp.but b/doc/psftp.but index d9c070c1..5f6a65de 100644 --- a/doc/psftp.but +++ b/doc/psftp.but @@ -338,6 +338,12 @@ You can also list the contents of a different directory by typing \c dir /home/fred \c dir sources +And you can list a subset of the contents of a directory by +providing a wildcard: + +\c dir /home/fred/*.txt +\c dir sources/*.c + The \c{ls} command works exactly the same way as \c{dir}. \S{psftp-cmd-chmod} The \c{chmod} command: change permissions on diff --git a/psftp.c b/psftp.c index bd1f9cbf..de1964e8 100644 --- a/psftp.c +++ b/psftp.c @@ -777,7 +777,7 @@ int sftp_cmd_ls(struct sftp_command *cmd) struct fxp_names *names; struct fxp_name **ournames; int nnames, namesize; - char *dir, *cdir; + char *dir, *cdir, *unwcdir, *wildcard; struct sftp_packet *pktin; struct sftp_request *req, *rreq; int i; @@ -792,9 +792,35 @@ int sftp_cmd_ls(struct sftp_command *cmd) else dir = cmd->words[1]; + unwcdir = snewn(1 + strlen(dir), char); + if (wc_unescape(unwcdir, dir)) { + dir = unwcdir; + wildcard = NULL; + } else { + char *tmpdir; + int len, check; + + wildcard = stripslashes(dir, 0); + unwcdir = dupstr(dir); + len = wildcard - dir; + unwcdir[len] = '\0'; + if (len > 0 && unwcdir[len-1] == '/') + unwcdir[len-1] = '\0'; + tmpdir = snewn(1 + len, char); + check = wc_unescape(tmpdir, unwcdir); + sfree(tmpdir); + if (!check) { + printf("Multiple-level wildcards are not supported\n"); + sfree(unwcdir); + return 0; + } + dir = unwcdir; + } + cdir = canonify(dir); if (!cdir) { printf("%s: %s\n", dir, fxp_error()); + sfree(unwcdir); return 0; } @@ -835,7 +861,8 @@ int sftp_cmd_ls(struct sftp_command *cmd) } for (i = 0; i < names->nnames; i++) - ournames[nnames++] = fxp_dup_name(&names->names[i]); + if (!wildcard || wc_match(wildcard, names->names[i].filename)) + ournames[nnames++] = fxp_dup_name(&names->names[i]); fxp_free_names(names); } @@ -861,6 +888,7 @@ int sftp_cmd_ls(struct sftp_command *cmd) } sfree(cdir); + sfree(unwcdir); return 1; } @@ -987,7 +1015,7 @@ int sftp_general_get(struct sftp_command *cmd, int restart, int multiple) if (!multiple && i < cmd->nwords) outfname = cmd->words[i++]; else - outfname = stripslashes(origfname, 1); + outfname = stripslashes(origfname, 0); ret = sftp_get_file(fname, outfname, recurse, restart, NULL); -- 2.11.0