zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: 3.1.4: getopts not reset properly for new function
@ 1998-10-06 12:18 Peter Stephenson
  1998-10-06 12:45 ` PATCH: 3.1.4: getopts: forget it Peter Stephenson
  1998-10-06 14:44 ` mla referencing (Was: PATCH: 3.1.4: getopts not reset properly for new function) Geoff Wing
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 1998-10-06 12:18 UTC (permalink / raw)
  To: Zsh hackers list

There have been various getopts() patches, but this hadn't been fixed
up to the last I saw, Bernd Eggink's in
http://www.zsh.org/mla/workers/1998/msg00132.html
which looks like it hasn't appeared yet.

However, my link to www.zsh.org is awful, involving 22 hops and more
delays than Gatwick Airport, so I couldn't check for anything more
recent.  We could do with a mirror north of the Equator, even if it
was only the index.

Strange, though, because it's a fairly blatant bug...

% zsh -f
% fn() { local f; while getopts abcd f; do print $f; done; }
% fn -a
a
% fn -abc
b
c
% fn -abc
%

(Workaround, if you get very frustrated in the meanwhile:  finish all
options with a -:
% fn -abcd -
a
b
c
d
% fn -a -   
a
% fn -abc -
a
b
c
% fn -abc -
a
b
c
.)

*** Src/builtin.c.opt	Tue Oct  6 11:57:57 1998
--- Src/builtin.c	Tue Oct  6 12:04:37 1998
***************
*** 2537,2542 ****
--- 2537,2545 ----
      return ret;
  }
  
+ /**/
+ int optcind;
+ 
  /* getopts: automagical option handling for shell scripts */
  
  /**/
***************
*** 2546,2552 ****
      int lenstr, lenoptstr, quiet, lenoptbuf;
      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 *
--- 2549,2554 ----
*** Src/exec.c.opt	Mon Sep 28 11:37:19 1998
--- Src/exec.c	Tue Oct  6 12:06:13 1998
***************
*** 2654,2660 ****
   * was executed.                                            */
  {
      char **tab, **x, *oargv0 = NULL;
!     int xexittr, newexittr, oldzoptind, oldlastval;
      char *ou;
      void *xexitfn, *newexitfn;
      char saveopts[OPT_SIZE];
--- 2654,2660 ----
   * was executed.                                            */
  {
      char **tab, **x, *oargv0 = NULL;
!     int xexittr, newexittr, oldzoptind, oldlastval, oldoptcind;
      char *ou;
      void *xexitfn, *newexitfn;
      char saveopts[OPT_SIZE];
***************
*** 2673,2680 ****
--- 2673,2683 ----
  	sigtrapped[SIGEXIT] = 0;
  	sigfuncs[SIGEXIT] = NULL;
  	tab = pparams;
+ 	/* Reset getopts variables for new function */
  	oldzoptind = zoptind;
  	zoptind = 1;
+ 	oldoptcind = optcind;
+ 	optcind = 0;
  
  	/* We need to save the current options even if LOCALOPTIONS is *
  	 * not currently set.  That's because if it gets set in the    *
***************
*** 2721,2726 ****
--- 2724,2730 ----
  	    argzero = oargv0;
  	}
  	zoptind = oldzoptind;
+ 	optcind = oldoptcind;
  	pparams = tab;
  
  	if (isset(LOCALOPTIONS)) {

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-10-07  8:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-06 12:18 PATCH: 3.1.4: getopts not reset properly for new function Peter Stephenson
1998-10-06 12:45 ` PATCH: 3.1.4: getopts: forget it Peter Stephenson
1998-10-07  3:43   ` PATCH: 3.1.4: getopts Bart Schaefer
1998-10-07  7:39     ` Peter Stephenson
1998-10-07  7:53     ` Bernd Eggink
1998-10-06 14:44 ` mla referencing (Was: PATCH: 3.1.4: getopts not reset properly for new function) Geoff Wing

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).