#!/usr/bin/perl ##################################################################### # Building a Web Site Index by Keywords to Search # with JavaScript SiteSearch Engine, see: # http://members.tripod.com/~schick/sitesuche.html # # Version 3.0 16Aug99, Perl Version 5.001 Win32 # written by Arnold Schick (copyright) # # This Perl script is free for domestic use # and is provided "as it is" (at your own risk) # # This Perl script spage.cgi is to copy into # your cgi-bin directory on your local machine # (file: http://members.tripod.com/~schick/spage.txt) # AND the related Perl script: key.cgi # (file: http://members.tripod.com/~schick/key.txt) # # The HTML document with the FORM element for these both # scripts are to copy into your Web subdirectory # (file: http://members.tripod.com/~schick/collect.html) # # Names: Perl script : key.cgi # Perl script : spage.cgi # HTML document : collect.html # call: this script is called by key.cgi if an Index File # should be created. # # note: Don't place this script into a public cgi-bin directory # on a public Web server, it's a maintain tool of # your own Web Site files on a local machine (PC) # # if you use Apace Web server on WIN32, use the directive # #!perl in place of #!/usr/bin/perl at top of this script # # For off-line Command-Line using, see below (nothing for beginners) ##################################################################### $now = time(); $now = localtime($now); @date = split(/ /,$now); $content_length = $ENV{'CONTENT_LENGTH'}; read(STDIN, $posted, $content_length); $posted =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $posted =~ s/\+/ /g; # for offline use: uncomment the following line and try that Perl script on command line, like: c:\perl5\perl.exe spage.cgi #$posted="indexfile=c:\\tmp\\my_index.js&spage=c:\\tmp\\search.html&frame="; # the parameters can be changed for your own conditions: # indexfile=... from the previous cgi script (key.cgi) run # spage=..... the search.html page # frame=..... the frame name of result output page, if empty there is no frame used # present=... number of index to continue at old index file -if used # file=..file=..list of files to index with virtual server path @fields = split (/&/, $posted); $h1 ="HT"; $h2 ="ML"; $h3 ="BO"; $h4 ="DY"; foreach $name (@fields) { ($n, $w) = split(/=/, $name); if ($n eq 'file') { @files = (@files, $w); } else { $tokens{$n} = $w; } } print "Content-type: text/html", "\n\n"; print "<$h1$h2>\n\n"; print "\n"; print "Search Page $tokens{'spage'}, created: @date\n"; print "<$h3$h4>\n\n"; if (!$tokens{'spage'}) { print "missing filename for the Search Page

\n"; goto fin; } open(INFILE, "<$tokens{'indexfile'}") || (print "Can't open Index File $tokens{'indexfile'}: $!\n"); chomp; @allLines = ; close(INFILE); $n=0; #find checked lines, save to newLines @s_files=@files; @newLines=(); foreach $line (@allLines) { #full list $line =~ s/^\s+//; $line =~ s/\\+/\\\\/g; if ( index($line,"indexedPage[") gt -1 ) { $s1 = substr($line,index($line,'("')+2); $s2 = substr($s1,0,index($s1,'",')); foreach $page (@s_files) { #checked list if ( $s2 =~ /$page/g ) { #compare filename and path in full list and checked list $n++; $line =~ s/indexedPage\[\d+\]?/indexedPage\[$n\]/s; @newLines = (@newLines, $line); #add to newLines shift @s_files; last; } } } else { @newLines = (@newLines, $line); } #header lines and comment(s) } if ( $tokens{'present'} ) { #if to append to an older index @oldLines = splice(@allLines,0,$tokens{'present'}+1); # appended lines $n=0; $remove=(); foreach $line (@oldLines) { #check of duplicates $s1 = substr($line,index($line,'("')+2); $s2 = substr($s1,0,index($s1,'",')); foreach $page (@files) { #checked list if ( $s2 =~ /$page/g ) { unshift(@remove, $n); #which lines are to remove } } $n++; } foreach $pos (@remove) { #remove the duplicates in the appended lines splice(@oldLines,$pos,1); } shift @newLines; #remove the old header lines shift @newLines; @newLines = (@oldLines, @newLines); #append at appended lines the new lines $n=0; foreach $new (@newLines) { if ( index($new,"indexedPage[") gt -1 ) { $n++; $new =~ s/indexedPage\[\d+\]?/indexedPage\[$n\]/s; #assign a new array index number } } } $h = "var indexedPage = new makeArray($n); // Don't delete the line below\n"; if ( $newLines[0] =~ m/new makeArray/g ) { $f = shift(@newLines); unshift(@newLines, $h); } if ( $newLines[1] =~ m/new makeArray/g ) { $f = shift(@newLines); unshift(@newLines, $h); } open(OUTFILE, ">$tokens{'indexfile'}") || (print "Can't open Index File $tokens{'indexfile'}: $!\n"); print OUTFILE "@newLines"; close(OUTFILE); foreach $new (@newLines) { # substitute something in the search page to shorten the size of the search page $new =~ s/indexedPage?/P/g; $new =~ s/new index?/new I/g; } open(OUTFILE, ">$tokens{'spage'}") || (print "Can't open Index File $tokens{'spage'}: $!\n"); print OUTFILE < Search my Web Pages <$h3$h4>

Search my Web Pages



This SiteSearch JavaScript runs in Netscape (version >=3) and
Microsoft Internet Explorer (version >=4) only, if JavaScript is enabled.

PART3 ; $p1 = rindex $tokens{'spage'}, "\\"; #DOS backslash $p2 = rindex $tokens{'spage'}, "\/"; #UNIX slash $p = $p1 + $p2 +2; $fn = substr($tokens{'spage'}, $p); #extract filename if ($n ==1) { $what = "$n indexed page" } else { $what = "$n indexed pages"; } if (@remove) { $r = @remove; if ($r == 1) { $r = "  " . $r . " duplicate page was not taken."; } else { $r = "  " . $r . " duplicate pages were not taken."; } } print "

Site Search Page with $what created and saved to: $tokens{'spage'}
$r
\n"; print "

This produced Search Page can be viewed and used offline
by loading that Web document into your browser.
\n"; print "
If the used local work subdirectory path, the virtual subdirectory path at the server
and the path of the Search Page above points to the same subdirectory
there can be used that link above to view the Site Search Page now.\n"; print "

Note: when you'll change now checked files on previous page,
         only unwanted files can be unchecked. To check additional files
         create before a new index file by reloading of previous page.\n"; print "

If it's O.K.? Yes, put the Site Search Page into the Web.

@date

\n"; print "


created with Perl Script written by Arnold Schick

\n"; fin : ; print "back
\n"; print "\n"; # finally, clean up some variables: $posted = ""; @allLines = (); @newLines = (); ################ End of this Perl Script #############################################