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

Diff of /trunk/parse_format.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Thu Jan 16 17:35:54 2003 UTC revision 62 by dpavlin, Fri Jul 4 20:11:48 2003 UTC
# Line 1  Line 1 
1  #-------------------------------------------------------------  #-------------------------------------------------------------
2  #  #
3  # parse_format('format',$isis_row);  # parse_format(...)
4  #  #
5    
 use isis_sf;  
6    
7  sub parse_format {  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;          my $format = shift;
27          my $row = shift;          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;          my $out;
36          my $out_swish;          my $out_swish;
37    
38          my $prefix = "";          my $prefix = "";
39          if ($format =~ s/^([^\d]+)//) {          if ($format =~ s/^([^\d]+)//) {
40                  $prefix = "pre: $1";                  $prefix = $1;
41          }          }
42    
43          my $display;          my $display;
44          my $swish;          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) {          while ($format) {
55  #print STDERR "#### $format\n";  #print STDERR "\n#### $format";
56                  if ($format =~ s/^(\d\d\d)(\w?)//) {                  # this is EBSCO special to support numeric subfield in
57                          my $isis_tmp = isis_sf($row,$1,$2);                  # form of 856#3
58                          if ($isis_tmp) {                  if ($format =~ s/^(\d\d\d)#*(\w?)//) {
59                                  $display .= $prefix . $isis_tmp;                          my $tmp = get_sf($row,$1,$2,$i);
60                                  $swish .= $isis_tmp." ";                          if ($tmp) {
61                                    $display .= $prefix.cnv_cp($tmp);
62                                    $swish .= $tmp." ";
63    #print STDERR " == $tmp";
64                          }                          }
65                          $prefix = "";                          $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/) {                  } elsif ($format =~ s/^([^\d]+)(\d{0,3})/$2/) {
80                          $prefix .= $1;                          $prefix .= $1 if ($display);
81                  } elsif ($format =~ s/^([^\d]+\d{0,2})//) {                  } elsif ($format =~ s/^([^\d]+\d{0,2})//) {
82                          $prefix .= $1;                          $prefix .= $1 if ($display);
83                  } elsif ($format =~ s/^(\d{1,2})//) {                  } elsif ($format =~ s/^(\d{1,2})//) {
84                          $prefix .= $1;                          $prefix .= $1 if ($display);
85                  } else {                  } else {
86                          print STDERR "unparsed format: $format\n";                          print STDERR "unparsed format: $format\n";
87                          $prefix .= $format;                          $prefix .= $format;
# Line 48  sub parse_format { Line 95  sub parse_format {
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;  1;

Legend:
Removed from v.10  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.26