/[webpac]/trunk2/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 /trunk2/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 78 by dpavlin, Sat Jul 5 23:39:04 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 $codepage = shift;
50                    my $tmp = shift || return;
51                    if ($codepage) {
52                            $tmp = $codepage->convert($tmp) || print STDERR "iso: '$tmp' can't convert\n";
53                    }
54                    return $tmp;
55            }
56    
57          while ($format) {          while ($format) {
58  #print STDERR "\n#### $format";  #print STDERR "\n#### $format";
59                  if ($format =~ s/^(\d\d\d)(\w?)//) {                  # this is EBSCO special to support numeric subfield in
60                          my $tmp = isis_sf($row,$1,$2,$i);                  # form of 856#3
61                    if ($format =~ s/^(\d\d\d)#*(\w?)//) {
62                            my $tmp = cnv_cp($codepage,get_sf($row,$1,$2,$i));
63                          if ($tmp) {                          if ($tmp) {
64                                  if ($codepage) {                                  $display .= $prefix.$tmp;
                                         $tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert";  
                                 }  
                                 $display .= $prefix . $tmp;  
65                                  $swish .= $tmp." ";                                  $swish .= $tmp." ";
66  #print STDERR " == $tmp";  #print STDERR " == $tmp";
67                          }                          }
# Line 55  sub parse_isis_format { Line 70  sub parse_isis_format {
70                  # (as opposed to 010 and 011) so they are strictly listed                  # (as opposed to 010 and 011) so they are strictly listed
71                  # here                  # here
72                  } elsif ($format =~ s/^(1[01])//) {                  } elsif ($format =~ s/^(1[01])//) {
73                          my $tmp = isis_sf($row,$1,undef,$i);                          my $tmp = cnv_cp($codepage,get_sf($row,$1,undef,$i));
74                          if ($tmp) {                          if ($tmp) {
75                                  if ($codepage) {                                  $display .= $prefix.$tmp;
                                         $tmp = $codepage->convert($tmp) || warn "row: ",$row->{mfn},", $1$2 '$tmp' can't convert";  
                                 }  
                                 $display .= $prefix . $tmp;  
76                                  $swish .= $tmp." ";                                  $swish .= $tmp." ";
77                          }                          }
78                          $prefix = "";                          $prefix = "";
# Line 133  sub parse_excel_format { Line 145  sub parse_excel_format {
145          return ($swish,$display);          return ($swish,$display);
146  }  }
147    
148    #-------------------------------------------------------------
149    
150    sub parse_feed_format {
151            my $format = shift;
152            my $data = shift;
153            my $i = shift;
154            my $codepage = shift;
155    
156            my $out;
157            my $out_swish;
158    
159            my $prefix = "";
160            if ($format =~ s/^([^\d\|]{1,3})//) {
161                    $prefix = $1;
162            }
163    
164            my $display;
165            my $swish;
166    
167            while ($format && length($format) > 0) {
168    #print STDERR "\n#### $format #";
169                    if ($format =~ s/^\|(\d+)\|//) {
170    #print STDERR "--$1-> $format -[",length($format),"] ";
171                            if ($data->{$1}) {
172                                    my $tmp = $data->{$1};
173                                    if ($codepage) {
174                                            $tmp = $codepage->convert($tmp) || warn "feed: $1 '$tmp' can't convert\n";
175                                    }
176                                    $display .= $prefix . $tmp;
177                                    $swish .= $tmp." ";
178    #print STDERR " == $tmp";
179                            }
180                            $prefix = "";
181                    } elsif ($format =~ s/^([^\d\|]+)(\|\d+\|)/$2/) {
182                            $prefix .= $1 if ($display);
183                    } else {
184                            print STDERR "unparsed format: $format\n";
185                            $prefix .= $format;
186                            $format = "";
187                    }
188    #print STDERR " display: $display swish: $swish [format: $format]";
189            }
190            # add suffix
191            $display .= $prefix if ($display);
192    
193            return ($swish,$display);
194    }
195    
196    #-------------------------------------------------------------
197    
198  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26