Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: 3.1.4: getopts



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@xxxxxxxxxxxxxxxxxx
http://www.rrz.uni-hamburg.de/eggink/BEggink.html



Messages sorted by: Reverse Date, Date, Thread, Author