CHARACTERS=kennocht fabricia
-all: $(addsuffix .pdf, $(CHARACTERS)) \
- $(addprefix check-, $(CHARACTERS)) \
+all: $(addprefix check-, $(CHARACTERS)) \
+ $(addsuffix .pdf, $(CHARACTERS)) \
+
%.pdf: %.md Makefile
pandoc -Vmargin-{top,left,right,bottom}=20mm -t latex -o .tmp.$@ $< && $i
check-%: %.md Makefile total-checker
- ./total-checker <$<
+ ./total-checker $<
use strict;
+die unless @ARGV == 1;
+my ($file) = @ARGV;
+die if $file =~ m{^-};
+
+open STDIN, "<", $file or die "$file $!";
open L, "expand -t4 |" or die $!;
-@l = <L>;
+our (@l) = <L>;
$?=0; $!=0; close L or die "$? $!";
my $block_start = 0;
+my $heading;
foreach my $i (0..$#l) {
$_ = $l[$i];
if (m{^\`\`\`}) {
- if (defined $block_start) {
- $block_start = undef;
+ if ($block_start) {
+ $block_start = 0;
} else {
$block_start = $i + 1;
}
}
+
+ if (!$block_start && m{^\#+ (\S.*)\n}) {
+ $heading = $1;
+ }
+
if (defined($block_start) && m{^(total +)(\d+)\s}) {
my ($lhs, $exp) = ($1, $2);
my $got = 0;
- foreach my $i ($block_start .. ($i-1)) {
- $_ = $j[$_];
- $earlier = len($lhs) - 1;
+ foreach my $j ($block_start .. ($i-1)) {
+ $_ = $l[$j];
+ my $earlier = length($lhs) - 1;
next unless length > $earlier+1;
die "$j: $_ ?" unless m{^.{$earlier} (\S+)\s};
my $here = $1;
next unless $here =~ m{^[-+]?\d+$};
$got += $here;
}
- my $delta = $exp - $here;
+ my $delta = $exp - $got;
+ print "$file: checking total: $heading\n";
if ($delta) {
print STDERR "line $i: expected $exp but got $got, delta $delta";
}
+ next;
}
}