";
# 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#(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#(.+?)#$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 "