#!/usr/local/bin/perl # # LongIndex -- Generate new 00longindex.{txt,html} files. # # For safety and system reliability, index.pl and longindex.pl are kept # in 2 separate files, disrecarding their similarity. # $ProgVersion= "1.0 PL 00 (26 Nov 1997)"; # # Written by # Tommi Saarinen (tsa@x2ftp.oulu.fi) # Jouko Valta (jopi@x2ftp.oulu.fi) # # Revision History # V0.9 pl 00 -- 18 Aug 1997 # Patched from index.pl script. # # V1.0 pl 00 -- 26 Nov 1997 # Initial revision finished. # # $Usage = "\ Options:\ -h Show help page and exit\ -f file Read text index 'file'\ -i file Read textfiles cross-index 'file'\ -wh file Write HTML index to 'file'\ -wt file Write TXT index to 'file'\n\n"; # ----------------------------------------------------------------------------- # 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"; $LONG_TXT = "00longindex.txt"; $LONG_HTML= "00longindex.html"; $LOGHOME = "/pc/log"; if (! -d $LOGHOME || ! -w $LOGHOME) { printf STDERR "Cannot access $LOGHOME. Please, check the setting or run\n create_dosadm_logs script.\n"; $LOGHOME = "/var/tmp"; } $INDEXDIR = $LOGHOME . "/programming"; # Re-formatted TXT files. $TEXTDIR = "/src/txt"; $FTPDIR = "/ftp-service/ftp/pub/msdos"; $CDROMDIR = "/ftp-service/cdrom/pub/msdos/programming"; $CROSSINDEX = $TEXTDIR . "/00index.txt"; # Index Files Generation Date $date = `/bin/date`; chop $date; @mons = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); $errs = 0; # Number of bad mainfiles. $n_files= 0; # Number of mainfiles found. $n_ok = 0; # Number of index files found. $n_fail = 0; # Number of index files missing. $opt = 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 (/^-f/) { $TXTINDEX = $ARGV[0]; shift; next; } if (/^-i/) { $CROSSINDEX= $ARGV[0]; shift; next; } if (/^-wh/) { $LONG_HTML = $ARGV[0]; $opt |= 1; shift; next; } if (/^-wt/) { $LONG_TXT = $ARGV[0]; $opt |= 2; shift; next; } if (/^-/) { die "\nUnsupported argument near $_\n Stopped"; } } if ($opt && $opt != 3) { die "Error: Both '-wh' and '-wt' options are required. Stopped"; } # ----------------------------------------------------------------------------- # Read textfiles cross-index file. # open (CI, "$CROSSINDEX") || printf STDERR "Cannot read index file '$CROSSINDEX'"; file: while () { chop; if (/^\s*$|^%/) { next file; } # Empty line or comment # category main txt longtext if (/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*/) { $RealCategory{$2} = $1; $TextName{$2} = $3; $IndexName{$2} = $4; next file; } print "Incorrect line '$_'\n"; } # while close(CI); # ----------------------------------------------------------------------------- # 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 (T, ">$DIR/$LONG_TXT") || die "Cannot open '$DIR/$LONG_TXT'"; open (H, ">$DIR/$LONG_HTML") || die "Cannot open '$DIR/$LONG_HTML'"; # rm -f ${DIR}/${LONG_HTML}; printf STDERR "Processing: $DIR/$TXTINDEX ..."; # Print headers print_text_headers(); print_html_headers(); # Directory Listing line: while () { chop; if (/^\s*$/) { # Empty line next; } if (/\s*(\S+)\s+(.+)/) { ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat("$DIR/$1"); ($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($1) < 8) { $s = "\t"; } else { $s = ""; } if ( -f _) { printf T ("\n%s%s\t%02d-%s-%d %02d:%02d Size %5.1f %s\n", $1, $s, $mday, $mons[$mon], $year, $hour, $min, $size, $size_string); printf H ("

\"[FILE]\" %s%s\t%02d-%s-%d %02d:%02d Size %5.1f %s\n", $1, $1, $1, $s, $mday, $mons[$mon], $year, $hour, $min, $size, $size_string); ++$n_files; # Count files in directory. copy_long_description ($1, $2); } elsif ( -d _) { printf T ("\n%s%s\t%02d-%s-%d %02d:%02d Size %5.1f %s\n", $1, $s, $mday, $mons[$mon], $year, $hour, $min, $size, $size_string); printf H ("

