/[webpac]/trunk/parse_format.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/parse_format.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (hide annotations)
Fri Jul 4 15:05:23 2003 UTC (16 years, 5 months ago) by dpavlin
File size: 3289 byte(s)
don't choke on input which iconv can't convert

1 dpavlin 10 #-------------------------------------------------------------
2     #
3 dpavlin 54 # parse_format(...)
4 dpavlin 10 #
5    
6    
7     sub parse_format {
8 dpavlin 54 my $type = shift || die "parset_format must be called with type!";
9 dpavlin 43 my $format = shift || die "parse_format must be called with format!";
10     my $row = shift || die "parse_format must be called with row!";
11 dpavlin 23 my $i = shift || 0; # isis repeatable number
12 dpavlin 43 my $codepage = shift || die "parse_format must be called with codepage!";
13 dpavlin 54 if ($type eq "isis") {
14     return parse_isis_format($format,$row,$i,$codepage);
15     } elsif ($type eq "excel") {
16     return parse_excel_format($format,$row,$i,$codepage);
17     }
18     }
19 dpavlin 10
20 dpavlin 54 #-------------------------------------------------------------
21    
22     sub parse_isis_format {
23     use isis_sf;
24    
25     my $format = shift;
26     my $row = shift;
27     my $i = shift;
28     my $codepage = shift;
29    
30 dpavlin 10 my $out;
31     my $out_swish;
32    
33     my $prefix = "";
34     if ($format =~ s/^([^\d]+)//) {
35 dpavlin 23 $prefix = $1;
36 dpavlin 10 }
37    
38     my $display;
39     my $swish;
40    
41     while ($format) {
42 dpavlin 23 #print STDERR "\n#### $format";
43 dpavlin 10 if ($format =~ s/^(\d\d\d)(\w?)//) {
44 dpavlin 57 my $tmp = isis_sf($row,$1,$2,$i);
45     if ($tmp) {
46     if ($codepage) {
47     $tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert";
48     }
49     $display .= $prefix . $tmp;
50     $swish .= $tmp." ";
51     #print STDERR " == $tmp";
52 dpavlin 10 }
53     $prefix = "";
54 dpavlin 22 # this might be our local scpeciality -- fields 10 and 11
55     # (as opposed to 010 and 011) so they are strictly listed
56     # here
57     } elsif ($format =~ s/^(1[01])//) {
58 dpavlin 57 my $tmp = isis_sf($row,$1,undef,$i);
59     if ($tmp) {
60     if ($codepage) {
61     $tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert";
62     }
63     $display .= $prefix . $tmp;
64     $swish .= $tmp." ";
65 dpavlin 22 }
66     $prefix = "";
67 dpavlin 23 } elsif ($format =~ s/^mfn//i) {
68     $display .= $prefix . $row->{mfn};
69     $prefix = "";
70 dpavlin 10 } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
71 dpavlin 23 $prefix .= $1 if ($display);
72 dpavlin 10 } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
73 dpavlin 23 $prefix .= $1 if ($display);
74 dpavlin 10 } elsif ($format =~ s/^(\d{1,2})//) {
75 dpavlin 23 $prefix .= $1 if ($display);
76 dpavlin 10 } else {
77     print STDERR "unparsed format: $format\n";
78     $prefix .= $format;
79     $format = "";
80     }
81     }
82     # add suffix
83     $display .= $prefix if ($display);
84    
85     return ($swish,$display);
86     }
87    
88     #-------------------------------------------------------------
89 dpavlin 54
90     sub parse_excel_format {
91     my $format = shift;
92     my $row = shift;
93     my $i = shift;
94     my $codepage = shift;
95    
96     my $out;
97     my $out_swish;
98    
99     my $prefix = "";
100     if ($format =~ s/^([^A-Z\|]{1,3})//) {
101     $prefix = $1;
102     }
103    
104     my $display;
105     my $swish;
106    
107     while ($format && length($format) > 0) {
108     #print STDERR "\n#### $format #";
109     if ($format =~ s/^\|([A-Z]{1,2})\|//) {
110     #print STDERR "--$1-> $format -[",length($format),"] ";
111     if ($row->{$1}) {
112     my $tmp = $row->{$1};
113 dpavlin 57 if ($codepage) {
114     $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
115     }
116 dpavlin 54 $display .= $prefix . $tmp;
117     $swish .= $tmp." ";
118     #print STDERR " == $tmp";
119     }
120     $prefix = "";
121     } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
122     $prefix .= $1 if ($display);
123     } else {
124     print STDERR "unparsed format: $format\n";
125     $prefix .= $format;
126     $format = "";
127     }
128     #print STDERR " display: $display swish: $swish [format: $format]";
129     }
130     # add suffix
131     $display .= $prefix if ($display);
132    
133     return ($swish,$display);
134     }
135    
136 dpavlin 10 1;

Properties

Name Value
cvs2svn:cvs-rev 1.8

  ViewVC Help
Powered by ViewVC 1.1.26