blob: 2f84f99b4dc935972f64411f902e6bbf3acdf2b1 [file] [log] [blame]
Nick Kralevichf73ff172014-09-27 12:41:49 -07001#! /usr/bin/perl
2
Janis Danisevskis112c9cc2016-03-31 13:35:25 +01003# A script to scan PCRE2's man pages to check for typos in the control
Nick Kralevichf73ff172014-09-27 12:41:49 -07004# sequences. I use only a small set of the available repertoire, so it is
5# straightforward to check that nothing else has slipped in by mistake. This
6# script should be called in the doc directory.
7
8$yield = 0;
9
10while (scalar(@ARGV) > 0)
11 {
12 $line = 0;
13 $file = shift @ARGV;
14
15 open (IN, $file) || die "Failed to open $file\n";
16
17 while (<IN>)
18 {
Elliott Hughes2dbd7d22020-06-03 14:32:37 -070019 $count = 0;
Nick Kralevichf73ff172014-09-27 12:41:49 -070020 $line++;
21 if (/^\s*$/)
22 {
23 printf "Empty line $line of $file\n";
24 $yield = 1;
25 }
26 elsif (/^\./)
27 {
28 if (!/^\.\s*$|
29 ^\.B\s+\S|
30 ^\.TH\s\S|
31 ^\.SH\s\S|
32 ^\.SS\s\S|
33 ^\.TP(?:\s?\d+)?\s*$|
34 ^\.SM\s*$|
35 ^\.br\s*$|
36 ^\.rs\s*$|
37 ^\.sp\s*$|
38 ^\.nf\s*$|
39 ^\.fi\s*$|
40 ^\.P\s*$|
41 ^\.PP\s*$|
42 ^\.\\"(?:\ HREF)?\s*$|
43 ^\.\\"\sHTML\s<a\shref="[^"]+?">\s*$|
44 ^\.\\"\sHTML\s<a\sname="[^"]+?"><\/a>\s*$|
45 ^\.\\"\s<\/a>\s*$|
46 ^\.\\"\sJOINSH\s*$|
47 ^\.\\"\sJOIN\s*$/x
48 )
49 {
50 printf "Bad control line $line of $file\n";
51 $yield = 1;
52 }
53 }
Elliott Hughes2dbd7d22020-06-03 14:32:37 -070054 elsif (/\\[^ef]|\\f[^IBP]/)
Nick Kralevichf73ff172014-09-27 12:41:49 -070055 {
Elliott Hughes2dbd7d22020-06-03 14:32:37 -070056 printf "Bad backslash in line $line of $file\n";
57 $yield = 1;
58 }
59 while (/\\f[BI]/g)
60 {
61 $count++;
62 }
63 while (/\\fP/g)
64 {
65 $count--;
66 }
67 if ($count != 0)
68 {
69 printf "Mismatching formatting in line $line of $file\n";
70 $yield = 1;
71 }
Nick Kralevichf73ff172014-09-27 12:41:49 -070072 }
73
74 close(IN);
75 }
76
77exit $yield;
78# End