From: Clint Adams <clint@zsh.org>
To: Bart Schaefer <schaefer@candle.brasslantern.com>
Cc: zsh-workers@sunsite.dk
Subject: PATCH: remove duplicate array values in parameter expansion
Date: Sun, 16 Dec 2001 15:50:32 -0500 [thread overview]
Message-ID: <20011216205032.GA32057@dman.com> (raw)
In-Reply-To: <011214141539.ZM32471@candle.brasslantern.com>
> Hrm. That might not be a bad idea. It'd be nice if we could figure out
> a way to optimize it when combined with (o) or (O).
Other than replacing qsort for the combined base, I wouldn't know what
to do. Here it is; I used (n) since it was an unused letter in
'unique'.
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.52
diff -u -r1.52 params.c
--- Src/params.c 2001/11/03 23:36:33 1.52
+++ Src/params.c 2001/12/16 20:42:50
@@ -2490,6 +2490,23 @@
}
}
+/**/
+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' */
/**/
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.25
diff -u -r1.25 subst.c
--- Src/subst.c 2001/11/03 23:34:50 1.25
+++ Src/subst.c 2001/12/16 20:42:50
@@ -767,6 +767,7 @@
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 @@
shsplit = 1;
break;
+ case 'n':
+ unique = 1;
+ break;
+
default:
flagerr:
zerr("error in flags", NULL, 0);
@@ -1872,6 +1877,14 @@
strcpy(*str, fstr);
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[] = {
next prev parent reply other threads:[~2001-12-16 20:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-14 21:51 gripes Clint Adams
2001-12-14 22:15 ` gripes Bart Schaefer
2001-12-16 20:50 ` Clint Adams [this message]
2001-12-16 21:05 ` PATCH: remove duplicate array values in parameter expansion Clint Adams
2001-12-16 22:58 ` Zefram
2001-12-17 1:12 ` Clint Adams
2001-12-17 4:24 ` Bart Schaefer
2001-12-17 14:03 ` Clint Adams
2002-01-07 14:40 ` gripes Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20011216205032.GA32057@dman.com \
--to=clint@zsh.org \
--cc=schaefer@candle.brasslantern.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).