%# -*-perl-*- $Id: bthread.html,v 1.1 2000/11/12 01:30:03 xi Exp $
<%doc>
###############################################################################
# Usenet Indexer - A nice and fast usenet indexer
# Copyright (C) 2000 Christian Laursen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
###############################################################################
%doc>
%show_hier(0,$top);
<%args>
$id => ''
%args>
<%init>
&deja_init;
if ($id !~ /^\d+$/) {
$m->out("You bastard!");
$m->abort(200);
}
# Find the top article
my $top = $id;
while (my $parent = parent($top)) {
$top = $parent;
}
%init>
<%once>
sub show_hier {
my $level = shift;
foreach my $id (@_) {
my ($from, $subject) = get_headers($id);
$m->out("Id: $id\n");
$m->out("From: $from\n");
$m->out("Subject: $subject\n");
$m->out("Level: $level\n");
my @children = children($id);
show_hier($level + 1, @children) if (@children > 0);
}
}
sub get_headers ($) {
my ($id) = @_;
my ($from,$subject);
local *FILE;
my $file = sprintf("../data/article/%08x.headers", $id);
open (FILE, "<$file") or die "Couldn't read file: $!";
while () {
if (m/^From: (.*)$/) {
$from = $1;
} elsif (m/^Subject: (.*)$/) {
$subject = $1;
}
}
close FILE;
return ($from, $subject);
}
sub parent ($) {
my ($id) = @_;
my $res = undef;
local *FILE;
my $file = sprintf("../data/article/%08x.headers", $id);
open (FILE, "<$file") or die "Couldn't read file: $!";
while () {
if (m/^Parent: (\d+)$/) {
$res = $1;
}
}
close FILE;
return $res;
}
sub children ($) {
my ($id) = @_;
local *FILE;
my @res = ();
my $buffer;
my $file = sprintf("../data/article/%08x.children", $id);
if (open (FILE, "<$file")) {
while (read(FILE, $buffer, 4)) {
push @res, unpack("I", $buffer);
}
close FILE;
}
return @res;
}
%once>