From 532fb8c3ecbf0bbd0a69e983cc86bbffbb0ac236 Mon Sep 17 00:00:00 2001 From: yargo-moni Date: Fri, 10 Mar 2017 16:09:48 +0100 Subject: [PATCH] add output file for last top of stack --- README.md | 8 ++++++-- wrapdc.sh | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4942f52..58f7cea 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ This wrapper renders `dc` more usable as a command line calculator by: - defining commonly used macros for more complex operations - saving precision, top of stack, and registers 0 to 9 ("memories") from one invocation to the next in the status file `$HOME/.wdcrc` +- saving last top of stack value in `$HOME/wdc` for further direct use + (change file name in the source, if desired) # PREREQUISITES @@ -160,8 +162,10 @@ only at the very end. Otherwise, e.g the `rem` command would first have its # FILES -The status between invocations is stored in the file `$HOME/.wdcrc` as a -list of `dc` commands. +- The status between invocations is stored in the file `$HOME/.wdcrc` as a list of `dc` commands. +- The last top of stack value is stored in `$HOME/wdc`. + +_These file names can be easily changed at the beginning of the script._ # BUGS diff --git a/wrapdc.sh b/wrapdc.sh index 19bbb80..53d880a 100755 --- a/wrapdc.sh +++ b/wrapdc.sh @@ -1,8 +1,10 @@ #!/bin/sh # wrapper for dc -info="wrapper for dc // 2016-11-22 Y.Bonetti // see https://gitlab.com/yargo/wrapdc" +info="wrapper for dc // 2017-03-10 Y.Bonetti // see https://gitlab.com/yargo/wrapdc" # global status file statf=$HOME/.wdcrc +# output file (last stack top) +outf=$HOME/wdc # clear state: precision 2, clear stack and reg.0..9 clstat='2k 0 0 0 0 0 0s00s10s20s30s40s50s60s70s80s9' if test ! -r $statf @@ -112,6 +114,8 @@ LEl:x[ # divide stack top by 10^A and print, print A lA10lAZLAX-1-sAlA^/n[E]nLAp ENDOFDCINPUT +# save stack top in output file for further direct processing + tail -n 1 $statf | sed -e 's/ *#.*//' >$outf # print stack top tail -n 1 $statf }