Improved comments.
[docutils/kirr.git] / prest / tbin / redom
blob287d7b69a8ddcad3d833eb70b2c7d8b3c6ebc7d9
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 if ($AFTER_REVISION) {
25 s/\d+(\\\.\d+)+/\\d+(\\.\\d+)+/;
26 $AFTER_REVISION = 0;
28 $AFTER_REVISION = /<revision>/;
29 # Deal with dates that may change
30 if ($AFTER_DATE) {
31 s|\d{4}[/-]\d{2}[/-]\d{2}|\\d{4}[/-]\\d{2}[/-]\\d{2}|;
32 $AFTER_DATE = 0;
34 # Deal with perl eval numbers that may change in error messages
35 s/\\\((eval )(\d+)\\\).*/\\($1\\d+\\).*/;
36 $AFTER_DATE = /<date>/;
37 # Perl trapped error message changed between 5.8.0 and 5.8.6.
38 s/(: )(.*)( trapped by operation mask)/$1($2|.*)$3/;
39 # System messages may differ in different locales
40 s/(\\\[Errno \d+\\\])(.*)/$1($2|.*)/;
41 s/(\bstates: )(.*)/$1($2|.*)/;
42 # Handle -d output
43 s!^.*(/Text/Restructured/Writer/dom\\\.wrt, line )\d+!.*$1\\d+!;
44 # Handle line numbers in error messages
45 s!\S+(/\S+\\\.(?:pm|wrt),? line )(\d+)!.*$1($2|\\d+)!g;