#!/usr/local/bin/perl
#
# Update_Mainhtml -- Update links on the Programming Main Page.
#
# Update the monthly upload index file references.
# This program edits the files 00Main.html and 00index-html.
#
$Version= "V1.1 PL 00 (1 Mar 1999)";
#
# Written by
# Jouko Valta (jopi@x2ftp.oulu.fi)
#
# Revision History
# V1.0 pl 00 -- 25 Feb 1999
# Initial revision.
#
# V1.1 pl 00 -- 1 Mar 1999
# Initial revision.
# .
#
#
$Usage = "\
Options:\
-h Show help page and exit\
-f file Specify input file\
-w file Write html index 'file'\n\n";
#$Usage = "\
# Options:\
# -h Show help page and exit\
# -c Check index file Consistency\
# -f AutoCorrect\
# -p Check file Permissions\
# -s Use Strict Find based on month day number\
# -t,-nw Test only. Don't update index file\
# -w file Specify index file to write\
# -nc Suppress Consistency checking\
# -nf No AutoCorrect\
# -np No Permission checking\n\n";
#
# -----------------------------------------------------------------------------
$FIND = "/bin/find";
$SORT = "/bin/sort";
B
# -----------------------------------------------------------------------------
B
## Determine some time constants
@months = (
"January", "February", "March", "April",
"May", "June", "July", "August",
"September","October", "November", "December"
);
@mons = (
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec"
);
# Get Date
($sec,$min,$hour, $Mday,$Mon,$Year, $wday,$yday,$isdst) = localtime;
# -----------------------------------------------------------------------------
# Defaults
$YEAR = `/bin/date +%Y`; # Copyright year (in 4 digits)
chop($YEAR);
## Default Filenames
$MASTER_INDEX = "00index.txt"; # Category descriptions.
$STATDIR = "x2info";
$RECENTFILE = "00recent.txt"; # Recent index file
$HTMLMAIN = "00Main.html";
$HTMLTARGET = $HTMLMAIN;
$TEMPTARGET = "#htmltemp#";
## Defaults
$TestMode = 0; # Test only. Don't write outfile.
$Consistency = 1;
$Permission = 1;
$AutoCorrect = 0; # Fix file permissions. Unused at the moment.
$StrictFind = 0; # Find $Mday old or newer files.
#
# HTML Index File Generation Date
$date = `/bin/date`;
chop $date;
### 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 (/^-t|^-nw/) { $TestMode = 1; next; }
if (/^-c/) { $Consistency = 1; next; }
if (/^-f/) { $HTMLMAIN = $ARGV[0]; shift; next; }
if (/^-w/) { $HTMLTARGET = $ARGV[0]; shift; next; }
if (/^-nc/) { $Consistency = 0; next; }
if (/^-/) { die "\nUnsupported argument near $_\n Stopped"; }
}
#print "\n";
#
# ----------------------------------------------------------------------------
#
$EDITBLOCKS = 2; # Number of locations to edit.
$blocksdone = 0;
$errs = 0;
chdir "/ftp-service/ftp/pub/msdos/programming";
#
# Determine proper filenames for the Monthly Upload index files.
# Current and previous month files.
$LASTMONTH = `/bin/ls -1tr $STATDIR/00*.new | tail -1`;
chop ($LASTMONTH);
# 00 + Abbreviated month name jan to dec + year + '.new'
$MONTHFILE = "00" . $mons[$Mon] . $Year . ".new";
# TODO list ...
$NEXTMONTH = "00todo.new";
# Make sure $LASTMONTH exists and is not the current month's index file.
# Clear the filaneme if no file was found.
if (!$LASTMONTH || ! -f "$LASTMONTH" || ! /$mons[$Mon]/ =~ $LASTMONTH) {
printf STDERR "WARNING: Previous *new file '$LASTMONTH' is rather old.\n";
$LASTMONTH = "";
}
#
# ----------------------------------------------------------------------------
#
# Get the directory descriptions ...
#
open (M, "<$MASTER_INDEX");
print "\nReading Directory list.\n";
while () {
if (/^\s*$/) { next; }
elsif (/^Index of all/) { next; }
elsif (/^\s*(\S+)\/\s+(.*)/) { # Real directory declaration.
$DIRSPEC{$1} = $2;
# print "\t$1:$DIRSPEC{$1}\n"; # any TABs removed
}
}
close (M);
#
# ----------------------------------------------------------------------------
#
# Open the old and a new HTML main index file.
#
open (I, "$HTMLMAIN") ||
die "Cannot read index file '$HTMLMAIN'";
open(H, ">$TEMPTARGET") || die "Cannot open '$TEMPTARGET'";
if ($TestMode) {
$HTMLTARGET = "/dev/null";
}
printf STDERR "Updating '$HTMLTARGET'\n";
line: while () {
if (/MONTHS:BEGINHTMLAUTOEDIT/) {
print "found the months Begin marker\n";
update_months();
skip_block();
next line;
}
#
# Index of all subdirectories in x2ftp.oulu.fi:/pub/msdos/programming/
#
#
ack * Animation Construction Kit 3D (ACK) related material
# ...
if (/CAT:BEGINHTMLAUTOEDIT/) {
print "found the categories Begin marker\n";
update_categories();
skip_block();
next line;
}
#
# No modifications for plain text
print H;
} # while
# Print footers
#print H "";
#print H "
";
#print H "Compilation Copyright $YEAR by X2 Support Group";
#print H "
";
#print H "";
#print H "HtmlLink $Version by X2 Support Group (x2ftp\@x2ftp.oulu.fi.NO.SPAM)";
#print H "";
#print H "