6 # Parse arguments, a simple state machine for input like:
8 # <file-to-check.txt> <valid-files-to-link-to> --section=1 git.txt git-add.txt [...] --to-lint git-add.txt a-file.txt [...]
13 my $to_check = shift @ARGV;
15 if (my ($sec) = $arg =~ /^--section=(\d+)$/s) {
20 my ($name) = $arg =~ /^(.*?)\.txt$/s;
21 unless (defined $section) {
26 $SECTION{$name} = $section;
31 my ($pos, $line, $target, $msg) = @_;
32 substr($line, $pos) = "' <-- HERE";
34 print STDERR
"$ARGV:$.: error: $target: $msg, shown with 'HERE' below:\n";
35 print STDERR
"$ARGV:$.:\t'$line\n";
39 @ARGV = sort values %TXT;
40 die "BUG: No list of valid linkgit:* files given" unless @ARGV;
44 while ($line =~ m/linkgit:((.*?)\[(\d)\])/g) {
46 my ($target, $page, $section) = ($1, $2, $3);
49 $page =~ s/{litdd}/--/g;
51 if (!exists $TXT{$page}) {
52 report
($pos, $line, $target, "link outside of our own docs");
55 if (!exists $SECTION{$page}) {
56 report
($pos, $line, $target, "link outside of our sectioned docs");
59 my $real_section = $SECTION{$page};
60 if ($section != $SECTION{$page}) {
61 report
($pos, $line, $target, "wrong section (should be $real_section)");
65 # this resets our $. for each file