summary refs log tree commit diff
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2001-12-16 20:53:44 +0000
committerClint Adams <clint@users.sourceforge.net>2001-12-16 20:53:44 +0000
commit1e103ebef330694fe94889127df2c166aa4804a1 (patch)
treec730f3b2d1833f8b1e6df853d40386d2d4f7c4d6
parent2c71f2ce29055c14083de7cc62b0bd6e652c712f (diff)
downloadzsh-1e103ebef330694fe94889127df2c166aa4804a1.tar.gz
zsh-1e103ebef330694fe94889127df2c166aa4804a1.tar.xz
zsh-1e103ebef330694fe94889127df2c166aa4804a1.zip
16345: (n) flag to remove duplicate array values during expansion.
-rw-r--r--ChangeLog6
-rw-r--r--Src/params.c17
-rw-r--r--Src/subst.c13
3 files changed, 36 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b090e5326..947057496 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-12-16  Clint Adams  <clint@zsh.org>
+
+	* 16345: Src/params.c, Src/subst.c:
+	(n) flag to remove duplicate array values during
+	expansion.
+
 2001-12-15  Clint Adams  <clint@zsh.org>
 
 	* unposted: zshconfig.ac: get rid of evil -Wno-implicit
diff --git a/Src/params.c b/Src/params.c
index 22346896d..cb08b4e6a 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2490,6 +2490,23 @@ uniqarray(char **x)
 	    }
 }
 
+/**/
+void
+zhuniqarray(char **x)
+{
+    char **t, **p = x;
+
+    if (!x || !*x)
+	return;
+    while (*++p)
+	for (t = x; t < p; t++)
+	    if (!strcmp(*p, *t)) {
+		*p = NULL;
+		for (t = p--; (*t = t[1]) != NULL; t++);
+		break;
+	    }
+}
+
 /* Function to get value of special parameter `#' and `ARGC' */
 
 /**/
diff --git a/Src/subst.c b/Src/subst.c
index a42b81358..9a59495d0 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -767,6 +767,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
     int flags = 0;
     int flnum = 0;
     int sortit = 0, casind = 0;
+    int unique = 0;
     int casmod = 0;
     int quotemod = 0, quotetype = 0, quoteerr = 0;
     int visiblemod = 0;
@@ -996,6 +997,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 		    shsplit = 1;
 		    break;
 
+		case 'n':
+		    unique = 1;
+		    break;
+
 		default:
 		  flagerr:
 		    zerr("error in flags", NULL, 0);
@@ -1873,6 +1878,14 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int ssub)
 	    setdata(n, y);
 	    return n;
 	}
+	if (unique) {
+/*	    if(!copied) */
+		aval = arrdup(aval);
+
+	    i = arrlen(aval);
+	    if (i > 1)
+		zhuniqarray(aval);
+	}
 	if (sortit) {
 	    static CompareFn sortfn[] = {
 		strpcmp, invstrpcmp, cstrpcmp, invcstrpcmp