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

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

revision 90 by dpavlin, Sun Jul 13 13:22:50 2003 UTC revision 187 by dpavlin, Sat Nov 29 18:58:34 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,get_sf($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,get_sf($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]\w?)//) {
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                                    # still prefix?
91                                    if ($#fmt == 0) {
92                                            $fmt[0] .= $1;
93                                    } else {
94                                            push @fmt,$1;
95                                    }
96                            } elsif ($f =~ s/^([^\d]+\d{0,2})//) {
97                                    if ($#fmt == 0) {
98                                            $fmt[0] .= $1;
99                                    } else {
100                                            push @fmt,$1;
101                                    }
102                            } elsif ($f =~ s/^(\d{1,2})//) {
103                                    if ($#fmt == 0) {
104                                            $fmt[0] .= $1;
105                                    } else {
106                                            push @fmt,$1;
107                                    }
108                            } else {
109                                    print STDERR "unparsed format: $f\n";
110                                    $f = "";
111                          }                          }
112                          $prefix = "";                  }
113                  } elsif ($format =~ s/^mfn//i) {                  push @fmt,'' if ($#fmt % 3 != 0);       # add empty suffix
114                          $display .= $prefix . $row->{mfn};                  $cache->{format}->{$format} = \@fmt;
115                          $prefix = "";                  
116                  } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {  #               print STDERR "storing format for '$format': [",join("|",@fmt),"]\n";
117                          $prefix .= $1 if ($display);  #               print STDERR "storing format for '$format':",Dumper(@fmt),"\n";
118                  } elsif ($format =~ s/^([^\d]+\d{0,2})//) {  #               print STDERR Dumper($cache->{format}->{$format});
119                          $prefix .= $1 if ($display);          }
120                  } elsif ($format =~ s/^(\d{1,2})//) {  
121                          $prefix .= $1 if ($display);          # now produce actual record
122            my $tmp = $cache->{format}->{$format} || die "no format cache for '$format'";
123            my @fmt = @{$tmp};
124    #       print STDERR "using format for '$format':",Dumper(@fmt),"\n";
125    #       print STDERR "tmp ",Dumper($tmp);
126    #       print STDERR "cache: ",Dumper($cache->{format}->{$format});
127    
128            # prefix
129            my $prefix = shift @fmt;
130            my $sufix;
131            while($#fmt > 1) {
132                    my $f = shift @fmt || die "BUG: field name can't be empty!";
133                    my $sf = shift @fmt;
134    
135                    if ($f eq 'mfn' && $i == 0) {
136                            $display .= $sufix if ($display);
137                            $display .= $row->{mfn};
138                  } else {                  } else {
139                          print STDERR "unparsed format: $format\n";                          my $val = &$func($row,$f,$sf,$i);
140                          $prefix .= $format;                          if ($val) {
141                          $format = "";  #                               print STDERR "val: $val\n";
142                                    my $tmp = cnv_cp($codepage,$val);
143                                    if ($display) {
144                                            $display .= $sufix.$tmp;
145                                    } else {
146                                            $display = $tmp;
147                                    }
148                                    $swish .= $tmp." ";
149                            }
150                  }                  }
151                    $sufix = shift @fmt;
152          }          }
153          # add suffix          $display = $prefix.$display.$sufix if ($display);
154          $display .= $prefix if ($display);          print STDERR "format left unused: [",join("|",@fmt),"]\n" if (@fmt);
155    
156            print STDERR "format: [",join("|",@{$tmp}),"]\n" if (@fmt);
157    
158    #       print STDERR "format: {",$format || '',"} display: {",$display || '',"} swish: {",$swish || '',"}\n";
159    
160          return ($swish,$display);          return ($swish,$display);
161  }  }
# Line 155  sub parse_feed_format { Line 218  sub parse_feed_format {
218          my $i = shift;          my $i = shift;
219          my $codepage = shift;          my $codepage = shift;
220    
221            # XXX feed doesn't support repeatable fields, but they really
222            # should, This is a bug. It should be fixed!
223            return if ($i > 0);
224    
225          my $out;          my $out;
226          my $out_swish;          my $out_swish;
227    

Legend:
Removed from v.90  
changed lines
  Added in v.187

  ViewVC Help
Powered by ViewVC 1.1.26