| 1 | #!/usr/bin/perl -w |
| 2 | # $Cambridge: exim/doc/doc-scripts/faqchk,v 1.1 2004/10/07 15:04:35 ph10 Exp $ |
| 3 | |
| 4 | # Script to check the FAQ source and make sure I have all the numbers |
| 5 | # in the right order without duplication. Also check the numbers of blank |
| 6 | # lines. It gives up on any error (other than bad blank line counts). |
| 7 | |
| 8 | sub oops { |
| 9 | print "\nLine $line: $_[0]\n"; |
| 10 | print; |
| 11 | exit 1; |
| 12 | } |
| 13 | |
| 14 | sub poops { |
| 15 | print "\nLine $line: $_[0]\n"; |
| 16 | print; |
| 17 | $precede_fail = 1; |
| 18 | } |
| 19 | |
| 20 | |
| 21 | $line = 0; |
| 22 | $section = -1; |
| 23 | $expect_answer = 0; |
| 24 | $precede_fail = 0; |
| 25 | |
| 26 | while (<>) |
| 27 | { |
| 28 | $line++; |
| 29 | if (/^\s*$/) |
| 30 | { |
| 31 | $blankcount++; |
| 32 | next; |
| 33 | } |
| 34 | $preceded = $blankcount; |
| 35 | $blankcount = 0; |
| 36 | |
| 37 | if (/^(\d+)\./) |
| 38 | { |
| 39 | &poops("$preceded empty lines precede (3 expected)") if $preceded != 3; |
| 40 | &oops(sprint("Answer %02d%02d is missing\n", $section, $question)) |
| 41 | if $expect_answer; |
| 42 | $section = $1; |
| 43 | $question = ($section == 20)? 0 : 1; |
| 44 | $expected = 1; |
| 45 | if ($section == 99) |
| 46 | { |
| 47 | $c = 1; |
| 48 | $f = 1; |
| 49 | } |
| 50 | next; |
| 51 | } |
| 52 | |
| 53 | if ($section != 99) |
| 54 | { |
| 55 | if (/^Q(\d\d)(\d\d):/) |
| 56 | { |
| 57 | &poops("$preceded empty lines precede ($expected expected)") |
| 58 | if $preceded != $expected; |
| 59 | $expected = 2; |
| 60 | |
| 61 | &oops("Answer expected") if $expect_answer; |
| 62 | &oops("Q$1$2 is in the wrong section") if ($1 != $section); |
| 63 | &oops("Q$1$2 is out of order") if $2 != $question; |
| 64 | |
| 65 | $expect_answer = 1; |
| 66 | next; |
| 67 | } |
| 68 | |
| 69 | if (/^A(\d\d)(\d\d):/) |
| 70 | { |
| 71 | &poops("$preceded empty lines precede (1 expected)") if $preceded != 1; |
| 72 | |
| 73 | &oops("Question expected") if !$expect_answer; |
| 74 | &oops("A$1$2 is in the wrong section") if $1 != $section; |
| 75 | &oops("A$1$2 is out of order") if $2 != $question++; |
| 76 | |
| 77 | $expect_answer = 0; |
| 78 | next; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | else |
| 83 | { |
| 84 | if (/^C(\d\d\d):/) |
| 85 | { |
| 86 | &oops("C$1 is mixed up in the Fs") if $f != 1; |
| 87 | # Some Cxxx configs are omitted (not translated from Exim 3) so can |
| 88 | # only check increasing number. |
| 89 | &oops("C$1 is out of order") if $1 < $c; |
| 90 | $c = $1; |
| 91 | } |
| 92 | elsif (/^F(\d\d\d):/) |
| 93 | { |
| 94 | &oops("F$1 is out of order") if $1 != $f++; |
| 95 | next; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | exit 1 if $precede_fail; |
| 101 | |
| 102 | # End |