zsh-workers
 help / color / mirror / code / Atom feed
* Re: Old 'cd ......' function broken.
       [not found] <199610011450.KAA15883@Pontryagin.McRCIM.McGill.EDU>
@ 1996-10-01 15:22 ` Peter Stephenson
  1996-10-02 21:56   ` Zoltan Hidvegi
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 1996-10-01 15:22 UTC (permalink / raw)
  To: peta, Zsh hackers list

peta@cim.mcgill.ca wrote:
> I got this from the zsh mailing list a while ago.  It used to work
> but no more (zsh-3.0.0).  It doesnt like ${(r:(${#1}-1)*3-1::../:)b}

It looks like the expression after the first : isn't being interpreted
as a mathematical expression for evaluation any more.  Somebody will
know if this is a feature, otherwise it's a bug.  You can get away
with:

eval "a=\${(r:$(((${#1}-1)*3-1))::../:)b}"

which evaluates the expression first.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


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

* Re: Old 'cd ......' function broken.
  1996-10-01 15:22 ` Old 'cd ......' function broken Peter Stephenson
@ 1996-10-02 21:56   ` Zoltan Hidvegi
  0 siblings, 0 replies; 2+ messages in thread
From: Zoltan Hidvegi @ 1996-10-02 21:56 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: peta, zsh-workers

> peta@cim.mcgill.ca wrote:
> > I got this from the zsh mailing list a while ago.  It used to work
> > but no more (zsh-3.0.0).  It doesnt like ${(r:(${#1}-1)*3-1::../:)b}
> 
> It looks like the expression after the first : isn't being interpreted
> as a mathematical expression for evaluation any more.  Somebody will
> know if this is a feature, otherwise it's a bug.  You can get away
> with:

The expression is interpreted as a mathematical expression but it does not
expanded before arithmetic evaluation.  The patch below fixes that.

Zoltan


rcsdiff -qc -kk -r2.50 -r2.51 subst.c
*** Src/subst.c
--- Src/subst.c	1996/10/02 21:51:13	2.51
***************
*** 654,659 ****
--- 654,687 ----
      return s;
  }
  
+ /**/
+ int
+ get_intarg(char **s)
+ {
+     char *t = get_strarg(*s + 1);
+     char *p, sav;
+     long ret;
+ 
+     if (!*t)
+ 	return -1;
+     sav = *t;
+     *t = '\0';
+     p = dupstring(*s + 2);
+     *s = t;
+     *t = sav;
+     if (parsestr(p))
+ 	return -1;
+     singsub(&p);
+     if (errflag)
+ 	return -1;
+     ret = matheval(p);
+     if (errflag)
+ 	return -1;
+     if (ret < 0)
+ 	ret = -ret;
+     return ret < 0 ? -ret : ret;
+ }
+ 
  /* parameter substitution */
  
  #define	isstring(c) ((c) == '$' || (char)(c) == String || (char)(c) == Qstring)
***************
*** 708,714 ****
  	inbrace = 1;
  	s++;
  	if (*s == '(' || *s == Inpar) {
! 	    char *t, sav, *d;
  	    int tt = 0;
  	    long num;
  	    int escapes = 0;
--- 736,742 ----
  	inbrace = 1;
  	s++;
  	if (*s == '(' || *s == Inpar) {
! 	    char *t, sav;
  	    int tt = 0;
  	    long num;
  	    int escapes = 0;
***************
*** 751,768 ****
  		    substr = 1;
  		    break;
  		case 'I':
! 		    flnum = 0;
! 		    t = get_strarg(++s);
! 		    if (*t) {
! 			sav = *t;
! 			*t = '\0';
! 			d = dupstring(s + 1);
! 			untokenize(d);
! 			if ((flnum = mathevalarg(s + 1, &d)) < 0)
! 			    flnum = -flnum;
! 			*t = sav;
! 			s = t;
! 		    } else
  			goto flagerr;
  		    break;
  
--- 779,786 ----
  		    substr = 1;
  		    break;
  		case 'I':
! 		    flnum = get_intarg(&s);
! 		    if (flnum < 0)
  			goto flagerr;
  		    break;
  
***************
*** 828,854 ****
  		    tt = 1;
  		/* fall through */
  		case 'r':
! 		    t = get_strarg(++s);
! 		    if (!*t)
  			goto flagerr;
- 		    sav = *t;
- 		    *t = '\0';
- 		    d = dupstring(s + 1);
- 		    untokenize(d);
- 		    if ((num = mathevalarg(d, &d)) < 0)
- 			num = -num;
  		    if (tt)
  			prenum = num;
  		    else
  			postnum = num;
! 		    *t = sav;
! 		    sav = *s;
! 		    s = t + 1;
! 		    if (*s != sav) {
! 			s--;
! 			break;
! 		    }
! 		    t = get_strarg(s);
  		    if (!*t)
  			goto flagerr;
  		    sav = *t;
--- 846,859 ----
  		    tt = 1;
  		/* fall through */
  		case 'r':
! 		    num = get_intarg(&s);
! 		    if (num < 0)
  			goto flagerr;
  		    if (tt)
  			prenum = num;
  		    else
  			postnum = num;
! 		    t = get_strarg(++s);
  		    if (!*t)
  			goto flagerr;
  		    sav = *t;
***************
*** 1608,1625 ****
  		(*ptr)++;
  		break;
  	    case 'F':
! 		rec = -1;
  		(*ptr)++;
- 		ptr1 = get_strarg(ptr2 = *ptr);
- 		if ((sav = *ptr1))
- 		    *ptr1 = '\0';
- 		ptr2 = dupstring(ptr2 + 1);
- 		if (sav)
- 		    *ptr1 = sav;
- 		untokenize(ptr2);
- 		rec = mathevalarg(ptr2, &ptr2);
- 		*ptr = ptr1 + 1;
- 		c = '\0';
  		break;
  	    default:
  		*ptr = lptr;
--- 1613,1620 ----
  		(*ptr)++;
  		break;
  	    case 'F':
! 		rec = get_intarg(ptr);
  		(*ptr)++;
  		break;
  	    default:
  		*ptr = lptr;


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

end of thread, other threads:[~1996-10-02 23:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <199610011450.KAA15883@Pontryagin.McRCIM.McGill.EDU>
1996-10-01 15:22 ` Old 'cd ......' function broken Peter Stephenson
1996-10-02 21:56   ` Zoltan Hidvegi

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