| Line | |
|---|
| 1 | #!/usr/bin/perl |
|---|
| 2 | # |
|---|
| 3 | # Search for missing 'itemhelp' entries in menus |
|---|
| 4 | |
|---|
| 5 | use strict; |
|---|
| 6 | use warnings; |
|---|
| 7 | |
|---|
| 8 | sub trim($) { |
|---|
| 9 | my ($str) = @_; |
|---|
| 10 | $str =~ s/^[\s]+//go; |
|---|
| 11 | $str =~ s/[\s]+$//go; |
|---|
| 12 | return $str; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | my $lastitem = undef; |
|---|
| 16 | my $lastitem_loc = undef; |
|---|
| 17 | my $lastitem_name = undef; |
|---|
| 18 | |
|---|
| 19 | foreach my $line (<>) { |
|---|
| 20 | chomp($line); |
|---|
| 21 | if ($line =~ /^([^:]+:[0-9]+):/o) { |
|---|
| 22 | my ($loc,$rest) = ($1,$'); |
|---|
| 23 | eval { |
|---|
| 24 | if ($rest =~ /[ ]*(item|itemhelp):/io) { |
|---|
| 25 | my ($tag,$content) = (lc($1), trim($')); |
|---|
| 26 | if ($tag eq 'item') { |
|---|
| 27 | if (defined $lastitem) { |
|---|
| 28 | print STDERR "$lastitem_loc: Warning: item '$lastitem_name' lacks an 'itemhelp' entry!\n"; |
|---|
| 29 | } |
|---|
| 30 | $lastitem = $line; |
|---|
| 31 | $lastitem_loc = $loc; |
|---|
| 32 | $lastitem_name = $content; |
|---|
| 33 | } |
|---|
| 34 | elsif ($tag eq 'itemhelp') { |
|---|
| 35 | if (not defined $lastitem) { |
|---|
| 36 | die "detected 'itemhelp' w/o preceeding 'item'\n "; |
|---|
| 37 | } |
|---|
| 38 | $lastitem = undef; |
|---|
| 39 | if ($content eq '') { |
|---|
| 40 | die "itemhelp lacks name of helpfile\n "; |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | else { die "Unexpected tag '$tag'\n "; } |
|---|
| 44 | } |
|---|
| 45 | else { |
|---|
| 46 | die "expected 'item' or 'itemhelp' (grep failure?)\n "; |
|---|
| 47 | } |
|---|
| 48 | }; |
|---|
| 49 | if ($@) { |
|---|
| 50 | die "$loc: Error: $@"; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | else { |
|---|
| 54 | die "Error: Unexpected line: '$line'\n "; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.