/[webpac]/branches/cpi/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 /branches/cpi/parse_format.pm

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

revision 169 by dpavlin, Mon Jul 14 17:08:37 2003 UTC revision 170 by dpavlin, Sun Nov 23 15:42:16 2003 UTC
# Line 3  Line 3 
3  # parse_format(...)  # parse_format(...)
4  #  #
5    
   
6  sub parse_format {  sub parse_format {
7          my $type = shift || die "parset_format must be called with type!";          my $type = shift || die "parset_format must be called with type!";
8          my $format = shift || die "parse_format must be called with format!";          my $format = shift || die "parse_format must be called with format!";
# Line 37  sub parse_iso_format { Line 36  sub parse_iso_format {
36          my $out;          my $out;
37          my $out_swish;          my $out_swish;
38    
         my $prefix = "";  
         if ($format =~ s/^([^\d]+)//) {  
                 $prefix = $1;  
         }  
   
39          my $display;          my $display;
40          my $swish;          my $swish;
41    
# Line 54  sub parse_iso_format { Line 48  sub parse_iso_format {
48                  return $tmp;                  return $tmp;
49          }          }
50    
51          while ($format) {          # if format doesn't exits, store it in cache
52  #print STDERR "\n#### $format";          if (! defined($cache->{format}->{$format})) {
53                  # this is EBSCO special to support numeric subfield in  #               print STDERR "parsing format for '$format'\n";
54                  # form of 856#3                  my @fmt;
55                  if ($format =~ s/^(\d\d\d)#*(\w?)//) {  
56                          my $tmp = cnv_cp($codepage,&$func($row,$1,$2,$i));                  my $f = $format;
57                          if ($tmp) {  
58                                  $display .= $prefix.$tmp;                  if ($f =~ s/^([^\d]+)//) {
59                                  $swish .= $tmp." ";                          if ($f) {       # there is more to parse
60  #print STDERR " == $tmp";                                  push @fmt,$1;
61                            } else {
62                                    @fmt = ('',$1,undef,'');
63    #print STDERR "just one field: $1\n";
64                          }                          }
65                          $prefix = "";                  } else {
66                  # this might be our local scpeciality -- fields 10 and 11                          push @fmt,'';
67                  # (as opposed to 010 and 011) so they are strictly listed                  }
68                  # here  
69                  } elsif ($format =~ s/^(1[01])//) {                  while ($f) {
70                          my $tmp = cnv_cp($codepage,&$func($row,$1,undef,$i));  #       print STDERR "\n#### $f";
71                          if ($tmp) {                          # this is EBSCO special to support numeric subfield in
72                                  $display .= $prefix.$tmp;                          # form of 856#3
73                                  $swish .= $tmp." ";                          if ($f =~ s/^(\d\d\d)#*(\w?)//) {
74                                    push @fmt,$1;
75                                    if ($2) {
76                                            push @fmt,$2;
77                                    } else {
78                                            push @fmt,undef;
79                                    }
80                            # this might be our local scpeciality -- fields 10 and 11
81                            # (as opposed to 010 and 011) so they are strictly listed
82                            # here
83                            } elsif ($f =~ s/^(1[01])//) {
84                                    push @fmt,$1;
85                                    push @fmt,undef;
86                            } elsif ($f =~ s/^mfn//i) {
87                                    push @fmt,'mfn';
88                                    push @fmt,'';
89                            } elsif ($f =~ s/^([^\d]+)(\d{0,3})/$2/) {
90                                    push @fmt,$1;
91                            } elsif ($f =~ s/^([^\d]+\d{0,2})//) {
92                                    push @fmt,$1;
93                            } elsif ($f =~ s/^(\d{1,2})//) {
94                                    push @fmt,$1;
95                            } else {
96                                    print STDERR "unparsed format: $f\n";
97                                    $f = "";
98                          }                          }
99                          $prefix = "";                  }
100                  } elsif ($format =~ s/^mfn//i) {                  push @fmt,'' if ($#fmt % 3 != 0);       # add empty suffix
101                          $display .= $prefix . $row->{mfn};                  $cache->{format}->{$format} = \@fmt;
102                          $prefix = "";                  
103                  } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {  #               print STDERR "storing format for '$format': [",join("|",@fmt),"]\n";
104                          $prefix .= $1 if ($display);  #               print STDERR "storing format for '$format':",Dumper(@fmt),"\n";
105                  } elsif ($format =~ s/^([^\d]+\d{0,2})//) {  #               print STDERR Dumper($cache->{format}->{$format});
106                          $prefix .= $1 if ($display);          }
107                  } elsif ($format =~ s/^(\d{1,2})//) {  
108                          $prefix .= $1 if ($display);          # now produce actual record
109            my $tmp = $cache->{format}->{$format} || die "no format cache for '$format'";
110            my @fmt = @{$tmp};
111    #       print STDERR "using format for '$format':",Dumper(@fmt),"\n";
112    #       print STDERR "tmp ",Dumper($tmp);
113    #       print STDERR "cache: ",Dumper($cache->{format}->{$format});
114    
115            # prefix
116            my $prefix = shift @fmt;
117            my $sufix;
118            while($#fmt > 1) {
119                    my $f = shift @fmt || die "BUG: field name can't be empty!";
120                    my $sf = shift @fmt;
121    
122                    if ($f eq 'mfn' && $i == 0) {
123                            $display .= $sufix if ($display);
124                            $display .= $row->{mfn};
125                  } else {                  } else {
126                          print STDERR "unparsed format: $format\n";                          my $val = &$func($row,$f,$sf,$i);
127                          $prefix .= $format;                          if ($val) {
128                          $format = "";  #                               print STDERR "val: $val\n";
129                                    my $tmp = cnv_cp($codepage,$val);
130                                    if ($display) {
131                                            $display .= $sufix.$tmp;
132                                    } else {
133                                            $display = $tmp;
134                                    }
135                                    $swish .= $tmp." ";
136                            }
137                  }                  }
138                    $sufix = shift @fmt;
139          }          }
140          # add suffix          $display = $prefix.$display.$sufix if ($display);
141          $display .= $prefix if ($display);          print STDERR "format left unused: [",join("|",@fmt),"]\n" if (@fmt);
142    
143    #       print STDERR "display: $display swish: $swish\n";
144    
145          return ($swish,$display);          return ($swish,$display);
146  }  }

Legend:
Removed from v.169  
changed lines
  Added in v.170

  ViewVC Help
Powered by ViewVC 1.1.26