From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: zcalc.
Date: Thu, 15 Nov 2001 18:39:25 +0000 [thread overview]
Message-ID: <27630.1005849565@csr.com> (raw)
Secondly, allow a default output base to be specified as an option to
zcalc.
Index: Functions/Misc/zcalc
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Misc/zcalc,v
retrieving revision 1.4
diff -u -r1.4 zcalc
--- Functions/Misc/zcalc 2001/10/08 15:18:26 1.4
+++ Functions/Misc/zcalc 2001/11/15 18:38:26
@@ -74,7 +74,11 @@
# also understood. However, leading 0 for octal is not understood --- it's
# too confusing in a calculator. Use 8#777 etc.
#
+# Options: -#<base> is the same as a line containing just `[#<base>],
+# similarly -##<base>; they set the default output base, with and without
+# a base discriminator in front, respectively.
#
+#
# To do:
# - separate zcalc history from shell history using arrays --- or allow
# zsh to switch internally to and from array-based history.
@@ -84,7 +88,7 @@
emulate -L zsh
setopt extendedglob
-local line latest base defbase match mbegin mend psvar
+local line latest base defbase match mbegin mend psvar optlist opt arg
integer num
zmodload -i zsh/mathfunc 2>/dev/null
@@ -94,6 +98,36 @@
# Supply some constants.
float PI E
(( PI = 4 * atan(1), E = exp(1) ))
+
+# Process command line
+while [[ -n $1 && $1 = -(|[#-]*) ]]; do
+ optlist=${1[2,-1]}
+ shift
+ [[ $optlist = (|-) ]] && break
+ while [[ -n $optlist ]]; do
+ opt=${optlist[1]}
+ optlist=${optlist[2,-1]}
+ case $opt in
+ ('#') # Default base
+ if [[ -n $optlist ]]; then
+ arg=$optlist
+ optlist=
+ elif [[ -n $1 ]]; then
+ arg=$1
+ shift
+ else
+ print "-# requires an argument" >&2
+ return 1
+ fi
+ if [[ $arg != (|\#)[[:digit:]]## ]]; then
+ print - "-# requires a decimal number as an argument" >&2
+ return 1
+ fi
+ defbase="[#${arg}]"
+ ;;
+ esac
+ done
+done
for (( num = 1; num <= $#; num++ )); do
# Make sure all arguments have been evaluated.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
next reply other threads:[~2001-11-15 18:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-15 18:39 Peter Stephenson [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-08-16 16:32 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=27630.1005849565@csr.com \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.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).