#!/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 ("\"[FILE]\"%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 ("\"[DIR]\"%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 "


"; print H "Compilation Copyright $YEAR by X2 Support Group"; print H "


"; print H "
"; print H "Index2html $Version by X2 Support Group (x2ftp\@x2ftp.oulu.fi.NO.SPAM)"; print H "
"; print H ""; printf H ("\n"); close H; chmod 0664, "$DIR/$HTMLINDEX"; printf STDERR "done\n"; exit $errs; # ----------------------------------------------------------------------------- # # Print headers # sub print_html_headers { print H ""; print H ""; print H "x2ftp.oulu.fi - ${DIR}\n"; print H "\n"; print H ""; print H ""; print H "

x2ftp.oulu.fi

"; print H "

X2 Support Group Game Development Archives
\n"; print H "Directory: /pub/msdos/programming/${DIR}

\n"; print H "
\n"; printf H ("What's new on X2FTP
\n", $RECENT); if ($MAINHTML && -f $MAINHTML && -s $MAINHTML) { print H 'Go back to /pub/msdos/programming Index'; } else { print H 'Go back to /pub/msdos/programming'; } print H "

";
print H "      Name\t   Last modified\tSize\t   Description";
print H "
"; } # sub print_html_headers # ----------------------------------------------------------------------------- # # Protect any HTML metacharacters. # sub html_encode { local ($value, $foo) = @_; $value =~ s/\&/\&/; $value =~ s/\/\>/; return $value; } # html_encode # ----------------------------------------------------------------------------- # # This part is only used on the CD-ROM Marker version. # # ---------------------------------------------------------------------------- # Read CDROM Database # sub Read_CDMarkers { $ReadCDList = 1; $TimeCheck = 0; $PrintNoMain = 1; $PrintTime = 0; $TimeLimit = 4*3600; # Allow delay (in seconds) $CheckRecent = 0; # Check recent files. $CheckLimit = 5*7; # Find recent files for N days. # Check we have valid Icon File. if (! -r "$DIR/$CDFileIcon") { # Test reference to the icon. $CDMarkers = 0; printf STDERR "*** Icon file '$DIR/$CDFileIcon' not found!\n"; } else { # Set CDROM Search Path if ($DIR =~ /^\//) { # Absolute path $cdpath = $DIR; } elsif ($DIR eq ".") { # Current work dir $cdpath = `/bin/cwd`; } else { # Relative path $cdpath = `/bin/cwd` . "/$DIR"; } if ($cdpath =~ /msdos\/(\S+)/) { # Check for default prefix... $cdpath = $1; # and cut off excess path. } $cdpath =~ s/\//\/\*/g; $FIND_CDROM = "$FIND $CDROMDIR/\*$cdpath -type f -name ON_\* -print"; scan_cdrom(); } } # read_cdmarkers # ----------------------------------------------------------------------------- # Scan the CDROM Database # # ----------------------------------------------------------------------------- # Get the directory descriptions for ON_dir and OFF_dir ... sub scan_cdrom { open (foo, "$FIND_CDROM |") || die "Can't excute '$FIND_CDROM'"; printf "\nScanning the CDROM Database for '$DIR'.\n"; printf "$FIND_CDROM\n"; printf "\n"; cdline: while () { print $_; chop; if (/^\s*$/) { next cdline; } # Empty line # Takes the last slash by default. if (/(\S+)\/(\S+)/) { # File in any CD dir $dir = $1; $file = $2; $main = $2; # $main = $dir . "/" . $file; $main =~ s/ON_//os; # Set flags for FTP file # Both the parent dir dir and the file must default to 0. if ($FileStatus{$dir} || $FileStatus{$main}) { printf "*** Conflicting CDROM values for $_.\n"; } if (/ON_/) { $FileStatus{$main} = $CD_YES; } elsif (/OFF_/) { $FileStatus{$main} = $CD_NO; } elsif (/ASKED_/) { printf "ASKED for: $_.\n"; $FileStatus{$main} = $CD_ASKED; } else { # Non-prefixed CD file printf "*** Invalid CDROM entry $_.\n"; $FileStatus{$main} = $CD_NONE; ++$CdFilesBad; } } # cdline } # while } # scan_cdrom