55 |
|
|
56 |
my $f = $format; |
my $f = $format; |
57 |
|
|
58 |
|
my $eval; |
59 |
|
$eval = $1 if ($f =~ s/^eval{([^}]+)}//); |
60 |
|
|
61 |
if ($f =~ s/^([^\d]+)//) { |
if ($f =~ s/^([^\d]+)//) { |
62 |
if ($f) { # there is more to parse |
if ($f) { # there is more to parse |
63 |
push @fmt,$1; |
push @fmt,$1; |
83 |
# this might be our local scpeciality -- fields 10 and 11 |
# this might be our local scpeciality -- fields 10 and 11 |
84 |
# (as opposed to 010 and 011) so they are strictly listed |
# (as opposed to 010 and 011) so they are strictly listed |
85 |
# here |
# here |
86 |
} elsif ($f =~ s/^(1[01])//) { |
} elsif ($f =~ s/^(1[01]\w?)//) { |
87 |
push @fmt,$1; |
push @fmt,$1; |
88 |
push @fmt,undef; |
push @fmt,undef; |
89 |
} elsif ($f =~ s/^mfn//i) { |
} elsif ($f =~ s/^mfn//i) { |
90 |
push @fmt,'mfn'; |
push @fmt,'mfn'; |
91 |
push @fmt,''; |
push @fmt,''; |
92 |
} elsif ($f =~ s/^([^\d]+)(\d{0,3})/$2/) { |
} elsif ($f =~ s/^([^\d]+)(\d{0,3})/$2/) { |
93 |
push @fmt,$1; |
# still prefix? |
94 |
|
if ($#fmt == 0) { |
95 |
|
$fmt[0] .= $1; |
96 |
|
} else { |
97 |
|
push @fmt,$1; |
98 |
|
} |
99 |
} elsif ($f =~ s/^([^\d]+\d{0,2})//) { |
} elsif ($f =~ s/^([^\d]+\d{0,2})//) { |
100 |
push @fmt,$1; |
if ($#fmt == 0) { |
101 |
|
$fmt[0] .= $1; |
102 |
|
} else { |
103 |
|
push @fmt,$1; |
104 |
|
} |
105 |
} elsif ($f =~ s/^(\d{1,2})//) { |
} elsif ($f =~ s/^(\d{1,2})//) { |
106 |
push @fmt,$1; |
if ($#fmt == 0) { |
107 |
|
$fmt[0] .= $1; |
108 |
|
} else { |
109 |
|
push @fmt,$1; |
110 |
|
} |
111 |
} else { |
} else { |
112 |
print STDERR "unparsed format: $f\n"; |
print STDERR "unparsed format: $f\n"; |
113 |
$f = ""; |
$f = ""; |
114 |
} |
} |
115 |
} |
} |
116 |
push @fmt,'' if ($#fmt % 3 != 0); # add empty suffix |
push @fmt,'' if ($#fmt % 3 != 0); # add empty suffix |
117 |
|
|
118 |
|
$cache->{format_eval}->{$format} = $eval; # store eval string (if any) |
119 |
|
|
120 |
$cache->{format}->{$format} = \@fmt; |
$cache->{format}->{$format} = \@fmt; |
121 |
|
|
122 |
# print STDERR "storing format for '$format': [",join("|",@fmt),"]\n"; |
# print STDERR "storing format for '$format': [",join("|",@fmt),"]\n"; |
157 |
$sufix = shift @fmt; |
$sufix = shift @fmt; |
158 |
} |
} |
159 |
$display = $prefix.$display.$sufix if ($display); |
$display = $prefix.$display.$sufix if ($display); |
|
print STDERR "format left unused: [",join("|",@fmt),"]\n" if (@fmt); |
|
160 |
|
|
161 |
# print STDERR "display: $display swish: $swish\n"; |
my $eval = $cache->{format_eval}->{$format}; |
162 |
|
if ($eval) { |
163 |
|
sub fld2str { |
164 |
|
my ($func,$row,$f,$sf,$i) = @_; |
165 |
|
#print STDERR "## in fld2str\n"; |
166 |
|
my $tmp = $codepage->convert(&$func($row,$f,$sf,$i)) || ''; |
167 |
|
return "'$tmp'"; |
168 |
|
} |
169 |
|
|
170 |
|
$eval =~ s/v(\d+)\^(\w*)/fld2str($func,$row,$1,$2,$i)/eg; |
171 |
|
#print STDERR "## eval: $eval\n"; |
172 |
|
if (eval "$eval") { |
173 |
|
return ($swish,$display); |
174 |
|
} else { |
175 |
|
return (undef,undef); |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
if (@fmt) { |
180 |
|
print STDERR "format left unused: [",join("|",@fmt),"]\n"; |
181 |
|
print STDERR "format: [",join("|",@{$tmp}),"]\n"; |
182 |
|
} |
183 |
|
|
184 |
|
# print STDERR "format: {",$format || '',"} display: {",$display || '',"} swish: {",$swish || '',"}\n"; |
185 |
|
|
186 |
return ($swish,$display); |
return ($swish,$display); |
187 |
} |
} |
224 |
} elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) { |
} elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) { |
225 |
$prefix .= $1 if ($display); |
$prefix .= $1 if ($display); |
226 |
} else { |
} else { |
227 |
print STDERR "unparsed format: $format\n"; |
#print STDERR "unparsed format: $format\n"; |
228 |
$prefix .= $format; |
$prefix .= $format; |
229 |
$format = ""; |
$format = ""; |
230 |
} |
} |