#!/usr/local/bin/perl5
@files = ("history.html","hands.html","conspiracies.html","comments.html");
# collect name="foo" tags
foreach $f (@files) {
open (F, "<$f") || die;
$l = 0;
while () {
$l++;
if (/name\s*=\s*\"?(\S[^" >]*)/i) {
$label = $1;
if ($known{$f}{$label}) {
print "$f:$l: duplicate label: $label\n";
}
$known{$f}{$label} = 1;
}
}
}
# check links
foreach $f (@files) {
open (F, "<$f") || die;
$l = 0;
while () {
$l++;
if (/href\s*=\s*\"?(\S[^" >]*)/i) {
$url = $1;
if ($url =~ /#/) {
$file = $`;
$file = $f if $file eq '';
$label = $';
if (!$known{$file}{$label}) {
print "$f:$l: bad link: $url\n";
}
} else {
print "$f:$l: skipping link $url\n" unless $url =~ /http/;
}
}
}
}