zsh-workers
 help / color / mirror / code / Atom feed
* Anomaly in "getopts" in 3.1.0 (possibly earlier)
@ 1996-12-30 12:59 Colm Buckley
  1997-10-29 12:41 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Colm Buckley @ 1996-12-30 12:59 UTC (permalink / raw)
  To: zsh-workers


Hi all -

I don't know if this has been pointed out before, but 3.1.0 is
exhibiting slightly anomalous behaviour in "getopts".  It seems that a
leading "+" sign is ignored for the last option in the list, if further
arguments follow - the following should demonstrate the problem...

vangogh % cat test.zsh
#!/usr/local/bin/zsh
# Test script to demonstrate "getopts"

while getopts ":abc" opt ; do
  echo "Option is : $opt"
done
shift ((--OPTIND))
echo Remaining arguments are : $@

vangogh % test.zsh +a
Option is : +a
Remaining arguments are :
vangogh % test.zsh +ab
Option is : +a
Option is : +b
Remaining arguments are :
vangogh % test.zsh +a +b      
Option is : +a
Option is : +b
Remaining arguments are :
vangogh % test.zsh +a hello
Option is : a
Remaining arguments are : hello
vangogh % test.zsh +ab hello
Option is : +a
Option is : b
Remaining arguments are : hello
vangogh % test.zsh +a +b hello
Option is : +a
Option is : b
Remaining arguments are : hello

Notice that the '+' is removed from the final option, when there are
following arguments...  I don't think that this is the correct
behaviour.

           Colm

-- 
Colm Buckley B.F. | EMail : Colm.Buckley@tcd.ie or colm@lspace.org
Computer Science  | WWW   : http://isg.cs.tcd.ie/cbuckley/
Trinity College   | Phone : +353 87 469146 (087-469146 within Ireland)
Dublin 2, Ireland | "Microsoft : Where do you want to crash today?"


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

* Re: Anomaly in "getopts" in 3.1.0 (possibly earlier)
  1996-12-30 12:59 Anomaly in "getopts" in 3.1.0 (possibly earlier) Colm Buckley
@ 1997-10-29 12:41 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1997-10-29 12:41 UTC (permalink / raw)
  To: Zsh hackers list

This finally fixes this old bug.

Colm Buckley wrote:
> I don't know if this has been pointed out before, but 3.1.0 is
> exhibiting slightly anomalous behaviour in "getopts".  It seems that a
> leading "+" sign is ignored for the last option in the list, if further
> arguments follow - the following should demonstrate the problem...
> 
> vangogh % cat test.zsh
> #!/usr/local/bin/zsh
> # Test script to demonstrate "getopts"
> 
> while getopts ":abc" opt ; do
>   echo "Option is : $opt"
> done
> shift ((--OPTIND))
> echo Remaining arguments are : $@
>
> vangogh % test.zsh +a +b
> Option is : +a
> Option is : +b
> Remaining arguments are :
> vangogh % test.zsh +a +b hello
> Option is : +a
> Option is : b
> Remaining arguments are : hello

*** Src/builtin.c.plus	Fri Sep 26 17:38:55 1997
--- Src/builtin.c	Wed Oct 29 12:27:41 1997
***************
*** 2362,2368 ****
  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;
--- 2362,2368 ----
  int
  bin_getopts(char *name, char **argv, char *ops, int func)
  {
!     int lenstr, lenoptstr, i, plus;
      char *optstr = unmetafy(*argv++, &lenoptstr), *var = *argv++;
      char **args = (*argv) ? argv : pparams;
      static int optcind = 1, quiet;
***************
*** 2399,2404 ****
--- 2399,2405 ----
      if (!optcind)
  	optcind = 1;
      *opch = str[optcind++];
+     plus = (*str == '+');
      if (optcind == lenstr) {
  	if(args[zoptind++])
  	    str = unmetafy(args[zoptind - 1], &lenstr);
***************
*** 2421,2427 ****
  	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] == ':') {
  	if (!args[zoptind - 1]) {
--- 2422,2428 ----
  	return 0;
      }
      /* copy option into specified parameter, with + if required */
!     setsparam(var, metafy(opch - plus, 1 + plus, META_DUP));
      /* handle case of an expected extra argument */
      if (optstr[i + 1] == ':') {
  	if (!args[zoptind - 1]) {

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


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

end of thread, other threads:[~1997-10-29 12:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-30 12:59 Anomaly in "getopts" in 3.1.0 (possibly earlier) Colm Buckley
1997-10-29 12:41 ` Peter Stephenson

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