/[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 105 - (hide annotations)
Mon Jul 14 17:08:37 2003 UTC (16 years, 4 months ago) by dpavlin
File size: 4931 byte(s)
renamed get_sf to (isis|marc)_sf to avoid warning abouts re-definining of
function

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 dpavlin 78 my $codepage = shift;
50     my $tmp = shift || return;
51 dpavlin 62 if ($codepage) {
52 dpavlin 78 $tmp = $codepage->convert($tmp) || print STDERR "iso: '$tmp' can't convert\n";
53 dpavlin 62 }
54     return $tmp;
55     }
56    
57 dpavlin 10 while ($format) {
58 dpavlin 23 #print STDERR "\n#### $format";
59 dpavlin 62 # this is EBSCO special to support numeric subfield in
60     # form of 856#3
61     if ($format =~ s/^(\d\d\d)#*(\w?)//) {
62 dpavlin 105 my $tmp = cnv_cp($codepage,&$func($row,$1,$2,$i));
63 dpavlin 57 if ($tmp) {
64 dpavlin 78 $display .= $prefix.$tmp;
65 dpavlin 57 $swish .= $tmp." ";
66     #print STDERR " == $tmp";
67 dpavlin 10 }
68     $prefix = "";
69 dpavlin 22 # this might be our local scpeciality -- fields 10 and 11
70     # (as opposed to 010 and 011) so they are strictly listed
71     # here
72     } elsif ($format =~ s/^(1[01])//) {
73 dpavlin 105 my $tmp = cnv_cp($codepage,&$func($row,$1,undef,$i));
74 dpavlin 57 if ($tmp) {
75 dpavlin 78 $display .= $prefix.$tmp;
76 dpavlin 57 $swish .= $tmp." ";
77 dpavlin 22 }
78     $prefix = "";
79 dpavlin 23 } elsif ($format =~ s/^mfn//i) {
80     $display .= $prefix . $row->{mfn};
81     $prefix = "";
82 dpavlin 10 } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
83 dpavlin 23 $prefix .= $1 if ($display);
84 dpavlin 10 } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
85 dpavlin 23 $prefix .= $1 if ($display);
86 dpavlin 10 } elsif ($format =~ s/^(\d{1,2})//) {
87 dpavlin 23 $prefix .= $1 if ($display);
88 dpavlin 10 } else {
89     print STDERR "unparsed format: $format\n";
90     $prefix .= $format;
91     $format = "";
92     }
93     }
94     # add suffix
95     $display .= $prefix if ($display);
96    
97     return ($swish,$display);
98     }
99    
100     #-------------------------------------------------------------
101 dpavlin 54
102     sub parse_excel_format {
103     my $format = shift;
104     my $row = shift;
105     my $i = shift;
106     my $codepage = shift;
107    
108 dpavlin 90 return if ($i > 0); # Excel doesn't support repeatable fields
109    
110 dpavlin 54 my $out;
111     my $out_swish;
112    
113     my $prefix = "";
114     if ($format =~ s/^([^A-Z\|]{1,3})//) {
115     $prefix = $1;
116     }
117    
118     my $display;
119     my $swish;
120    
121     while ($format && length($format) > 0) {
122     #print STDERR "\n#### $format #";
123     if ($format =~ s/^\|([A-Z]{1,2})\|//) {
124     #print STDERR "--$1-> $format -[",length($format),"] ";
125     if ($row->{$1}) {
126     my $tmp = $row->{$1};
127 dpavlin 57 if ($codepage) {
128     $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
129     }
130 dpavlin 54 $display .= $prefix . $tmp;
131     $swish .= $tmp." ";
132     #print STDERR " == $tmp";
133     }
134     $prefix = "";
135     } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
136     $prefix .= $1 if ($display);
137     } else {
138     print STDERR "unparsed format: $format\n";
139     $prefix .= $format;
140     $format = "";
141     }
142     #print STDERR " display: $display swish: $swish [format: $format]";
143     }
144     # add suffix
145     $display .= $prefix if ($display);
146    
147     return ($swish,$display);
148     }
149    
150 dpavlin 67 #-------------------------------------------------------------
151    
152     sub parse_feed_format {
153     my $format = shift;
154     my $data = shift;
155     my $i = shift;
156     my $codepage = shift;
157    
158 dpavlin 92 # XXX feed doesn't support repeatable fields, but they really
159     # should, This is a bug. It should be fixed!
160     return if ($i > 0);
161    
162 dpavlin 67 my $out;
163     my $out_swish;
164    
165     my $prefix = "";
166     if ($format =~ s/^([^\d\|]{1,3})//) {
167     $prefix = $1;
168     }
169    
170     my $display;
171     my $swish;
172    
173     while ($format && length($format) > 0) {
174     #print STDERR "\n#### $format #";
175     if ($format =~ s/^\|(\d+)\|//) {
176     #print STDERR "--$1-> $format -[",length($format),"] ";
177     if ($data->{$1}) {
178     my $tmp = $data->{$1};
179     if ($codepage) {
180     $tmp = $codepage->convert($tmp) || warn "feed: $1 '$tmp' can't convert\n";
181     }
182     $display .= $prefix . $tmp;
183     $swish .= $tmp." ";
184     #print STDERR " == $tmp";
185     }
186     $prefix = "";
187     } elsif ($format =~ s/^([^\d\|]+)(\|\d+\|)/$2/) {
188     $prefix .= $1 if ($display);
189     } else {
190     print STDERR "unparsed format: $format\n";
191     $prefix .= $format;
192     $format = "";
193     }
194     #print STDERR " display: $display swish: $swish [format: $format]";
195     }
196     # add suffix
197     $display .= $prefix if ($display);
198    
199     return ($swish,$display);
200     }
201    
202     #-------------------------------------------------------------
203    
204 dpavlin 10 1;

Properties

Name Value
cvs2svn:cvs-rev 1.14

  ViewVC Help
Powered by ViewVC 1.1.26