#!/usr/local/bin/perl # # Index2html -- Generate new 00index.html files. # # This program also creates the djgpp/00allindex.html file. # For safety and system reliability, index.pl and longindex.pl are kept # in 2 separate files, disrecarding their similarity. # $Version= "V1.4 PL 01 (17 Jun 1998)"; # # 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. # # V1.3 pl 00 -- 21 Mar 1998 # Add 'Included on CDROM' markers via an option. # CD-ROM database checking taken from CdTest V1.1 pl 00. # # V1.4 pl 00 -- 12 Jun 1998 # Distinquish icons between Text, Binary, and unknown files. # Icons can be selected according to the file type, with default value # from binary test based on the actual data contained on the file. # Relative subdirectories (mainly for djgpp directory). # # V1.4 pl 01 -- 17 Jun 1998 # Combined main version with the separate parallel CD-ROM patch. # # # $Usage = "\ Options:\ -h Show help page and exit\ -CD Specify alternate path for CDROM database\ -cd Add 'included on cdrom' markers\ -nc Suppress cdrom markers\ -f file Specify input file\ -w file Write html index 'file'\n\n"; # ----------------------------------------------------------------------------- ## Declare CDROM Constants $CD_NONE = 0; $CD_YES = 1; $CD_FREE = 2; $CD_NONPROFIT = 3; $CD_GPL = 4; $CD_DEMO = 5; # Demo version, not for CD $CD_PERM = 6; # Prior permission required $CD_NO = 7; $CD_CONFL = 8; # Claimed yes, but contents seem suspicious $CD_ASKED = 16; @CDPrefix = ( "", "ON_", "ON_", "ON_", "", "OFF_", "OFF_", "OFF_", "OFF_", "", "", "", "", "", "", "", "ASKED_" ); @CDString = ( "N/A", "Yes", "Yes", "Yes", "N/A", "No", "No", "No", "No", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A" ); $FIND = "/bin/find"; $SORT = "/bin/sort"; $CDROMDIR = "/ftp-service/cdrom/pub/msdos"; # The X2 CDROM Database $CDMarkers = 0; $CDFileIcon = "../x2www/cdfile32.gif"; # ----------------------------------------------------------------------------- # Defaults $YEAR = `/bin/date +%Y`; # Copyright year (in 4 digits) $RECENT = "00recent.txt"; # Recent index file $MAINHTML = "../00index.html"; # The programming/ main index. $TXTINDEX = "00index.txt"; $HTMLINDEX= "00index.html"; # HTML Index File Generation Date $date = `/bin/date`; chop $date; @mons = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); ### 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 (1) { 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; } } else { if (/^-CD/) { if ($ARGV[0]) { ++$CDMarkers; $CDROMDIR = $ARGV[0]; shift; } next; } if (/^-cd/) { ++$CDMarkers; next; } if (/^-nc/) { $CDMarkers = 0; 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"; # ---------------------------------------------------------------------------- # Read CDROM Database # if ($CDMarkers) { Read_CDMarkers(); } # cdmarkers # ---------------------------------------------------------------------------- $errs = 0; # 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 $LastDir = ""; # All files listed are on the CWD by default. 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); if ($LastDir && ! -e"$DIR/$file") { if ( -e "$DIR/$LastDir/$file") { $file = "$LastDir/$file"; } } ($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 "; } # Align filename if (length($file) < 8) { $s = "\t"; } else { $s = ""; } # # Select icon type and print one directory entry. # if ( -f _) { $LinkType="internal-gopher-unknown"; # \s matches whitespace or newline if ($file =~ /(\S+)\.([0-9A-Za-z\+\-\_\~\^\$\*\%\!\|]+)\s*$/) { $MainName = $1; (($MainType = $2)) || die "Filename extraction failed for '$file'"; ## Binary file: zip, lzh, lha, arj, arc, exe, com, ... # # An option may be used to flag these all as "binary" or # to distinquish between these types even further: # archive, audio, image, executable, ... # if ($MainType =~ /^arc|^arj|^lha|^lzh|^zip|^zoo|^rar|^exe|^com|^hlp|^rtf|^pif|^dll|^cur|^fnt|^pal|^sys/i || $MainType =~ /^\S\S_|^dsm|^s3m|^voc|^wav|^dat|^3ds|^bbm|^bmp|^lbm|^map|^gif|^jpg|^pcx|^pic|^ppm|^raw|^tga/i) { $LinkType="internal-gopher-binary"; } ## Text file: txt, doc, inf, ini, diz, c, h, pas, ... # # Note: *.doc is assumed text unless further separation is performed. # if ($MainType =~ /^txt|^e?ps|^faq|^man|^htm|^swg/i || $MainType =~ /^diz|^nfo|^log|^lsm|^www|^bbs/i || $MainType =~ /^asm|^bas|^cc*$|^cpp|^hh*$|^hpp|^hxx|^inc|^mak|^prj|^pas|^tpu|^s$/i || $MainName =~ /^\!*read$|readme|read1st|descript|howto/i || $MainType =~ /^me|^now|^1st/i) { $LinkType="internal-gopher-text"; } # Unspecified files and the .doc format. else { if ( -T _) { $LinkType="internal-gopher-text"; } elsif ( -B _) { $LinkType="internal-gopher-binary"; } } } # file name # Extensionless files else { if ( -T _) { $LinkType="internal-gopher-text"; } elsif ( -B _) { $LinkType="internal-gopher-binary"; } } ## Default is Unknown filetype 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); } # file 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); $LastDir = $file; } # directory else { print H "$_\n"; printf STDERR "BAD LINE >>$_<<\n"; ++$errs; } # any dir entry } # line } # while # Print footers print H ""; print H "