From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22969 invoked from network); 15 Nov 2001 18:40:04 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 15 Nov 2001 18:40:04 -0000 Received: (qmail 1506 invoked by alias); 15 Nov 2001 18:39:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16255 Received: (qmail 1495 invoked from network); 15 Nov 2001 18:39:57 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: PATCH: zcalc. Date: Thu, 15 Nov 2001 18:39:25 +0000 Message-ID: <27630.1005849565@csr.com> From: Peter Stephenson 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: -# is the same as a line containing just `[#], +# similarly -##; 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 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. **********************************************************************