From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17235 invoked from network); 10 Aug 2000 16:12:24 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 10 Aug 2000 16:12:24 -0000 Received: (qmail 18583 invoked by alias); 10 Aug 2000 16:12:03 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12581 Received: (qmail 18576 invoked from network); 10 Aug 2000 16:12:02 -0000 Date: Thu, 10 Aug 2000 17:11:24 +0100 From: Peter Stephenson Subject: PATCH: C_BASES option for outputting hex and octal To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Message-id: <0FZ300DOM3N03H@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT Does anyone object to my adding options for trivial things like this? Because if so they ought to have got the point and given up objecting years ago :-/. (I finally got fed up with 0x${$(([#16]$num))##*\#}.) If it weren't for backward compatibility, I'd set C_BASES by default and just unset it for ksh compatibility. But the current format could have worked its way into a lot of scripts. % print $(( [#16] 0xff )) 16#FF % setopt cbases % print $(( [#16] 0xff )) 0xFF % print $(( [#8] 8#77 )) 8#77 % setopt octalzeroes % print $(( [#8] 077 )) 077 Index: Doc/Zsh/options.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v retrieving revision 1.11 diff -u -r1.11 options.yo --- Doc/Zsh/options.yo 2000/08/03 07:51:53 1.11 +++ Doc/Zsh/options.yo 2000/08/10 16:05:06 @@ -206,6 +206,19 @@ 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)))( Index: Src/options.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/options.c,v retrieving revision 1.5 diff -u -r1.5 options.c --- Src/options.c 2000/07/30 17:03:53 1.5 +++ Src/options.c 2000/08/10 16:05:07 @@ -90,6 +90,7 @@ {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}, Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.25 diff -u -r1.25 params.c --- Src/params.c 2000/08/03 13:10:13 1.25 +++ Src/params.c 2000/08/10 16:05:07 @@ -3045,7 +3045,12 @@ 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++) Index: Src/zsh.h =================================================================== RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v retrieving revision 1.20 diff -u -r1.20 zsh.h --- Src/zsh.h 2000/08/08 09:13:37 1.20 +++ Src/zsh.h 2000/08/10 16:05:07 @@ -1326,6 +1326,7 @@ BGNICE, BRACECCL, BSDECHO, + CBASES, CDABLEVARS, CHASEDOTS, CHASELINKS, -- Peter Stephenson Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070