* Re: bug in getopts
[not found] <3.0.1.32.19970523124527.0068bae4@zin.adei.com>
@ 1997-05-25 21:57 ` Bernd Eggink
0 siblings, 0 replies; only message in thread
From: Bernd Eggink @ 1997-05-25 21:57 UTC (permalink / raw)
To: zsh workers mailing list; +Cc: Christopher T. White
[-- Attachment #1: Type: text/plain, Size: 758 bytes --]
Christopher T. White wrote:
>
> Dear ZSH users and workers,
>
> Forgive me if this has been addressed previously, but I haven't run into
> this particular situation before.
>
> Getops seems to be broken in zsh version 3.1.0.
It's broken in 3.0.2, too.
I looked into the sources and think I found the bug(s). Edit the file
zsh-3.1.0/Src/buitin.c, look for the function 'bin_getopts' and replace
that function by the attached version. I marked the changes with /*!!
(sorry, I'm not yet familiar with the patch utility).
After rebuild ingand reinstalling zsh, getopts should work correctly.
Regards,
Bernd
---
Bernd Eggink
Regionales Rechenzentrum der Universitaet Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html
[-- Attachment #2: getopts --]
[-- Type: text/plain, Size: 2383 bytes --]
int
bin_getopts(char *name, char **argv, char *ops, int func)
{
int lenstr, lenoptstr, i;
char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
char **args = (*argv) ? argv : pparams;
static int optcind = 1, quiet;
char *str, optbuf[2], *opch = optbuf + 1;
/* zoptind keeps count of the current argument number */
if (zoptind < 1)
/* first call */
zoptind = 1;
if (zoptind == 1)
{ /*!! added*/
quiet = 0;
optbuf[0] = '+';
zsfree(zoptarg);
zoptarg = ztrdup("");
setsparam(var, ztrdup(""));
if (*optstr == ':') {
quiet = 1;
optstr++;
}
} /*!! added*/
if (zoptind > arrlen(args))
return 1;
str = unmetafy(args[zoptind - 1], &lenstr);
if ((*str != '+' && *str != '-') || optcind >= lenstr ||
(lenstr == 2 && str[0] == '-' && str[1] == '-')) {
/* current argument doesn't contain options, or optcind is impossibly
large */
if (*str == '+' || *str == '-')
zoptind++;
optcind = 0;
return 1;
}
/* Get the option character. optcind records the current position within
the argument. */
if (!optcind)
optcind = 1;
*opch = str[optcind++];
if (optcind == lenstr) {
if(args[zoptind++])
str = unmetafy(args[zoptind - 1], &lenstr);
optcind = 0;
}
/* look for option in the provided optstr */
for (i = 0; i != lenoptstr; i++)
if (*opch == optstr[i])
break;
if (i == lenoptstr) {
/* not a valid option */
setsparam(var, ztrdup("?"));
if (quiet) {
zsfree(zoptarg);
zoptarg = metafy(opch, 1, META_DUP);
return 0;
}
zerr("bad option: -%c", NULL, *opch);
errflag = 0;
return 0;
}
/* copy option into specified parameter, with + if required */
setsparam(var, metafy(opch - (*str == '+'), 1 + (*str == '+'), META_DUP));
/* handle case of an expected extra argument */
if (optstr[i + 1] == ':') { /*!! changed 1 to i + 1 */
if (!args[zoptind - 1]) {
/* no extra argument was provided */
if (quiet) {
zsfree(zoptarg);
zoptarg = metafy(opch, 1, META_DUP);
setsparam(var, ztrdup(":"));
return 0;
}
setsparam(var, ztrdup("?"));
zerr("argument expected after -%c option", NULL, *opch);
errflag = 0;
return 0;
}
/* skip over the extra argument */
zsfree(zoptarg);
zoptarg = metafy(str + optcind, lenstr - optcind, META_DUP);
zoptind++;
optcind = 0;
}
return 0;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~1997-05-25 22:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <3.0.1.32.19970523124527.0068bae4@zin.adei.com>
1997-05-25 21:57 ` bug in getopts Bernd Eggink
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).