inital checking of OpenECHO module
[Business-OnlinePayment-OpenECHO.git] / generror / errortable2hash.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my($code, $short, $explanation);
6 my $mode = 'code';
7
8 my $DEBUG = 0;
9
10 while (<>) {
11
12   if ( /^\s*<tr>\s*$/i ) {
13     ($code, $short, $explanation) = ('', '', '');
14   } elsif ( /^\s*<td[^>]*>(\d+)(\s|&nbsp;)*<\/td>\s*$/i ) {
15     $code = $1;
16     warn "found code $code" if $DEBUG;
17     $mode = 'short';
18   } elsif ( /^\s*<td[^>]*>(\d+(\s|&nbsp;)*\-\s*\d+)<\/td>\s*$/i ){
19     warn "skipping range $1" if $DEBUG;
20     until ( ($_=<>) =~ /^\s*<\/tr>\s*$/i ) {
21       #nop
22     }
23     next;
24   } elsif ( /^\s*<td[^>]*>(.*)<\/td>\s*$/i ) {
25     warn "found one line data" if $DEBUG;
26     if ( $mode eq 'short' ) {
27       $short = $1;
28       $short =~ s/<\/?FONT[^>]*>//gi;
29       $short =~ s/&nbsp;/ /g;
30       $short =~ s/<\/?a[^>]*>//gi;
31       $mode = 'explanation';
32     } elsif ( $mode eq 'explanation' ) {
33       $explanation = $1;
34       $explanation =~ s/<\/?FONT[^>]*>//gi;
35       $explanation =~ s/&nbsp;/ /g;
36       $mode = 'code';
37     } else {
38       die "found (one-line) data, but in unknown mode $mode";
39     }
40   } elsif ( /^\s*<td[^>]*>(.*)$/i ) {
41     warn "found multi-line data (mode $mode)" if $DEBUG;
42     chop(my $data = $1);
43     #$data =~ s/<\/?FONT[^>]*>//g;
44     until ( ($_=<>) =~ /^\s*(.*)<\/td>/i ) {
45       /^\s*(.*)\s*$/ or die;
46       chop($data .= $1);
47       warn "found intermediate data $1" if $DEBUG;
48     }
49     $_ =~ /^\s*(.*)<\/td>/i;
50     $data .= $1;
51     $data =~ s/<\/?FONT[^>]*>//gi;
52     $data =~ s/&nbsp;/ /g;
53     $data =~ s/<\/?[BI]>//gi;
54     $data =~ s/<\/?BR>/ /gi;
55     $data =~ s/<\/?a[^>]*>//gi;
56     warn "last line $1 ($_)" if $DEBUG;
57     warn "coalesced multi-line data: $data" if $DEBUG;
58     if ( $mode eq 'short' ) {
59       $short = $data;
60       $mode = 'explanation';
61     } elsif ( $mode eq 'explanation' ) {
62       $explanation = $data;
63       $mode = 'code';
64     } elsif ( $mode eq 'code' && $data =~ /^(\d+)$/ ) {
65       $code = $1;
66       warn "found code $code" if $DEBUG;
67       $mode = 'short';
68     } else {
69       die "found (multi-line) data, but in unknown mode $mode or don't know what to do with it: $data";
70     }
71   
72   } elsif ( /^\s*<\/tr>\s*$/i ) {
73     #$short =~ s/<\/?FONT[^>]*>//g;
74     #$explanation =~ s/<\/?FONT[^>]*>//g;
75     #$short =~ s/[\n\r]//;
76     #$explanation =~ s/[\n\r]//;
77
78     $short =~ s/"/\\"/gi;
79     $explanation =~ s/"/\\"/gi;
80     
81     warn "end of row, printing hash element (code $code)" if $DEBUG;
82     print qq!  "$code" => \[ "$short", "$explanation" \],\n!
83       unless $short  =~ /^\s*not\s*used\s*/i;
84     $mode = 'code';
85   }
86
87 }
88