#!/usr/bin/perl -w # This script performs a headword search within GCIDE_XML. # Submitted by Alexei Puzikov (kidd@validio.com.ua), # and modified by Michael Dyck (jmdyck@ibiblio.org). $real = 1; use CGI qw (param escape); use CGI::Carp qw (fatalsToBrowser); if ( $real ) { $query = param('query'); $script_url = $ENV{"SCRIPT_URL"}; $xml_file_dir = "/public/html/webster/xml_files" } else { # test at home $query = "pyxis"; $script_url = "$0"; $xml_file_dir = "C:/User/Michael/gcide_xml/0.43/xml_files"; } if ($query eq ""){ $query = "x"; } print << "EOM"; Content-type: text/html GCIDE_XML - search results for $query
Search:
EOM # print "
";
# while( ($key,$value) = each %ENV )
# {
# 	print "$key = $value\n";
# }
# print "
"; # print ""; # print ""; # exit; # Get the first character of the query. $first = lc(substr($query,0,1)); if ( $first =~ /[a-z]/ ) { # That character is a letter, # so we only have to examine the file(s) for that letter. $file_pattern = "$xml_file_dir/gcide_${first}*.xml"; } else { # That character isn't a letter # (i.e., it's some sort of regexp metacharacter), # so we have to examine all files. $file_pattern = "$xml_file_dir/gcide_*.xml"; } @files = glob( $file_pattern ); $pattern = "$query"; foreach $datafile (@files) { # print "$datafile\n"; open(DATAFILE,"$datafile"); while (1) { $astring = ; last if !defined($astring); # Headwords appear with syllabification/stress marks * " `. # There also might be an initial "‖". # We need to remove those before comparing with $pattern. # Possible bug: what if those marks appear in $astring # *outside* of the element? $astring =~ s/["*`]//g; $astring =~ s/‖//g; if ($astring =~ /$pattern/i) { # We have found a headword element that matches the query! # Read lines to the end of this "entry". $result = ''; while (1) { chomp($astring); $result = "$result$astring\n"; $astring=; last if !defined($astring); last if $astring =~ //; } # Convert GCIDE_XML tags into their HTML renditions $_ = $result; s###g; s###g; s###g; s###g; # s##
#g; # s##
#g; s#
#
#g; s##
#g; s#<(qex|qau|source|xex|pos|fld|ets|etsep|au|src|altname|altnpluf|mark|ex|asp|cref|sd|contr|ant|spn|ord|gen|pluf|uex|stype|mathex|ratio|singf|xlati|iref|figref|ptcl|part|var|tr)>##g; s###g; s#(.+?)#$1#g; push @matches, $_; redo; # Redo the body of the while-loop, # in case the that we just read # (which signalled the end of the previous entry) # is also a match for the query. } # End of if. } # End of while. close(DATAFILE); } print "
Search results for: $query
\n"; print "\n"; $count=@matches; print "
$count " . ( $count == 1 ? "match" : "matches" ) . " found.
\n"; if ($count > 0) { foreach $match (@matches) { print "
\n"; print "\n"; print "$match\n"; } } print "\n"; print "\n";