zsh-workers
 help / color / mirror / code / Atom feed
* parameter substitution used in _values
@ 2001-06-01 13:14 Oliver Kiddle
  2001-06-01 13:39 ` Sven Wischnowsky
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Kiddle @ 2001-06-01 13:14 UTC (permalink / raw)
  To: zsh-workers

Any ideas why the difference between using $1 and $a here below:

% set -- '-Opath'
% a="$1"
% echo ${(@P)1[3,-1]}
9XZfims
% echo ${(@P)a[3,-1]}
/usr/lib/jdk1.3/bin /usr/bin /bin ... etc ...

I'm guessing that the 9XZfims is the list of single letter options but
why that and not the value of $path? This stuff is used at the beginning
of _values where it parses its options so it looks to me like _values
won't work with no space between -O and its argument.

Oliver


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

* Re: parameter substitution used in _values
  2001-06-01 13:14 parameter substitution used in _values Oliver Kiddle
@ 2001-06-01 13:39 ` Sven Wischnowsky
  2001-06-01 14:21   ` Oliver Kiddle
  2001-06-01 15:01   ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2001-06-01 13:39 UTC (permalink / raw)
  To: zsh-workers

Oliver Kiddle wrote:

> Any ideas why the difference between using $1 and $a here below:
> 
> % set -- '-Opath'
> % a="$1"
> % echo ${(@P)1[3,-1]}
> 9XZfims
> % echo ${(@P)a[3,-1]}
> /usr/lib/jdk1.3/bin /usr/bin /bin ... etc ...
> 
> I'm guessing that the 9XZfims is the list of single letter options but
> why that and not the value of $path? This stuff is used at the beginning
> of _values where it parses its options so it looks to me like _values
> won't work with no space between -O and its argument.

Oh rats.

The problem is that the positional parameters are internally turned into
`$argv[n]'.  And, as one can see, 

  % a=(-opath)
  % echo ${(@P)a[1][3,-1]}

doesn't `work' either. The reason is that fetchvalue() applies only one
subscript level, so the second fetchvalue() for the P flags doesn't get
`path' in those cases.

Obviously I wasn't aware of that and I don;t like it either, but see no
simple fix (for the C-code).

In the shell code we have to use `${(@P)${1[1,3]}}' for now.  Oliver, if
you have your hands in there anyway, could you?


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: parameter substitution used in _values
  2001-06-01 13:39 ` Sven Wischnowsky
@ 2001-06-01 14:21   ` Oliver Kiddle
  2001-06-01 15:01   ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2001-06-01 14:21 UTC (permalink / raw)
  To: zsh-workers

Sven Wischnowsky wrote:
> 
> The problem is that the positional parameters are internally turned into
> `$argv[n]'.  And, as one can see,

Ah, that explains.

> In the shell code we have to use `${(@P)${1[1,3]}}' for now.  Oliver, if
> you have your hands in there anyway, could you?

Okay. I assume you meant ${(@P)${1[3,-1]}} and this change does that and
the same for a similar piece of code in _arguments. I was looking at
using zparseopts to handle more options but I won't change it to that
this close to the release.

Does `opt' need to be declared local in _values for any reason or is
that some old leftover?

Oliver

Index: Base/Utility/_arguments
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_arguments,v
retrieving revision 1.6
diff -u -r1.6 _arguments
--- Base/Utility/_arguments     2001/05/31 12:38:34     1.6
+++ Base/Utility/_arguments     2001/06/01 14:13:20
@@ -178,7 +178,7 @@
   case "$1" in
   -C)  usecc=yes; shift ;;
   -O)  subopts=( "${(@P)2}" ); shift 2 ;;
-  -O*) subopts=( "${(@P)1[3,-1]}" ); shift ;;
+  -O*) subopts=( "${(@P)${1[3,-1]}}" ); shift ;;
   -R)  rawret=yes; shift;;
   -w)  optarg=yes; shift;;
   -s)  singopt=(-s); shift;;
Index: Base/Utility/_values
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Utility/_values,v
retrieving revision 1.3
diff -u -r1.3 _values
--- Base/Utility/_values        2001/05/31 08:18:37     1.3
+++ Base/Utility/_values        2001/06/01 14:13:20
@@ -7,7 +7,7 @@
   case "$1" in
   -C) usecc=yes; shift ;;
   -O) subopts=( "${(@P)2}" ); shift 2 ;;
-  *)  subopts=( "${(@P)1[3,-1]}" ); shift ;;
+  *)  subopts=( "${(@P)${1[3,-1]}}" ); shift ;;
   esac
 done


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

* Re: parameter substitution used in _values
  2001-06-01 13:39 ` Sven Wischnowsky
  2001-06-01 14:21   ` Oliver Kiddle
@ 2001-06-01 15:01   ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2001-06-01 15:01 UTC (permalink / raw)
  To: zsh-workers

On Jun 1,  3:39pm, Sven Wischnowsky wrote:
} Subject: Re: parameter substitution used in _values
}
} The problem is that the positional parameters are internally turned into
} `$argv[n]'.

This is a bit strange on many levels:

zsh% noargv() { unset argv }
zsh% showargv() {
function> echo 1=$1 2=$2 @=\($@\) argv=\($argv\) $+argv
function> noargv
function> echo 1=$1 2=$2 @=\($@\) argv=\($argv\) $+argv
function> unset argv
function> echo 1=$1 2=$2 @=\($@\) argv=\($argv\) $+argv
function> }
zsh% showargv a b c d
1=a 2=b @=(a b c d) argv=(a b c d) 1
1=a 2=b @=(a b c d) argv=() 0
1= 2= @=() argv=() 0

So `unset argv' somehow did something with a param that was already unset.
Now run `showargv' a second time in the same shell:

zsh% showargv d c b a
1=d 2=c @=(d c b a) argv=() 0
1=d 2=c @=(d c b a) argv=() 0
1= 2= @=() argv=() 0

This is sort of documented:

argv <S> <Z>
     Same as *.  Assigning to argv changes the local positional
     parameters, but argv is *not* itself a local parameter.  Deleting
     argv with unset in any function deletes it everywhere, although
     only the innermost positional parameter array is deleted (so * and
     @ in other scopes are not affected).

It seems a bit odd that `unset argv' continues to have side effects after
argv has already been "deleted" but I guess that's just part of it being
<S>pecial.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

end of thread, other threads:[~2001-06-01 15:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-01 13:14 parameter substitution used in _values Oliver Kiddle
2001-06-01 13:39 ` Sven Wischnowsky
2001-06-01 14:21   ` Oliver Kiddle
2001-06-01 15:01   ` Bart Schaefer

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