#!/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.3 PL 00 (21 Mar 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. # # $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 = 1; $CDFileIcon = "../x2www/cdfile32.gif"; # ----------------------------------------------------------------------------- # Defaults $YEAR = `/bin/date +%Y`; # Copyright year (in 4 digits) $RECENT = "00recent.txt"; # Recent index file $TXTINDEX = "00inde.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 (/^-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) { $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(); } } # 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 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 ("\"[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); } 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); } else { print H "$_\n"; printf STDERR "BAD LINE >>$_<<\n"; ++$errs; } } # 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); 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 # ----------------------------------------------------------------------------- # # 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