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])//) {
86 } elsif ($f =~ s/^mfn//i) {
89 } elsif ($f =~ s/^([^\d]+)(\d{0,3})/$2/) {
91 } elsif ($f =~ s/^([^\d]+\d{0,2})//) {
93 } elsif ($f =~ s/^(\d{1,2})//) {
96 print STDERR "unparsed format: $f\n";
100 push @fmt,'' if ($#fmt % 3 != 0); # add empty suffix
101 $cache->{format}->{$format} = \@fmt;
103 # print STDERR "storing format for '$format': [",join("|",@fmt),"]\n";
104 # print STDERR "storing format for '$format':",Dumper(@fmt),"\n";
105 # print STDERR Dumper($cache->{format}->{$format});
108 # now produce actual record
109 my $tmp = $cache->{format}->{$format} || die "no format cache for '$format'";
111 # print STDERR "using format for '$format':",Dumper(@fmt),"\n";
112 # print STDERR "tmp ",Dumper($tmp);
113 # print STDERR "cache: ",Dumper($cache->{format}->{$format});
116 my $prefix = shift @fmt;
119 my $f = shift @fmt || die "BUG: field name can't be empty!";
122 if ($f eq 'mfn' && $i == 0) {
123 $display .= $sufix if ($display);
124 $display .= $row->{mfn};
126 my $val = &$func($row,$f,$sf,$i);
128 # print STDERR "val: $val\n";
129 my $tmp = cnv_cp($codepage,$val);
131 $display .= $sufix.$tmp;
140 $display = $prefix.$display.$sufix if ($display);
141 print STDERR "format left unused: [",join("|",@fmt),"]\n" if (@fmt);
143 # print STDERR "display: $display swish: $swish\n";
145 return ($swish,$display);
148 #-------------------------------------------------------------
150 sub parse_excel_format {
154 my $codepage = shift;
156 return if ($i > 0); # Excel doesn't support repeatable fields
162 if ($format =~ s/^([^A-Z\|]{1,3})//) {
169 while ($format && length($format) > 0) {
170 #print STDERR "\n#### $format #";
171 if ($format =~ s/^\|([A-Z]{1,2})\|//) {
172 #print STDERR "--$1-> $format -[",length($format),"] ";
174 my $tmp = $row->{$1};
176 $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
178 $display .= $prefix . $tmp;
180 #print STDERR " == $tmp";
183 } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
184 $prefix .= $1 if ($display);
186 print STDERR "unparsed format: $format\n";
190 #print STDERR " display: $display swish: $swish [format: $format]";
193 $display .= $prefix if ($display);
195 return ($swish,$display);
198 #-------------------------------------------------------------
200 sub parse_feed_format {
204 my $codepage = shift;
206 # XXX feed doesn't support repeatable fields, but they really
207 # should, This is a bug. It should be fixed!
214 if ($format =~ s/^([^\d\|]{1,3})//) {
221 while ($format && length($format) > 0) {
222 #print STDERR "\n#### $format #";
223 if ($format =~ s/^\|(\d+)\|//) {
224 #print STDERR "--$1-> $format -[",length($format),"] ";
226 my $tmp = $data->{$1};
228 $tmp = $codepage->convert($tmp) || warn "feed: $1 '$tmp' can't convert\n";
230 $display .= $prefix . $tmp;
232 #print STDERR " == $tmp";
235 } elsif ($format =~ s/^([^\d\|]+)(\|\d+\|)/$2/) {
236 $prefix .= $1 if ($display);
238 print STDERR "unparsed format: $format\n";
242 #print STDERR " display: $display swish: $swish [format: $format]";
245 $display .= $prefix if ($display);
247 return ($swish,$display);
250 #-------------------------------------------------------------