#!/usr/sbin/perl # Notes: # # - going to have a problem with casing # - handle metachars # ---------------------------------------------------- # VARIABLES $docroot = "\/performer"; $maindocroot = "\/var\/www\/htdocs"; $absdocroot = "$maindocroot$docroot"; $dbsdir = "$absdocroot\/dbs"; $abssrcdir = "$absdocroot\/src"; $cgiroot = "\/cgi-bin"; $fullcgiroot = "/var/www$cgiroot"; # ---------------------------------------------------- # Main &read_in_args(); if ($TYPE ne "SAMPLE") { &do_search($TYPE,$STRING); } elsif ($TYPE eq "SAMPLE") { $PRINTED_TYPE = "Sample"; &which_lang(); &start_page(); #&searchsamples($TYPE,$STRING,$PRINTED_TYPE,$LANG); &searchsamples(); &printnine(); &end_page(); exit; } if ($TYPE eq "CLASS") { $PRINTED_TYPE = "Class"; } elsif ($TYPE eq "TOKEN") { $PRINTED_TYPE = "Token"; } else { $PRINTED_TYPE = "Method"; } if ($RESULT_LENGTH == 0) { &start_page(); print "

Search for $PRINTED_TYPE $PASSED_IN_STRING "; print "returned 0 results.\n"; &end_page(); } elsif ($RESULT_LENGTH == 1) { &which_lang(); #&start_page(); # problem here 10-28-97 # Sends args to pfmakepage.cgi. The page is created from there print `$fullcgiroot/pfmakepage.cgi ${TYPE},@MATCHLIST,$LANG`; } else { # if more than one hit print options &start_page(); print "

Search for $PASSED_IN_STRING in $PRINTED_TYPE table "; if ($PRINTED_TYPE =~ /Token/) { print "resulted in the following $TKNRESULT_LENGTH hit(s):

\n"; } else { print "resulted in the following $RESULT_LENGTH hit(s):

\n"; } &which_lang(); &print_results(); &end_page(); } # Subs sub read_in_args { # Get the input coming from the FORM as standard input: read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @PAIRS = split(/&/, $buffer); foreach $PAIR (@PAIRS) { #print "

Pair is $PAIR\n"; ($NAME, $VALUE) = split(/=/, $PAIR); #print "

NAME is $NAME, and VALUE is $VALUE\n"; if ($NAME =~ /RESET/) { print "Location:$cgiroot/pfsearch.cgi\n\n"; #print "there"; exit; } if ($NAME =~ /STRING/) { #print "

Preparsed \$STRING is $VALUE\n"; # This is for reporting back to the user $PASSED_IN_STRING = $VALUE; $PASSED_IN_STRING =~ s/\%3F/\?/g; $PASSED_IN_STRING =~ s/\%5C/\\/g; $PASSED_IN_STRING =~ s/\%2B/\+/g; $PASSED_IN_STRING =~ s/\%3D/\=/g; $PASSED_IN_STRING =~ s/\%24/$/g; $PASSED_IN_STRING =~ s/\%5E/^/g; #$PASSED_IN_STRING =~ y/A-Z/a-z/; $STRING = $VALUE; # wildcard support (a UNIX/Perl Hybrid; escape wildcards for literals) #$STRING =~ s/\*/\*/g; $STRING =~ s/\%3F/\?/g; $STRING =~ s/\%2B/\+/g; $STRING =~ s/\%5C/\\/g; $STRING =~ s/\%3D/\\=/g; $STRING =~ s/\%24/$/g; $STRING =~ s/\%5E/^/g; $STRING =~ y/A-Z/a-z/; #print "

