|
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
# -- -*- coding: utf-8-unix -*-
require "cgi-lib.pl";
&ReadParse(*values);
print "Content-type: text/html; charset=utf-8\n\n";
print "<HTML><HEAD><TITLE>CEDICT Add/Change Entry Form</TITLE></HEAD>\n";
print "<BODY>\n";
$count = 0;
while (defined($values{"tc$count"}) ||
defined($values{"sc$count"}) ||
defined($values{"py$count"}) ||
defined($values{"en$count"})) {
$count++;
}
# if called with no arguments, just print out a blank set of entry forms
if ($count == 0) {
# Have row of trad chinese, simp chinese, pinyin (mainland), English, comments
print <<TABLE;
<form method="post" action="http://www.mandarintools.com/cgi-bin/addentries.pl">
<input type="hidden" name="attempt" value="0">
<table>
<tr>
<td><strong>Traditional Chinese</strong></td>
<td><strong>Simplified Chinese</strong></td>
<td><strong>Pinyin</strong></td>
<td><strong>English Definition</strong></td>
</tr>
TABLE
for ($i = 0; $i < 10; $i++) {
$color = "";
#if ($i % 2 == 0) { $color = "style=\"background: lightyellow\""; }
print <<ROWS;
<tr $color>
<td> <input type="text" maxlength = 20 name="tc$i" $color> </td>
<td> <input type="text" maxlength = 20 name="sc$i" $color> </td>
<td> <input type="text" size=40 maxlength = 70 name="py$i" $color> </td>
<td> <input type="text" size=50 name="en$i" $color> </td>
</tr>
ROWS
}
print "</table>\n<P>";
print "<h3>Sample Entry</h3>
<table>
<tr $color>
<td> <input type=\"text\" maxlength = 20 name=\"tcsamp\" value=\"中國\"> </td>
<td> <input type=\"text\" maxlength = 20 name=\"scsamp\" value=\"中国\"> </td>
<td> <input type=\"text\" size=40 maxlength = 70 name=\"pysamp\" value=\"Zhong1 guo2\"> </td>
<td> <input type=\"text\" size=50 name=\"ensamp\" value=\"China; Chinese\"> </td>
</tr>
</table>
";
print "<P>For each entry, please fill out at least the English definition and either the simplified or traditional Chinese word.<P>\n";
} elsif (defined($values{"add5"})) {
print <<TABLE;
<form method="post" action="http://www.mandarintools.com/cgi-bin/addentries.pl">
<input type="hidden" name="attempt" value="$values{'attempt'}">
<table>
<tr>
<td><strong>Traditional Chinese</strong></td>
<td><strong>Simplified Chinese</strong></td>
<td><strong>Pinyin</strong></td>
<td><strong>English Definition</strong></td>
</tr>
TABLE
# Have option for adding more entries
for ($i = 0; $i < $count; $i++) {
if (defined($values{"original$i"})) {
print "<tr>\n";
print "<td colspan=\"4\" bgcolor=\"lightyellow\">Original Entry:</td>";
print "</tr>\n";
my($otc, $osc, $opy, $oen) =
($values{"original$i"} =~ m/^(\S+)\s+(\S+)\s+\[([^\]]+)\]\s+\/(.*?)\/$/);
$oen =~ s/\//; /g;
print "<tr bgcolor=\"lightyellow\"><td>$otc</td> <td>$osc</td> <td>$opy</td> <td>$oen</td></tr>\n";
print "<input type=\"hidden\" name=\"original$i\" value=\"" . $values{"original$i"} . "\">\n";
}
print "<tr>\n";
print '<td> <input type="text" maxlength = 20 name="tc' . $i . '" value="' . $values{"tc$i"} . '"> </td>' . "\n";
print '<td> <input type="text" maxlength = 20 name="sc' . $i . '" value="' . $values{"sc$i"} . '"> </td>' . "\n";
print '<td> <input type="text" size=40 maxlength=70 name="py' . $i . '" value="' . $values{"py$i"} . '"> </td>' . "\n";
print '<td> <input type="text" size=50 name="en' . $i . '" value="' . $values{"en$i"} . '"> </td>' . "\n";
print "</tr>\n";
}
for ($i = $count; $i < $count+5; $i++) {
print <<ROWS;
<tr>
<td> <input type="text" maxlength = 20 name="tc$i"> </td>
<td> <input type="text" maxlength = 20 name="sc$i"> </td>
<td> <input type="text" size=40 maxlength = 70 name="py$i"> </td>
<td> <input type="text" size=50 name="en$i"> </td>
</tr>
ROWS
}
print "</table>\n";
} elsif (defined($values{"fill"})) {
# Have option to fill in trad/simp/pinyin if trad or simp given
open(TS, "hcutf8.txt") or die $!;
while ($line = <TS>) {
$line =~ s/[\r\n]*$//;
next if $line =~ m/^\s*\#/ or $line =~ m/^\s*$/;
$s2t{substr($line, 0, 3)} = substr($line, 3, 3);
for ($i = 3; $i < length($line); $i+=3) {
$t2s{substr($line, $i, 3)} = substr($line, 0, 3);
}
}
close(TS);
# Load in UTF-8 pinyin table
open(PY, "uni8py.txt") or die "Can't open uni8py.txt";
while (<PY>) {
s/[\r\n]*$//;
next if m/^\s*\#/;
($char, $py) = split(/\t/);
(@pys) = split(/\s/, $py);
$char2py{$char} = $pys[0];
}
close(PY);
print <<TABLE;
<form method="post" action="http://www.mandarintools.com/cgi-bin/addentries.pl">
<input type="hidden" name="attempt" value="$values{'attempt'}">
<table>
<tr>
<td><strong>Traditional Chinese</strong></td>
<td><strong>Simplified Chinese</strong></td>
<td><strong>Pinyin</strong></td>
<td><strong>English Definition</strong></td>
</tr>
TABLE
for ($i = 0; $i < $count; $i++) {
if ($values{"tc$i"} =~ /^\s*$/ and $values{"sc$i"} =~ /\S/) {
$chinese = $values{"sc$i"};
$trad = "";
for ($j = 0; $j < length($chinese); $j+=3) {
if (defined($s2t{substr($chinese, $j, 3)})) {
$trad .= $s2t{substr($chinese, $j, 3)};
} else {
$trad .= substr($chinese, $j, 3);
}
}
$values{"tc$i"} = $trad;
} elsif ($values{"sc$i"} =~ /^\s*$/ and $values{"tc$i"} =~ /\S/) {
$chinese = $values{"tc$i"};
$simp = "";
for ($j = 0; $j < length($chinese); $j+=3) {
if (defined($t2s{substr($chinese, $j, 3)})) {
$simp .= $t2s{substr($chinese, $j, 3)};
} else {
$simp .= substr($chinese, $j, 3);
}
}
$values{"sc$i"} = $simp;
}
if ($values{"sc$i"} =~ /\S/ and $values{"py$i"} =~ /^\s*$/) {
$py = "";
for ($j = 0; $j < length($values{"sc$i"}); $j +=3) {
if ($j == 0) {
$py = $char2py{substr($values{"sc$i"}, $j, 3)};
} else {
$py .= " " . $char2py{substr($values{"sc$i"}, $j, 3)};
}
}
$values{"py$i"} = $py;
}
if (defined($values{"original$i"})) {
print "<tr>\n";
print "<td colspan=\"4\" bgcolor=\"lightyellow\">Original Entry:</td>";
print "</tr>\n";
my($otc, $osc, $opy, $oen) =
($values{"original$i"} =~ m/^(\S+)\s+(\S+)\s+\[([^\]]+)\]\s+\/(.*?)\/$/);
$oen =~ s/\//; /g;
print "<tr bgcolor=\"lightyellow\"><td>$otc</td> <td>$osc</td> <td>$opy</td> <td>$oen</td></tr>\n";
print "<input type=\"hidden\" name=\"original$i\" value=\"" . $values{"original$i"} . "\">\n";
}
print "<tr>\n";
print '<td> <input type="text" maxlength = 20 name="tc' . $i . '" value="' . $values{"tc$i"} . '"> </td>' . "\n";
print '<td> <input type="text" maxlength = 20 name="sc' . $i . '" value="' . $values{"sc$i"} . '"> </td>' . "\n";
print '<td> <input type="text" size=40 maxlength = 70 name="py' . $i . '" value="' . $values{"py$i"} . '"> </td>' . "\n";
print '<td> <input type="text" size=50 name="en' . $i . '" value="' . $values{"en$i"} . '"> </td>' . "\n";
print "</tr>\n";
}
print "</table>\n";
} elsif (defined($values{"submit"})) {
# Have final check and return for adjustments
open(PY, "./uni8py.txt") or die "Can't open uni8py.txt";
while (<PY>) {
chomp;
next if m/^\s*\#/;
($char, $py) = split(/\t/);
(@pys) = split(/\s/, $py);
$char2py{$char} = {};
foreach $pystr (@pys) {
$char2py{$char}->{$pystr} = 1;
}
}
open(TS, "hcutf8.txt") or die $!;
while ($line = <TS>) {
$line =~ s/[\r\n]*$//;
next if $line =~ m/^\s*\#/ or $line =~ m/^\s*$/;
$s2t{substr($line, 0, 3)} = substr($line, 3, 3);
for ($i = 3; $i < length($line); $i+=3) {
$t2s{substr($line, $i, 3)} = substr($line, 0, 3);
}
}
close(TS);
# Set some index mneumonics
$tchinese = 0; $schinese = 1; $pinyin = 2; $english = 3;
# First do ill-formed check on new additions
# Check
# - simp/trad have same number of characters
# - same number of pinyin syllables as characters
# - pinyin is plausible for character
# - duplicate existing entry
$added = 0;
$errorcount = 0;
for ($i = 0; $i < $count; $i++) {
$error = "";
$values{"tc$i"} =~ s/^\s*//; $values{"tc$i"} =~ s/\s*$//;
$values{"sc$i"} =~ s/^\s*//; $values{"sc$i"} =~ s/\s*$//;
$values{"py$i"} =~ s/^\s*//; $values{"py$i"} =~ s/\s*$//;
$values{"en$i"} =~ s/^\s*//; $values{"en$i"} =~ s/\s*$//;
if ($values{"tc$i"} =~ /^\s*$/ and $values{"sc$i"} =~ /^\s*$/ and
$values{"py$i"} =~ /^\s*$/ and $values{"en$i"} =~ /^\s*$/) {
next;
}
if ($values{"tc$i"} =~ /^\s*$/ and $values{"sc$i"} =~ /^\s*$/) {
$error = "Please fill out at least one of the Traditional or Simplified Chinese fields";
} elsif ($values{"tc$i"} !~ /^\s*$/ and
$values{"tc$i"} !~ /[\x80-\xff]/) {
$error = "Value in Traditional Chinese field does not appear to be Chinese";
} elsif ($values{"sc$i"} !~ /^\s*$/ and
$values{"sc$i"} !~ /[\x80-\xff]/) {
$error = "Value in Simplified Chinese field does not appear to be Chinese";
} elsif ($values{"en$i"} =~ /^\s*$/) {
$error = "Please fill out the English definition field";
} elsif ($values{"tc$i"} !~ /^\s*$/ and $values{"sc$i"} !~ /^\s*$/ and
length($values{"tc$i"}) != length($values{"sc$i"})) {
$error = "Size of simplified and traditional Chinese forms of word are not the same.";
} elsif ($values{"tc$i"} !~ m/^\s*$/ and $values{"py$i"} !~ /^\s*$/ and
length($values{"tc$i"})/3 != split(/\s+/, $values{"py$i"})) {
$error = "Number of characters does not match number of pinyin syllables";
} elsif ($values{"sc$i"} !~ m/^\s*$/ and $values{"py$i"} !~ /^\s*$/ and
length($values{"sc$i"})/3 != split(/\s+/, $values{"py$i"})) {
$error = "Number of characters does not match number of pinyin syllables";
}
$attempt = $values{'attempt'};
#if attempt greater than zero for pinyin mismatch, then assume user knows what they want and let it slide
# ...
if ($error eq "") {
# if everything well-formed, go back and check for missing but not required fields
if ($values{"tc$i"} =~ /^\s*$/ and $values{"sc$i"} =~ /\S/) {
$chinese = $values{"sc$i"};
$trad = "";
for ($j = 0; $j < length($chinese); $j+=3) {
if (defined($s2t{substr($chinese, $j, 3)})) {
$trad .= $s2t{substr($chinese, $j, 3)};
} else {
$trad .= substr($chinese, $j, 3);
}
}
$values{"tc$i"} = $trad;
} elsif ($values{"sc$i"} =~ /^\s*$/ and $values{"tc$i"} =~ /\S/) {
$chinese = $values{"tc$i"};
$simp = "";
for ($j = 0; $j < length($chinese); $j+=3) {
if (defined($t2s{substr($chinese, $j, 3)})) {
$simp .= $t2s{substr($chinese, $j, 3)};
} else {
$simp .= substr($chinese, $j, 3);
}
}
$values{"sc$i"} = $simp;
}
if ($values{"py$i"} !~ /^\s*$/ and $values{"py$i"} =~ m/[\x80-\xFF]/) {
# Replace tone marks with tone numbers
$values{"py$i"} =~ s/\xc4\x81/a1/;
$values{"py$i"} =~ s/\xc3\xa1/a2/;
$values{"py$i"} =~ s/\xc4\x83/a3/;
$values{"py$i"} =~ s/\xc3\xa0/a4/;
$values{"py$i"} =~ s/\xc4\x93/e1/;
$values{"py$i"} =~ s/\xc3\xa9/e2/;
$values{"py$i"} =~ s/\xc4\x95/e3/;
$values{"py$i"} =~ s/\xc3\xa8/e4/;
$values{"py$i"} =~ s/\xc4\xab/i1/;
$values{"py$i"} =~ s/\xc3\xad/i2/;
$values{"py$i"} =~ s/\xc4\xad/i3/;
$values{"py$i"} =~ s/\xc3\xac/i4/;
$values{"py$i"} =~ s/\xc5\x8d/o1/;
$values{"py$i"} =~ s/\xc3\xb3/o2/;
$values{"py$i"} =~ s/\xc5\x8f/o3/;
$values{"py$i"} =~ s/\xc3\xb2/o4/;
$values{"py$i"} =~ s/\xc5\xab/u1/;
$values{"py$i"} =~ s/\xc3\xba/u2/;
$values{"py$i"} =~ s/\xc5\xad/u3/;
$values{"py$i"} =~ s/\xc3\xb9/u4/;
$values{"py$i"} =~ s/\xc7\x96/u:1/;
$values{"py$i"} =~ s/\xc7\x98/u:2/;
$values{"py$i"} =~ s/\xc7\x9a/u:3/;
$values{"py$i"} =~ s/\xc7\x9c/u:4/;
}
if ($values{"sc$i"} =~ /\S/ and $values{"py$i"} =~ /^\s*$/) {
$py = "";
for ($j = 0; $j < length($values{"sc$i"}); $j +=3) {
if ($j == 0) {
$py = $char2py{substr($values{"sc$i"}, $j, 3)};
} else {
$py .= " " . $char2py{substr($values{"sc$i"}, $j, 3)};
}
}
$values{"py$i"} = $py;
}
$added++;
if (defined($values{"original$i"})) {
$newentries .= "#Replace: " . $values{"original$i"} . "\n";
}
$newentries .= $values{"tc$i"} . ' ' . $values{"sc$i"} . ' [' . $values{"py$i"} . '] /' . $values{"en$i"}
. "/\n";
} else {
$errors .= "<tr>\n";
$errors .= "<td colspan=\"4\" bgcolor=lightyellow>$error</td>\n";
$errors .= "</tr>\n";
$errors .= "<tr>\n";
$errors .= '<td> <input type="text" maxlength = 20 name="tc' . $errorcount . '" value="' . $values{"tc$i"} . '"> </td>' . "\n";
$errors .= '<td> <input type="text" maxlength = 20 name="sc' . $errorcount . '" value="' . $values{"sc$i"} . '"> </td>' . "\n";
$errors .= '<td> <input type="text" size=40 maxlength = 70 name="py' . $errorcount . '" value="' . $values{"py$i"} . '"> </td>' . "\n";
$errors .= '<td> <input type="text" size=50 name="en' . $errorcount . '" value="' . $values{"en$i"} . '"> </td>' . "\n";
$errors .= "</tr>\n";
$errorcount++;
}
}
print '<form method="post" action="http://www.mandarintools.com/cgi-bin/addentries.pl">';
print '<input type="hidden" name="attempt" value="' . ++$attempt . '">';
if ($errors ne "") {
print <<TABLE;
<table>
<tr>
<td><strong>Traditional Chinese</strong></td>
<td><strong>Simplified Chinese</strong></td>
<td><strong>Pinyin</strong></td>
<td><strong>English Definition</strong></td>
</tr>
TABLE
print $errors;
print "</table>\n";
}
if ($added > 0) {
open(NEW, ">> newentries.txt");
print NEW $newentries;
close(NEW);
}
} elsif (defined($values{"edit"})) {
# Submit edit for existing entry
for ($i = 0; $i < $count; $i++) {
print "<tr>\n";
print '<td> <input type="text" maxlength = 20 name="tc' . $i . '" value="' . $values{"tc$i"} . '"> </td>' . "\n";
print '<td> <input type="text" maxlength = 20 name="sc' . $i . '" value="' . $values{"sc$i"} . '"> </td>' . "\n";
print '<td> <input type="text" size=40 maxlength = 70 name="py' . $i . '" value="' . $values{"py$i"} . '"> </td>' . "\n";
print '<td> <input type="text" size=50 name="en' . $i . '" value="' . $values{"en$i"} . '"> </td>' . "\n";
print "</tr>\n";
}
}
if ($added == 1) {
print "<P>$added new entry added. Thank you!\n<P>\n";
}
elsif ($added > 1) {
print "<P>$added new entries added. Thank you!\n<P>\n";
}
print <<SUBMIT;
<!--
<P>Comments:
<br>
<textarea>$values{'comment'}</textarea> -->
<P><b>Actions</b>:<P>
<table>
<tr>
<td><input type="submit" name="submit" value="Submit Entries"> </td>
<td> Click here when you are ready to submit the new entries<BR></td>
</tr>
<tr>
<td><input type="submit" name="add5" value="Add 5 Empty Rows"></td>
<td> Click here to add 5 more empty rows for new etnries.</td>
</tr>
<!--<input type="submit" name="force" value="Submit without Checking">-->
<!-- <input type="submit" name="add10" value="Add 10 Empty Rows"> -->
<tr>
<td><input type="submit" name="fill" value="Guess Empty Fields"> </td>
<td>Once you have filled in one of the Chinese fields, you can click here for hints on the pinyin and simplified or traditional Chinese version.
</td>
</tr>
</table>
SUBMIT
print "</form>";
print <<GUIDE;
<h2>Submission Guidelines</H2>
Please fill out at least one of the traditional Chinese character and simplified Chinese character fields (preferably both, but not required). Traditional Chinese characters are mostly used in Taiwan and Hong Kong, while simplified Chinese characters are mostly used in mainland China and Singapore. If you are unsure if the word uses simplified or traditional characters, consider its source.
<P>
The pinyin should follow the format below:
<ul>
<li> It should have a space between each pinyin syllable.
<li> Each pinyin syllable should have a tone number. Use 5 for the light tone (qing sheng).
<li> For pinyin that uses the umlauted-u (ü), represent it with a u followed by a colon (u:).
</ul>
<p>
For the English part, separate each definition with a semi-colon ";".
<P>
Please respect the copyright of other dictionaries.
GUIDE
print "</body></html>";