#!/usr/bin/perl -w
# vim: set sw=4 ts=4 si et ic ruler nowrapscan nowrap:
# Copyright: Guido Socher
#
use strict;
use vars qw($opt_o $opt_h);
use Getopt::Std;
sub help();
#
getopts("ho:")||die "ERROR: No such option. -h for help\n";
help() if ($opt_h);
my $imgdir = "../../common/images";
my $lang="en";
my %intdat=(
 'en'=>{'chset'=>"iso-8859-1",'abstract'=>'Abstract'},
 );
my $icon="$imgdir/dir_list_file.gif";
my $alt;
my $ver="1.0";
my $dir=".";
my $type;
my @files;
my $outfile ="index.shtml";
#
delete $ENV{'IFS'};
delete $ENV{'CDPATH'};
delete $ENV{'ENV'};
delete $ENV{'BASH_ENV'};
$ENV{'PATH'}="/bin:/usr/bin";
#
$outfile ="$opt_o" if ($opt_o);
if ($ARGV[0]){
    $dir=$ARGV[0]; 
    $dir=~s/\/$//;
    $outfile="$dir/$outfile";
}
#
opendir(DIR,"$dir")||die "ERROR: can not read $dir\n";
@files=readdir(DIR);
closedir DIR;
my $issuename;
if ($dir eq "."){
    $issuename=`pwd`;
}else{
    $issuename=$dir;
}
$issuename=~s/^.*\///;
#
open (OUT,">$outfile")||die "ERROR: can not write to $outfile\n";
#
print OUT "<HTML><HEAD><TITLE>LinuxFocus $issuename</TITLE></HEAD>\n";
print OUT "<!-- generated by webls_issue version $ver -->\n";
print OUT "<!-- webls_issue is part of the lfparser package avilable from: http://main.linuxfocus.org/~guido/dev/ -->\n";
print OUT "<body>\n";
print OUT "<H1>LinuxFocus $issuename</H1>\n";

print OUT "<TABLE BORDER=1 summary=\"index $issuename\">\n";
foreach (reverse sort @files){
    next if (/index/o);
    next if ($_ eq ".");
    next if ($_ eq "..");
    next if ($_ eq "RCS");
	if (-f "$dir/$_"){
        next unless(/article\d+\.s?html/);
        $icon="$imgdir/dir_list_file.gif";
		$type = "file";
		$alt = "\"file\"";
		$type = "html file" if (/html$/);
        if (/article\d+\.s?html/){
            $alt = "\"article $_\"";
            $type = "Linuxfocus article:<br>"; 
            my $tmp=`grep \"=LF=TITLE_\" \"$dir/$_\"`;
            $tmp=~s/=LF=TITLE_://;
            $tmp=~s/\s+/ /g;
            $type .="<a href=\"$_\"><b>$tmp</b></a>";
            $icon="$imgdir/dir_list_tux.gif";
        }
	}
	print OUT "<tr><td><A HREF=\"$_\"><IMG BORDER=\"0\" ALT=$alt SRC=\"$icon\"> $_</A></td><td> $type</td></tr>\n";
}
$icon="$imgdir/dir_list_lftux.jpg";
$alt="\"LF home\"";
print OUT "<tr><td><A HREF=\"../../\"><IMG BORDER=\"0\" ALT=$alt SRC=\"$icon\"> &lt;-- LF Home</A></td><td> <a href=\"../../\">Go to the front page of LinuxFocus</a></td></tr>\n";
print OUT "</TABLE></body></HTML>\n";
close OUT;
#
#-------------
#
sub help(){
print "webls -- genrate an article index file for the files
in of a linuxfocus issue
USAGE: webls [-h] [-o index.html] [directory]

The output is written by default to index.shtml but may be overwritten
with option -o.

This program shall be used form October 2004 onwards to generate
an index for available articles in a given month. There will be
no more editorial everything goes to the front page therefore
a new index.shtml file is needed for the directory where
the articles are stored.

did already exist.

OPTIONS: -h this help
         -o write to a different html file (not index.shtml)
\n";
exit 0;
}
__END__ 

