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

Re: numeric brace expansion



> Richard>  This is broken on both beta8/beta9 (and maybe beta7).  It will be
> Richard>  fixed in beta10 (by the end of the week).  To fix this now, you
> Richard>  should be able to undefine HAVE_STRTOL in config.h and recompile.
> 
> With Solaris 2.4 and gcc 2.6.3, I get an error (follows) doing this.  Guess
> I'll wait till beta 10.
> ==============================================================================

Hmm.. better yet, here is a quick patch (originally posted by Mark Borges).
I didn't think the prototypes would be a problem like that.  Sorry for
the lame advice.

Richard Coleman
coleman@xxxxxxxxxxxxxxx


Note this is a temporary fix until Richard decides the right thing to
do (use zstrtol or somehow work around the (broken?) system supplied
strtol) and adjusts configure accordingly. I did nothing w.r.t. the
configure script, i.e., if configure detects you have strtol, you will
have to manually edit config.h and undef the HAVE_STRTOL line:

/* Define if you have the strtol function.  */
/* #define HAVE_STRTOL 1 */

  -mb-

-------------------------------- cut here --------------------------------
diff -c Src.orig/builtin.c Src/builtin.c
*** Src.orig/builtin.c	Tue May 30 22:10:07 1995
--- Src/builtin.c	Wed May 31 06:58:22 1995
***************
*** 1249,1255 ****
  	doprintdir++;
  	if (argv[0][1] && argv[0][0] == (isset(PUSHDMINUS) ? '-' : '+')) {
  	    /* popping directory, specified with + */
! 	    dd = strtol(argv[0] + 1, &end, 10) - 1;
  	    if (dd >= 0 && *end == '\0') {
  		for (n = firstnode(dirstack); n && dd; dd--, incnode(n));
  		if (!n) {
--- 1249,1255 ----
  	doprintdir++;
  	if (argv[0][1] && argv[0][0] == (isset(PUSHDMINUS) ? '-' : '+')) {
  	    /* popping directory, specified with + */
! 	    dd = zstrtol(argv[0] + 1, &end, 10) - 1;
  	    if (dd >= 0 && *end == '\0') {
  		for (n = firstnode(dirstack); n && dd; dd--, incnode(n));
  		if (!n) {
***************
*** 1260,1266 ****
  	    }
  	} else if (argv[0][1] && argv[0][0] == (isset(PUSHDMINUS) ? '+' : '-')) {
  	    /* popping directory, specified with - */
! 	    dd = strtol(argv[0] + 1, &end, 10);
  	    if (*end == '\0') {
  		for (n = lastnode(dirstack); n != (Lknode) dirstack && dd;
  		     dd--, n = prevnode(n));
--- 1260,1266 ----
  	    }
  	} else if (argv[0][1] && argv[0][0] == (isset(PUSHDMINUS) ? '+' : '-')) {
  	    /* popping directory, specified with - */
! 	    dd = zstrtol(argv[0] + 1, &end, 10);
  	    if (*end == '\0') {
  		for (n = lastnode(dirstack); n != (Lknode) dirstack && dd;
  		     dd--, n = prevnode(n));
***************
*** 4071,4084 ****
  	    hours with the `m' and `h' modifiers, and `:' may be used to add
  	    together more than one of these.  It's easier to understand from
  	    the code: */
! 	    val = strtol(s, &s, 10);
  	    if (*s)
  		if ((*s == 'h' || *s == 'H') && !s[1])
  		    val *= 3600L;
  		else if ((*s == 'm' || *s == 'M') && !s[1])
  		    val *= 60L;
  		else if (*s == ':')
! 		    val = val * 60 + strtol(s + 1, &s, 10);
  		else {
  		    zwarnnam("limit", "unknown scaling factor: %s", s, 0);
  		    return 1;
--- 4071,4084 ----
  	    hours with the `m' and `h' modifiers, and `:' may be used to add
  	    together more than one of these.  It's easier to understand from
  	    the code: */
! 	    val = zstrtol(s, &s, 10);
  	    if (*s)
  		if ((*s == 'h' || *s == 'H') && !s[1])
  		    val *= 3600L;
  		else if ((*s == 'm' || *s == 'M') && !s[1])
  		    val *= 60L;
  		else if (*s == ':')
! 		    val = val * 60 + zstrtol(s + 1, &s, 10);
  		else {
  		    zwarnnam("limit", "unknown scaling factor: %s", s, 0);
  		    return 1;
***************
*** 4088,4105 ****
  	else if (lim == RLIMIT_NPROC)
  	    /* pure numeric resource -- only a straight decimal number is
  	    permitted. */
! 	    val = strtol(s, &s, 10);
  # endif /* RLIMIT_NPROC */
  # ifdef RLIMIT_NOFILE
  	else if (lim == RLIMIT_NOFILE)
  	    /* pure numeric resource -- only a straight decimal number is
  	    permitted. */
! 	    val = strtol(s, &s, 10);
  # endif /* RLIMIT_NOFILE */
  	else {
  	    /* memory-type resource -- `k' and `M' modifiers are permitted,
  	    meaning (respectively) 2^10 and 2^20. */
! 	    val = strtol(s, &s, 10);
  	    if (!*s || ((*s == 'k' || *s == 'K') && !s[1]))
  		val *= 1024L;
  	    else if ((*s == 'M' || *s == 'm') && !s[1])
--- 4088,4105 ----
  	else if (lim == RLIMIT_NPROC)
  	    /* pure numeric resource -- only a straight decimal number is
  	    permitted. */
! 	    val = zstrtol(s, &s, 10);
  # endif /* RLIMIT_NPROC */
  # ifdef RLIMIT_NOFILE
  	else if (lim == RLIMIT_NOFILE)
  	    /* pure numeric resource -- only a straight decimal number is
  	    permitted. */
! 	    val = zstrtol(s, &s, 10);
  # endif /* RLIMIT_NOFILE */
  	else {
  	    /* memory-type resource -- `k' and `M' modifiers are permitted,
  	    meaning (respectively) 2^10 and 2^20. */
! 	    val = zstrtol(s, &s, 10);
  	    if (!*s || ((*s == 'k' || *s == 'K') && !s[1]))
  		val *= 1024L;
  	    else if ((*s == 'M' || *s == 'm') && !s[1])
***************
*** 5466,5477 ****
  	hour:minute offset from the current time.  Once the hour and minute
  	numbers have been extracted, and the format verified, the resulting
  	offset is simply added to the current time. */
! 	h = strtol(s + 1, &s, 10);
  	if (*s != ':') {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
  	}
! 	m = strtol(s + 1, &s, 10);
  	if (*s) {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
--- 5466,5477 ----
  	hour:minute offset from the current time.  Once the hour and minute
  	numbers have been extracted, and the format verified, the resulting
  	offset is simply added to the current time. */
! 	h = zstrtol(s + 1, &s, 10);
  	if (*s != ':') {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
  	}
! 	m = zstrtol(s + 1, &s, 10);
  	if (*s) {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
***************
*** 5482,5493 ****
  	This is in hour:minute format, optionally followed by a string starting
  	with `a' or `p' (for a.m. or p.m.).  Characters after the `a' or `p'
  	are ignored. */
! 	h = strtol(s, &s, 10);
  	if (*s != ':') {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
  	}
! 	m = strtol(s + 1, &s, 10);
  	if (*s && *s != 'a' && *s != 'A' && *s != 'p' && *s != 'P') {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
--- 5482,5493 ----
  	This is in hour:minute format, optionally followed by a string starting
  	with `a' or `p' (for a.m. or p.m.).  Characters after the `a' or `p'
  	are ignored. */
! 	h = zstrtol(s, &s, 10);
  	if (*s != ':') {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
  	}
! 	m = zstrtol(s + 1, &s, 10);
  	if (*s && *s != 'a' && *s != 'A' && *s != 'p' && *s != 'P') {
  	    zwarnnam("sched", "bad time specifier", NULL, 0);
  	    return 1;
***************
*** 5722,5728 ****
  
      if (idigit(*s)) {
  	/* Simple digital umask. */
! 	um = strtol(s, &s, 8);
  	if (*s) {
  	    zwarnnam(nam, "bad umask", NULL, 0);
  	    return 1;
--- 5722,5728 ----
  
      if (idigit(*s)) {
  	/* Simple digital umask. */
! 	um = zstrtol(s, &s, 8);
  	if (*s) {
  	    zwarnnam(nam, "bad umask", NULL, 0);
  	    return 1;
diff -c Src.orig/compat.c Src/compat.c
*** Src.orig/compat.c	Tue May 30 22:10:08 1995
--- Src/compat.c	Wed May 31 06:57:24 1995
***************
*** 35,41 ****
  
  #ifndef HAVE_STRTOL
  long
! strtol(char *s, char **t, int base)
  {
      long ret = 0;
  
--- 35,41 ----
  
  #ifndef HAVE_STRTOL
  long
! zstrtol(char *s, char **t, int base)
  {
      long ret = 0;
  
diff -c Src.orig/glob.c Src/glob.c
*** Src.orig/glob.c	Tue May 30 22:10:15 1995
--- Src/glob.c	Wed May 31 06:59:07 1995
***************
*** 815,821 ****
  	char *dots, *p;
  	Lknode olast = last;
  	/* Get the first number of the range */
! 	int rstart = strtol(str+1,&dots,10), rend = 0, err = 0, rev = 0;
  	int wid1 = (dots - str) - 1, wid2 = (str2 - dots) - 2;
  	int strp = str - str3;
        
--- 815,821 ----
  	char *dots, *p;
  	Lknode olast = last;
  	/* Get the first number of the range */
! 	int rstart = zstrtol(str+1,&dots,10), rend = 0, err = 0, rev = 0;
  	int wid1 = (dots - str) - 1, wid2 = (str2 - dots) - 2;
  	int strp = str - str3;
        
***************
*** 823,829 ****
  	    err++;
  	else {
  	    /* Get the last number of the range */
! 	    rend = strtol(dots+2,&p,10);
  	    if (p == dots+2 || p != str2)
  		err++;
  	}
--- 823,829 ----
  	    err++;
  	else {
  	    /* Get the last number of the range */
! 	    rend = zstrtol(dots+2,&p,10);
  	    if (p == dots+2 || p != str2)
  		err++;
  	}
***************
*** 1454,1460 ****
  	    if (*++pat == Outang || 
  		(*pat == '-' && pat[1] == Outang && ++pat)) {
  		/* <> or <->:  any number matches */
! 		(void)strtol(pptr, &ptr, 10);
  		if (ptr == pptr)
  		    break;
  		pptr = ptr;
--- 1454,1460 ----
  	    if (*++pat == Outang || 
  		(*pat == '-' && pat[1] == Outang && ++pat)) {
  		/* <> or <->:  any number matches */
! 		(void)zstrtol(pptr, &ptr, 10);
  		if (ptr == pptr)
  		    break;
  		pptr = ptr;
***************
*** 1467,1483 ****
  		 * t1 = number supplied:  must be positive, so use
  		 * unsigned arithmetic.
  		 */
! 		t1 = (unsigned long)strtol(pptr, &ptr, 10);
  		if (ptr == pptr)
  		    break;
  		pptr = ptr;
  		/* t2 = lower limit */
! 		t2 = (unsigned long)strtol(pat, &ptr, 10);
  		if (*ptr != '-' || (not3 = (ptr[1] == Outang)))
  				/* exact match or no upper limit */
  		    t3 = t2, pat = ptr + not3;
  		else		/* t3 = upper limit */
! 		    t3 = (unsigned long)strtol(ptr + 1, &pat, 10);
  		if (*pat++ != Outang)
  		    exit(21);
  		if (t1 < t2 || (!not3 && t1 > t3))
--- 1467,1483 ----
  		 * t1 = number supplied:  must be positive, so use
  		 * unsigned arithmetic.
  		 */
! 		t1 = (unsigned long)zstrtol(pptr, &ptr, 10);
  		if (ptr == pptr)
  		    break;
  		pptr = ptr;
  		/* t2 = lower limit */
! 		t2 = (unsigned long)zstrtol(pat, &ptr, 10);
  		if (*ptr != '-' || (not3 = (ptr[1] == Outang)))
  				/* exact match or no upper limit */
  		    t3 = t2, pat = ptr + not3;
  		else		/* t3 = upper limit */
! 		    t3 = (unsigned long)zstrtol(ptr + 1, &pat, 10);
  		if (*pat++ != Outang)
  		    exit(21);
  		if (t1 < t2 || (!not3 && t1 > t3))
diff -c Src.orig/math.c Src/math.c
*** Src.orig/math.c	Tue May 30 22:10:26 1995
--- Src/math.c	Wed May 31 06:59:23 1995
***************
*** 309,319 ****
  	case '[':
  	    unary = 0;
  	    {
! 		int base = strtol(ptr, &ptr, 10);
  
  		if (*ptr == ']')
  		    ptr++;
! 		yyval = strtol(ptr, &ptr, lastbase = base);
  		return NUM;
  	    }
  	case ' ':
--- 309,319 ----
  	case '[':
  	    unary = 0;
  	    {
! 		int base = zstrtol(ptr, &ptr, 10);
  
  		if (*ptr == ']')
  		    ptr++;
! 		yyval = zstrtol(ptr, &ptr, lastbase = base);
  		return NUM;
  	    }
  	case ' ':
***************
*** 331,341 ****
  	default:
  	    if (idigit(*--ptr)) {
  		unary = 0;
! 		yyval = strtol(ptr, &ptr, 0);
  
  		if (*ptr == '#') {
  		    ptr++;
! 		    yyval = strtol(ptr, &ptr, lastbase = yyval);
  		}
  		return NUM;
  	    }
--- 331,341 ----
  	default:
  	    if (idigit(*--ptr)) {
  		unary = 0;
! 		yyval = zstrtol(ptr, &ptr, 0);
  
  		if (*ptr == '#') {
  		    ptr++;
! 		    yyval = zstrtol(ptr, &ptr, lastbase = yyval);
  		}
  		return NUM;
  	    }
***************
*** 943,948 ****
       * This is only used when reading from strings outside the formula,
       * e.g. in parameter substitutions, so does not set lastbase.
       */
!     long num1 = strtol(s, &s, 10);
!     return (*s == '#' || *s == Pound) ? strtol(s+1, &s, num1) : num1;
  }
--- 943,948 ----
       * This is only used when reading from strings outside the formula,
       * e.g. in parameter substitutions, so does not set lastbase.
       */
!     long num1 = zstrtol(s, &s, 10);
!     return (*s == '#' || *s == Pound) ? zstrtol(s+1, &s, num1) : num1;
  }
diff -c Src.orig/prototypes.h Src/prototypes.h
*** Src.orig/prototypes.h	Tue May 30 22:09:46 1995
--- Src/prototypes.h	Wed May 31 06:57:36 1995
***************
*** 122,128 ****
  /**************************************************/
  /*** prototypes for functions built in compat.c ***/
  #ifndef HAVE_STRTOL
! extern long strtol _((char *s, char **t, int base));
  #endif
  
  #ifndef HAVE_STRSTR
--- 122,128 ----
  /**************************************************/
  /*** prototypes for functions built in compat.c ***/
  #ifndef HAVE_STRTOL
! extern long zstrtol _((char *s, char **t, int base));
  #endif
  
  #ifndef HAVE_STRSTR
diff -c Src.orig/subst.c Src/subst.c
*** Src.orig/subst.c	Tue May 30 22:10:38 1995
--- Src/subst.c	Wed May 31 06:59:34 1995
***************
*** 263,269 ****
  	    val = -1;
  	    ptr = str + 2;
  	} else if (idigit(str[1]))
! 	    val = strtol(str + 1, &ptr, 10);	/* =# */
  	else
  	/* =foo */
  	{
--- 263,269 ----
  	    val = -1;
  	    ptr = str + 2;
  	} else if (idigit(str[1]))
! 	    val = zstrtol(str + 1, &ptr, 10);	/* =# */
  	else
  	/* =foo */
  	{
diff -c Src.orig/zle_main.c Src/zle_main.c
*** Src.orig/zle_main.c	Tue May 30 22:10:52 1995
--- Src/zle_main.c	Wed May 31 06:59:43 1995
***************
*** 754,760 ****
  			s[3] = '\0';
  			u = s;
  		    }
! 		    *t++ = strtol(s + (*s == 'x'), &s,
  				   (*s == 'x') ? 16 : 8);
  		    if (svchar) {
  			u[3] = svchar;
--- 754,760 ----
  			s[3] = '\0';
  			u = s;
  		    }
! 		    *t++ = zstrtol(s + (*s == 'x'), &s,
  				   (*s == 'x') ? 16 : 8);
  		    if (svchar) {
  			u[3] = svchar;
diff -c Src.orig/zle_misc.c Src/zle_misc.c
*** Src.orig/zle_misc.c	Tue May 30 22:10:54 1995
--- Src/zle_misc.c	Wed May 31 06:59:55 1995
***************
*** 818,830 ****
  	arg = 0;
  	if (*fm == '%') {
  	    if (idigit(*++fm)) {
! 		arg = strtol(fm, &fm, 10);
  	    }
  	    if (*fm == '(') {
  		int tc;
  
  		if (idigit(*++fm)) {
! 		    arg = strtol(fm, &fm, 10);
  		}
  		test = 0;
  		ss = pwd;
--- 818,830 ----
  	arg = 0;
  	if (*fm == '%') {
  	    if (idigit(*++fm)) {
! 		arg = zstrtol(fm, &fm, 10);
  	    }
  	    if (*fm == '(') {
  		int tc;
  
  		if (idigit(*++fm)) {
! 		    arg = zstrtol(fm, &fm, 10);
  		}
  		test = 0;
  		ss = pwd;
***************
*** 1015,1021 ****
  		break;
  	    case '[':
                  if (idigit(*++fm))
!                     trunclen = strtol(fm, &fm, 10);
                  else
                      trunclen = arg;
                  ss = bp;
--- 1015,1021 ----
  		break;
  	    case '[':
                  if (idigit(*++fm))
!                     trunclen = zstrtol(fm, &fm, 10);
                  else
                      trunclen = arg;
                  ss = bp;





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