From 0ce6b621c8e58b492be36a0d4dfb014b8afe6aed Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 24 Sep 2023 16:29:04 +0100 Subject: [PATCH] wip with total checker etc. --- Makefile | 7 ++++--- total-checker | 27 ++++++++++++++++++++------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 32b3f1a..4690eb1 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,12 @@ SHELL=/bin/bash 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 $< diff --git a/total-checker b/total-checker index 9ddea75..f773c27 100755 --- a/total-checker +++ b/total-checker @@ -2,36 +2,49 @@ 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 = ; +our (@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; } } -- 2.30.2