Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 1 | #! /usr/bin/perl |
| 2 | |
Janis Danisevskis | 112c9cc | 2016-03-31 13:35:25 +0100 | [diff] [blame] | 3 | # A script to scan PCRE2's man pages to check for typos in the control |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 4 | # 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 | |
| 10 | while (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 Hughes | 2dbd7d2 | 2020-06-03 14:32:37 -0700 | [diff] [blame] | 19 | $count = 0; |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 20 | $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 Hughes | 2dbd7d2 | 2020-06-03 14:32:37 -0700 | [diff] [blame] | 54 | elsif (/\\[^ef]|\\f[^IBP]/) |
Nick Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 55 | { |
Elliott Hughes | 2dbd7d2 | 2020-06-03 14:32:37 -0700 | [diff] [blame] | 56 | 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 Kralevich | f73ff17 | 2014-09-27 12:41:49 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | close(IN); |
| 75 | } |
| 76 | |
| 77 | exit $yield; |
| 78 | # End |