1 |
#------------------------------------------------------------- |
#------------------------------------------------------------- |
2 |
# |
# |
3 |
# parse_format('format',$isis_row); |
# parse_format(...) |
4 |
# |
# |
5 |
|
|
|
use isis_sf; |
|
6 |
|
|
7 |
sub parse_format { |
sub parse_format { |
8 |
|
my $type = shift || die "parset_format must be called with type!"; |
9 |
|
my $format = shift || die "parse_format must be called with format!"; |
10 |
|
my $row = shift || die "parse_format must be called with row!"; |
11 |
|
my $i = shift || 0; # isis repeatable number |
12 |
|
my $codepage = shift || die "parse_format must be called with codepage!"; |
13 |
|
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 |
|
|
20 |
|
#------------------------------------------------------------- |
21 |
|
|
22 |
|
sub parse_isis_format { |
23 |
|
use isis_sf; |
24 |
|
|
25 |
my $format = shift; |
my $format = shift; |
26 |
my $row = shift; |
my $row = shift; |
27 |
my $i = shift || 0; # isis repeatable number |
my $i = shift; |
28 |
my $codepage = shift || die; |
my $codepage = shift; |
29 |
|
|
30 |
my $out; |
my $out; |
31 |
my $out_swish; |
my $out_swish; |
41 |
while ($format) { |
while ($format) { |
42 |
#print STDERR "\n#### $format"; |
#print STDERR "\n#### $format"; |
43 |
if ($format =~ s/^(\d\d\d)(\w?)//) { |
if ($format =~ s/^(\d\d\d)(\w?)//) { |
44 |
my $isis_tmp = isis_sf($row,$1,$2,$i); |
my $tmp = isis_sf($row,$1,$2,$i); |
45 |
if ($isis_tmp) { |
if ($tmp) { |
46 |
$isis_tmp = $codepage->convert($isis_tmp) if ($codepage); |
if ($codepage) { |
47 |
$display .= $prefix . $isis_tmp; |
$tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert"; |
48 |
$swish .= $isis_tmp." "; |
} |
49 |
#print STDERR " == $isis_tmp"; |
$display .= $prefix . $tmp; |
50 |
|
$swish .= $tmp." "; |
51 |
|
#print STDERR " == $tmp"; |
52 |
} |
} |
53 |
$prefix = ""; |
$prefix = ""; |
54 |
# this might be our local scpeciality -- fields 10 and 11 |
# this might be our local scpeciality -- fields 10 and 11 |
55 |
# (as opposed to 010 and 011) so they are strictly listed |
# (as opposed to 010 and 011) so they are strictly listed |
56 |
# here |
# here |
57 |
} elsif ($format =~ s/^(1[01])//) { |
} elsif ($format =~ s/^(1[01])//) { |
58 |
my $isis_tmp = isis_sf($row,$1,undef,$i); |
my $tmp = isis_sf($row,$1,undef,$i); |
59 |
if ($isis_tmp) { |
if ($tmp) { |
60 |
$isis_tmp = $codepage->convert($isis_tmp) if ($codepage); |
if ($codepage) { |
61 |
$display .= $prefix . $isis_tmp; |
$tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert"; |
62 |
$swish .= $isis_tmp." "; |
} |
63 |
|
$display .= $prefix . $tmp; |
64 |
|
$swish .= $tmp." "; |
65 |
} |
} |
66 |
$prefix = ""; |
$prefix = ""; |
67 |
} elsif ($format =~ s/^mfn//i) { |
} elsif ($format =~ s/^mfn//i) { |
86 |
} |
} |
87 |
|
|
88 |
#------------------------------------------------------------- |
#------------------------------------------------------------- |
89 |
|
|
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 |
|
if ($codepage) { |
114 |
|
$tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert"; |
115 |
|
} |
116 |
|
$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 |
1; |
1; |