#!/usr/bin/perl

$mode=0;

open(tmp,">/tmp/wcount.$$") || exit(1);
main: while (<STDIN>) {
	if (/^##TEXT##$/) { $mode=1; next main; }
	if (/^##KLUDGES##$|^###MESSAGE_END###$/) { $mode=0; next main; }
	if ($mode) { print tmp; }
}
close(tmp);

open(wc,"wc /tmp/wcount.$$ |") || exit(1);
$count=<wc>;
close(wc);

$count =~ /\s*(\d+)\s+(\d+)\s+(\d+)\s+/;
print <<EOF;
###STATUS_START###
Bytes: $1
Words: $2
Lines: $3
###STATUS_END###
EOF

unlink "/tmp/wcount.$$";
