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

Annotation of /trunk/parse_format.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 67 - (hide annotations)
Fri Jul 4 23:29:27 2003 UTC (16 years, 6 months ago) by dpavlin
File size: 4682 byte(s)
implemented feed method which calls external program that returns
data line-by-line

1 dpavlin 10 #-------------------------------------------------------------
2     #
3 dpavlin 54 # parse_format(...)
4 dpavlin 10 #
5    
6    
7     sub parse_format {
8 dpavlin 54 my $type = shift || die "parset_format must be called with type!";
9 dpavlin 43 my $format = shift || die "parse_format must be called with format!";
10     my $row = shift || die "parse_format must be called with row!";
11 dpavlin 23 my $i = shift || 0; # isis repeatable number
12 dpavlin 43 my $codepage = shift || die "parse_format must be called with codepage!";
13 dpavlin 54 if ($type eq "isis") {
14 dpavlin 62 return parse_iso_format($format,$row,$i,$codepage,'isis_sf');
15 dpavlin 54 } elsif ($type eq "excel") {
16     return parse_excel_format($format,$row,$i,$codepage);
17 dpavlin 62 } elsif ($type eq "marc") {
18     return parse_iso_format($format,$row,$i,$codepage,'marc_sf');
19 dpavlin 67 } elsif ($type eq "feed") {
20     return parse_feed_format($format,$row,$i,$codepage);
21 dpavlin 54 }
22     }
23 dpavlin 10
24 dpavlin 54 #-------------------------------------------------------------
25    
26 dpavlin 62 sub parse_iso_format {
27 dpavlin 54
28     my $format = shift;
29     my $row = shift;
30     my $i = shift;
31     my $codepage = shift;
32    
33 dpavlin 62 my $func = shift || die "need to know which sub-field function to use";
34    
35     require $func.".pm";
36    
37 dpavlin 10 my $out;
38     my $out_swish;
39    
40     my $prefix = "";
41     if ($format =~ s/^([^\d]+)//) {
42 dpavlin 23 $prefix = $1;
43 dpavlin 10 }
44    
45     my $display;
46     my $swish;
47    
48 dpavlin 62 sub cnv_cp {
49     my $tmp = shift;
50     if ($codepage) {
51     $tmp = $codepage->convert($tmp) || print STDERR "$1$2 = '$tmp' can't convert";
52     }
53     return $tmp;
54     }
55    
56 dpavlin 10 while ($format) {
57 dpavlin 23 #print STDERR "\n#### $format";
58 dpavlin 62 # this is EBSCO special to support numeric subfield in
59     # form of 856#3
60     if ($format =~ s/^(\d\d\d)#*(\w?)//) {
61     my $tmp = get_sf($row,$1,$2,$i);
62 dpavlin 57 if ($tmp) {
63 dpavlin 62 $display .= $prefix.cnv_cp($tmp);
64 dpavlin 57 $swish .= $tmp." ";
65     #print STDERR " == $tmp";
66 dpavlin 10 }
67     $prefix = "";
68 dpavlin 22 # this might be our local scpeciality -- fields 10 and 11
69     # (as opposed to 010 and 011) so they are strictly listed
70     # here
71     } elsif ($format =~ s/^(1[01])//) {
72 dpavlin 62 my $tmp = get_sf($row,$1,undef,$i);
73 dpavlin 57 if ($tmp) {
74 dpavlin 62 $display .= $prefix.cnv_cp($tmp);
75 dpavlin 57 $swish .= $tmp." ";
76 dpavlin 22 }
77     $prefix = "";
78 dpavlin 23 } elsif ($format =~ s/^mfn//i) {
79     $display .= $prefix . $row->{mfn};
80     $prefix = "";
81 dpavlin 10 } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
82 dpavlin 23 $prefix .= $1 if ($display);
83 dpavlin 10 } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
84 dpavlin 23 $prefix .= $1 if ($display);
85 dpavlin 10 } elsif ($format =~ s/^(\d{1,2})//) {
86 dpavlin 23 $prefix .= $1 if ($display);
87 dpavlin 10 } else {
88     print STDERR "unparsed format: $format\n";
89     $prefix .= $format;
90     $format = "";
91     }
92     }
93     # add suffix
94     $display .= $prefix if ($display);
95    
96     return ($swish,$display);
97     }
98    
99     #-------------------------------------------------------------
100 dpavlin 54
101     sub parse_excel_format {
102     my $format = shift;
103     my $row = shift;
104     my $i = shift;
105     my $codepage = shift;
106    
107     my $out;
108     my $out_swish;
109    
110     my $prefix = "";
111     if ($format =~ s/^([^A-Z\|]{1,3})//) {
112     $prefix = $1;
113     }
114    
115     my $display;
116     my $swish;
117    
118     while ($format && length($format) > 0) {
119     #print STDERR "\n#### $format #";
120     if ($format =~ s/^\|([A-Z]{1,2})\|//) {
121     #print STDERR "--$1-> $format -[",length($format),"] ";
122     if ($row->{$1}) {
123     my $tmp = $row->{$1};
124 dpavlin 57 if ($codepage) {
125     $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
126     }
127 dpavlin 54 $display .= $prefix . $tmp;
128     $swish .= $tmp." ";
129     #print STDERR " == $tmp";
130     }
131     $prefix = "";
132     } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
133     $prefix .= $1 if ($display);
134     } else {
135     print STDERR "unparsed format: $format\n";
136     $prefix .= $format;
137     $format = "";
138     }
139     #print STDERR " display: $display swish: $swish [format: $format]";
140     }
141     # add suffix
142     $display .= $prefix if ($display);
143    
144     return ($swish,$display);
145     }
146    
147 dpavlin 67 #-------------------------------------------------------------
148    
149     sub parse_feed_format {
150     my $format = shift;
151     my $data = shift;
152     my $i = shift;
153     my $codepage = shift;
154    
155     my $out;
156     my $out_swish;
157    
158     my $prefix = "";
159     if ($format =~ s/^([^\d\|]{1,3})//) {
160     $prefix = $1;
161     }
162    
163     my $display;
164     my $swish;
165    
166     while ($format && length($format) > 0) {
167     #print STDERR "\n#### $format #";
168     if ($format =~ s/^\|(\d+)\|//) {
169     #print STDERR "--$1-> $format -[",length($format),"] ";
170     if ($data->{$1}) {
171     my $tmp = $data->{$1};
172     if ($codepage) {
173     $tmp = $codepage->convert($tmp) || warn "feed: $1 '$tmp' can't convert\n";
174     }
175     $display .= $prefix . $tmp;
176     $swish .= $tmp." ";
177     #print STDERR " == $tmp";
178     }
179     $prefix = "";
180     } elsif ($format =~ s/^([^\d\|]+)(\|\d+\|)/$2/) {
181     $prefix .= $1 if ($display);
182     } else {
183     print STDERR "unparsed format: $format\n";
184     $prefix .= $format;
185     $format = "";
186     }
187     #print STDERR " display: $display swish: $swish [format: $format]";
188     }
189     # add suffix
190     $display .= $prefix if ($display);
191    
192     return ($swish,$display);
193     }
194    
195     #-------------------------------------------------------------
196    
197 dpavlin 10 1;

Properties

Name Value
cvs2svn:cvs-rev 1.10

  ViewVC Help
Powered by ViewVC 1.1.26