Date: Sat, 3 Apr 1999 19:52:51 +0200 From: Andrea Manzini To: mulinux@lists.linux.it Subject: [mu-release] mu-bc Message-ID: <19990403195251.A629@fastidio.manzonet> Hello, this is a little awk implementation of 'bc' command line calculator :) please test it, and report any bugs... Do you know how to remove /tmp files at the end of program ? %% cut here %% #!/usr/bin/nawk -f BEGIN { print "mu-bc 0.01 (3 apr 1999) by Andrea Manzini " print "For details, type help; to quit, press CTRL+D" prompt() } END { print "Bye!" } /(HELP)|(help)/ {help();next} /(LET)|(let) +[A-Za-z]+/ {assign($2);next} /(DEL)|(del) +[A-Za-z]+/ {del($2);next} /./ {eval($0)} function help() { print "Enter any algebric expression. You can use + - * / % ^ () operators." print "Valid math functions are: int(), sin(), cos(), exp(), log(), rand(), sqrt()" print "You can assign variables to the last result with the command LET and" print "then use variables in expressions. To delete variables, type DEL ." prompt() } function del(varname) { delete VAR[varname] print varname " deleted." prompt() } function assign(varname) { VAR[varname]=LST print varname "=" LST " now." prompt() } function eval(expr) { CMD= "BEGIN{" for(v in VAR) { CMD= CMD v "=" VAR[v] ";" } CMD=CMD "print(" expr ")}" CMD=sprintf("/usr/bin/nawk '%s' > /tmp/mubc",CMD) system(CMD) getline LST < "/tmp/mubc" close("/tmp/mubc") print LST prompt() } function prompt() { T=ORS ORS="" print "> " getline < /dev/stdin ORS=T } %% cut here %% -- Andrea Manzini | "Tristo e' quel discepolo che non supera il linux registered user #104528 | proprio maestro" (Leonardo Da Vinci, 1452-1519)