#!/usr/local/bin/perl # # Index2html -- Generate new 00index.html files. # # For safety and system reliability, index.pl and longindex.pl are kept # in 2 separate files, disrecarding their similarity. # $Version= "1.2 PL 01 (28 Nov 1997)"; # # Written by # Tommi Saarinen (tsa@x2ftp.oulu.fi) # Jouko Valta (jopi@x2ftp.oulu.fi) # # Revision History # V1.1 pl 01 -- 11 Apr 1997 # Updated "Copyright 1997". # # V1.2 pl 00 -- 15 Aug 1997 # Newlines and NO.SPAM added. # Alternate TXT index file names. # Test if target is File, Dir or even non-existent. # Option to write alternate file. (For DJGPP). # # V1.2 pl 01 -- 28 Nov 1997 # Protect any HTML metacharacters in the description. # # $Usage = "\ Options:\ -h show help page and exit\ -f file specify input file\ -w file write html index 'file'\n\n"; # ----------------------------------------------------------------------------- # Defaults $YEAR = `/bin/date +%Y`; # Copyright year (in 4 digits) $RECENT = "00recent"; # Recent index file $TXTINDEX = "00index.txt"; $HTMLINDEX= "00index.html"; # HTML Generation Date $date = `/bin/date`; chop $date; @mons = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); $errs = 0; ### process any FOO=bar switches eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift; ### Command line options while ($_ = $ARGV[0], /^-/) { shift; last if /^--$/; if (/^-h/) { print $Usage; exit 2; } if (/^-CD/) { print STDERR "-CD ignored\n"; shift; next; } if (/^-cd/) { print STDERR "-cd ignored\n"; next; } if (/^-nc/) { print STDERR "-nc ignored\n"; next; } if (/^-f/) { $TXTINDEX = $ARGV[0]; shift; next; } if (/^-w/) { $HTMLINDEX = $ARGV[0]; shift; next; } if (/^-/) { die "\nUnsupported argument near $_\n Stopped"; } } # Directory for which a HTML-index should be generated $DIR = $ARGV[0]; $DIR || die "No directory specified. Stopped"; # Try all ascii index file names open (I, "$DIR/$TXTINDEX") || open (I, "$DIR/00_index.txt") || open (I, "$DIR/00index") || open (I, "$DIR/00INDEX") || die "Cannot read index file for '$DIR/$TXTINDEX'"; open(H, ">$DIR/$HTMLINDEX") || die "Cannot open '$DIR/$HTMLINDEX'"; #select(H); # rm -f ${DIR}/${HTMLINDEX}; printf STDERR "Processing: $DIR/$TXTINDEX ..."; # Print headers print_html_headers(); # Directory Listing line: while () { chop; if (/^\s*$/) { # Empty line print H "\n"; next; } if (/\s*(\S+)\s+(.+)/) { $file = $1; # Protect any HTML metacharacters in the description. $short = html_encode($2); ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat("$DIR/$file"); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($mtime); # $datestring=$mday.'-'.$mons[$mon].'-'.$year.' '.$hour.':'.$min; if ($size < 1024) { $size_string="bytes"; } elsif($size/1024 < 1024) { $size=$size/1024; $size_string="kB "; } else { $size=$size/(1024*1024); $size_string="MB "; } if (length($file) < 8) { $s = "\t"; } else { $s = ""; } if ( -f _) { printf H ("%s%s\t%02d-%s-%d %02d:%02d %5.1f %s\t%s\n", $file, $file, $s, $mday, $mons[$mon], $year, $hour, $min, $size, $size_string, $short); } elsif ( -d _) { printf H ("%s%s\t%02d-%s-%d %02d:%02d %5.1f %s\t%s\n", $file, $file, $s, $mday, $mons[$mon], $year, $hour, $min, $size, $size_string, $short); } else { print H "$_\n"; printf STDERR "BAD LINE >>$_<<\n"; ++$errs; } } # line } # while # Print footers print H ""; print H "