summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2016-07-04 12:08:14 +0100
committerPeter Stephenson <pws@zsh.org>2016-07-04 12:08:14 +0100
commita7d5d239e6ab729515083a88cfaf955e078c1685 (patch)
treea2360a93c901a994fdd7bde238cc1d17737d1484 /Functions
parenta73ae70e8217d7163aecdbdad4d8af08eced8a55 (diff)
downloadzsh-a7d5d239e6ab729515083a88cfaf955e078c1685.tar.gz
zsh-a7d5d239e6ab729515083a88cfaf955e078c1685.tar.xz
zsh-a7d5d239e6ab729515083a88cfaf955e078c1685.zip
38783: zcalc tweaks for RPN mode.
Make it more straightforward to exchange variables with stack.
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Misc/zcalc26
1 files changed, 18 insertions, 8 deletions
diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc
index 86b1e4a5b..480373345 100644
--- a/Functions/Misc/zcalc
+++ b/Functions/Misc/zcalc
@@ -94,7 +94,7 @@
 # sequentially just as if read automatically.
 
 emulate -L zsh
-setopt extendedglob
+setopt extendedglob typesetsilent
 
 zcalc_show_value() {
   if [[ -n $_base ]]; then
@@ -301,7 +301,7 @@ while (( _expression_mode )) ||
     ;;
 
     ((:|)local([[:blank:]]##*|))
-      eval $_line
+      eval ${_line##:}
       _line=
       continue
     ;;
@@ -333,7 +333,11 @@ while (( _expression_mode )) ||
 	_push=1
 	_matched=1
 	case $_line in
-	  (\=|pop|\<[[:IDENT:]]#)
+	  (\<[[:IDENT:]]##)
+	  ans=${(P)${_line##\<}}
+	  ;;
+
+	  (\=|pop|\>[[:IDENT:]]#)
 	  if (( ${#stack} < 1 )); then
 	    print -r -- "${_line}: not enough values on stack" >&2
 	    _line=
@@ -343,12 +347,18 @@ while (( _expression_mode )) ||
 	    (=)
 	    ans=${stack[1]}
 	    ;;
-	    (pop|\<)
+	    (pop|\>)
 	    _push=0
 	    shift stack
 	    ;;
-	    (\<[[:IDENT:]]##)
-	    (( ${_line##\<} = ${stack[1]} ))
+	    (\>[[:IDENT:]]##)
+	    if [[ ${_line##\>} = (_*|stack|ans|PI|E) ]]; then
+	      print "${_line##\>}: reserved variable" >&2
+	      _line=
+	      continue
+	    fi
+	    local ${_line##\>}
+	    (( ${_line##\>} = ${stack[1]} ))
 	    _push=0
 	    shift stack
 	    ;;
@@ -371,14 +381,14 @@ while (( _expression_mode )) ||
 	  shift 2 stack
 	  ;;
 
-	  (ldexp|jn|yn|scalb|xy)
+	  (ldexp|jn|yn|scalb|xy|\<\>)
 	  # Functions with two arguments
 	  if (( ${#stack} < 2 )); then
 	    print -r -- "${_line}: not enough values on stack" >&2
 	    _line=
 	    continue
 	  fi
-	  if [[ $_line = xy ]]; then
+	  if [[ $_line = (xy|\<\>) ]]; then
 	    _tmp=${stack[1]}
 	    stack[1]=${stack[2]}
 	    stack[2]=$_tmp