From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20698 invoked from network); 7 Oct 1998 08:00:35 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 7 Oct 1998 08:00:35 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id DAA07982; Wed, 7 Oct 1998 03:49:40 -0400 (EDT) Resent-Date: Wed, 7 Oct 1998 03:49:40 -0400 (EDT) Sender: rz2a022@uni-hamburg.de Message-ID: <361B1DF8.4F4833A5@rrz.uni-hamburg.de> Date: Wed, 07 Oct 1998 09:53:28 +0200 From: Bernd Eggink Organization: RRZ Uni Hamburg X-Mailer: Mozilla 4.06 [en] (X11; I; AIX 4.2) MIME-Version: 1.0 To: Bart Schaefer CC: Zsh hackers list Subject: Re: PATCH: 3.1.4: getopts References: <9810061245.AA28058@ibmth.df.unipi.it> <981006204350.ZM9969@candle.brasslantern.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Resent-Message-ID: <"5gGnR1.0.cy1.Kqn6s"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4418 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Bart Schaefer wrote: > > On Oct 6, 2:45pm, Peter Stephenson wrote: > } Subject: Re: PATCH: 3.1.4: getopts: forget it. > } > } I spoke too soon. Bernd's patch that I referred to does fix the > } problem, only more simply, so use that. It needs merging by hand. > > Is the following the correct merge? > > Index: Src/builtin.c > =================================================================== > *** builtin.c 1998/09/16 15:35:52 1.2 > --- builtin.c 1998/10/07 03:37:08 > *************** > *** 2546,2552 **** > char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++; > char **args = (*argv) ? argv : pparams; > static int optcind = 0; > ! char *str, optbuf[2], *p, opch; > > /* zoptind keeps count of the current argument number. The * > * user can set it to zero to start a new option parse. */ > --- 2546,2552 ---- > char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++; > char **args = (*argv) ? argv : pparams; > static int optcind = 0; > ! char *str, optbuf[2] = " ", *p, opch; > > /* zoptind keeps count of the current argument number. The * > * user can set it to zero to start a new option parse. */ > *************** > *** 2567,2576 **** > /* find place in relevant argument */ > str = unmetafy(dupstring(args[zoptind - 1]), &lenstr); > if(optcind >= lenstr) { > if(!args[zoptind++]) > return 1; > str = unmetafy(dupstring(args[zoptind - 1]), &lenstr); > - optcind = 0; > } > if(!optcind) { > if(lenstr < 2 || (*str != '-' && *str != '+')) > --- 2567,2576 ---- > /* find place in relevant argument */ > str = unmetafy(dupstring(args[zoptind - 1]), &lenstr); > if(optcind >= lenstr) { > + optcind = 0; > if(!args[zoptind++]) > return 1; > str = unmetafy(dupstring(args[zoptind - 1]), &lenstr); > } > if(!optcind) { > if(lenstr < 2 || (*str != '-' && *str != '+')) > *************** > *** 2593,2605 **** > if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) { > p = "?"; > err: > if(quiet) { > setsparam(var, ztrdup(p)); > - zsfree(zoptarg); > zoptarg = metafy(optbuf, lenoptbuf, META_DUP); > } else { > zerr(*p == '?' ? "bad option: -%c" : > "argument expected after -%c option", NULL, opch); > errflag = 0; > } > return 0; > --- 2593,2606 ---- > if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) { > p = "?"; > err: > + zsfree(zoptarg); > if(quiet) { > setsparam(var, ztrdup(p)); > zoptarg = metafy(optbuf, lenoptbuf, META_DUP); > } else { > zerr(*p == '?' ? "bad option: -%c" : > "argument expected after -%c option", NULL, opch); > + zoptarg=ztrdup(""); > errflag = 0; > } > return 0; > Yes, looks OK. Bernd -- Bernd Eggink Regionales Rechenzentrum der Uni Hamburg eggink@rrz.uni-hamburg.de http://www.rrz.uni-hamburg.de/eggink/BEggink.html