6 |
use isis_sf; |
use isis_sf; |
7 |
|
|
8 |
sub parse_format { |
sub parse_format { |
9 |
my $format = shift; |
my $format = shift || die "parse_format must be called with format!"; |
10 |
my $row = shift; |
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 |
|
|
14 |
my $out; |
my $out; |
15 |
my $out_swish; |
my $out_swish; |
16 |
|
|
17 |
my $prefix = ""; |
my $prefix = ""; |
18 |
if ($format =~ s/^([^\d]+)//) { |
if ($format =~ s/^([^\d]+)//) { |
19 |
$prefix = "pre: $1"; |
$prefix = $1; |
20 |
} |
} |
21 |
|
|
22 |
my $display; |
my $display; |
23 |
my $swish; |
my $swish; |
24 |
|
|
25 |
while ($format) { |
while ($format) { |
26 |
#print STDERR "#### $format\n"; |
#print STDERR "\n#### $format"; |
27 |
if ($format =~ s/^(\d\d\d)(\w?)//) { |
if ($format =~ s/^(\d\d\d)(\w?)//) { |
28 |
my $isis_tmp = isis_sf($row,$1,$2); |
my $isis_tmp = isis_sf($row,$1,$2,$i); |
29 |
if ($isis_tmp) { |
if ($isis_tmp) { |
30 |
|
eval { |
31 |
|
$isis_tmp = $codepage->convert($isis_tmp) if ($codepage); |
32 |
|
}; |
33 |
|
if ($@) { |
34 |
|
print STDERR "FATAL: something bad happend while trying to convert '$isis_tmp' [mfn: ",$row->{mfn},"]\n" |
35 |
|
} |
36 |
$display .= $prefix . $isis_tmp; |
$display .= $prefix . $isis_tmp; |
37 |
$swish .= $isis_tmp." "; |
$swish .= $isis_tmp." "; |
38 |
|
#print STDERR " == $isis_tmp"; |
39 |
} |
} |
40 |
$prefix = ""; |
$prefix = ""; |
41 |
|
# this might be our local scpeciality -- fields 10 and 11 |
42 |
|
# (as opposed to 010 and 011) so they are strictly listed |
43 |
|
# here |
44 |
|
} elsif ($format =~ s/^(1[01])//) { |
45 |
|
my $isis_tmp = isis_sf($row,$1,undef,$i); |
46 |
|
if ($isis_tmp) { |
47 |
|
eval { |
48 |
|
$isis_tmp = $codepage->convert($isis_tmp) if ($codepage); |
49 |
|
}; |
50 |
|
if ($@) { |
51 |
|
print STDERR "FATAL: something bad happend while trying to convert '$isis_tmp' [mfn: ",$row->{mfn},"]\n" |
52 |
|
} |
53 |
|
$display .= $prefix . $isis_tmp; |
54 |
|
$swish .= $isis_tmp." "; |
55 |
|
} |
56 |
|
$prefix = ""; |
57 |
|
} elsif ($format =~ s/^mfn//i) { |
58 |
|
$display .= $prefix . $row->{mfn}; |
59 |
|
$prefix = ""; |
60 |
} elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) { |
} elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) { |
61 |
$prefix .= $1; |
$prefix .= $1 if ($display); |
62 |
} elsif ($format =~ s/^([^\d]+\d{0,2})//) { |
} elsif ($format =~ s/^([^\d]+\d{0,2})//) { |
63 |
$prefix .= $1; |
$prefix .= $1 if ($display); |
64 |
} elsif ($format =~ s/^(\d{1,2})//) { |
} elsif ($format =~ s/^(\d{1,2})//) { |
65 |
$prefix .= $1; |
$prefix .= $1 if ($display); |
66 |
} else { |
} else { |
67 |
print STDERR "unparsed format: $format\n"; |
print STDERR "unparsed format: $format\n"; |
68 |
$prefix .= $format; |
$prefix .= $format; |