1#! /usr/bin/perl 2 3# A script to scan PCRE2's man pages to check for typos in the control 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 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 { 19 $count = 0; 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 } 54 elsif (/\\[^ef]|\\f[^IBP]/) 55 { 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 } 72 } 73 74 close(IN); 75 } 76 77exit $yield; 78# End 79