210 |
|
|
211 |
# placeholder for all repeatable entries for index |
# placeholder for all repeatable entries for index |
212 |
|
|
|
sub chk_eval($) { |
|
|
my $data = shift; |
|
|
if ($data =~ s/eval{([^}]+)}//) { |
|
|
if (eval "$1") { |
|
|
return $data; |
|
|
} else { |
|
|
return undef; |
|
|
} |
|
|
} else { |
|
|
return $data; |
|
|
} |
|
|
} |
|
|
|
|
213 |
sub mkformat($$) { |
sub mkformat($$) { |
214 |
my $x = shift || die "mkformat needs tag reference"; |
my $x = shift || die "mkformat needs tag reference"; |
215 |
my $data = shift || return; |
my $data = shift || return; |
216 |
my $format_name = x($x->{format_name}) || return chk_eval($data); |
my $format_name = x($x->{format_name}) || return $data; |
217 |
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!"; |
218 |
my $format_delimiter = x($x->{format_delimiter}); |
my $format_delimiter = x($x->{format_delimiter}); |
219 |
my @data; |
my @data; |
226 |
if ($fmt) { |
if ($fmt) { |
227 |
my $nr = scalar $fmt =~ s/%s/%s/g; |
my $nr = scalar $fmt =~ s/%s/%s/g; |
228 |
if (($#data+1) == $nr) { |
if (($#data+1) == $nr) { |
229 |
return chk_eval(sprintf($fmt,@data)); |
return sprintf($fmt,@data); |
230 |
} else { |
} else { |
231 |
#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"; |
232 |
return chk_eval($data); |
return $data; |
233 |
} |
} |
234 |
} else { |
} else { |
235 |
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"; |
257 |
$display = $new_display; |
$display = $new_display; |
258 |
$cache->{lhash}->{$display} = $new_display; |
$cache->{lhash}->{$display} = $new_display; |
259 |
} else { |
} else { |
260 |
print STDERR "WARNING: lookup for '$display' didn't find anything.\n"; |
# print STDERR "WARNING: lookup for '$display' didn't find anything.\n"; |
261 |
$display = ""; |
$display = ""; |
262 |
$cache->{lhash}->{$display} = $null; |
$cache->{lhash}->{$display} = $null; |
263 |
} |
} |
278 |
} |
} |
279 |
# type="swish" ; field for swish |
# type="swish" ; field for swish |
280 |
if ($swish) { |
if ($swish) { |
281 |
|
my $tmp = $swish; |
282 |
if ($filter && ($s || $se)) { |
if ($filter && ($s || $se)) { |
283 |
no strict 'refs'; |
no strict 'refs'; |
284 |
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 ""); |
|
285 |
} |
} |
286 |
|
|
287 |
|
$swish_data .= $tmp if ($s && $tmp); |
288 |
|
$swish_exact_data .= "xxbxx $tmp xxexx " if ($tmp && $tmp ne "" && $se); |
289 |
} |
} |
290 |
|
|
291 |
# type="display" ; field for display |
# type="display" ; field for display |
306 |
} else { |
} else { |
307 |
$display_data .= $ldel if ($display_data); |
$display_data .= $ldel if ($display_data); |
308 |
my $tmp = mkformat($x,$display); |
my $tmp = mkformat($x,$display); |
309 |
$display_data = $tmp if ($tmp); |
$display_data .= $tmp if ($tmp); |
310 |
} |
} |
311 |
} |
} |
312 |
|
|
318 |
no strict 'refs'; |
no strict 'refs'; |
319 |
$idisplay = &$filter($idisplay); |
$idisplay = &$filter($idisplay); |
320 |
} |
} |
321 |
push @index_data, $idisplay if (! $iterate_by_page); |
push @index_data, $idisplay if ($idisplay && !$iterate_by_page); |
322 |
} |
} |
323 |
|
|
324 |
# store fields in lookup |
# store fields in lookup |
327 |
if ($lookup_key) { |
if ($lookup_key) { |
328 |
print STDERR "WARNING: try to redefine lookup_key (keys shouldn't be repeatable fields!)"; |
print STDERR "WARNING: try to redefine lookup_key (keys shouldn't be repeatable fields!)"; |
329 |
} else { |
} else { |
330 |
$lookup_key = $display; |
if ($filter) { |
331 |
|
no strict 'refs'; |
332 |
|
$lookup_key = &$filter($display); |
333 |
|
} else { |
334 |
|
$lookup_key = $display; |
335 |
|
} |
336 |
} |
} |
337 |
} elsif (lc($x->{type}) eq "lookup_val") { |
} elsif (lc($x->{type}) eq "lookup_val") { |
338 |
if ($lookup_key) { |
if ($lookup_key) { |
339 |
$lhash{$lookup_key} = $display; |
if ($filter) { |
340 |
|
no strict 'refs'; |
341 |
|
$lhash{$lookup_key} = &$filter($display); |
342 |
|
} else { |
343 |
|
$lhash{$lookup_key} = $display; |
344 |
|
} |
345 |
} else { |
} else { |
346 |
print STDERR "WARNING: no lookup_key defined for '$display'?"; |
print STDERR "WARNING: no lookup_key defined for '$display'?"; |
347 |
} |
} |
587 |
#tie %lhash, 'GDBM_File', $lookup_file, &GDBM_NEWDB, 0644; |
#tie %lhash, 'GDBM_File', $lookup_file, &GDBM_NEWDB, 0644; |
588 |
tie %lhash, 'TDB_File', $lookup_file, TDB_CLEAR_IF_FIRST, O_RDWR, 0644; |
tie %lhash, 'TDB_File', $lookup_file, TDB_CLEAR_IF_FIRST, O_RDWR, 0644; |
589 |
print STDERR "creating lookup file '$lookup_file'\n"; |
print STDERR "creating lookup file '$lookup_file'\n"; |
590 |
|
# delete memory cache for lookup file |
591 |
|
delete $cache->{lhash}; |
592 |
} |
} |
593 |
|
|
594 |
# open existing lookup file |
# open existing lookup file |
725 |
print STDERR "\n"; |
print STDERR "\n"; |
726 |
|
|
727 |
} elsif ($type_base eq "excel") { |
} elsif ($type_base eq "excel") { |
728 |
use Spreadsheet::ParseExcel; |
require Spreadsheet::ParseExcel; |
729 |
use Spreadsheet::ParseExcel::Utility qw(int2col); |
require Spreadsheet::ParseExcel::Utility; |
730 |
|
import Spreadsheet::ParseExcel::Utility qw(int2col); |
731 |
|
|
732 |
$import2cp = Text::Iconv->new($config->{excel_codepage},$codepage); |
$import2cp = Text::Iconv->new($config->{excel_codepage},$codepage); |
733 |
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!"; |
781 |
} |
} |
782 |
} elsif ($type_base eq "marc") { |
} elsif ($type_base eq "marc") { |
783 |
|
|
784 |
use MARC; |
require MARC; |
785 |
|
|
786 |
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); |
$import2cp = Text::Iconv->new($config->{marc_codepage},$codepage); |
787 |
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!"; |
788 |
|
|
789 |
# optional argument is format |
# optional argument is format |
790 |
my $format = x($config->{format}) || 'usmarc'; |
my $format = x($config->{marc_format}) || 'usmarc'; |
791 |
|
|
792 |
print STDERR "Reading MARC file '$marc_file'\n"; |
print STDERR "Reading MARC file '$marc_file'\n"; |
793 |
|
|
794 |
my $marc = new MARC; |
my $marc = new MARC; |
795 |
my $nr = $marc->openmarc({ |
my $nr = $marc->openmarc({ |
796 |
file=>$marc_file, format=>$format |
file=>$marc_file, format=>$format |
797 |
}) || die "Can't open MARC file '$marc_file'"; |
}) || die "Can't open MARC file '$marc_file' with format '$format'"; |
798 |
|
|
799 |
# read MARC file in memory |
# read MARC file in memory |
800 |
$marc->nextmarc(-1); |
$marc->nextmarc(-1); |