#! /usr/local/bin/perl require 'ctime.pl'; require 'newgetopt.pl'; #require '/usr/local/lib/perl5/ctime.pl'; #require '/usr/local/lib/perl5/newgetopt.pl'; #require '/usr/local/lib/perl5/sys/socket.ph'; # # ----> parse_hotlist <---- # takes a file (default /chronos/c1/jerry/.hotlist # with tabs as delimiters for depth # and generate # $MaxTabs -> number of levels # %Keys -> array of keys per level # %Topics -> array of topics # sub parse_hotlist { if (defined @_) { $hotlist = $_[0]; } else { $hotlist = "hotlist"; } open (IT2, "<$hotlist"); $CurTabs = 0; $CurKey = "top_"; $MaxTabs = 0; while () { chop $_; # print ("Parsing ::: $_\n"); # # count the number of tabs on each line # for ($i =0; $i < length; $i++) { if (substr($_,$i,1) ne "\t") { $v = substr($_, $i); last; } } # # if # tabs more than current # if ($i > $CurTabs) { # print ("$i > $CurTabs, $CurKey\n"); $CurTabs = $i; @tmp = split(/\000/, $Topic{$CurKey}); $CurKey .= "\000".$tmp[$#tmp]; } # # if # tabs less than current # if ($i < $CurTabs) { # print ("$i < $CurTabs, $CurKey\n"); $CurTabs = $i; @tmp = split (/\000/, $CurKey); $CurKey = $tmp[0]; for ($j = 1; $j <= $i; $j++) { $CurKey .= "\000".$tmp[$j]; } } # # insert this into $Topic # while ($CurKey =~ /^(.*)<([a-z]*):(.*)>$/) { $CurKey = $1; } # if ($CurKey=~ /^(.*)$/) { # strip off comment fied # $CurKey = $1; # assume that cannot have one with url... # } if (! defined($Topic{$CurKey})) { $Topic{$CurKey} = $v; } else { $Topic{$CurKey} .= "\000".$v; } # print ("inserting into $CurKey\n"); # # check if maxtab is exceeded # if ($CurTabs > $MaxTabs) { $MaxTabs = $CurTabs; } # # insert CurKey into Key array # if (! defined($Key[$CurTabs])) { $Key[$CurTabs] = $CurKey; } else { @val = split(/\003/, $Key[$CurTabs]); $no = 0; foreach $z (@val) { if ($CurKey eq $z) { $no = 1; last; } } if ($no == 0) { $Key[$CurTabs] .= "\003".$CurKey; } } } close IT2; # print ("keys are :\n", join ("\n", keys(%Topic)), "\n"); # print ("MaxTabs is $MaxTabs\n"); # for ($i =0; $i <= $MaxTabs; $i++) { # print ("$i, $Key[$i] \n"); # } return; } # # canonicalize a directory name # sub canon_path { local($path) = $_[0]; while ($path =~ /^(.*)<([a-z]*):(.*)>$/) { $path = $1; } $path=~ s/[\']//g; # remove any bad chars ... (better way...) $path =~ s/[\/]/+/g; # remove any bad chars ... (better way...) return $path; } # # prints output of parse_hotlist to files # sub print2file { undef($dirlist); $dircnt=0; if ($opt_update) { open (HOTDOC, ">$hotstat") ; $date = &ctime(time); chop $date; print HOTODC "

"; print HOTDOC " Last modified on $date
\n"; close HOTDOC; open (HOTDOC, ">$hotdoc") ; } # do the iterative thing here... for ($i =0; $i <= $MaxTabs; $i++) { if ($i != 0) { # # # print ("=======($i, $Key[$i])=====\n"); # # print HOTDOC "

