summaryrefslogtreecommitdiff
path: root/doc/doc-scripts/faqchk
blob: 939d0b253fb1eb101b6e5ea0f8f8642fa91470f7 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w
# $Cambridge: exim/doc/doc-scripts/faqchk,v 1.1 2004/10/07 15:04:35 ph10 Exp $

# Script to check the FAQ source and make sure I have all the numbers
# in the right order without duplication. Also check the numbers of blank
# lines. It gives up on any error (other than bad blank line counts).

sub oops {
print "\nLine $line: $_[0]\n";
print;
exit 1;
}

sub poops {
print "\nLine $line: $_[0]\n";
print;
$precede_fail = 1;
}


$line = 0;
$section = -1;
$expect_answer = 0;
$precede_fail = 0;

while (<>)
  {
  $line++;
  if (/^\s*$/)
    {
    $blankcount++;
    next;
    }
  $preceded = $blankcount;
  $blankcount = 0;

  if (/^(\d+)\./)
    {
    &poops("$preceded empty lines precede (3 expected)") if $preceded != 3;
    &oops(sprint("Answer %02d%02d is missing\n", $section, $question))
      if $expect_answer;
    $section = $1;
    $question = ($section == 20)? 0 : 1;
    $expected = 1;
    if ($section == 99)
      {
      $c = 1;
      $f = 1;
      }
    next;
    }

  if ($section != 99)
    {
    if (/^Q(\d\d)(\d\d):/)
      {
      &poops("$preceded empty lines precede ($expected expected)")
        if $preceded != $expected;
      $expected = 2;

      &oops("Answer expected") if $expect_answer;
      &oops("Q$1$2 is in the wrong section") if ($1 != $section);
      &oops("Q$1$2 is out of order") if $2 != $question;

      $expect_answer = 1;
      next;
      }

    if (/^A(\d\d)(\d\d):/)
      {
      &poops("$preceded empty lines precede (1 expected)") if $preceded != 1;

      &oops("Question expected") if !$expect_answer;
      &oops("A$1$2 is in the wrong section") if $1 != $section;
      &oops("A$1$2 is out of order") if $2 != $question++;

      $expect_answer = 0;
      next;
      }
    }

  else
    {
    if (/^C(\d\d\d):/)
      {
      &oops("C$1 is mixed up in the Fs") if $f != 1;
      # Some Cxxx configs are omitted (not translated from Exim 3) so can
      # only check increasing number.
      &oops("C$1 is out of order") if $1 < $c;
      $c = $1;
      }
    elsif (/^F(\d\d\d):/)
      {
      &oops("F$1 is out of order") if $1 != $f++;
      next;
      }
    }
  }

exit 1 if $precede_fail;

# End