|
Server : Apache/2.4.62 System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64 User : www ( 80) PHP Version : 8.3.8 Disable Function : NONE Directory : /domains/mandarintools/cgi-bin/ |
Upload File : |
#!/usr/bin/perl
require "./cgi-lib.pl";
$termfile = "church-terms.u8";
&ReadParse(*values);
print "Content-type: text/html; charset=utf-8\n\n";
print <<INTRO;
<HTML>\n<HEAD>
<TITLE>Chinese LDS Term Search Result</TITLE>
<script>
<!--
function sf(){document.forms[0].estring.focus();}
// -->
</script>
<HEAD>
<BODY onLoad=sf()>
<H1>Search Result</H1>
<P>
INTRO
&TermSearch;
print <<TAIL;
<P>
<H2>Do another search:</H2>
<P>
<FORM ACTION="http://www.mandarintools.com/cgi-bin/church-terms.pl" METHOD="POST">
Please enter the English LDS term you wish to look up in Chinese:<BR>
Term: <INPUT TYPE="text" name="estring"><BR>
<INPUT TYPE="submit" value="Do Search">
<INPUT TYPE="reset" value="Clear Entry">
<P>
The search is not case sensitive.
</FORM>
</BODY>
</HTML>
TAIL
exit;
sub alphabetically {
uc($a) cmp uc($b);
}
sub TermSearch {
open(TFILE, $termfile) || print "Can't open the file.<BR>\n";
my($found) = 0;
my(@terms);
print "<TABLE cellpadding=5>\n<TR bgcolor=lightblue>\n<TD><STRONG>English</STRONG></TD>" .
"<TD><STRONG>Trad. Chinese</STRONG></TD><TD><STRONG>Simp. Chinese</STRONG></TD>" .
"<TD><STRONG>Pinyin</STRONG></TD>\n</TR>\n";
while ($line = <TFILE>) {
@terms = split(/\t/, $line);
if ($terms[0] =~ m/$values{'estring'}/i) {
push @results, $line;
$found++;
}
}
@results = sort alphabetically @results;
for ($i = 0; $i < scalar(@results); $i++) {
@terms = split(/\t/, $results[$i]);
if ($i % 2 == 0) {
print "<TR bgcolor=skyblue>";
} else {
print "<TR bgcolor=lightblue>";
}
$terms[3] = addTones($terms[3]);
print "<TD>$terms[0]</TD><TD>$terms[1]</TD><TD>$terms[2]</TD><TD>$terms[3]</TD></TR>\n";
}
print "</TABLE>";
print "Sorry, the term \"$values{'estring'}\" is not currently in the database.\n" if $found == 0;
close TFILE;
}
sub addTones {
my($withnumbers) = shift;
my($i);
$withnumbers =~ s/ng(\d)\b/${1}ng/g;
$withnumbers =~ s/n(\d)\b/${1}n/g;
$withnumbers =~ s/ao(\d)\b/a${1}o/g;
$withnumbers =~ s/ai(\d)\b/a${1}i/g;
$withnumbers =~ s/ei(\d)\b/e${1}i/g;
$withnumbers =~ s/ou(\d)\b/o${1}u/g;
@tonenums = ("a1", "a2", "a3", "a4", "a5", "e1", "e2", "e3", "e4", "e5",
"i1", "i2", "i3", "i4", "i5", "o1", "o2", "o3", "o4", "o5",
"u1", "u2", "u3", "u4", "u5",
"u:1", "u:2", "u:3", "u:4", "u:5", "u:",
"v1", "v2", "v3", "v4", "v5", "v");
@tonemarks = ('ā', 'á', 'ǎ', 'à', 'a',
'ē', 'é', 'ě', 'è', 'e',
'ī', 'í', 'ǐ', 'ì', 'i',
'ō', 'ó', 'ǒ', 'ò', 'o',
'ū', 'ú', 'ǔ', 'ù', 'u',
'ǖ', 'ǘ', 'ǚ', 'ǜ', 'ü', 'ü',
'ǖ', 'ǘ', 'ǚ', 'ǜ', 'ü', 'ü');
for ($i = 0; $i < scalar(@tonenums); $i++) {
$withnumbers =~ s/$tonenums[$i]/$tonemarks[$i]/ge;
}
$withnumbers =~ s/5//g;
return $withnumbers;
}