/[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 43 by dpavlin, Sat Mar 22 22:43:05 2003 UTC revision 54 by dpavlin, Mon Jun 23 20:20:32 2003 UTC
# Line 1  Line 1 
1  #-------------------------------------------------------------  #-------------------------------------------------------------
2  #  #
3  # parse_format('format',$isis_row);  # parse_format(...)
4  #  #
5    
 use isis_sf;  
6    
7  sub parse_format {  sub parse_format {
8            my $type = shift || die "parset_format must be called with type!";
9          my $format = shift || die "parse_format must be called with format!";          my $format = shift || die "parse_format must be called with format!";
10          my $row = shift || die "parse_format must be called with row!";          my $row = shift || die "parse_format must be called with row!";
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") {
14                    return parse_isis_format($format,$row,$i,$codepage);
15            } elsif ($type eq "excel") {
16                    return parse_excel_format($format,$row,$i,$codepage);
17            }
18    }
19    
20    #-------------------------------------------------------------
21    
22    sub parse_isis_format {
23            use isis_sf;
24    
25            my $format = shift;
26            my $row = shift;
27            my $i = shift;
28            my $codepage = shift;
29    
30          my $out;          my $out;
31          my $out_swish;          my $out_swish;
# Line 27  sub parse_format { Line 43  sub parse_format {
43                  if ($format =~ s/^(\d\d\d)(\w?)//) {                  if ($format =~ s/^(\d\d\d)(\w?)//) {
44                          my $isis_tmp = isis_sf($row,$1,$2,$i);                          my $isis_tmp = isis_sf($row,$1,$2,$i);
45                          if ($isis_tmp) {                          if ($isis_tmp) {
46                                  eval {                                  $isis_tmp = $codepage->convert($isis_tmp) if ($codepage);
                                         $isis_tmp = $codepage->convert($isis_tmp) if ($codepage);  
                                 };  
                                 if ($@) {  
                                         print STDERR "FATAL: something bad happend while trying to convert '$isis_tmp' [mfn: ",$row->{mfn},"]\n"  
                                 }  
47                                  $display .= $prefix . $isis_tmp;                                  $display .= $prefix . $isis_tmp;
48                                  $swish .= $isis_tmp." ";                                  $swish .= $isis_tmp." ";
49  #print STDERR " == $isis_tmp";  #print STDERR " == $isis_tmp";
# Line 44  sub parse_format { Line 55  sub parse_format {
55                  } elsif ($format =~ s/^(1[01])//) {                  } elsif ($format =~ s/^(1[01])//) {
56                          my $isis_tmp = isis_sf($row,$1,undef,$i);                          my $isis_tmp = isis_sf($row,$1,undef,$i);
57                          if ($isis_tmp) {                          if ($isis_tmp) {
58                                  eval {                                  $isis_tmp = $codepage->convert($isis_tmp) if ($codepage);
                                         $isis_tmp = $codepage->convert($isis_tmp) if ($codepage);  
                                 };  
                                 if ($@) {  
                                         print STDERR "FATAL: something bad happend while trying to convert '$isis_tmp' [mfn: ",$row->{mfn},"]\n"  
                                 }  
59                                  $display .= $prefix . $isis_tmp;                                  $display .= $prefix . $isis_tmp;
60                                  $swish .= $isis_tmp." ";                                  $swish .= $isis_tmp." ";
61                          }                          }
# Line 76  sub parse_format { Line 82  sub parse_format {
82  }  }
83    
84  #-------------------------------------------------------------  #-------------------------------------------------------------
85    
86    sub parse_excel_format {
87            my $format = shift;
88            my $row = shift;
89            my $i = shift;
90            my $codepage = shift;
91    
92            my $out;
93            my $out_swish;
94    
95            my $prefix = "";
96            if ($format =~ s/^([^A-Z\|]{1,3})//) {
97                    $prefix = $1;
98            }
99    
100            my $display;
101            my $swish;
102    
103            while ($format && length($format) > 0) {
104    #print STDERR "\n#### $format #";
105                    if ($format =~ s/^\|([A-Z]{1,2})\|//) {
106    #print STDERR "--$1-> $format -[",length($format),"] ";
107                            if ($row->{$1}) {
108                                    my $tmp = $row->{$1};
109                                    $tmp = $codepage->convert($tmp) if ($codepage);
110                                    $display .= $prefix . $tmp;
111                                    $swish .= $tmp." ";
112    #print STDERR " == $tmp";
113                            }
114                            $prefix = "";
115                    } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
116                            $prefix .= $1 if ($display);
117                    } else {
118                            print STDERR "unparsed format: $format\n";
119                            $prefix .= $format;
120                            $format = "";
121                    }
122    #print STDERR " display: $display swish: $swish [format: $format]";
123            }
124            # add suffix
125            $display .= $prefix if ($display);
126    
127            return ($swish,$display);
128    }
129    
130  1;  1;

Legend:
Removed from v.43  
changed lines
  Added in v.54

  ViewVC Help
Powered by ViewVC 1.1.26