\$STRING is \"$STRING\""; next; } if ($NAME =~ /TYPE/) { $TYPE = $VALUE; next; } if ($NAME =~ /CNOT/) { $CNOT = "A"; #next; } if ($NAME =~ /LANGCPLUS/) { $LANGCPLUS = "C"; #next; } } } # end read_in_args sub start_page { print "Content-type: text/html\n\n"; # Required for HTTP/1.0 compat. print "Search Results\n"; print "\n"; if ($PRINTED_TYPE eq "Sample") { print "\n"; print "\n"; foreach $key (sort byhits (keys(%hitfiles))) { ($name = $key) =~ s/.*\/(.*)$/$1/; ($dirpath = $key) =~ s/\/performer\/(.*)\/.*$/\/usr\/share\/Performer\/$1/; #print "

$key has $hitfiles{$key} hits.\n"; #print "

$name has $hitfiles{$key} hits.\n"; print "

\n"; } } } sub byhits { $hitfiles{$b} <=> $hitfiles{$a}; } sub examinedirs { local($DIR) = @_ ; local($EMPTY) = "Y"; local(@FILES) = (); opendir(DIR,"$DIR"); rewinddir(DIR); foreach $DIR_ENTRY (grep(!/^\./, readdir(DIR))) { # print "4 $DIR/$DIR_ENTRY\n"; if (-d "$DIR/$DIR_ENTRY") { #print "\n5 $DIR/$DIR_ENTRY\n"; &examinedirs("$DIR/$DIR_ENTRY"); } elsif ((-f "$DIR/$DIR_ENTRY") && ($DIR_ENTRY =~ /\.c$/ || $DIR_ENTRY =~ /\.C$/ || $DIR_ENTRY =~ /\.h$/)) { &searchfile("$DIR/$DIR_ENTRY"); } } } # end examinedirs # ------ sub searchfile { local($SRCFILE) = @_ ; $RESULT_LENGTH = 0; # print "6 $SRCFILE Lang is $LANG, result length is $RESULT_LENGTH\n "; $RESULT_COUNTER = 0; open(SAMFILE,"$SRCFILE"); foreach $LIST () { $LIST =~ tr/A-Z/a-z/; #$srchstring =~ tr/A-Z/a-z/; $STRING =~ tr/A-Z/a-z/; if ($LIST =~ /$STRING/) { $RESULT_COUNTER++; #if ($RESULT_COUNTER == 1) { # need an assoc array with name of file and number hits #$filename = $SRCFILE; # print "8 $filename\n"; $SRCFILE =~ s/$maindocroot(.*)/$1/; $hitfiles{$SRCFILE} = $RESULT_COUNTER; #} #print "7 $SRCFILE Lang is $LANG, result length is $RESULT_COUNTER\n"; } } close(SAMFILE); #&printnine(); } # end searchfile
"; } else { print "
"; } print "

Search Results

\n"; } sub end_page { print "
"; print "\n"; print "\n"; } sub do_search { local($TYPE,$STRING) = @_; $RESULT_LENGTH = 0; if ($TYPE eq "CLASS") { $TBL = "$dbsdir/class.dbm"; } elsif ($TYPE eq "TOKEN") { $TBL = "$dbsdir/tokens.dbm"; } elsif ($TYPE eq "METHOD") { $TBL = "$dbsdir/meth.dbm"; } dbmopen(%TABLE,"$TBL",0444) || die "$!"; $KEY = ""; while (($KEY, $FOO) = each(%TABLE)) { if (($TYPE eq "METHOD") && !($KEY =~ s/_0$//)) { next; } if ($TYPE eq "TOKEN") { $KEY =~ s/(.*)_\d*$/$1/; } ($L_KEY = $KEY) =~ y/A-Z/a-z/; if ($L_KEY =~ /$STRING/) { if ($TYPE eq "TOKEN") { push(@MATCHLIST,"$FOO"); #$TOKENRESULT_LENGTH++; } else { push(@MATCHLIST,"$KEY"); } $RESULT_LENGTH++; } # end if } # end while @TOKENLIST = grep(!$seen{$_}++, @MATCHLIST); $TKNRESULT_LENGTH = @TOKENLIST; dbmclose(%TABLE); } # end do_search sub which_lang { SWITCH: { if (($CNOT eq "A") && ($LANGCPLUS eq "C")) { $LANG = "B"; last SWITCH; } if (($CNOT eq "A") && ($LANGCPLUS ne "C")) { $LANG = "A"; last SWITCH; } if (($CNOT ne "A") && ($LANGCPLUS eq "C")) { $LANG = "C"; last SWITCH; } if (($CNOT ne "A") && ($LANGCPLUS ne "C")) { $LANG = "B"; last SWITCH; } } } sub print_results { if ($TYPE =~ /TOKEN/) { #print "

TEST\n"; #print "

Match list is @TOKENLIST\n"; foreach $MATCH (sort(@TOKENLIST)) { $NAME = $MATCH; &selectmanpage($NAME); } } else { foreach $MATCH (sort(@MATCHLIST)) { #print "

Match is $MATCH\n"; $MAKEPAGE_ARG = &PACK($MATCH); print "     $MATCH
\n"; #print "$MATCH
\n"; } } } sub PACK { $ALL = ""; local (@string) = split(//,(pop(@_))); # Split all chars in string foreach $i (@string) { $j = ord($i); # Get the ordinal value of this char $ALL = "$ALL" . "-$j" ; # Concatenate to string ALL w/- sign } return $ALL ; # Give back better than what you got } sub selectmanpage { # Check to see if C and C++ have been selected and for existence of # man page in C or C++ if (-f "$absdocroot/html_mans/${NAME}.html") { print " \; \; \; \; \;${NAME}
\n"; } elsif ($LANG =~ "C") { print " \; \; \; \; \;${NAME}
\n"; } elsif ($LANG =~ "A") { print " \; \; \; \; \;${NAME}
\n"; } elsif (($LANG =~ "B") && (-f "$absdocroot/html_mans/c/${NAME}.html")) { print " \; \; \; \; \;${NAME}
\n"; } } # --------------------------------------------------------------- sub searchsamples { #local($TYPE,$STRING,$PRINTED_TYPE,$LANG) = @_; $RESULT_LENGTH = 0; opendir(SRC_DIR,"$abssrcdir"); #print "Lang is $LANG\n"; #print "3 $abssrcdir\n"; foreach $ENTRY (grep(!/^\./, readdir(SRC_DIR))) { #print "1 $srcdir\/$ENTRY\n"; if (-d "$abssrcdir/$ENTRY") { #print "\n2 $srcdir/$ENTRY\n"; &examinedirs("$abssrcdir/$ENTRY"); } } # end foreach } # end searchsamples sub printnine { local($dirpath); if (! keys(%hitfiles)) { print "Search for $STRING in Samples returned 0 results.\n"; } else { print "Search for $STRING in Samples resulted in the following " . keys(%hitfiles) . " file(s):

     File nameDirectory NameHit(s) per file
     $name$dirpath$hitfiles{$key}