summary refs log tree commit diff
path: root/src/etc/check-links.pl
blob: 6492be53d34814a5867ae6f83fc40134e6e16714 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/perl -w

my $file = $ARGV[0];

my @lines = <>;

my $anchors = {};

my $i = 0;
foreach $line (@lines) {
    $i++;
    if ($line =~ m/id="([^"]+)"/) {
        $anchors->{$1} = $i;
    }
}

$i = 0;
foreach $line (@lines) {
    $i++;
    while ($line =~ m/href="#([^"]+)"/g) {
        if (! exists($anchors->{$1})) {
            print "$file:$i: $1 referenced\n";
        }
    }
}