about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2014-11-26 17:26:58 +0000
committerPeter Stephenson <pws@zsh.org>2014-11-26 17:26:58 +0000
commita8927bf27b57a1f49d525f628a97de9c1fce710b (patch)
tree909779151c4a6b93822e69fe0faff133ea66e7d9
parentc4110f7f4eac347fdbce71c286659a77beb138f7 (diff)
downloadzsh-a8927bf27b57a1f49d525f628a97de9c1fce710b.tar.gz
zsh-a8927bf27b57a1f49d525f628a97de9c1fce710b.tar.xz
zsh-a8927bf27b57a1f49d525f628a97de9c1fce710b.zip
33793: add 0b binary interpretation to integer constants
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/arith.yo3
-rw-r--r--Src/math.c6
-rw-r--r--Src/utils.c2
4 files changed, 13 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 834537d64..7b56eca4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-11-26  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 33793: Src/math.c, Src/utils.c, Doc/Zsh/arith.yo: Arithmetic
+	constants beginning 0b specify binary.
+
 2014-11-25  Oliver Kiddle  <opk@zsh.org>
 
 	* Jun T: 33769: Test/comptest: workaround for KEYTIMEOUT to
diff --git a/Doc/Zsh/arith.yo b/Doc/Zsh/arith.yo
index 96dc2dc68..a620b73d1 100644
--- a/Doc/Zsh/arith.yo
+++ b/Doc/Zsh/arith.yo
@@ -39,7 +39,8 @@ zero status.
 cindex(arithmetic base)
 cindex(bases, in arithmetic)
 Integers can be in bases other than 10.
-A leading `tt(0x)' or `tt(0X)' denotes hexadecimal.
+A leading `tt(0x)' or `tt(0X)' denotes hexadecimal and a leading
+`tt(0b)' or `tt(0B) binary.
 Integers may also be of the form `var(base)tt(#)var(n)',
 where var(base) is a decimal number between two and thirty-six
 representing the arithmetic base and var(n)
diff --git a/Src/math.c b/Src/math.c
index 266569827..438a17089 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -449,12 +449,14 @@ lexconstant(void)
 	nptr++;
 
     if (*nptr == '0') {
+	int lowchar;
 	nptr++;
-	if (*nptr == 'x' || *nptr == 'X') {
+	lowchar = tolower(*nptr);
+	if (lowchar == 'x' || lowchar == 'b') {
 	    /* Let zstrtol parse number with base */
 	    yyval.u.l = zstrtol_underscore(ptr, &ptr, 0, 1);
 	    /* Should we set lastbase here? */
-	    lastbase = 16;
+	    lastbase = (lowchar == 'b') ? 2 : 16;
 	    if (isset(FORCEFLOAT))
 	    {
 		yyval.type = MN_FLOAT;
diff --git a/Src/utils.c b/Src/utils.c
index c6e7aed35..5f0c1062b 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2082,6 +2082,8 @@ zstrtol_underscore(const char *s, char **t, int base, int underscore)
 	    base = 10;
 	else if (*++s == 'x' || *s == 'X')
 	    base = 16, s++;
+	else if (*s == 'b' || *s == 'B')
+	    base = 2, s++;
 	else
 	    base = 8;
     }