From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9965 invoked from network); 25 May 1997 22:00:34 -0000 Received: from euclid.skiles.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 25 May 1997 22:00:34 -0000 Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id RAA11000; Sun, 25 May 1997 17:53:27 -0400 (EDT) Resent-Date: Sun, 25 May 1997 17:53:27 -0400 (EDT) Sender: rz2a022@rrz.uni-hamburg.de Message-Id: <3388B5BC.23485FC9@rrz.uni-hamburg.de> Date: Sun, 25 May 1997 23:57:16 +0200 From: Bernd Eggink Organization: Regionales Rechenzentrum der Uni Hamburg X-Mailer: Mozilla 3.01 (X11; I; Linux 2.0.29 i586) Mime-Version: 1.0 To: zsh workers mailing list Cc: "Christopher T. White" Subject: Re: bug in getopts References: <3.0.1.32.19970523124527.0068bae4@zin.adei.com> Content-Type: multipart/mixed; boundary="------------197C18D92009171C3B5205CF" Resent-Message-ID: <"J8_nm3.0.oh2.NJBYp"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3167 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu This is a multi-part message in MIME format. --------------197C18D92009171C3B5205CF Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 --------------197C18D92009171C3B5205CF Content-Type: text/plain; charset=us-ascii; name="getopts" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="getopts" 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; } --------------197C18D92009171C3B5205CF--