#!/usr/bin/perl
# install in cgi-bin/picknewsgroups
# tchrist@mox.perl.com
# v1.0; Fri Apr 21 10:34:19 MDT 1995
require 5.0;
##############################################
# BEGIN CONFIG SECTION
##############################################
$EGREP = 'egrep'; # prefer to use gnu egrep for speed
$SORT = 'sort -t. -u +0 -1 '; # maybe +1 -2 if you live in a sad world
# run from cron now and then : nntplist newsgroups > $NGFILE
#$NGFILE = '/usr/local/lib/news/newsgroups';
$NGFILE = '/tmp/newsgroups';
# I'd rather you chose yourself. :-(
### $HOST = 'mox.perl.com';
$HOST = 'sirius';
### ($HOST) = gethostbyname(chop($host=`hostname`), $host);
### chop($HOST=`hostname`);
##############################################
# END CONFIG SECTION
##############################################
if ($HOST) { $HOST = "//$HOST"; }
%Groups = ();
die "No $NGFILE: $!" unless -f $NGFILE && -r _;
if ($ENV{HTTP_USER_AGENT} =~ m#Mozilla/1.1#) {
$file_icon = "";
$dir_icon = "
";
}
if (@ARGV) {
$Target = shift;
} else {
get_request();
if (!($Target = $rqpairs{'newsgroup'})) {
($Target) = each %rqpairs; # top level
}
}
die "Cannot fork: $!" unless defined ($pid = open(INPUT, "-|"));
unless ($pid) {
if ($Target) {
exec $EGREP, "^\Q$Target", $NGFILE;
} else {
exec "$SORT $NGFILE 2>/dev/null";
}
die "exec failed: $!";
}
###############################
# Here's the kinda data structure we're going to be building ...
###############################
#
# %Groups = (
# alt => {
# DESC => "useless drivel",
# NEXT => {
# activism => {
# DESC => "Activities for activists",
# NEXT => {
# d => {
# DESC => "A place to discuss issues in alt.activism",
# },
# "death-penalty" => {
# DESC => "For people opposed to capital punishment",
# },
# },
# },
# adoption => {
# DESC => "For those involved with or contemplating adoption",
# }
# },
# },
# comp => {
# DESC => "computer stuff",
# NEXT => {
# lang => {
# DESC => "programming languages",
# NEXT => {
# C => "it's better than a boot to the head",
# perl => "welcome to Larry's World",
# python => "here be snakes, but not poisonous ones",
# tcl => "but for tk, none would bother",
# scheme => "job security tips in the ivory tower",
# }
# }
# }
# }
# );
while () {
chomp;
# now for the darned tabs in the newsgroups file
1 while s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
($ng, $desc) = unpack("A24 A*", $_);
if (length($ng) == 24) {
$desc =~ s/^(\S+)\s*//;
$ng .= $1;
}
@parts = split /\./, $ng;
$last = pop @parts;
$gp = \%Groups;
for $hier (@parts) {
if (!ref $gp->{$hier}{NEXT}) {
$gp->{$hier}{NEXT} = {};
}
$gp = $gp->{$hier}{NEXT};
}
$gp->{$last}{DESC} = $desc;
}
close(INPUT) || warn "Trouble processing input";
if (!$Target) { read_top_level_descs(); }
#hierprint(\%Groups);
$gp = \%Groups;
# this copies the DESC down a level into a blank key for groups
# like comp.lang.c that have their own raison d'etre
# apart from holding comp.lang.c.moderated, etc.
if ($Target) {
$what = "Newsgroups under $Target";
for $hier (split(/\./, $Target)) {
if ( $gp->{$hier}{DESC} ) {
$gp->{$hier}{NEXT}{""}{DESC} = $gp->{$hier}{DESC};
}
$gp = $gp->{$hier}{NEXT};
}
promote($gp);
} else {
$what = "Top Level News Hierarchies";
}
html_header($what);
if ($Target) {
print "