zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: C_BASES option for outputting hex and octal
Date: Thu, 10 Aug 2000 17:11:24 +0100	[thread overview]
Message-ID: <0FZ300DOM3N03H@la-la.cambridgesiliconradio.com> (raw)

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 <pws@csr.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


             reply	other threads:[~2000-08-10 16:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-08-10 16:11 Peter Stephenson [this message]
2000-08-11 20:16 ` Zefram
2000-08-12 15:46   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0FZ300DOM3N03H@la-la.cambridgesiliconradio.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).