1 #-------------------------------------------------------------
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_iso_format($format,$row,$i,$codepage,'isis_sf');
15 } elsif ($type eq "excel") {
16 return parse_excel_format($format,$row,$i,$codepage);
17 } elsif ($type eq "marc") {
18 return parse_iso_format($format,$row,$i,$codepage,'marc_sf');
19 } elsif ($type eq "feed") {
20 return parse_feed_format($format,$row,$i,$codepage);
24 #-------------------------------------------------------------
26 sub parse_iso_format {
33 my $func = shift || die "need to know which sub-field function to use";
41 if ($format =~ s/^([^\d]+)//) {
50 my $tmp = shift || return;
52 $tmp = $codepage->convert($tmp) || print STDERR "iso: '$tmp' can't convert\n";
58 #print STDERR "\n#### $format";
59 # this is EBSCO special to support numeric subfield in
61 if ($format =~ s/^(\d\d\d)#*(\w?)//) {
62 my $tmp = cnv_cp($codepage,&$func($row,$1,$2,$i));
64 $display .= $prefix.$tmp;
66 #print STDERR " == $tmp";
69 # this might be our local scpeciality -- fields 10 and 11
70 # (as opposed to 010 and 011) so they are strictly listed
72 } elsif ($format =~ s/^(1[01])//) {
73 my $tmp = cnv_cp($codepage,&$func($row,$1,undef,$i));
75 $display .= $prefix.$tmp;
79 } elsif ($format =~ s/^mfn//i) {
80 $display .= $prefix . $row->{mfn};
82 } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
83 $prefix .= $1 if ($display);
84 } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
85 $prefix .= $1 if ($display);
86 } elsif ($format =~ s/^(\d{1,2})//) {
87 $prefix .= $1 if ($display);
89 print STDERR "unparsed format: $format\n";
95 $display .= $prefix if ($display);
97 return ($swish,$display);
100 #-------------------------------------------------------------
102 sub parse_excel_format {
106 my $codepage = shift;
108 return if ($i > 0); # Excel doesn't support repeatable fields
114 if ($format =~ s/^([^A-Z\|]{1,3})//) {
121 while ($format && length($format) > 0) {
122 #print STDERR "\n#### $format #";
123 if ($format =~ s/^\|([A-Z]{1,2})\|//) {
124 #print STDERR "--$1-> $format -[",length($format),"] ";
126 my $tmp = $row->{$1};
128 $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
130 $display .= $prefix . $tmp;
132 #print STDERR " == $tmp";
135 } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
136 $prefix .= $1 if ($display);
138 print STDERR "unparsed format: $format\n";
142 #print STDERR " display: $display swish: $swish [format: $format]";
145 $display .= $prefix if ($display);
147 return ($swish,$display);
150 #-------------------------------------------------------------
152 sub parse_feed_format {
156 my $codepage = shift;
158 # XXX feed doesn't support repeatable fields, but they really
159 # should, This is a bug. It should be fixed!
166 if ($format =~ s/^([^\d\|]{1,3})//) {
173 while ($format && length($format) > 0) {
174 #print STDERR "\n#### $format #";
175 if ($format =~ s/^\|(\d+)\|//) {
176 #print STDERR "--$1-> $format -[",length($format),"] ";
178 my $tmp = $data->{$1};
180 $tmp = $codepage->convert($tmp) || warn "feed: $1 '$tmp' can't convert\n";
182 $display .= $prefix . $tmp;
184 #print STDERR " == $tmp";
187 } elsif ($format =~ s/^([^\d\|]+)(\|\d+\|)/$2/) {
188 $prefix .= $1 if ($display);
190 print STDERR "unparsed format: $format\n";
194 #print STDERR " display: $display swish: $swish [format: $format]";
197 $display .= $prefix if ($display);
199 return ($swish,$display);
202 #-------------------------------------------------------------