Path: utzoo!utgpu!watmath!uunet!mailrus!shadooby!samsung!cs.utexas.edu!wuarchive!brutus.cs.uiuc.edu!apple!spies!zorch!srctwr From: tanya@srctwr (Tanya Katz x430) Newsgroups: unix-pc.general Subject: Submission for Unix-PC Message-ID: <8911280549.AA25096@pyramid.pyramid.com> Date: 27 Nov 89 15:06:26 GMT Sender: scott@zorch.SF-Bay.ORG Organization: Unix-PC/Mail Gateway Lines: 204 To: adds!ncrlnk!ncr-sd!pyramid!zorch!unix-pc X-Mailer: Elm [version 2.1 PL1] In an article Originally-From: lj@spdcc.COM (Len Jacobs) Len writes: >I am searching for the cource to a 3B1 program that was posted several >months ago. It was an interactive calculator that apparently was an >intelligent front end to bc. >If you have a copy or know where it could be extracted, please post >or send mail. >Thanks. I'm not sure if this is what you are referring to, but I use kc. It originally appeared in Unix World as the Ksh Tool of the Month. Any way, it is short, so here it is... -Tanya ...uunet!ncrlnk!adds!tanya tanya.katz@adds.newyork.ncr.com # o / o / o / o / #--Cut-here-------X---------------X---------------X---------------X---- # o \ o \ o \ o \ # This is a shell archive. Remove anything above this line! # Save the results in a file. # To unpack "sh file". # To unpack & overwrite existing files, "sh file -c". # PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f kc -a "$1" != "-c" then echo file kc exists. \"sh $0 -c\" forces overwrite! else echo kc 1>&2 cat >kc << 'END_OF_kc' # ------------------------------------------------------------------------ #sccs "@(#) KC Version 1.0" # # BC front-end originally "ksh tool of the month," # UnixWorld Magazine, April, 1988 # # ------------------------------------------------------------------------ if [ $# -gt 0 ] then # exec bc directly with command line arg echo "$*" | bc exit 0 fi # force letters to upper case typeset -u BCIN M=0 menu() { echo " Kc memory functions: m+\tAdd to memory\t\t\tm- Subtract from memory mi\tMemory in (direct)\t\tmr Memory recall mc\tMemory clear\t\t\t= Print current totals +-/*\tMath op using current total\tac Clear accumulator & memory " } # put bc in background and set up pipe bc -l |& print -p "obase=10; ibase=10; scale=2" print -p "m=0" PROMPT="> " echo "Welcome to KC: the k-shell calculator. Type ? for the help menu. To quit: q " while : do if echo "$PROMPT\c" KBD=`line` then case "$KBD" in help |\?) menu ;; q|Q|quit|QUIT) exit ;; !) ksh ;; !*) eval "${KBD##!}" ;; #strip off leading ! m+) print -p "m = m + ${ANS:=0}; m" read -p M if [ ! "${M}" = "0" ] then print - "\tm= $M" PROMPT="m> " else PROMPT="> " fi ;; m-) print -p - "m = m - ${ANS:=0}; m" read -p M if [ ! "${M}" = "0" ] then print - "\tm= $M" PROMPT="m> " else PROMPT="> " fi ;; mi) print -p - "m = ${ANS:=0}; m" read -p M if [ ! "${M}" = "0" ] then print - "\tm= $M" PROMPT="m> " else PROMPT="> " fi ;; mr) print -p - "m" read -p ANS print - "\t$ANS" ;; mc) print -p "m = 0" PROMPT="> " ;; scale) print -p "scale" read -p ANS print - "\t$ANS" ;; scale*) print -p "$KBD" ;; obase) print -p "obase" read -p ANS print - "\t$ANS" ;; obase*) print -p "$KBD" ;; ibase) print -p "ibase" read -p ANS print - "\t$ANS" ;; ibase*) print -p "$KBD" ;; /0) print "divide by 0\007" ;; / | \* | + | -) ;; +* | -* | /* | \**) BCIN="$KBD" print -p - "${ANS:=0}${BCIN}" if [ $? -ne 0 ] then echo "kc: ${ANS:=0}${BCIN}" exit 1 fi read -p ANS print - "\t$ANS" ;; =) print - "\t${ANS:=0}" if [ $M -ne 0 ] then print - "\tm= $M" fi ;; ac) print -p "m = 0" print -p "0" read -p ANS print - "\t$ANS" PROMPT="> " ;; [!G-Zg-z]*) #matches 0-9 and a-f input if [ ! "$KBD" ] then continue fi BCIN="$KBD" print -p "$BCIN" read -p ANS print - "\t$ANS" ;; esac else exit fi done END_OF_kc if test 2650 -ne `wc -c