\"[DIR]\" %s%s\t%02d-%s-%d %02d:%02d Size %5.1f %s\t%s\n", $1, $1, $1, $s, $mday, $mons[$mon], $year, $hour, $min, $size, $size_string, $2); } else { print T "$_\n"; print H "$_\n"; printf STDERR "BAD LINE >>$_<<\n"; ++$errs; } } # line } # while # Print footers print T "\n------------------------------------------------------------------------------\n"; print T "Compilation Copyright and Index Files Copyright (C) $YEAR by X2 Support Group\n\n"; print T "LongIndex $ProgVersion by X2 Support Group\n"; # print H ""; print H "


"; print H "Compilation Copyright and Index Files Copyright (C) $YEAR by X2 Support Group"; print H "


"; print H "
"; print H "LongIndex $ProgVersion by X2 Support Group (x2ftp+\@\@+x2ftp.oulu.fi.NO.SPAM)"; print H "
"; print H ""; printf H ("\n"); close T; close H; chmod 0664, "$DIR/$LONG_TXT"; chmod 0664, "$DIR/$LONG_HTML"; printf "\nDirectory %-10s [ %2d files]: %2d Ok, %2d failed.\n", $DIR, $n_files, $n_ok, $n_fail; printf STDERR "done\n"; exit $errs; # ----------------------------------------------------------------------------- # ## TXT File Handling Subroutines # # ----------------------------------------------------------------------------- # Find matching txtfile on the INDEXDIR. This routine is called if # the pre-formatted txtfile was not named specificly. # sub get_txt_name { local ($mainfile, $seekpath) = @_; local $txtfile = ''; ($hum, $foo) = split (/\./, $mainfile, 2); print "\nSearch $mainfile => $hum (DIR $seekpath)"; if ($hum) { $hum .= ".*"; while(<"$seekpath/${hum}">) { if (/(\S+\.)(txt|lsm|doc|diz|nfo|readme)/i) { $txtfile = $_; } } } # hum return $txtfile; } # ----------------------------------------------------------------------------- # # Copy the Long Description Form from database directory. # # NOTE: The output does not comply with LSM rules any more. # sub copy_long_description { local ($mainfile, $short) = @_; $LSMmode = 0; $Category = ""; $Filename = ""; $Title = ""; $Version = ""; $EnterDate = ""; $Description= ""; $Keywords = ""; $Source = ""; $FormatsList= ""; $Author = ""; $Maintainer = ""; $Site = ""; $Platforms = ""; $Requires = ""; $CopyingPolicy=""; # $txtfile = $TextName{$mainfile}; # $txtfile = get_txt_name ($mainfile, $TXTDIR); if ( ($keysfile = $IndexName{$mainfile})) { $keysfile = $INDEXDIR . "/" . $keysfile; } else { $keysfile = get_txt_name ($mainfile, $INDEXDIR); } if (!open (D, $keysfile)) { printf STDERR "Cannot read '$keysfile'\n"; print T "\t$short\n"; print H "\n\n"; return -1; } # Check that correct fields are copied. Skip the rest. # The text file being read here is completely re-formatted by # 'dosadm' to ensure correct keyword syntax troughout the file. # while () { chop; if (/^\s*$/) { next; } last if (/^-----------------------/); # Unused feature # if (/^Begin3$/) { # ++$LSMmode; # next; # } ### Scan for Required fields ### if (/^Type\s*:\s*(.+)/i || /^Category\s*:\s*(.+)/i) { $Category = $1; next; } elsif (/^\s*Program\s*:\s*(.+)/i) { $Filename = $1; next; } elsif (/^\s*Title\s*:\s*(.+)/i) { $Title = $1; next; } elsif (/^\s*Version\s*:\s*V?\s*(.+)/i) { $Version = $1; next; } elsif (/^\s*Entered-date\s*:\s*(.+)/i) { $EnterDate = $1; next; } elsif (/^\s*Description\s*:\s*(.+)/i) { $Description = $1; next; } elsif (/^\s*Keywords\s*:\s*(.+)/i) { $Keywords = $1; next; } elsif (/^\s*Source-code\s*:\s*(.+)/i) { $Source = $1; next; } elsif (/^\s*Formats\s*:\s*(.+)/i) { $FormatsList = $1; next; } elsif (/^\s*Authors?\s*:\s*(.+)/i) { $Author = $1; $Author =~ tr/\<\>/\(\)/; next; } elsif (/^\s*Maintained-by\s*:\s*(.+)/i) { $Maintainer = $1; $Maintainer =~ tr/\<\>/\(\)/; next; } # elsif (/^\s*Primary-site\s*:\s*(.+)/i) { # $Site = $1; # next; # } elsif (/^\s*Platforms\s*:\s*(.+)/i) { $Platforms = $1; next; } elsif (/^\s*Requires\s*:\s*(.+)/i) { $Requires = $1; next; } elsif (/^\s*Copying-policy\s*:\s*(.+)/i) { $CopyingPolicy = $1; $CopyingPolicy =~ tr/\<\>/\(\)/; next; } else { print STDERR "Unrecognised keyword near >>$_<<\n"; next; } } # while # ----------------------------------------------------------------- # Checking. if (! $Filename) { $Filename = $mainfile; } if (! $Description) { $Description = $short; } # ----------------------------------------------------------------- # printf T "Category: %s\n", $Category; printf T "Program: %s\n", $Filename; printf T "Title: %s\n", $Title; printf T "Version: %s\n", $Version; ($LSMmode || $EnterDate) && printf T "Entered-date: %s\n", $EnterDate; printf T "Description: %s\n", $Description; printf T "Keywords: %s\n", $Keywords; # --- # X2 Format additions printf T "Source-code: %s\n", $Source; $FormatsList && printf T "Formats: %s\n", $FormatsList; # --- printf T "Author: %s\n", $Author; if ($LSMmode) { printf T "Maintained-by: %s\n", $Maintainer; # printf T "Primary-site: %s\n", ""; # printf T "Alternate-site: %s\n", ""; # printf T "Original-site: %s\n", ""; } # LSM Format printf T "Platforms: %s\n", $Platforms; $Requires && printf T "Requires: %s\n", $Requires; printf T "Copying-policy: %s\n", $CopyingPolicy; print T "\n"; # ----------------------------------------------------------------- # After printing text version, protect any HTML metacharacters. $Description = html_encode($Description); $Requires = html_encode($Requires); print H "
    \n"; # printf H "Category: %s\n", $Category; printf H "Program: %s
    \n", $Filename; printf H "Title: %s
    \n", $Title; printf H "Version: %s
    \n", $Version; ($LSMmode || $EnterDate) && printf H "Entered-date: %s
    \n", $EnterDate; printf H "Description: %s
    \n", $Description; printf H "Keywords: %s
    \n", $Keywords; # --- # X2 Format additions printf H "Source-code: %s
    \n", $Source; $FormatsList && printf H "Formats: %s
    \n", $FormatsList; # --- printf H "Author: %s
    \n", $Author; if ($LSMmode) { printf H "Maintained-by: %s
    \n", $Maintainer; # printf H "Primary-site: %s
    \n", ""; # printf H "Alternate-site: %s
    \n", ""; # printf H "Original-site: %s
    \n", ""; } # LSM Format printf H "Platforms: %s
    \n", $Platforms; $Requires && printf H "Requires: %s
    \n", $Requires; printf H "Copying-policy: %s
    \n", $CopyingPolicy; print H "
\n\n"; } # copy_long_description # ----------------------------------------------------------------------------- # # Protect any HTML metacharacters. # sub html_encode { local ($value, $foo) = @_; $value =~ s/\&/\&/; $value =~ s/\/\>/; return $value; } # html_encode # ----------------------------------------------------------------------------- # # Print headers # sub print_text_headers { print T "\n\t\t\tx2ftp.oulu.fi\n"; print T "\tX2 Support Group Game Development Archives\n"; print T "\nDirectory: /pub/msdos/programming/${DIR}\n"; print T "\n------------------------------------------------------------------------------\n"; print T "\n"; print T "Index updated: $date\n"; print T "This is a new index file format. Please, tell us what you think about it.\n"; print T "\n------------------------------------------------------------------------------\n\n"; } # print_text_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 "


\nThis is a new index file format. Please, tell us what you think about it.\nAny patches welcome. ;-)\n"; print H "


"; } # print_html_headers