/[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 62 - (show annotations)
Fri Jul 4 20:11:48 2003 UTC (20 years, 8 months ago) by dpavlin
File size: 3471 byte(s)
added MARC 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_iso_format($format,$row,$i,$codepage,'isis_sf');
15 } elsif ($type eq "excel") {
16 return parse_excel_format($format,$row,$i,$codepage);
17 } elsif ($type eq "marc") {
18 return parse_iso_format($format,$row,$i,$codepage,'marc_sf');
19 }
20 }
21
22 #-------------------------------------------------------------
23
24 sub parse_iso_format {
25
26 my $format = shift;
27 my $row = shift;
28 my $i = shift;
29 my $codepage = shift;
30
31 my $func = shift || die "need to know which sub-field function to use";
32
33 require $func.".pm";
34
35 my $out;
36 my $out_swish;
37
38 my $prefix = "";
39 if ($format =~ s/^([^\d]+)//) {
40 $prefix = $1;
41 }
42
43 my $display;
44 my $swish;
45
46 sub cnv_cp {
47 my $tmp = shift;
48 if ($codepage) {
49 $tmp = $codepage->convert($tmp) || print STDERR "$1$2 = '$tmp' can't convert";
50 }
51 return $tmp;
52 }
53
54 while ($format) {
55 #print STDERR "\n#### $format";
56 # this is EBSCO special to support numeric subfield in
57 # form of 856#3
58 if ($format =~ s/^(\d\d\d)#*(\w?)//) {
59 my $tmp = get_sf($row,$1,$2,$i);
60 if ($tmp) {
61 $display .= $prefix.cnv_cp($tmp);
62 $swish .= $tmp." ";
63 #print STDERR " == $tmp";
64 }
65 $prefix = "";
66 # this might be our local scpeciality -- fields 10 and 11
67 # (as opposed to 010 and 011) so they are strictly listed
68 # here
69 } elsif ($format =~ s/^(1[01])//) {
70 my $tmp = get_sf($row,$1,undef,$i);
71 if ($tmp) {
72 $display .= $prefix.cnv_cp($tmp);
73 $swish .= $tmp." ";
74 }
75 $prefix = "";
76 } elsif ($format =~ s/^mfn//i) {
77 $display .= $prefix . $row->{mfn};
78 $prefix = "";
79 } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
80 $prefix .= $1 if ($display);
81 } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
82 $prefix .= $1 if ($display);
83 } elsif ($format =~ s/^(\d{1,2})//) {
84 $prefix .= $1 if ($display);
85 } else {
86 print STDERR "unparsed format: $format\n";
87 $prefix .= $format;
88 $format = "";
89 }
90 }
91 # add suffix
92 $display .= $prefix if ($display);
93
94 return ($swish,$display);
95 }
96
97 #-------------------------------------------------------------
98
99 sub parse_excel_format {
100 my $format = shift;
101 my $row = shift;
102 my $i = shift;
103 my $codepage = shift;
104
105 my $out;
106 my $out_swish;
107
108 my $prefix = "";
109 if ($format =~ s/^([^A-Z\|]{1,3})//) {
110 $prefix = $1;
111 }
112
113 my $display;
114 my $swish;
115
116 while ($format && length($format) > 0) {
117 #print STDERR "\n#### $format #";
118 if ($format =~ s/^\|([A-Z]{1,2})\|//) {
119 #print STDERR "--$1-> $format -[",length($format),"] ";
120 if ($row->{$1}) {
121 my $tmp = $row->{$1};
122 if ($codepage) {
123 $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
124 }
125 $display .= $prefix . $tmp;
126 $swish .= $tmp." ";
127 #print STDERR " == $tmp";
128 }
129 $prefix = "";
130 } elsif ($format =~ s/^([^A-Z\|]+)(\|[A-Z]{1,2}\|)/$2/) {
131 $prefix .= $1 if ($display);
132 } else {
133 print STDERR "unparsed format: $format\n";
134 $prefix .= $format;
135 $format = "";
136 }
137 #print STDERR " display: $display swish: $swish [format: $format]";
138 }
139 # add suffix
140 $display .= $prefix if ($display);
141
142 return ($swish,$display);
143 }
144
145 1;

Properties

Name Value
cvs2svn:cvs-rev 1.9

  ViewVC Help
Powered by ViewVC 1.1.26