--- trunk2/all2all.pl 2004/09/11 20:21:28 423
+++ trunk2/all2all.pl 2004/09/11 22:32:06 424
@@ -56,6 +56,8 @@
$webpac->open_import_xml(type => 'isis_hidra_ths');
+if(0) { # XXX
+
while (my $rec = $webpac->fetch_rec) {
my @ds = $webpac->data_structure($rec);
@@ -146,6 +148,8 @@
}
}
+} # XXX if(0)
+
$log->info("lookup hash: ",Dumper($webpac->{'lookup'}));
#
@@ -166,58 +170,90 @@
};
-foreach my $code (sort keys %{$webpac->{'lookup'}}) {
-
- my $l = $webpac->{'lookup'} || $log->logconfess("can't find lookup");
-
- if ($code =~ m/^root:/) {
- my $v900 = shift @{ $l->{$code} } || $log->logconfess("can't lookup '$code'");
- $code =~ s/^root:// || die;
-
- my $term = shift @{ $l->{"d:${v900}"} } || die;
- my $mfn = shift @{ $l->{"900_mfn:${v900}"} } || die;
-
- $log->debug("$code -> $v900 : $term [$mfn]");
-
- print HTML qq{ - $term »
\n} if (-e "out/thes/$mfn.html");
-
- unless ($l->{"a:${code}::"}) {
- $log->warn("can't find 'a:${code}::'");
- next;
- }
+my $l = $webpac->{'lookup'} || $log->logconfess("can't find lookup");
- print HTML qq{ \n};
+my @tree = ({
+ # level 0
+ code_arr => sub { sort keys %{$l} },
+ filter_code => sub {
+ my $t = shift;
+ return $t if ($t =~ s/root://);
+ },
+ lookup_v900 => sub { shift @{$l->{"root:".$_[0]}} },
+ lookup_term => sub { shift @{$l->{"d:".$_[1]}} },
+ lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[1]}} },
+ have_children => sub { $l->{"a:".$_[0]."::" } },
+ child_code => sub { return $_[0] },
+ style => 'display: none',
+ },{
+ # 1
+ code_arr => sub { @{$l->{"a:".$_[0]."::"}} },
+ filter_code => sub { shift }, # nop
+ lookup_v900 => sub { shift @{$l->{"code:".$_[0]}} },
+ lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
+ lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
+ have_children => sub { $l->{"a:".$_[1].":" } },
+ child_code => sub { return $_[1] },
+ style => 'display: none',
+ },{
+ # 2
+ code_arr => sub { @{$l->{"a:".$_[0].":"}} },
+ filter_code => sub { shift },
+ lookup_v900 => sub { shift },
+ lookup_term => sub { shift @{$l->{"d:".$_[0]}} },
+ lookup_mfn => sub { shift @{$l->{"900_mfn:".$_[0]}} },
+ have_children => sub { 0 },
+ child_code => sub { 0 },
+
+});
+
+unroll(0,'');
+
+$log->debug("test filter: ",$tree[0]->{'filter_code'}->("root:99"));
+
+sub unroll {
+ my ($level,$start_code) = @_;
+
+ $log->logconfess("need level") unless (defined($level));
+
+ # all levels passed?
+ return if (! defined($tree[$level]));
+
+ $log->debug("unroll level $level, start code $start_code");
+
+ foreach my $code ($tree[$level]->{'code_arr'}->($start_code)) {
+
+ if ($code = $tree[$level]->{'filter_code'}->($code)) {
+
+ $log->debug("# $level filter passed code $code");
+
+ my $v900 = $tree[$level]->{'lookup_v900'}->($code) || $log->logdie("can't lookup_v900 '$code'");
+ $log->debug("# $level lookup_v900($code) = $v900");
+ my $term = $tree[$level]->{'lookup_term'}->($code,$v900) || $log->logdie("can't lookup_term '$v900'");
+ $log->debug("# $level lookup_term($code,$v900) = $term");
+ my $mfn = $tree[$level]->{'lookup_mfn'}->($code,$v900) || $log->logdie("can't lookup_mfn '$v900'");
+ $log->debug("# $level lookup_mfn($code,$v900) = $mfn");
- foreach my $l2_v900 (@{ $l->{"a:${code}::"} }) {
-
- my $l2_code = shift @{ $l->{"code:${l2_v900}"} } || die;
- my $l2_term = shift @{ $l->{"d:$l2_v900"} } || die;
- my $l2_mfn = shift @{ $l->{"900_mfn:${l2_v900}"} } || die;
+ $log->debug("$code -> $v900 : $term [$mfn]");
- $log->debug("$l2_code -> $l2_v900 : $l2_term [$l2_mfn]");
+ print HTML " " x $level .
+ qq{- $term »
\n} if (-e "out/thes/$mfn.html");
- print HTML qq{ - $l2_term »
\n} if (-e "out/thes/$l2_mfn.html");
-
- unless ($l->{"a:${l2_code}:"}) {
- $log->warn("can't find 'a:${l2_code}:'");
+ unless ($tree[$level]->{'have_children'}->($code,$v900)) {
+ $log->warn("can't find children of $code at level $level");
next;
}
+
+ print HTML " " x $level .
+ qq{\n {'style'} ? ' style="'.$tree[$level]->{'style'}.'"' : '').
+ qq{>\n};
- print HTML qq{ \n};
-
- foreach my $l3_v900 (@{ $l->{"a:${l2_code}:"} }) {
-
- my $l3_term = shift @{ $l->{"d:$l3_v900"} } || die;
- my $l3_mfn = shift @{ $l->{"900_mfn:${l3_v900}"} } || die;
-
- $log->debug(" -> $l3_v900 : $l3_term [$l3_mfn]");
-
- print HTML qq{ - $l3_term »
\n} if (-e "out/thes/$l3_mfn.html");
- }
+ unroll($level+1, $tree[$level]->{'child_code'}->($code,$v900));
+
+ print HTML " " x $level . qq{
\n};
- print HTML qq{
\n};
}
- print HTML qq{
\n};
}
}