#! /usr/bin/perl -w
# Creates an html table listing all the packages
# present in the directories listed on the command line.
# Each directory must contain a 'desc.txt' file.
# with fields defined line-per-line.
#
# Author: christophe.pallier@m4x.org
# Date: 3 Nov. 2002
#
#
# Usage: buildindex [-s field_name] dir1 dir2 dir3 ... >index.html
use strict;
use Getopt::Std;
use English;
$RS=""; # input records are separated by empty lines
my (@fields)=qw/name date type desc files links status/;
my ($sortfield)="date";
my (%HoH);
my ($rec,$f,$role,$i);
my (%opts);
getopts("s:",\%opts);
if ($opts{'s'}) {
$sortfield=$opts{'s'};
if (!grep(/$sortfield/,@fields)) {
die("field '$sortfield' unknown");
}
}
print "
Christophe Pallier's files
\n";
print "\n";
print "\n";
foreach $f (@fields) {
print "| $f | \n";
}
print "
\n";
foreach $f (@ARGV)
{
$rec=parse($f . "/desc.txt");
for (@fields) {
if (!defined($rec->{$_})) {
print STDERR " Warning: field '$_' missing\n";
}
}
$HoH{$rec->{$sortfield}. "_" . $rec->{date} . "_" . $rec->{name}}=$rec;
}
foreach (reverse sort keys %HoH) {
print "\n";
for $role (@fields) {
print "| $HoH{$_}{$role} | \n";
}
print "
\n";
}
print "\n
\n";
sub parse ()
# reads the fields from the description file
{
my $fname = shift;
my $rec={};
my ($key,$value);
open(HAN,"<".$fname) || die "Can't open '$fname'";
print STDERR "Processing '$fname' \n";
while () {
chop;
($key,$value) = split(" ", $_ , 2);
if (defined($key)) {
if (grep(/$key/,@fields)) {
$rec->{$key} = $value;
}
else {
print STDERR " Warning: field '$key' unknown\n";
}
}
}
close(HAN);
return $rec;
}