#!/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 ""; #printf H ("\n"); close H; if ($errs || $blocksdone != $EDITBLOCKS) { printf STDERR "\n Unrecoverable error occurred on HtmlLink. Program aborted. (errs = $errs, count = $blocksdone)\n\n"; exit 1; } printf STDERR ("Move '$TEMPTARGET' => '$HTMLTARGET'\n"); #unlink($HTMLTARGET); rename($TEMPTARGET, $HTMLTARGET); chmod 0664, $HTMLTARGET; printf STDERR "done\n"; exit $errs; # ----------------------------------------------------------------------------- # # Protect any HTML metacharacters. # sub html_encode { local ($value, $foo) = @_; $value =~ s/\&/\&/; $value =~ s/\/\>/; return $value; } # html_encode # -----------------------------------------------------------------------------# # # Scan until the END marker to remove old data. # sub skip_block { while () { # print; if (/ENDHTMLAUTOEDIT/) { # print "found the End marker '$_'\n\n"; ++$blocksdone; ## fatal error trap return; } } # while } sub update_months { # # # Update links # #

    #

    New Files by Month

    #
      print H "\n"; if ($LASTMONTH && -f $LASTMONTH) { print H " Last Month --\n"; } else { print H " Last Month --\n"; } if ($MONTHFILE && -f $MONTHFILE) { print H " This Month --\n"; } else { print H " This Month --\n"; } if ($NEXTMONTH && -f $NEXTMONTH && -s $NEXTMONTH) { print H " Next Month\n"; } else { print H " Next Month\n"; } if ($RECENTFILE && -f $RECENTFILE && -s $RECENTFILE) { print H "
      \n"; print H " Last 14 days\n"; } print H " \n
    \n"; print H " \n

    \n"; print H "

    Material Updated in $YEAR

    \n"; # Century included print H " \n
      \n"; # Update Index file. # "00jul97.new Material added during July 1997" # # for ($i = 0; $i < 12; ++$i) { for ($i = 12; $i >= 0; --$i) { # 00 + Abbreviated month name jan to dec + year + '.new' $tmp = "00" . $mons[$i] . $Year . ".new"; if (-f $tmp) { printf H " %s\tMaterial added during %s %d
      \n", $tmp, $months[$i], $months[$i], $YEAR; } elsif (-f "$STATDIR/$tmp") { printf H " %s\tMaterial added during %s %d
      \n", $STATDIR, $tmp, $months[$i], $months[$i], $YEAR; } } # for months # # List Files for the previous year, if any exists. # use a blank line as the year separator. $LastYear = ($YEAR -1) % 100; $separate = 0; for ($i = 12; $i >= 0; --$i) { # 00 + Abbreviated month name jan to dec + year + '.new' $tmp = "$STATDIR/00" . $mons[$i] . $LastYear . ".new"; if (-f $tmp) { if (! $separate) { print H " \n

      \n"; ++$separate; } printf H " %s\tMaterial added during %s %d
      \n", $tmp, $months[$i], $months[$i], $YEAR -1; } } # for months print H " \n

    \n"; print H "\n"; #print H "\n"; #print H "

    \n"; #print H "

    Updates in the past

    \n"; #print H " \n "; #print H ""; # # ... } # update_months # # ----------------------------------------------------------------------------- # sub update_categories { print H "\n"; # # Only include the offocial categories listed on main index. # foreach $file (sort {$a cmp $b} (keys %DIRSPEC)) { # printf "%s\t%s\n", $dir, $DIRSPEC{$file}; # Protect any HTML metacharacters in the description. $short = html_encode($DIRSPEC{$file}); ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat($file); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($mtime); # Align filename if (length($file) < 8) { $s = "\t"; } else { $s = ""; } # # Directory Listing # This part is slightly modified pprinting routine from index.pl # # Select icon type and print one directory entry. # if ( -f _) { $LinkType="internal-gopher-unknown"; 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 %s\t%s\n", $file, $file, $s, $mday, $mons[$mon], $year, $hour, $min, $new_string, $short); } # file elsif ( -d _) { printf H ("\"[DIR]\"%s%s\t%02d-%s-%d %02d:%02d %s\t%s\n", $file, $file, $s, $mday, $mons[$mon], $year, $hour, $min, $new_string, $short); $LastDir = $file; } # directory else { print H "$file\n"; printf STDERR "BAD LINE >>$file<<\n"; ++$errs; } # any dir entry # print H "
    "; } # file print H "\n"; } # update_categories