1 #-------------------------------------------------------------
7 my $type = shift || die "parset_format must be called with type!";
8 my $format = shift || die "parse_format must be called with format!";
9 my $row = shift || die "parse_format must be called with row!";
10 my $i = shift || 0; # isis repeatable number
11 my $codepage = shift || die "parse_format must be called with codepage!";
12 if ($type eq "isis") {
13 return parse_iso_format($format,$row,$i,$codepage,'isis_sf');
14 } elsif ($type eq "excel") {
15 return parse_excel_format($format,$row,$i,$codepage);
16 } elsif ($type eq "marc") {
17 return parse_iso_format($format,$row,$i,$codepage,'marc_sf');
18 } elsif ($type eq "feed") {
19 return parse_feed_format($format,$row,$i,$codepage);
23 #-------------------------------------------------------------
25 sub parse_iso_format {
32 my $func = shift || die "need to know which sub-field function to use";
44 my $tmp = shift || return;
46 $tmp = $codepage->convert($tmp) || print STDERR "iso: '$tmp' can't convert\n";
51 # if format doesn't exits, store it in cache
52 if (! defined($cache->{format}->{$format})) {
53 # print STDERR "parsing format for '$format'\n";
58 if ($f =~ s/^([^\d]+)//) {
59 if ($f) { # there is more to parse
62 @fmt = ('',$1,undef,'');
63 #print STDERR "just one field: $1\n";
70 # print STDERR "\n#### $f";
71 # this is EBSCO special to support numeric subfield in
73 if ($f =~ s/^(\d\d\d)#*(\w?)//) {
80 # this might be our local scpeciality -- fields 10 and 11
81 # (as opposed to 010 and 011) so they are strictly listed
83 } elsif ($f =~ s/^(1[01]\w?)//) {
86 } elsif ($f =~ s/^mfn//i) {
89 } elsif ($f =~ s/^([^\d]+)(\d{0,3})/$2/) {
96 } elsif ($f =~ s/^([^\d]+\d{0,2})//) {
102 } elsif ($f =~ s/^(\d{1,2})//) {
109 print STDERR "unparsed format: $f\n";
113 push @fmt,'' if ($#fmt % 3 != 0); # add empty suffix
114 $cache->{format}->{$format} = \@fmt;
116 # print STDERR "storing format for '$format': [",join("|",@fmt),"]\n";
117 # print STDERR "storing format for '$format':",Dumper(@fmt),"\n";
118 # print STDERR Dumper($cache->{format}->{$format});
121 # now produce actual record
122 my $tmp = $cache->{format}->{$format} || die "no format cache for '$format'";
124 # print STDERR "using format for '$format':",Dumper(@fmt),"\n";
125 # print STDERR "tmp ",Dumper($tmp);
126 # print STDERR "cache: ",Dumper($cache->{format}->{$format});
129 my $prefix = shift @fmt;
132 my $f = shift @fmt || die "BUG: field name can't be empty!";
135 if ($f eq 'mfn' && $i == 0) {
136 $display .= $sufix if ($display);
137 $display .= $row->{mfn};
139 my $val = &$func($row,$f,$sf,$i);
141 # print STDERR "val: $val\n";
142 my $tmp = cnv_cp($codepage,$val);
144 $display .= $sufix.$tmp;
153 $display = $prefix.$display.$sufix if ($display);
154 print STDERR "format left unused: [",join("|",@fmt),"]\n" if (@fmt);
156 print STDERR "format: [",join("|",@{$tmp}),"]\n" if (@fmt);
158 # print STDERR "format: {",$format || '',"} display: {",$display || '',"} swish: {",$swish || '',"}\n";
160 return ($swish,$display);
163 #-------------------------------------------------------------
165 sub parse_excel_format {
169 my $codepage = shift;
171 return if ($i > 0); # Excel doesn't support repeatable fields
177 if ($format =~ s/^([^A-Z\|]{1,3})//) {
184 while ($format && length($format) > 0) {
185 #print STDERR "\n#### $format #";
186 if ($format =~ s/^\|([A-Z]{1,2})\|//) {
187 #print STDERR "--$1-> $format -[",length($format),"] ";
189 my $tmp = $row->{$1};
191 $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
193 $display .= $prefix . $tmp;
195 #print STDERR " == $tmp";
198 } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
199 $prefix .= $1 if ($display);
201 print STDERR "unparsed format: $format\n";
205 #print STDERR " display: $display swish: $swish [format: $format]";
208 $display .= $prefix if ($display);
210 return ($swish,$display);
213 #-------------------------------------------------------------
215 sub parse_feed_format {
219 my $codepage = shift;
221 # XXX feed doesn't support repeatable fields, but they really
222 # should, This is a bug. It should be fixed!
229 if ($format =~ s/^([^\d\|]{1,3})//) {
236 while ($format && length($format) > 0) {
237 #print STDERR "\n#### $format #";
238 if ($format =~ s/^\|(\d+)\|//) {
239 #print STDERR "--$1-> $format -[",length($format),"] ";
241 my $tmp = $data->{$1};
243 $tmp = $codepage->convert($tmp) || warn "feed: $1 '$tmp' can't convert\n";
245 $display .= $prefix . $tmp;
247 #print STDERR " == $tmp";
250 } elsif ($format =~ s/^([^\d\|]+)(\|\d+\|)/$2/) {
251 $prefix .= $1 if ($display);
253 print STDERR "unparsed format: $format\n";
257 #print STDERR " display: $display swish: $swish [format: $format]";
260 $display .= $prefix if ($display);
262 return ($swish,$display);
265 #-------------------------------------------------------------