+ }
+
+ # is this field is lookup?
+ if ($display && $x->{lookup}) {
+ my $null = "<!-- null -->";
+ if ($use_lhash_cache) {
+ if (!defined($cache->{lhash}->{$display})) {
+ my $new_display = $lhash{$display};
+ if (defined($new_display)) {
+#print STDERR "lookup cache store '$display' = '$new_display'\n";
+ $display = $new_display;
+ $cache->{lhash}->{$display} = $new_display;
+ } else {
+# print STDERR "WARNING: lookup for '$display' didn't find anything.\n";
+ $display = "";
+ $cache->{lhash}->{$display} = $null;
+ }
+ } else {
+ $display = $cache->{lhash}->{$display};
+ }
+ } else {
+ $display = $lhash{$display} || $null;
+ }
+ }
+
+ # filter="name" ; filter this field through
+ # filter/[name].pm
+ my $filter = $x->{filter};
+ if ($filter && !$cache->{filter_loaded}->{$filter}) {
+ require "filter/".$filter.".pm";
+ $cache->{filter_loaded}->{$filter}++;
+ }
+ # type="swish" ; field for swish
+ if ($swish) {
+ my $tmp = $swish;
+ if ($filter && ($s || $se)) {
+ no strict 'refs';
+ $tmp = join(" ",&$filter($tmp)) if ($s || $se);
+ }
+
+ $swish_data .= $tmp if ($s && $tmp);
+ $swish_exact_data .= "xxbxx $tmp xxexx " if ($tmp && $tmp ne "" && $se);
+ }
+
+ # type="display" ; field for display
+ if ($d && $display) {
+ my $ldel = $delimiter;
+ if ($line_delimiter && $display_data) {
+ $ldel = $line_delimiter;
+ }
+ if ($filter) {
+ no strict 'refs';
+ my @arr;
+ foreach my $tmp (&$filter($display)) {
+ my $tmp2 = mkformat($x,$tmp);
+ push @arr,$tmp2 if ($tmp2);
+ }
+ $display_data .= $ldel if ($display_data && @arr);
+ $display_data .= join($delimiter,@arr);
+ } else {
+ $display_data .= $ldel if ($display_data);
+ my $tmp = mkformat($x,$display);
+ $display_data .= $tmp if ($tmp);
+ }
+ }
+
+ # type="index" ; insert into index
+ my $idisplay;
+ if ($i && $display) {
+ $idisplay = $display;
+ if ($filter) {
+ no strict 'refs';
+ $idisplay = &$filter($idisplay);
+ }
+ push @index_data, $idisplay if ($idisplay && !$iterate_by_page);
+ }
+
+ # store fields in lookup
+ if ($il && $display) {
+ if (lc($x->{type}) eq "lookup_key") {
+ if ($lookup_key) {
+ print STDERR "WARNING: try to redefine lookup_key (keys shouldn't be repeatable fields!)";
+ } else {
+ if ($filter) {
+ no strict 'refs';
+ $lookup_key = &$filter($display);
+ } else {
+ $lookup_key = $display;
+ }
+ }
+ } elsif (lc($x->{type}) eq "lookup_val") {
+ if ($lookup_key) {
+ if ($filter) {
+ no strict 'refs';
+ $lhash{$lookup_key} = &$filter($display);
+ } else {
+ $lhash{$lookup_key} = $display;
+ }
+ } else {
+ print STDERR "WARNING: no lookup_key defined for '$display'?";
+ }
+ }
+
+ }
+
+ # store data for page-by-page repeatable fields
+ if ($iterate_by_page) {
+ sub iterate_fld($$$$$$) {
+ my ($cache,$what,$field,$page,$data,$append) = @_;
+ return if (!$data);
+
+ my $ldel = $page_line_delimiter;
+ $ldel = " " if ($append);
+#print STDERR "line delimiter: ",Dumper($ldel) if ($ldel);
+ if (! $cache->{$what}->{$field}->[$page]) {
+ $cache->{$what}->{$field}->[$page] = $data;
+ } else {
+ $cache->{$what}->{$field}->[$page] .= $ldel.$data;
+ }
+ }
+
+ if ($display_data) {
+ iterate_fld($cache,'display_data',$field,$page,$display_data,$x->{append});
+ }
+ $display_data = "";
+ if ($swish_data) {
+ iterate_fld($cache,'swish_data',$field,$page,$swish_data,$x->{append});
+ $swish_data = "";
+ }
+ if ($swish_exact_data) {
+ iterate_fld($cache,'swish_exact_data',$field,$page,$swish_exact_data,$x->{append});
+ $swish_exact_data = "";
+ }
+
+ if ($idisplay) {
+ my $ldel=$page_line_delimiter;
+ my @index_data;
+ if ($cache->{index_data}->{$field}->[$page]) {
+
+ @index_data = @{$cache->{index_data}->{$field}->[$page]};
+ }
+ if ($x->{append}) {
+ if (@index_data) {
+ $index_data[$#index_data] .= $idisplay;
+ } else {
+ push @index_data, $idisplay;
+ }
+ } else {
+ push @index_data, $idisplay;
+ }
+ $idisplay = "";
+ @{$cache->{index_data}->{$field}->[$page]} = @index_data;
+ }
+ }