/[webpac]/trunk/parse_format.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/parse_format.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 57 by dpavlin, Fri Jul 4 15:05:23 2003 UTC revision 67 by dpavlin, Fri Jul 4 23:29:27 2003 UTC
# Line 11  sub parse_format { Line 11  sub parse_format {
11          my $i = shift || 0;     # isis repeatable number          my $i = shift || 0;     # isis repeatable number
12          my $codepage = shift || die "parse_format must be called with codepage!";          my $codepage = shift || die "parse_format must be called with codepage!";
13          if ($type eq "isis") {          if ($type eq "isis") {
14                  return parse_isis_format($format,$row,$i,$codepage);                  return parse_iso_format($format,$row,$i,$codepage,'isis_sf');
15          } elsif ($type eq "excel") {          } elsif ($type eq "excel") {
16                  return parse_excel_format($format,$row,$i,$codepage);                  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);
21          }          }
22  }  }
23    
24  #-------------------------------------------------------------  #-------------------------------------------------------------
25    
26  sub parse_isis_format {  sub parse_iso_format {
         use isis_sf;  
27    
28          my $format = shift;          my $format = shift;
29          my $row = shift;          my $row = shift;
30          my $i = shift;          my $i = shift;
31          my $codepage = shift;          my $codepage = shift;
32    
33            my $func = shift || die "need to know which sub-field function to use";
34    
35            require $func.".pm";
36    
37          my $out;          my $out;
38          my $out_swish;          my $out_swish;
39    
# Line 38  sub parse_isis_format { Line 45  sub parse_isis_format {
45          my $display;          my $display;
46          my $swish;          my $swish;
47    
48            sub cnv_cp {
49                    my $tmp = shift;
50                    if ($codepage) {
51                            $tmp = $codepage->convert($tmp) || print STDERR "$1$2 = '$tmp' can't convert";
52                    }
53                    return $tmp;
54            }
55    
56          while ($format) {          while ($format) {
57  #print STDERR "\n#### $format";  #print STDERR "\n#### $format";
58                  if ($format =~ s/^(\d\d\d)(\w?)//) {                  # this is EBSCO special to support numeric subfield in
59                          my $tmp = isis_sf($row,$1,$2,$i);                  # form of 856#3
60                    if ($format =~ s/^(\d\d\d)#*(\w?)//) {
61                            my $tmp = get_sf($row,$1,$2,$i);
62                          if ($tmp) {                          if ($tmp) {
63                                  if ($codepage) {                                  $display .= $prefix.cnv_cp($tmp);
                                         $tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert";  
                                 }  
                                 $display .= $prefix . $tmp;  
64                                  $swish .= $tmp." ";                                  $swish .= $tmp." ";
65  #print STDERR " == $tmp";  #print STDERR " == $tmp";
66                          }                          }
# Line 55  sub parse_isis_format { Line 69  sub parse_isis_format {
69                  # (as opposed to 010 and 011) so they are strictly listed                  # (as opposed to 010 and 011) so they are strictly listed
70                  # here                  # here
71                  } elsif ($format =~ s/^(1[01])//) {                  } elsif ($format =~ s/^(1[01])//) {
72                          my $tmp = isis_sf($row,$1,undef,$i);                          my $tmp = get_sf($row,$1,undef,$i);
73                          if ($tmp) {                          if ($tmp) {
74                                  if ($codepage) {                                  $display .= $prefix.cnv_cp($tmp);
                                         $tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert";  
                                 }  
                                 $display .= $prefix . $tmp;  
75                                  $swish .= $tmp." ";                                  $swish .= $tmp." ";
76                          }                          }
77                          $prefix = "";                          $prefix = "";
# Line 133  sub parse_excel_format { Line 144  sub parse_excel_format {
144          return ($swish,$display);          return ($swish,$display);
145  }  }
146    
147    #-------------------------------------------------------------
148    
149    sub parse_feed_format {
150            my $format = shift;
151            my $data = shift;
152            my $i = shift;
153            my $codepage = shift;
154    
155            my $out;
156            my $out_swish;
157    
158            my $prefix = "";
159            if ($format =~ s/^([^\d\|]{1,3})//) {
160                    $prefix = $1;
161            }
162    
163            my $display;
164            my $swish;
165    
166            while ($format && length($format) > 0) {
167    #print STDERR "\n#### $format #";
168                    if ($format =~ s/^\|(\d+)\|//) {
169    #print STDERR "--$1-> $format -[",length($format),"] ";
170                            if ($data->{$1}) {
171                                    my $tmp = $data->{$1};
172                                    if ($codepage) {
173                                            $tmp = $codepage->convert($tmp) || warn "feed: $1 '$tmp' can't convert\n";
174                                    }
175                                    $display .= $prefix . $tmp;
176                                    $swish .= $tmp." ";
177    #print STDERR " == $tmp";
178                            }
179                            $prefix = "";
180                    } elsif ($format =~ s/^([^\d\|]+)(\|\d+\|)/$2/) {
181                            $prefix .= $1 if ($display);
182                    } else {
183                            print STDERR "unparsed format: $format\n";
184                            $prefix .= $format;
185                            $format = "";
186                    }
187    #print STDERR " display: $display swish: $swish [format: $format]";
188            }
189            # add suffix
190            $display .= $prefix if ($display);
191    
192            return ($swish,$display);
193    }
194    
195    #-------------------------------------------------------------
196    
197  1;  1;

Legend:
Removed from v.57  
changed lines
  Added in v.67

  ViewVC Help
Powered by ViewVC 1.1.26