From f2e7cf4a05a5b74a16bf4f0280ef26f19b686925 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 15 Nov 2001 18:42:31 +0000 Subject: 16254: complete map names after ypmatch 16255: options for default output base for zcalc --- Functions/Misc/zcalc | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'Functions') diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc index 78a48b9b0..5d0264922 100644 --- a/Functions/Misc/zcalc +++ b/Functions/Misc/zcalc @@ -74,6 +74,10 @@ # 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 @@ -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 @@ -95,6 +99,36 @@ zmodload -i zsh/mathfunc 2>/dev/null 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. # The `$' before the second argv forces string rather than numeric -- cgit 1.4.1