/[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 176 by dpavlin, Mon Nov 24 01:16:04 2003 UTC revision 381 by dpavlin, Wed Jul 7 17:34:42 2004 UTC
# Line 55  sub parse_iso_format { Line 55  sub parse_iso_format {
55    
56                  my $f = $format;                  my $f = $format;
57    
58                    my $eval;
59                    $eval = $1 if ($f =~ s/^eval{([^}]+)}//);
60    
61                  if ($f =~ s/^([^\d]+)//) {                  if ($f =~ s/^([^\d]+)//) {
62                          if ($f) {       # there is more to parse                          if ($f) {       # there is more to parse
63                                  push @fmt,$1;                                  push @fmt,$1;
# Line 80  sub parse_iso_format { Line 83  sub parse_iso_format {
83                          # this might be our local scpeciality -- fields 10 and 11                          # this might be our local scpeciality -- fields 10 and 11
84                          # (as opposed to 010 and 011) so they are strictly listed                          # (as opposed to 010 and 011) so they are strictly listed
85                          # here                          # here
86                          } elsif ($f =~ s/^(1[01])//) {                          } elsif ($f =~ s/^(1[01]\w?)//) {
87                                  push @fmt,$1;                                  push @fmt,$1;
88                                  push @fmt,undef;                                  push @fmt,undef;
89                          } elsif ($f =~ s/^mfn//i) {                          } elsif ($f =~ s/^mfn//i) {
# Line 111  sub parse_iso_format { Line 114  sub parse_iso_format {
114                          }                          }
115                  }                  }
116                  push @fmt,'' if ($#fmt % 3 != 0);       # add empty suffix                  push @fmt,'' if ($#fmt % 3 != 0);       # add empty suffix
117    
118                    $cache->{format_eval}->{$format} = $eval; # store eval string (if any)
119    
120                  $cache->{format}->{$format} = \@fmt;                  $cache->{format}->{$format} = \@fmt;
121                                    
122                  print STDERR "storing format for '$format': [",join("|",@fmt),"]\n";  #               print STDERR "storing format for '$format': [",join("|",@fmt),"]\n";
123  #               print STDERR "storing format for '$format':",Dumper(@fmt),"\n";  #               print STDERR "storing format for '$format':",Dumper(@fmt),"\n";
124  #               print STDERR Dumper($cache->{format}->{$format});  #               print STDERR Dumper($cache->{format}->{$format});
125          }          }
# Line 151  sub parse_iso_format { Line 157  sub parse_iso_format {
157                  $sufix = shift @fmt;                  $sufix = shift @fmt;
158          }          }
159          $display = $prefix.$display.$sufix if ($display);          $display = $prefix.$display.$sufix if ($display);
         print STDERR "format left unused: [",join("|",@fmt),"]\n" if (@fmt);  
160    
161          print STDERR "format: [",join("|",@{$tmp}),"]\n" if (@fmt);          my $eval = $cache->{format_eval}->{$format};
162            if ($eval) {
163                    sub fld2str {
164                            my ($func,$row,$f,$sf,$i) = @_;
165    #print STDERR "## in fld2str\n";
166                            my $tmp = $codepage->convert(&$func($row,$f,$sf,$i)) ||  $codepage->convert(&$func($row,$f,$sf,0)) || '';
167                            return "'$tmp'";
168                    }
169    
170                    $eval =~ s/v(\d+)\^(\w*)/fld2str($func,$row,$1,$2,$i)/eg;
171    #print STDERR "## eval: $eval\n";
172                    if (eval "$eval") {
173                            die "eval error: eval{$eval}: $@" if ($@);
174                            return ($swish,$display);
175                    } else {
176                            die "eval error: eval{$eval}: $@" if ($@);
177                            return (undef,undef);
178                    }
179            }
180    
181            if (@fmt) {
182                    print STDERR "format left unused: [",join("|",@fmt),"]\n";
183                    print STDERR "format: [",join("|",@{$tmp}),"]\n";
184            }
185    
186  #       print STDERR "display: $display swish: $swish\n";  #       print STDERR "format: {",$format || '',"} display: {",$display || '',"} swish: {",$swish || '',"}\n";
187    
188          return ($swish,$display);          return ($swish,$display);
189  }  }
# Line 198  sub parse_excel_format { Line 226  sub parse_excel_format {
226                  } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {                  } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
227                          $prefix .= $1 if ($display);                          $prefix .= $1 if ($display);
228                  } else {                  } else {
229                          print STDERR "unparsed format: $format\n";                          #print STDERR "unparsed format: $format\n";
230                          $prefix .= $format;                          $prefix .= $format;
231                          $format = "";                          $format = "";
232                  }                  }

Legend:
Removed from v.176  
changed lines
  Added in v.381

  ViewVC Help
Powered by ViewVC 1.1.26