\nJerry and Dave\'s Guide to WWW \n
\n\n"; } # # big for loop to make appropriate directories # foreach $j (split (/\003/, $Key[$i])) { # # # print ("($j, $Topic{$j}) \n"); # # if ($i != 0) { # # make sure this is same as below for references # @_ = split(/\000/, &canon_path($j)); shift(@_); # get rid of top_ $curdir = join("/",@_); # form directory path $curdir =~ s/[\000\s]+$//g; # remove any trailing whitespace $curdir =~ s/[\000\s]+/_/g; # sub white spaces with _ $curdir = $hotdir."/".$curdir; if (!(-e $curdir)) { $dirlist .= " ".$curdir; $dircnt++; if ($dircnt > 15) { # some random number i made up... # print "mkdir -m g+w $dirlist
\n"; # system "mkdir -m g+w $dirlist"; $dirlist =""; $dircnt=0; } } } } if ($dircnt > 0) { # print "mkdir -m g+w $dirlist
\n"; # system "mkdir -m g+w $dirlist"; $dirlist =""; $dircnt=0; } # # big for loop to create all files # foreach $j (split (/\003/, $Key[$i])) { # # # print ("($j, $Topic{$j}) \n"); # # if ($i != 0) { # # make sure this is same as above for references # $curfile = &canon_path($j); @_ = split(/\000/,$curfile); shift(@_); $curfile=join("/",@_); $curfile =~ s/[\000\s]+$//g; # remove any trailing whitespace $curfile =~ s/[\000\s]+/_/g; # sub white spaces with _ $curtitle = $curfile; $curfile .= "/index.html"; # current file name $curfile = $hotdir."/".$curfile; $here = pop(@_); # # open up $curfile # open (HOTDOC, ">$curfile"); if (-w $curfile) { # # print "writing to file $curfile
\n"; # } else { print "cannot write to file $curfile
\n"; } print HOTDOC "
\n$curtitle\n
\n\n"; print HOTDOC "\n"; # print HOTDOC " "; $mod = $i % 3; # horizontal menu bar print HOTDOC "\n"; if ($i == 1) { print HOTDOC "

"; print HOTDOC join(": ", @_)," $here

\n"; } else { print HOTDOC "

"; print HOTDOC ""; print HOTDOC join(": ", @_),": $here

\n"; } print HOTDOC "\n"; print HOTDOC"
jerry\@akebono.stanford.edu
\n"; } close HOTDOC; } } if ($opt_update) { open (IT, ">>$hotstat"); print IT " There are currently $num_url entries in the hotlist database \n
"; close IT; } return; } # # help # sub usage { print "-h = help\n"; print "-s = filo's search for string\n"; print "-update = force an update from ~jerry/.hotlist\n"; return; } # # main search mechanism # sub filo_search { # # serach using filo's remote server... # @query = @_; $pquery = join(" ", @query); $pquery =~ s/\\(.)/$1/g; # # print out search strings to a log # open (SEARCH_LOG,">>$hotdir/search.log"); print SEARCH_LOG "$ENV{REMOTE_HOST} $pquery ", &ctime(time); close SEARCH_LOG; # # talk to dave's server via socket 2345 # $sockaddr_t = 'S n a4 x8'; $port = 2345; $host = 'konishiki'; ($x, $x, $proto) = getprotobyname('tcp'); socket(SEARCH, &AF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; ($name, $aliases, $type, $len, $thataddr) = gethostbyname($host); $that = pack($sockaddr_t, &PF_INET, $port, $thataddr); connect(SEARCH, $that) || die "connect: $!"; select((select(SEARCH), $| = 1)[0]); print SEARCH "search\nkey $pquery\n\n"; $_ = ; # skip the first empty line $_ = ; if ($_ =~/error/) { print "An error has occurred while searching for \`$pquery\':

