: # use perl                                  -*- mode: Perl; -*-
        eval 'exec perl -T -w -S $0 $*'
                if 0;

# Ackley: Text line counter for CS293
my $version = "2"; # Wed Jan 30 23:24:14 2008 Handle Mac line endings, sigh
#my $version = "1"; # Sun Jan 27 11:16:42 2008 Initial version

print STDERR "CS293 line counter v$version\n";

my $minCharsPerLine = 64;
my $minLinesPerText = 32;

my @lines = <>;
if (scalar(@lines) > 0) {
    if ($lines[0] =~ /\015[^\012]/) { 
        @lines = split(/\015/,$lines[0]);
    }
}

my $totalLines = 0;
my $longEnough = 0;
while (defined($_ = shift @lines)) {
    chomp;
    ++$totalLines;
    s/\s{3,}/ /g;
    if (length($_) >= $minCharsPerLine) {
        ++$longEnough;
        printf("%3d+ %s\n",$longEnough,$_);
    } else {
        printf STDERR ("%3d- %s\n",$longEnough,$_);
    }
}

print STDERR "\n-----\n";
my $okay = $longEnough >= $minLinesPerText;
print STDERR ($okay?"OKAY":"TOO SHORT")." $longEnough acceptable lines (out of $totalLines total)\n";
exit ($okay?0:1);

