zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: octal in arithmetic expressions
@ 2000-05-15 17:51 Clint Adams
  2000-05-15 18:20 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Clint Adams @ 2000-05-15 17:51 UTC (permalink / raw)
  To: zsh-workers

http://www.pasc.org/interps/unofficial/db/p1003.2/pasc-1003.2-173.html

This should make zsh conform to POSIX in this regard.

Index: Src/math.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/math.c,v
retrieving revision 1.2
diff -u -r1.2 math.c
--- Src/math.c	2000/04/30 17:58:35	1.2
+++ Src/math.c	2000/05/15 17:44:51
@@ -357,6 +357,10 @@
 		yyval.u.l = zstrtol(++ptr, &ptr, lastbase = 16);
 		return NUM;
 	    }
+	    else if (idigit(*ptr) && (memchr(ptr, '.', strlen(ptr)) == NULL)) {
+	        yyval.u.l = zstrtol(ptr, &ptr, lastbase = 8);
+	        return NUM;
+	    }
 	/* Fall through! */
 	default:
 	    if (idigit(*--ptr) || *ptr == '.') {


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

* Re: PATCH: octal in arithmetic expressions
  2000-05-15 17:51 PATCH: octal in arithmetic expressions Clint Adams
@ 2000-05-15 18:20 ` Peter Stephenson
  2000-05-15 18:44   ` Clint Adams
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2000-05-15 18:20 UTC (permalink / raw)
  To: Zsh hackers list

> This should make zsh conform to POSIX in this regard.

i.e. $(( 010 )) is treated as 8.

We had this, but removed it because it messed up huge numbers of shell
scripts (including mine) with perfectly reasonable leading zeroes that
never did anyone any harm, and very few people needed octal, and there are
other, less ambiguous ways of specifying it.  Consider for example,

% print -P %D
00-05-15

If you extract bits of this as a string and then try to do math on it, it
falls other if the number is 08 or 09.  This is much more the sort of thing
most zsh users are likely to want to do rather than parsing octal.

It should be settable with some option such as
MATH_MODE_MESSES_UP_CONVERSIONS_FROM_STRING_TO_INTEGER... well, all right,
OCTAL_ZEROES.  As ksh doesn't do this it probably shouldn't be set for
ksh emulation.  Unfortunately there isn't a specific posix emulation mode;
there probably should be.  I suppose it would be OK to set it in sh
emulation, since only sh's trying to be posix-like would have math
evaluation.

-- 
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


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

* Re: PATCH: octal in arithmetic expressions
  2000-05-15 18:20 ` Peter Stephenson
@ 2000-05-15 18:44   ` Clint Adams
  0 siblings, 0 replies; 3+ messages in thread
From: Clint Adams @ 2000-05-15 18:44 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

> It should be settable with some option such as
> MATH_MODE_MESSES_UP_CONVERSIONS_FROM_STRING_TO_INTEGER... well, all right,
> OCTAL_ZEROES.  As ksh doesn't do this it probably shouldn't be set for

Okay.

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.4
diff -u -r1.4 options.yo
--- Doc/Zsh/options.yo	2000/05/11 00:01:03	1.4
+++ Doc/Zsh/options.yo	2000/05/15 18:43:45
@@ -777,6 +777,12 @@
 If numeric filenames are matched by a filename generation pattern,
 sort the filenames numerically rather than lexicographically.
 )
+pindex(OCTAL_ZEROES)
+cindex(octal, arithmetic expressions)
+item(tt(OCTAL_ZEROES) <S>)(
+Interpret any integer constant beginning with a 0 and not
+as octal, per IEEE Std 1003.2-1992 (ISO 9945-2:1993).
+)
 pindex(OVERSTRIKE)
 cindex(editor, overstrike mode)
 cindex(overstrike mode, of editor)
Index: Src/math.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/math.c,v
retrieving revision 1.3
diff -u -r1.3 math.c
--- Src/math.c	2000/05/15 17:54:59	1.3
+++ Src/math.c	2000/05/15 18:43:45
@@ -357,7 +357,8 @@
 		yyval.u.l = zstrtol(++ptr, &ptr, lastbase = 16);
 		return NUM;
 	    }
-	    else if (idigit(*ptr) && (memchr(ptr, '.', strlen(ptr)) == NULL)) {
+	    else if (isset(OCTALZEROES) &&
+		    (memchr(ptr, '.', strlen(ptr)) == NULL)) {
 	        yyval.u.l = zstrtol(ptr, &ptr, lastbase = 8);
 	        return NUM;
 	    }
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.3
diff -u -r1.3 options.c
--- Src/options.c	2000/05/08 15:56:37	1.3
+++ Src/options.c	2000/05/15 18:43:45
@@ -162,6 +162,7 @@
 {NULL, "notify",	      OPT_ZSH,			 NOTIFY},
 {NULL, "nullglob",	      OPT_EMULATE,		 NULLGLOB},
 {NULL, "numericglobsort",     OPT_EMULATE,		 NUMERICGLOBSORT},
+{NULL, "octalzeroes",         OPT_EMULATE|OPT_SH,	 OCTALZEROES},
 {NULL, "overstrike",	      0,			 OVERSTRIKE},
 {NULL, "pathdirs",	      OPT_EMULATE,		 PATHDIRS},
 {NULL, "posixbuiltins",	      OPT_EMULATE|OPT_BOURNE,	 POSIXBUILTINS},
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.8
diff -u -r1.8 zsh.h
--- Src/zsh.h	2000/05/08 15:56:37	1.8
+++ Src/zsh.h	2000/05/15 18:43:45
@@ -1395,6 +1395,7 @@
     NOTIFY,
     NULLGLOB,
     NUMERICGLOBSORT,
+    OCTALZEROES,
     OVERSTRIKE,
     PATHDIRS,
     POSIXBUILTINS,


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

end of thread, other threads:[~2000-05-15 18:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-15 17:51 PATCH: octal in arithmetic expressions Clint Adams
2000-05-15 18:20 ` Peter Stephenson
2000-05-15 18:44   ` Clint Adams

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