/[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 62 - (hide annotations)
Fri Jul 4 20:11:48 2003 UTC (16 years, 5 months ago) by dpavlin
File size: 3471 byte(s)
added MARC file import

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 54 }
20     }
21 dpavlin 10
22 dpavlin 54 #-------------------------------------------------------------
23    
24 dpavlin 62 sub parse_iso_format {
25 dpavlin 54
26     my $format = shift;
27     my $row = shift;
28     my $i = shift;
29     my $codepage = shift;
30    
31 dpavlin 62 my $func = shift || die "need to know which sub-field function to use";
32    
33     require $func.".pm";
34    
35 dpavlin 10 my $out;
36     my $out_swish;
37    
38     my $prefix = "";
39     if ($format =~ s/^([^\d]+)//) {
40 dpavlin 23 $prefix = $1;
41 dpavlin 10 }
42    
43     my $display;
44     my $swish;
45    
46 dpavlin 62 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 dpavlin 10 while ($format) {
55 dpavlin 23 #print STDERR "\n#### $format";
56 dpavlin 62 # 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 dpavlin 57 if ($tmp) {
61 dpavlin 62 $display .= $prefix.cnv_cp($tmp);
62 dpavlin 57 $swish .= $tmp." ";
63     #print STDERR " == $tmp";
64 dpavlin 10 }
65     $prefix = "";
66 dpavlin 22 # 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 dpavlin 62 my $tmp = get_sf($row,$1,undef,$i);
71 dpavlin 57 if ($tmp) {
72 dpavlin 62 $display .= $prefix.cnv_cp($tmp);
73 dpavlin 57 $swish .= $tmp." ";
74 dpavlin 22 }
75     $prefix = "";
76 dpavlin 23 } elsif ($format =~ s/^mfn//i) {
77     $display .= $prefix . $row->{mfn};
78     $prefix = "";
79 dpavlin 10 } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
80 dpavlin 23 $prefix .= $1 if ($display);
81 dpavlin 10 } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
82 dpavlin 23 $prefix .= $1 if ($display);
83 dpavlin 10 } elsif ($format =~ s/^(\d{1,2})//) {
84 dpavlin 23 $prefix .= $1 if ($display);
85 dpavlin 10 } 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 dpavlin 54
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 dpavlin 57 if ($codepage) {
123     $tmp = $codepage->convert($tmp) || warn "excel: $1 '$tmp' can't convert";
124     }
125 dpavlin 54 $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 dpavlin 10 1;

Properties

Name Value
cvs2svn:cvs-rev 1.9

  ViewVC Help
Powered by ViewVC 1.1.26