chiark / gitweb /
wip with total checker etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 24 Sep 2023 15:29:04 +0000 (16:29 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 24 Sep 2023 15:29:04 +0000 (16:29 +0100)
Makefile
total-checker

index 32b3f1abf43df3267f05c35dc37e14f822a15718..4690eb10b562d949c682e9fc3b1e6bdf5e4fa740 100644 (file)
--- 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 $<
index 9ddea758ef1f65ef7320fcee2172b559cc5a439a..f773c27f0eddf05aab0dae075a59f0ccb8ddfc28 100755 (executable)
@@ -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 = <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;
   }
 }