From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Russ Cox" To: 9fans@cse.psu.edu Subject: Re: [9fans] plan9 program to balance your checking account MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Message-Id: <20010303070707.352BF19A07@mail.cse.psu.edu> Date: Sat, 3 Mar 2001 02:06:59 -0500 Topicbox-Message-UUID: 6befa41a-eac9-11e9-9e20-41e7f4b1d025 The C program admittedly does more than this, but I've been quite happy with: g% cat balance.awk /^#/ { next; } NF>=3 && $1 == "+" { total += $3; next; } NF>=3 && $1 == "-" { total -= $3; next; } NF>=3 && $1 ~ /^[0-9]+$/ { total -= $3; next; } NF>=3 && $1 == "=" { n = total - $3; if(n < -0.005 || 0.005 < n) printf("%s:%d: computed total %.2f expected %.2f\n", FILENAME, NR, total, $3); next; } { printf("%s:%d: syntax error: %s\n", FILENAME, NR, $0); } END{ print total } g% The input file is a sequence of lines of the form +|-|=|checknumber mm/dd/yyyy amount comment Russ