#!/usr/local/bin/perl # # Keywords # V1.0 pl 00 - 19 Nov 1997 # # Written by # Jouko Valta (jopi@x2ftp.oulu.fi) # # # List keywords provided with each archive and check they are within correct # category. Create public index with all current keywords. # # # BUGS: Must change $CENTURY 19xx -> 20xx in January 2000. # # Revision History # V1.0 pl 00 - 19 Nov 1997 # Initial revision. # # ## 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; $CENTURY = 19; ## Default Filenames $LOGHOME = "/pc/log"; $KEYWORDLOG = $LOGHOME . "/keywords"; $STATDIR = "x2info"; $TARGET = "00keywords.txt"; $FINDSTRICT= "/bin/find \. -type f -mtime -$Mday -print | /bin/cut -c3-"; $SORT = "/bin/sort"; ## Defaults $TestMode = 0; # Test only. Don't write outfile. $Consistency = 1; ## Command line options while ($_ = $ARGV[0], /^-/) { shift; last if /^--$/; if (/^-t|^-nw/) { $TestMode = 1; next; } if (/^-c/) { $Consistency = 1; next; } if (/^-w/) { $TARGET = $ARGV[0]; next; } if (/^-nc/) { $Consistency = 0; next; } if (/^-/) { die "\nUnsupported argument near $_\n Stopped"; } } print "\n"; # ----------------------------------------------------------------------------- # Backup existing target file. # if (!$TestMode && -e $TARGET) { $old = "$TARGET.old"; printf STDERR "WARNING: Moving '$TARGET' to '$old'.\n"; rename ($TARGET, $old); } # ----------------------------------------------------------------------------- # # Create Keywords Index file # if ($TestMode) { $TARGET = "/dev/null"; } print "Writing to $TARGET\n\n"; # Get the directory descriptions ... open (M, "<$MASTER_INDEX"); print "Reading Directory list (25 sec)\n"; # (Actually, it's find + sort) while () { if (/^\s*$/) { next; } elsif (/^Index of all/) { next; } elsif (/\s*(\S+)\/(.*)/) { # Real directory declaration. $DIRSPEC{$1} = $2; # print "\t$1:$DIRSPEC{$1}\n"; # any TABs inclusive } } close (M); open (foo, "$FINDNEW | $SORT |") || die "Can't excute '$FINDNEW | $SORT'"; open (OF, ">$TARGET"); ## Title ## The century must be changed in January 2000. print OF "New files in x2ftp.oulu.fi:/pub/msdos/programming in $months[$Mon] $CENTURY$Year\n"; $newdir = 0; line: while () { if (/^\s*$/) { next line; } # Empty line if (/^00|\/00|00\_*index|index.html/) { next line; } # Index files if (/rejected\.\d+/) { next line; } # Info file (constantly edited) if (/contest95/) { next line; } # Nothing new elsif (/([A-Za-z0-9_\-\.]+)\/(\S+)/) { # File in any FTP directory $tmp = $1; $file = $2; # May contain subdir ... # Directory was not updated at the same time as the file (touch file). if ($tmp ne $dir) { $dir = $tmp; read_00index(); ++$newdir; } if ($newdir) { printf OF ("\n$dir/$DIRSPEC{$dir}\n"); $newdir = 0; } if ($FILESPEC{$file}) { printf OF ("$FILESPEC{$file}\n"); } else { printf "*** No description for '$dir/$file'. ***\n"; } next line; } # This rule only handles directories where no new files exist. elsif (/^(\S+)$/) { # FTP Directory $dir = $1; read_00index(); ++$newdir; next line; } } printf OF "\n"; close OF; chmod 0664, $TARGET; # ----------------------------------------------------------------------------- if ($Consistency) { print "\n\nChecking index file consistency ...\n"; $FileCnt = 0; foreach $dir (sort {$a cmp $b} (keys %DIRSPEC)) { # printf "%s\t%s\n", $dir, $DIRSPEC{$dir}; # Try all ascii index file names open (M, "$dir/00index.txt") || open (M, "$dir/00_index.txt") || open (M, "$dir/00index") || open (M, "$dir/00INDEX") || printf STDERR "Cannot read index file for '$dir'\n"; while () { if (/\s*(\S+)(.*)/) { if (! -e "$dir/$1") { printf "\n$dir:\n$_"; ++$FileCnt; } } } # while close (M); } # for } # Consistency print "\ndone.\n";