/[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

Contents of /trunk/parse_format.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 54 - (show annotations)
Mon Jun 23 20:20:32 2003 UTC (20 years, 9 months ago) by dpavlin
File size: 3158 byte(s)
added Microsoft Excel file import

1 #-------------------------------------------------------------
2 #
3 # parse_format(...)
4 #
5
6
7 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!";
10 my $row = shift || die "parse_format must be called with row!";
11 my $i = shift || 0; # isis repeatable number
12 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;
31 my $out_swish;
32
33 my $prefix = "";
34 if ($format =~ s/^([^\d]+)//) {
35 $prefix = $1;
36 }
37
38 my $display;
39 my $swish;
40
41 while ($format) {
42 #print STDERR "\n#### $format";
43 if ($format =~ s/^(\d\d\d)(\w?)//) {
44 my $isis_tmp = isis_sf($row,$1,$2,$i);
45 if ($isis_tmp) {
46 $isis_tmp = $codepage->convert($isis_tmp) if ($codepage);
47 $display .= $prefix . $isis_tmp;
48 $swish .= $isis_tmp." ";
49 #print STDERR " == $isis_tmp";
50 }
51 $prefix = "";
52 # this might be our local scpeciality -- fields 10 and 11
53 # (as opposed to 010 and 011) so they are strictly listed
54 # here
55 } elsif ($format =~ s/^(1[01])//) {
56 my $isis_tmp = isis_sf($row,$1,undef,$i);
57 if ($isis_tmp) {
58 $isis_tmp = $codepage->convert($isis_tmp) if ($codepage);
59 $display .= $prefix . $isis_tmp;
60 $swish .= $isis_tmp." ";
61 }
62 $prefix = "";
63 } elsif ($format =~ s/^mfn//i) {
64 $display .= $prefix . $row->{mfn};
65 $prefix = "";
66 } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
67 $prefix .= $1 if ($display);
68 } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
69 $prefix .= $1 if ($display);
70 } elsif ($format =~ s/^(\d{1,2})//) {
71 $prefix .= $1 if ($display);
72 } else {
73 print STDERR "unparsed format: $format\n";
74 $prefix .= $format;
75 $format = "";
76 }
77 }
78 # add suffix
79 $display .= $prefix if ($display);
80
81 return ($swish,$display);
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;

Properties

Name Value
cvs2svn:cvs-rev 1.7

  ViewVC Help
Powered by ViewVC 1.1.26