From: Sven Wischnowsky <wischnow@informatik.hu-berlin.de>
To: zsh-workers@sunsite.auc.dk
Subject: Re: PATCH: Re: _netscape
Date: Tue, 23 May 2000 15:15:13 +0200 (MET DST) [thread overview]
Message-ID: <200005231315.PAA24546@beta.informatik.hu-berlin.de> (raw)
In-Reply-To: Sven Wischnowsky's message of Mon, 22 May 2000 10:37:00 +0200 (MET DST)
I wrote:
> Oliver Kiddle wrote:
>
> > ...
> >
> > Basically, what a helper function needs to do is
> > take the suffix passed to it and when it is completing a final component
> > of itself, it should pass any suffix it wants with the one passed to it
> > appended. Pulling out -S options from "$@" is going to look messy
> > without some special handling at a lower level somewhere.
>
> It's mostly a bit of [(i)...] stuff, but yes, it's probably common
> enough... One idea would be to add an option to zparseopts to allow it
> to extract options. Actually, I've been wishing for something like
> that, too.
This is so simple to write that I think it's worth adding. So, this
adds the -E option to zparseopts that can be used to extract options
from the positional parameters. When combined with -D, the options
described are actually removed from $*.
Bye
Sven
Index: Doc/Zsh/mod_zutil.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_zutil.yo,v
retrieving revision 1.6
diff -u -r1.6 mod_zutil.yo
--- Doc/Zsh/mod_zutil.yo 2000/05/22 09:32:33 1.6
+++ Doc/Zsh/mod_zutil.yo 2000/05/23 13:14:08
@@ -131,7 +131,7 @@
This implements the internals of the `tt(_regex_arguments)'.
)
findex(zparseopts)
-item(tt(zparseopts) [ tt(-D) ] [ tt(-a) var(array) ] [ tt(-A) var(assoc) ] var(specs))(
+item(tt(zparseopts) [ tt(-D) ] [ tt(-E) ] [ tt(-a) var(array) ] [ tt(-A) var(assoc) ] var(specs))(
This builtin simplifies the parsing of options in positional
parameters, i.e. the set of arguments given by tt($*). Each var(spec)
describes one option and should be of the form
@@ -166,6 +166,9 @@
positional parameters, up to but not including any not described by the
var(specs). This means that any options processed by tt(zparseopts) are
removed from the positional parameters.
+
+The tt(-E) option allows to extract the options described by the
+var(specs) from the positional parameters, ignoring all other strings.
For example,
Index: Src/Modules/zutil.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/zutil.c,v
retrieving revision 1.4
diff -u -r1.4 zutil.c
--- Src/Modules/zutil.c 2000/05/22 09:32:33 1.4
+++ Src/Modules/zutil.c 2000/05/23 13:14:09
@@ -1261,8 +1261,8 @@
static int
bin_zparseopts(char *nam, char **args, char *ops, int func)
{
- char *o, *p, *n, **pp, **aval, **ap, *assoc = NULL;
- int del = 0, f;
+ char *o, *p, *n, **pp, **aval, **ap, *assoc = NULL, **cp, **np;
+ int del = 0, f, extract = 0;
Zoptdesc sopts[256], d;
Zoptarr a, defarr = NULL;
Zoptval v;
@@ -1290,6 +1290,14 @@
}
del = 1;
break;
+ case 'E':
+ if (o[2]) {
+ args--;
+ o = NULL;
+ break;
+ }
+ extract = 1;
+ break;
case 'a':
if (defarr) {
zwarnnam(nam, "default array given more than once", NULL, 0);
@@ -1400,10 +1408,19 @@
if (!o[1])
sopts[STOUC(*o)] = d;
}
- for (pp = pparams; (o = *pp); pp++) {
- if (*o != '-')
- break;
+ np = cp = pp = ((extract && del) ? arrdup(pparams) : pparams);
+ for (; (o = *pp); pp++) {
+ if (*o != '-') {
+ if (extract) {
+ if (del)
+ *cp++ = o;
+ continue;
+ } else
+ break;
+ }
if (!o[1] || (o[1] == '-' && !o[2])) {
+ if (del && extract)
+ *cp++ = o;
pp++;
break;
}
@@ -1429,8 +1446,14 @@
} else
add_opt_val(d, NULL);
}
- if (!o)
- break;
+ if (!o) {
+ if (extract) {
+ if (del)
+ *cp++ = *pp;
+ continue;
+ } else
+ break;
+ }
} else {
if (d->flags & ZOF_ARG) {
char *e = o + strlen(d->name) + 1;
@@ -1450,6 +1473,10 @@
add_opt_val(d, NULL);
}
}
+ if (extract && del)
+ while (*pp)
+ *cp++ = *pp++;
+
for (a = opt_arrs; a; a = a->next) {
aval = (char **) zalloc((a->num + 1) * sizeof(char *));
for (ap = aval, v = a->vals; v; ap++, v = v->next) {
@@ -1498,9 +1525,15 @@
sethparam(assoc, aval);
}
if (del) {
- pp = zarrdup(pp);
- freearray(pparams);
- pparams = pp;
+ if (extract) {
+ *cp = NULL;
+ freearray(pparams);
+ pparams = zarrdup(np);
+ } else {
+ pp = zarrdup(pp);
+ freearray(pparams);
+ pparams = pp;
+ }
}
return 0;
}
--
Sven Wischnowsky wischnow@informatik.hu-berlin.de
next reply other threads:[~2000-05-23 13:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-23 13:15 Sven Wischnowsky [this message]
2000-05-23 13:50 ` Oliver Kiddle
2000-05-23 14:43 ` zparseopts change (Re: PATCH: Re: _netscape) Bart Schaefer
-- strict thread matches above, loose matches on Subject: below --
2000-05-24 8:05 PATCH: Re: _netscape Sven Wischnowsky
2000-05-23 13:58 Sven Wischnowsky
2000-05-22 8:37 Sven Wischnowsky
2000-05-23 16:07 ` Oliver Kiddle
2000-05-18 11:02 Sven Wischnowsky
2000-05-19 18:39 ` Oliver Kiddle
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=200005231315.PAA24546@beta.informatik.hu-berlin.de \
--to=wischnow@informatik.hu-berlin.de \
--cc=zsh-workers@sunsite.auc.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).