about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2012-05-31 21:08:31 +0200
committerMikael Magnusson <mikachu@gmail.com>2014-09-16 00:27:05 +0200
commit78dd672e1a8550f93ccd586b6a9ad35369c796f7 (patch)
tree9959af12149dfcfa2f5a4b7db8a380066dcb0dc4
parent089123f9e892e435dc23f5958571be4c26d52d7b (diff)
downloadzsh-78dd672e1a8550f93ccd586b6a9ad35369c796f7.tar.gz
zsh-78dd672e1a8550f93ccd586b6a9ad35369c796f7.tar.xz
zsh-78dd672e1a8550f93ccd586b6a9ad35369c796f7.zip
33136: P glob qual appends words when negated
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/expn.yo6
-rw-r--r--Src/glob.c21
3 files changed, 26 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index f2e65a89c..01db3d53d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-09-16  Mikael Magnusson  <mikachu@gmail.com>
+
+	* 33136: Doc/Zsh/expn.yo, Src/glob.c: P glob qualifier appends
+	words when negated.
+
 2014-09-14  Marc Finet  <m.dreadlock@gmail.com>
 
 	* 33149: Misc/vcs_info-examples: vcs_info examples: fix typo
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 532672b10..3fad8667d 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -2663,6 +2663,12 @@ 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) ...'
+
+If the modifier tt(^) is active, then var(string) will be appended
+instead of prepended.  Prepending and appending is done independently
+so both can be used on the same glob expression; for example by writing
+`tt(*(P:foo:^P:bar:^P:baz:))' which produces the command line arguments
+`tt(foo) tt(baz) var(file1) tt(bar) ...'
 )
 enditem()
 
diff --git a/Src/glob.c b/Src/glob.c
index cb853870a..c24bfec93 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -178,7 +178,7 @@ struct globdata {
     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;
+    LinkList gd_gf_pre_words, gd_gf_post_words;
 
     char *gd_glob_pre, *gd_glob_suf;
 };
@@ -210,6 +210,7 @@ static struct globdata curglobdata;
 #define gf_nsorts     (curglobdata.gd_gf_nsorts)
 #define gf_sortlist   (curglobdata.gd_gf_sortlist)
 #define gf_pre_words  (curglobdata.gd_gf_pre_words)
+#define gf_post_words (curglobdata.gd_gf_post_words)
 
 /* and macros for save/restore */
 
@@ -1074,7 +1075,14 @@ insert_glob_match(LinkList list, LinkNode next, char *data)
 	}
     }
 
-    insertlinknode(list, next, data);
+    next = insertlinknode(list, next, data);
+
+    if (gf_post_words) {
+	LinkNode added;
+	for (added = firstnode(gf_post_words); added; incnode(added)) {
+	    next = insertlinknode(list, next, dupstring(getdata(added)));
+	}
+    }
 }
 
 /*
@@ -1190,7 +1198,7 @@ zglob(LinkList list, LinkNode np, int nountok)
     gf_noglobdots = unset(GLOBDOTS);
     gf_numsort = isset(NUMERICGLOBSORT);
     gf_sorts = gf_nsorts = 0;
-    gf_pre_words = NULL;
+    gf_pre_words = gf_post_words = NULL;
 
     /* Check for qualifiers */
     while (!nobareglob ||
@@ -1679,9 +1687,10 @@ zglob(LinkList list, LinkNode np, int nountok)
 
 		    if (tt != NULL)
 		    {
-			if (!gf_pre_words)
-			    gf_pre_words = newlinklist();
-			addlinknode(gf_pre_words, tt);
+			LinkList *words = sense & 1 ? &gf_post_words : &gf_pre_words;
+			if (!*words)
+			    *words = newlinklist();
+			addlinknode(*words, tt);
 		    }
 		    break;
 		}