Properly escape LaTeX commands in test samples.
[docutils.git] / prest / tbin / redom
blob045c1cbd755c08be072b237d6f5a9035b62e4539
1 #!/usr/local/bin/perl -p
3 # Converts a dom to a regular-expression DOM
4 s/([\(\)\[\]\{\}\.\+\*\?\|\\\^\$])/\\$1/g;
5 s/id\d+/id\\d+/g;
6 s/line="\d+"/line="\\d+"/g;
7 # Remove bogus A-circumflex
8 s/\xc2//g;
9 # Deal with unicode characters
10 s/([\x00-\x09\x0b-\x1f\x7f-\xff\x{0100}-\x{ffff}])/sprintf '\\\\u%04x', ord $1/ge;
11 # Handle the "Generated on" date
12 s/(Generated on: *).*/$1.*/;
13 # Handle the "Generated by" description
14 s/^( *Generated by *)/$1.*/;
15 # Accommodate different date formats
16 BEGIN {
17 $time = '(\s+\d+:\d+:\d+(\s+[-+]\d+(\s+\(.+?\))?)?)?';
18 ($timere = $time) =~ s/\\([()])/\\\\\\$1/g;
20 s!(\d{4})([-/])(\d{2})\2(\d{2})$timere!\\d{4}[-/\]\\d{2}\[-/\]\\d{2}$time!go;
21 # Handle uppercase vs lowercase unicode
22 s/(\\u)([\da-f]{4})/$1(?i)$2/ig;
23 # Deal with revisions that may change
24 s/(prest release )\d+(\\\.\d+)+/$1\\d+(\\.\\d+)+/;
25 if ($AFTER_REVISION) {
26 s/\d+(\\\.\d+)+/\\d+(\\.\\d+)+/;
27 $AFTER_REVISION = 0;
29 $AFTER_REVISION = /<revision>/;
30 # Deal with dates that may change
31 if ($AFTER_DATE) {
32 s|\d{4}[/-]\d{2}[/-]\d{2}|\\d{4}[/-]\\d{2}[/-]\\d{2}|;
33 $AFTER_DATE = 0;
35 # Deal with perl eval numbers that may change in error messages
36 s/\\\((eval )(\d+)\\\).*/\\($1\\d+\\).*/;
37 $AFTER_DATE = /<date>/;
38 # Perl trapped error message changed between 5.8.0 and 5.8.6.
39 s/(: )(.*)( trapped by operation mask)/$1($2|.*)$3/;
40 # System messages may differ in different locales
41 s/(\\\[Errno \d+\\\])(.*)/$1($2|.*)/;
42 s/(\bstates: )(.*)/$1($2|.*)/;
43 # Handle -d output
44 s!^.*(/Text/Restructured/Writer/dom\\\.wrt, line )\d+!.*$1\\d+!;
45 # Handle line numbers in error messages
46 s!\S+(/\S+\\\.(?:pm|wrt),? line )(\d+)(, <\w+> line \d+)?!.*$1($2|\\d+)(, <\\w+> line \\d+)?!g;