about summary refs log tree commit diff
path: root/Functions/Misc
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2001-11-15 18:42:31 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2001-11-15 18:42:31 +0000
commitf2e7cf4a05a5b74a16bf4f0280ef26f19b686925 (patch)
treedb9dcb3fa7ae92dfb0bd3baa18f29f969b3b1428 /Functions/Misc
parent195d8c5ec6feb88847f11e96a10b20bb543233c1 (diff)
downloadzsh-f2e7cf4a05a5b74a16bf4f0280ef26f19b686925.tar.gz
zsh-f2e7cf4a05a5b74a16bf4f0280ef26f19b686925.tar.xz
zsh-f2e7cf4a05a5b74a16bf4f0280ef26f19b686925.zip
16254: complete map names after ypmatch
16255: options for default output base for zcalc
Diffstat (limited to 'Functions/Misc')
-rw-r--r--Functions/Misc/zcalc36
1 files changed, 35 insertions, 1 deletions
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: -#<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
@@ -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