about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/options.yo13
-rw-r--r--Src/options.c1
-rw-r--r--Src/params.c7
-rw-r--r--Src/zsh.h1
5 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index de4ae298f..8b23f0d6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2000-08-10  Peter Stephenson  <pws@csr.com>
+
+	* 12581: Doc/Zsh/options.yo, Src/options.c, Src/params.c,
+	Src/zsh.h: Add C_BASES option to output hexadecimal as 0xFF
+	instead of 16#FF, and similarly for octal if OCTAL_ZEROES is set.
+
 2000-08-09  Oliver Kiddle  <opk@zsh.org>
 
 	* 12578: Completion/Builtins/_read, Completion/Builtins/_vars,
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 7e0bba825..bc58b7084 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -206,6 +206,19 @@ Make the tt(echo) builtin compatible with the BSD manref(echo)(1) command.
 This disables backslashed escape sequences in echo strings unless the
 tt(-e) option is specified.
 )
+pindex(C_BASES)
+cindex(bases, output in C format)
+cindex(hexadecimal, output in C format)
+cindex(octal, output in C format)
+item(tt(C_BASES))(
+Output hexadecimal numbers in the standard C format, for example `tt(0xFF)'
+instead of the usual `tt(16#FF)'.  If the option tt(OCTAL_ZEROES) is also
+set (it is not by default), octal numbers will be treated similarly and
+hence appear as `tt(077)' instead of `tt(8#77)'.  This option has no effect
+on the choice of the output base, nor on the output of bases other than
+hexadecimal and octal.  Note that these formats will be understood on input
+irrespective of the setting of tt(C_BASES).
+)
 pindex(CDABLE_VARS)
 cindex(cd, to parameter)
 item(tt(CDABLE_VARS) (tt(-T)))(
diff --git a/Src/options.c b/Src/options.c
index 0bbe6b844..8660ade68 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -90,6 +90,7 @@ static struct optname optns[] = {
 {NULL, "bgnice",	      OPT_EMULATE|OPT_NONBOURNE, BGNICE},
 {NULL, "braceccl",	      OPT_EMULATE,		 BRACECCL},
 {NULL, "bsdecho",	      OPT_EMULATE|OPT_SH,	 BSDECHO},
+{NULL, "cbases",	      0,			 CBASES},
 {NULL, "cdablevars",	      OPT_EMULATE,		 CDABLEVARS},
 {NULL, "chasedots",	      OPT_EMULATE,		 CHASEDOTS},
 {NULL, "chaselinks",	      OPT_EMULATE,		 CHASELINKS},
diff --git a/Src/params.c b/Src/params.c
index 9ef3e61ca..1439e9af8 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3045,7 +3045,12 @@ convbase(char *s, zlong v, int base)
 	base = 10;
 
     if (base != 10) {
-	sprintf(s, "%d#", base);
+	if (isset(CBASES) && base == 16)
+	    sprintf(s, "0x");
+	else if (isset(CBASES) && base == 8 && isset(OCTALZEROES))
+	    sprintf(s, "0");
+	else
+	    sprintf(s, "%d#", base);
 	s += strlen(s);
     }
     for (x = v; x; digs++)
diff --git a/Src/zsh.h b/Src/zsh.h
index bf59641b5..cdb90e264 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1326,6 +1326,7 @@ enum {
     BGNICE,
     BRACECCL,
     BSDECHO,
+    CBASES,
     CDABLEVARS,
     CHASEDOTS,
     CHASELINKS,