\n"; while ($_ !~ /^$/) { print $_; $_ = ; } } else { print "Following items relevant to \`$pquery\' are found:

\n"; print "

\n"; while ($_ !~ /^$/) { if ($_ =~ /^path/) { # chew up the path undef($path); undef($url); undef($comment); $_ =; while ($_ =~ /^\t/) { chop; $path .= $_; $_ =; } $path = &canon_path($path); @p = split(/\t/,$path); } # # wait for the next ^path # while ($_ !~ /^path/) { if ($_ =~ /^$/) { last; } if ($_ =~/^url (.*)$/) { #chew up url $url = $1; } if ($_ =~/^comment (.*)$/) { #chew up comment $comment = $1; } if ($_ =~/^date (.*)$/) { #chew up date $url_date = $1; } $_=; } # # print out the correct stuff... # if (defined($path)) { if (defined($url)) { $tail = pop @p; $path = join ("/",@p); $path =~ s/[\s\000]+/_/g; # sub white spaces with _ if (!$seen{$path}++) { print "

\n"; print "\n"; print "$path

\n"; } print "
  • $tail\n"; } else { $path = join ("/",@p); $path =~ s/[\s\000]+/_/g; # sub white spaces with _ if (!$seen{$path}++) { print "

    \n"; print "\n"; print "$path

    \n"; } } if (defined($comment)) { print "- $comment\n"; } print "
\n"; } if ($_ =~ /^$/) { last; } } } close SEARCH; } # # main routine # { # # definitions # $title = "Hotlist Search"; $http_url = "http://akebono.stanford.edu/~jerry/bin/index.html"; $htdocs_root = "/usr/local/etc/httpd/htdocs"; $hottree = "/users/www_server"; $hotdir = "/home/filo/public/stanford/940520"; $hotdoc = "$hotdir/hotdoc.html"; $hotstat = "$hotdir/hotstat.html"; $rootdoc = "$htdocs_root/users/jerry/stuff.html"; undef($MaxTabs); undef($Topic); undef($Key); $num_url = 0; # # if there is an argument, process it... # if (defined @ARGV) { &NGetOpt('h','update','s=s','search'); print "Content-type: text/html\n\n"; if ($opt_h) { print "\nHelp\n\n"; print "

Help

\n"; print "
\n";
      &usage;
      print "
\n"; } elsif ($opt_update){ print "\nUpdate hotlist\n\n"; print "

Updating hotlist

\n"; print "

This may take a while...

\n"; # print ("umask is ", umask,"
\n"); umask((umask() & 0) | 75); # print ("umask is ", umask,"
\n"); &parse_hotlist; &print2file; print "Reload hotlist
\n"; } else { # # do the search # print "\nSearch of ", $title, "\n"; print "\n"; print "\n

", $title, "

\n"; print "\n"; # print "Perl regular expressions can also be entered
\n"; print "The words will be matched against title, URL, and comments
\n"; print "Enter string(s) or substring(s) you wish to search for, and hit return.
\n"; print " "; if (!$opt_search) { &filo_search(@ARGV); } # print "
"; print "
\n"; print "Press to go to "; print "
\n"; print "

\n"; } } # # no argument - just print out the list # else { # # print out the hotlist # $i = 0; print "Content-type: text/html\n\n"; # # foreach $k (keys(%ENV)) { # print "$k=$ENV{$k}

\n"; # } # print "

\nJerry and Dave\'s Guide to WWW \n"; print "\n"; print "
\n"; print "\n"; print "

Jerry and Dave's WWW Interface... (Always Under construction)

"; if (defined($ENV{HTTP_FROM})) { if ($ENV{HTTP_FROM}=~/(.+)@(.+)/) { print "

Welcome, $1 from $2


"; } else { print "

Welcome, $ENV{HTTP_FROM}


"; } } else { print "

Welcome, visitor from $ENV{REMOTE_HOST}


"; } open (IT, "<$rootdoc"); while () { print ; } close IT; # print "

Please Read!!

This is the new version of the hotlist with new directory organization. Please tell me of any bugs. Thanks.
"; open (IT, "<$hotstat"); while () { print ; } close IT; # print "
\n"; open (HOTDOC, "<$hotdoc") || warn ("open: $hotdoc"); while () { print ; $i++; # to handle the bug!! sleep 1 unless ($i % 1400 ); # to handle the bug!! } close HOTDOC; } print "\n"; }