150 |
} |
} |
151 |
} |
} |
152 |
|
|
153 |
|
sub init_visible_type($) { |
154 |
|
my $type = shift; |
155 |
|
|
156 |
|
# swish, swish_exact, display, index, index_lookup |
157 |
|
# swish and display defaults |
158 |
|
my ($s,$se,$d,$i,$il) = (1,0,1,0,0); |
159 |
|
if (lc($type) eq "display") { |
160 |
|
$s = 0; |
161 |
|
} elsif (lc($type) eq "swish") { |
162 |
|
$d = 0; |
163 |
|
} elsif (lc($type) eq "index") { |
164 |
|
($s,$se,$d,$i) = (0,1,0,1); |
165 |
|
} elsif (lc($type) eq "swish_exact") { |
166 |
|
($s,$se,$d,$i) = (0,1,0,0); |
167 |
|
} elsif (lc($type) =~ /^lookup/) { |
168 |
|
($s,$se,$d,$i,$il) = (0,1,0,0,1); |
169 |
|
} |
170 |
|
return ($s,$se,$d,$i,$il); |
171 |
|
} |
172 |
|
|
173 |
# begin real work: go field by field |
# begin real work: go field by field |
174 |
foreach my $field (@sorted_tags) { |
foreach my $field (@sorted_tags) { |
208 |
|
|
209 |
my $repeat_off = 0; # init repeatable offset |
my $repeat_off = 0; # init repeatable offset |
210 |
|
|
211 |
# swish, swish_exact, display, index, index_lookup |
my ($s,$se,$d,$i,$il) = init_visible_type($x->{type}); |
|
# swish and display defaults |
|
|
my ($s,$se,$d,$i,$il) = (1,0,1,0,0); |
|
|
$s = 0 if (lc($x->{type}) eq "display"); |
|
|
$d = 0 if (lc($x->{type}) eq "swish"); |
|
|
($s,$se,$d,$i) = (0,1,0,1) if (lc($x->{type}) eq "index"); |
|
|
($s,$se,$d,$i) = (0,1,0,0) if (lc($x->{type}) eq "swish_exact"); |
|
|
($s,$se,$d,$i,$il) = (0,1,0,0,1) if (lc($x->{type}) =~ /^lookup/); |
|
212 |
|
|
213 |
# what will separate last line from this one? |
# what will separate last line from this one? |
214 |
if ($display_data && $x->{append}) { |
if ($display_data && $x->{append}) { |
222 |
|
|
223 |
# placeholder for all repeatable entries for index |
# placeholder for all repeatable entries for index |
224 |
|
|
|
sub chk_eval($) { |
|
|
my $data = shift; |
|
|
if ($data =~ s/eval{([^}]+)}//) { |
|
|
if (eval "$1") { |
|
|
return $data; |
|
|
} else { |
|
|
return undef; |
|
|
} |
|
|
} else { |
|
|
return $data; |
|
|
} |
|
|
} |
|
|
|
|
225 |
sub mkformat($$) { |
sub mkformat($$) { |
226 |
my $x = shift || die "mkformat needs tag reference"; |
my $x = shift || die "mkformat needs tag reference"; |
227 |
my $data = shift || return; |
my $data = shift || return; |
228 |
my $format_name = x($x->{format_name}) || return chk_eval($data); |
my $format_name = x($x->{format_name}) || return $data; |
229 |
my $fmt = x($config->{format}->{$format_name}->{content}) || die "<format name=\"$format_name\"> is not defined!"; |
my $fmt = x($config->{format}->{$format_name}->{content}) || die "<format name=\"$format_name\"> is not defined!"; |
230 |
my $format_delimiter = x($x->{format_delimiter}); |
my $format_delimiter = x($x->{format_delimiter}); |
231 |
my @data; |
my @data; |
238 |
if ($fmt) { |
if ($fmt) { |
239 |
my $nr = scalar $fmt =~ s/%s/%s/g; |
my $nr = scalar $fmt =~ s/%s/%s/g; |
240 |
if (($#data+1) == $nr) { |
if (($#data+1) == $nr) { |
241 |
return chk_eval(sprintf($fmt,@data)); |
return sprintf($fmt,@data); |
242 |
} else { |
} else { |
243 |
#print STDERR "mkformat: [$data] can't be split on [$format_delimiter] to $nr fields!\n"; |
#print STDERR "mkformat: [$data] can't be split on [$format_delimiter] to $nr fields!\n"; |
244 |
return chk_eval($data); |
return $data; |
245 |
} |
} |
246 |
} else { |
} else { |
247 |
print STDERR "usage of link '$format_name' without defined format (<link> tag)\n"; |
print STDERR "usage of link '$format_name' without defined format (<link> tag)\n"; |
269 |
$display = $new_display; |
$display = $new_display; |
270 |
$cache->{lhash}->{$display} = $new_display; |
$cache->{lhash}->{$display} = $new_display; |
271 |
} else { |
} else { |
272 |
print STDERR "WARNING: lookup for '$display' didn't find anything.\n"; |
# print STDERR "WARNING: lookup for '$display' didn't find anything.\n"; |
273 |
$display = ""; |
$display = ""; |
274 |
$cache->{lhash}->{$display} = $null; |
$cache->{lhash}->{$display} = $null; |
275 |
} |
} |
290 |
} |
} |
291 |
# type="swish" ; field for swish |
# type="swish" ; field for swish |
292 |
if ($swish) { |
if ($swish) { |
293 |
|
my $tmp = $swish; |
294 |
if ($filter && ($s || $se)) { |
if ($filter && ($s || $se)) { |
295 |
no strict 'refs'; |
no strict 'refs'; |
296 |
my $tmp = join(" ",&$filter($swish)) if ($s || $se); |
$tmp = join(" ",&$filter($tmp)) if ($s || $se); |
|
$swish_data .= $tmp if ($s); |
|
|
$swish_exact_data .= "xxbxx $tmp xxexx " if ($se && $tmp ne ""); |
|
|
|
|
|
} else { |
|
|
$swish_data .= $swish if ($s); |
|
|
$swish_exact_data .= "xxbxx $swish xxexx " if ($se && $swish ne ""); |
|
297 |
} |
} |
298 |
|
|
299 |
|
$swish_data .= $tmp if ($s && $tmp); |
300 |
|
$swish_exact_data .= "xxbxx $tmp xxexx " if ($tmp && $tmp ne "" && $se); |
301 |
} |
} |
302 |
|
|
303 |
# type="display" ; field for display |
# type="display" ; field for display |
330 |
no strict 'refs'; |
no strict 'refs'; |
331 |
$idisplay = &$filter($idisplay); |
$idisplay = &$filter($idisplay); |
332 |
} |
} |
333 |
push @index_data, $idisplay if (! $iterate_by_page); |
push @index_data, $idisplay if ($idisplay && !$iterate_by_page); |
334 |
} |
} |
335 |
|
|
336 |
# store fields in lookup |
# store fields in lookup |
432 |
my $delimiter = x($x->{delimiter}) || ' '; |
my $delimiter = x($x->{delimiter}) || ' '; |
433 |
my $val = $cfg->val($database, x($x->{content})); |
my $val = $cfg->val($database, x($x->{content})); |
434 |
|
|
435 |
my ($s,$d,$i) = (1,1,0); # swish, display default |
# FIXME index_lookup is not supported! |
436 |
$s = 0 if (lc($x->{type}) eq "display"); |
my ($s,$se,$d,$i,$il) = init_visible_type($x->{type}); |
|
$d = 0 if (lc($x->{type}) eq "swish"); |
|
|
# no support for swish exact in config. |
|
|
# IMHO, it's useless |
|
|
($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index"); |
|
437 |
|
|
438 |
if ($val) { |
if ($val) { |
439 |
$display_data .= $delimiter.$val if ($d); |
$display_data .= $delimiter.$val if ($d); |
440 |
$swish_data .= $val if ($s); |
$swish_data .= " ".$val if ($s); |
441 |
$index->insert($field, $val, $path) if ($i); |
$index->insert($field, $val, $path) if ($i); |
442 |
} |
} |
443 |
|
|
733 |
print STDERR "\n"; |
print STDERR "\n"; |
734 |
|
|
735 |
} elsif ($type_base eq "excel") { |
} elsif ($type_base eq "excel") { |
736 |
use Spreadsheet::ParseExcel; |
require Spreadsheet::ParseExcel; |
737 |
use Spreadsheet::ParseExcel::Utility qw(int2col); |
require Spreadsheet::ParseExcel::Utility; |
738 |
|
import Spreadsheet::ParseExcel::Utility qw(int2col); |
739 |
|
|
740 |
$import2cp = Text::Iconv->new($config->{excel_codepage},$codepage); |
$import2cp = Text::Iconv->new($config->{excel_codepage},$codepage); |
741 |
my $excel_file = $cfg -> val($database, 'excel_file') || die "$database doesn't have 'excel_file' defined!"; |
my $excel_file = $cfg -> val($database, 'excel_file') || die "$database doesn't have 'excel_file' defined!"; |
789 |
} |
} |
790 |
} elsif ($type_base eq "marc") { |
} elsif ($type_base eq "marc") { |
791 |
|
|
792 |
use MARC; |
require MARC; |
793 |
|
|
794 |
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); |
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); |
795 |
my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!"; |
my $marc_file = $cfg -> val($database, 'marc_file') || die "$database doesn't have 'marc_file' defined!"; |