--- trunk/all2xml.pl 2004/03/09 12:17:05 255 +++ trunk/all2xml.pl 2004/03/14 11:50:29 274 @@ -150,6 +150,25 @@ } } + sub init_visible_type($) { + my $type = shift; + + # swish, swish_exact, display, index, index_lookup + # swish and display defaults + my ($s,$se,$d,$i,$il) = (1,0,1,0,0); + if (lc($type) eq "display") { + $s = 0; + } elsif (lc($type) eq "swish") { + $d = 0; + } elsif (lc($type) eq "index") { + ($s,$se,$d,$i) = (0,1,0,1); + } elsif (lc($type) eq "swish_exact") { + ($s,$se,$d,$i) = (0,1,0,0); + } elsif (lc($type) =~ /^lookup/) { + ($s,$se,$d,$i,$il) = (0,1,0,0,1); + } + return ($s,$se,$d,$i,$il); + } # begin real work: go field by field foreach my $field (@sorted_tags) { @@ -189,14 +208,7 @@ my $repeat_off = 0; # init repeatable offset - # swish, swish_exact, display, index, index_lookup - # 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/); + my ($s,$se,$d,$i,$il) = init_visible_type($x->{type}); # what will separate last line from this one? if ($display_data && $x->{append}) { @@ -210,24 +222,10 @@ # placeholder for all repeatable entries for index - sub chk_eval($) { - my $data = shift; - return if (! defined($data)); - if ($data && $data =~ s/\s*eval{([^}]+)}\s*//) { - if (eval "$1") { - return $data; - } else { - return undef; - } - } else { - return $data; - } - } - sub mkformat($$) { my $x = shift || die "mkformat needs tag reference"; my $data = shift || return; - my $format_name = x($x->{format_name}) || return chk_eval($data); + my $format_name = x($x->{format_name}) || return $data; my $fmt = x($config->{format}->{$format_name}->{content}) || die " is not defined!"; my $format_delimiter = x($x->{format_delimiter}); my @data; @@ -240,10 +238,10 @@ if ($fmt) { my $nr = scalar $fmt =~ s/%s/%s/g; if (($#data+1) == $nr) { - return chk_eval(sprintf($fmt,@data)); + return sprintf($fmt,@data); } else { #print STDERR "mkformat: [$data] can't be split on [$format_delimiter] to $nr fields!\n"; - return chk_eval($data); + return $data; } } else { print STDERR "usage of link '$format_name' without defined format ( tag)\n"; @@ -292,20 +290,14 @@ } # type="swish" ; field for swish if ($swish) { + my $tmp = $swish; if ($filter && ($s || $se)) { no strict 'refs'; - my $tmp = join(" ",&$filter($swish)) 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 ""); + $tmp = join(" ",&$filter($tmp)) if ($s || $se); } - $tmp = chk_eval($tmp); $swish_data .= $tmp if ($s && $tmp); - $swish_exact_data .= "xxbxx $tmp xxexx " if ($se && $tmp ne ""); + $swish_exact_data .= "xxbxx $tmp xxexx " if ($tmp && $tmp ne "" && $se); } # type="display" ; field for display @@ -338,7 +330,6 @@ no strict 'refs'; $idisplay = &$filter($idisplay); } - $idisplay = chk_eval($idisplay); push @index_data, $idisplay if ($idisplay && !$iterate_by_page); } @@ -441,16 +432,12 @@ my $delimiter = x($x->{delimiter}) || ' '; my $val = $cfg->val($database, x($x->{content})); - my ($s,$d,$i) = (1,1,0); # swish, display default - $s = 0 if (lc($x->{type}) eq "display"); - $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"); + # FIXME index_lookup is not supported! + my ($s,$se,$d,$i,$il) = init_visible_type($x->{type}); if ($val) { $display_data .= $delimiter.$val if ($d); - $swish_data .= $val if ($s); + $swish_data .= " ".$val if ($s); $index->insert($field, $val, $path) if ($i); }