2015-12-27 13:33:11 +00:00
|
|
|
#! /usr/bin/env perl
|
|
|
|
# -*- mode: perl; -*-
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my @stack = ();
|
|
|
|
my $depth = 0;
|
|
|
|
my $input = $ARGV[0];
|
|
|
|
my $line = 0;
|
|
|
|
if (open(FI, $input)) {
|
|
|
|
while (my $l = <FI>) {
|
|
|
|
chomp($l);
|
|
|
|
$line++;
|
|
|
|
if ($l =~ /^\s*\\begin_([a-z]+)/) {
|
|
|
|
$stack[$depth] = $1;
|
|
|
|
$depth++;
|
|
|
|
}
|
|
|
|
elsif ($l =~ /^\s*\\(index|branch)\s/) {
|
|
|
|
# does not start with e.g. \begin_index, but ends with \end_index!!
|
|
|
|
$stack[$depth] = $1;
|
|
|
|
$depth++;
|
|
|
|
}
|
|
|
|
elsif ($l =~ /^\s*\\end_([a-z]+)/) {
|
|
|
|
my $expect = $1;
|
|
|
|
if ($depth > 0) {
|
|
|
|
if ($stack[$depth-1] eq $expect) {
|
|
|
|
$depth--;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print "expected \\end_$stack[$depth-1], got \\end_$expect instead at $input:$line\n";
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print "got \\end_$expect, but depth is already 0 at $input:$line\n";
|
|
|
|
exit(-2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-28 13:56:13 +00:00
|
|
|
if ($depth > 0) {
|
|
|
|
for (my $i = $depth-1; $i >= 0; $i--) {
|
|
|
|
print "Missing \\end_$stack[$i]\n";
|
|
|
|
}
|
|
|
|
exit(-3);
|
|
|
|
}
|
2015-12-27 13:33:11 +00:00
|
|
|
exit(0);
|