9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@plan9.bell-labs.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] plan9 program to balance your checking account
Date: Sat,  3 Mar 2001 02:06:59 -0500	[thread overview]
Message-ID: <20010303070707.352BF19A07@mail.cse.psu.edu> (raw)

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


             reply	other threads:[~2001-03-03  7:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-03  7:06 Russ Cox [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-03-06  9:23 okamoto
2001-03-03 11:02 forsyth
2001-03-03  2:34 tad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010303070707.352BF19A07@mail.cse.psu.edu \
    --to=rsc@plan9.bell-labs.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).