From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23203 invoked by alias); 9 Feb 2010 14:30:24 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27694 Received: (qmail 23620 invoked from network); 9 Feb 2010 14:30:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=ham version=3.2.5 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@zsh.org (Zsh hackers list) Subject: PATCH: glob qualifier to prepend a word X-Mailer: MH-E 8.0.3; nmh 1.3; GNU Emacs 22.1.1 Date: Tue, 09 Feb 2010 14:30:08 +0000 Message-ID: <6084.1265725808@csr.com> From: Peter Stephenson X-OriginalArrivalTime: 09 Feb 2010 14:30:10.0251 (UTC) FILETIME=[624651B0:01CAA994] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-09-22-10 (www.mailcontrol.com) on 10.68.0.128 Done properly, this time; fairly small and localised change so it looks worth having. The word "prepend" doesn't exist in Chambers, but is already liberally sprinkled around the documentation. Index: NEWS =================================================================== RCS file: /cvsroot/zsh/zsh/NEWS,v retrieving revision 1.28 diff -u -r1.28 NEWS --- NEWS 22 Oct 2009 09:28:04 -0000 1.28 +++ NEWS 9 Feb 2010 14:27:08 -0000 @@ -4,6 +4,13 @@ Note also the list of incompatibilities in the README file. +Changes between versions 4.3.10 and 4.3.11 +------------------------------------------ + +The glob qualifier P can be used to add a separate word before each +match. For example, *(P:-f:) produces the command line +`-f file1 -f file2 ...'. + Changes between versions 4.3.9 and 4.3.10 ----------------------------------------- Index: Completion/Zsh/Type/_globquals =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Type/_globquals,v retrieving revision 1.4 diff -u -r1.4 _globquals --- Completion/Zsh/Type/_globquals 31 Jan 2010 19:50:44 -0000 1.4 +++ Completion/Zsh/Type/_globquals 9 Feb 2010 14:27:08 -0000 @@ -31,10 +31,10 @@ fi ;; - (e) + ([eP]) # complete/skip delimited command line if [[ -z $PREFIX ]]; then - _delimiters qualifer-e + _delimiters qualifer-$char return elif ! _globqual_delims; then # still completing command to eval Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.107 diff -u -r1.107 expn.yo --- Doc/Zsh/expn.yo 19 Sep 2009 16:23:22 -0000 1.107 +++ Doc/Zsh/expn.yo 9 Feb 2010 14:27:08 -0000 @@ -2296,6 +2296,18 @@ them count from the last match backward. E.g.: `tt(*(-OL[1,3]))' gives a list of the names of the three largest files. ) +item(tt(P))(var(string))( +The var(string) will be prepended to each glob match as a separate +word. var(string) is delimited in the same way as arguments to the +tt(e) glob qualifier described above. The qualifier can be repeated; +the words are prepended separately so that the resulting command +line contains the words in the same order they were given in the +list of glob qualifiers. + +A typical use for this is to prepend an option before all occurrences +of a file name; for example, the pattern `tt(*(P:-f:))' produces the +command line arguments `tt(-f) var(file1) tt(-f) var(file2) ...' +) enditem() More than one of these lists can be combined, separated by commas. The Index: Src/glob.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/glob.c,v retrieving revision 1.70 diff -u -r1.70 glob.c --- Src/glob.c 24 Mar 2009 12:52:07 -0000 1.70 +++ Src/glob.c 9 Feb 2010 14:27:08 -0000 @@ -176,6 +176,7 @@ int gd_gf_numsort; int gd_gf_follow, gd_gf_sorts, gd_gf_nsorts; struct globsort gd_gf_sortlist[MAX_SORTS]; + LinkList gd_gf_pre_words; char *gd_glob_pre, *gd_glob_suf; }; @@ -206,6 +207,7 @@ #define gf_sorts (curglobdata.gd_gf_sorts) #define gf_nsorts (curglobdata.gd_gf_nsorts) #define gf_sortlist (curglobdata.gd_gf_sortlist) +#define gf_pre_words (curglobdata.gd_gf_pre_words) /* and macros for save/restore */ @@ -1031,8 +1033,8 @@ /* - * Get a glob string for execution, following e or + qualifiers. - * Pointer is character after the e or +. + * Get a glob string for execution, following e, P or + qualifiers. + * Pointer is character after the e, P or +. */ /**/ @@ -1072,6 +1074,23 @@ return sdata; } +/* + * Insert a glob match. + * If there were words to prepend given by the P glob qualifier, do so. + */ +static void +insert_glob_match(LinkList list, LinkNode next, char *data) +{ + if (gf_pre_words) { + LinkNode added; + for (added = firstnode(gf_pre_words); added; incnode(added)) { + next = insertlinknode(list, next, dupstring(getdata(added))); + } + } + + insertlinknode(list, next, data); +} + /* Main entry point to the globbing code for filename globbing. * * np points to a node in the list list which will be expanded * * into a series of nodes. */ @@ -1606,6 +1625,19 @@ end = v.end; break; } + case 'P': + { + char *tt; + tt = glob_exec_string(&s); + + if (tt != NULL) + { + if (!gf_pre_words) + gf_pre_words = newlinklist(); + addlinknode(gf_pre_words, tt); + } + break; + } default: zerr("unknown file attribute"); restore_globstate(saved); @@ -1816,14 +1848,14 @@ matchptr = matchbuf + matchct - first - 1; while (end-- > 0) { /* insert matches in the arg list */ - insertlinknode(list, node, matchptr->name); + insert_glob_match(list, node, matchptr->name); matchptr--; } } else { matchptr = matchbuf + matchct - first - end; while (end-- > 0) { /* insert matches in the arg list */ - insertlinknode(list, node, matchptr->name); + insert_glob_match(list, node, matchptr->name); matchptr++; } } Index: Test/D02glob.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/D02glob.ztst,v retrieving revision 1.15 diff -u -r1.15 D02glob.ztst --- Test/D02glob.ztst 18 Nov 2008 10:07:31 -0000 1.15 +++ Test/D02glob.ztst 9 Feb 2010 14:27:08 -0000 @@ -343,6 +343,47 @@ 0:Exclusions with complicated path specifications >glob.tmp/dir1 glob.tmp/dir2 glob.tmp/dir4 + print -l -- glob.tmp/*(P:-f:) +0:Prepending words to each argument +>-f +>glob.tmp/a +>-f +>glob.tmp/b +>-f +>glob.tmp/c +>-f +>glob.tmp/dir1 +>-f +>glob.tmp/dir2 +>-f +>glob.tmp/dir3 +>-f +>glob.tmp/dir4 + + print -l -- glob.tmp/*(P:one word:P:another word:) +0:Prepending two words to each argument +>one word +>another word +>glob.tmp/a +>one word +>another word +>glob.tmp/b +>one word +>another word +>glob.tmp/c +>one word +>another word +>glob.tmp/dir1 +>one word +>another word +>glob.tmp/dir2 +>one word +>another word +>glob.tmp/dir3 +>one word +>another word +>glob.tmp/dir4 + [[ "" = "" ]] && echo OK 0:Empty strings >OK -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom