|
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 -- # -*- perl -*-
use CGI;
$query = new CGI;
require "./callib.pl";
#require "cgi-lib.pl";
#&ReadParse(*values);
unless ($ENV{'HTTP_REFERER'} =~ /http:\/\/www.mandarintools.com\/chinesename.html/i or
$ENV{'HTTP_REFERER'} =~ /mandarintools/i or
$ENV{'HTTP_REFERER'} eq "" or
$ENV{'HTTP_REFERER'} =~ /mail/i) {
open (FD, ">> accessors.txt");
print FD "CNAME: ", $ENV{'HTTP_REFERER'}, "\n";
close(FD);
}
=comment
if ($ENV{'HTTP_REFERER'} =~ /http:\/\/cgibin.erols.com\/mandarintools\/chinesename.html/i) {
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE> Moving to correct address </TITLE>";
print "<META HTTP-EQUIV=\"REFRESH\" content=\"3;url=http://www.mandarintools.com/chinesename.html\"></HEAD>";
print "<BODY></BODY></HTML>";
exit;
}
unless ($ENV{'HTTP_REFERER'} =~ /http:\/\/www.mandarintools.com\/chinesename.html/i or
$ENV{'HTTP_REFERER'} =~ /mandarintools/i or
$ENV{'HTTP_REFERER'} eq "" or
$ENV{'HTTP_REFERER'} =~ /mail/i) {
open (FD, ">> accessors.txt");
print FD "CNAME: ", $ENV{'HTTP_REFERER'}, "\n";
close(FD);
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Unauthorized access from " . $ENV{'HTTP_REFERER'} ."</TITLE>";
print "<META HTTP-EQUIV=\"REFRESH\" content=\"4;url=http://www.mandarintools.com/index.html\"></HEAD>";
print "<BODY> Some people have been copying my web page and ";
print "not giving me credit. I can no longer allow this. Please visit the authorized ";
print "address for the Chinese name at <A HREF=\"http://www.mandarintools.com/chinesename.html\" target=\"_top\">";
print "http://www.mandarintools.com/chinesename.html</A></BODY></HTML>";
exit;
}
=cut
#print "Content-type: text/plain\n\n";
# $origsurname = $values{'surname'};
# $surname = "\L$origsurname\E";
# $origfname = $values{'fname'};
# $fname = "\L$origfname\E";
# $mname = $values{'mname'};
# $mname = "\L$mname\E";
# $type = $values{'type'};
$origsurname = $query->param('surname');
$surname = "\L$origsurname\E";
$origfname = $query->param('fname');
$fname = "\L$origfname\E";
$mname = $query->param('mname');
$mname = "\L$mname\E";
$type = $query->param('type');
if ($surname =~ m/^\s*$/ or $fname =~ m/^\s*$/) {
print "Content-type: text/html\n\n";
print "<html><head>";
print "<META HTTP-EQUIV=\"REFRESH\" content=\"2;url=http://www.mandarintools.com/chinesename.html\">";
print "</HEAD>";
print "<body>";
#foreach $key (keys %ENV) {
#print "$key $ENV{$key}<BR>\n";
#}
print "Must enter both a surname and first name.</body></html>";
exit;
}
$e2c{'a'} = "a";
$e2c{'b'} = "b";
$e2c{'c'} = "k s";
$e2c{'d'} = "d t";
$e2c{'e'} = "a e";
$e2c{'f'} = "f";
$e2c{'g'} = "g k";
$e2c{'h'} = "h";
$e2c{'i'} = "y";
$e2c{'j'} = "j zh";
$e2c{'k'} = "k";
$e2c{'l'} = "l";
$e2c{'m'} = "m";
$e2c{'n'} = "n";
$e2c{'o'} = "a o";
$e2c{'p'} = "p b";
$e2c{'q'} = "k";
$e2c{'r'} = "r";
$e2c{'s'} = "s x sh";
$e2c{'t'} = "t";
$e2c{'u'} = "yu";
$e2c{'v'} = "f w";
$e2c{'w'} = "w";
$e2c{'x'} = "x sh";
$e2c{'y'} = "y";
$e2c{'z'} = "z zh";
$schar = getrandom(split(/\s/, $e2c{substr($surname, 0, 1)}));
$fchar1 = substr($fname, 0, 1);
# Look for next consonant
$index = 1;
$fchar2 = "";
while ($index < length($fname)) {
if (substr($fname, $index, 1) =~ m/^[bcdfghjklmnpqrstvwxyz]$/) {
$fchar2 = substr($fname, $index, 1);
last;
}
$index++;
}
if ($fchar2 eq "") { # no consonants after first letter. By default use second letter
$fchar2 = substr($fname, 1, 1);
}
$fchar1 = getrandom(split(/\s/, $e2c{$fchar1}));
$fchar2 = getrandom(split(/\s/, $e2c{$fchar2}));
open(SUR, "surnames.b5") or die "Content-type: text/plain\n\nCan't find Surname file.";
while (<SUR>) {
next if m/^#/;
@info = split;
if ($info[2] =~ m/^$schar/) {
push @scandidates, $info[0];
if ($info[4] eq "*") {
push @slikely_candidates, $info[0];
}
$surnameuni{$info[0]} = $info[1];
$surnamepy{$info[0]} = $info[2];
}
}
close(SUR);
# Use this to mimic surname distribution
# People are most likely to get common Chinese surnames,
# but unlikely ones are also still possible
if ($#slikely_candidates == -1 or ((rand 50) < 4)) {
$csurname = getrandom(@scandidates);
} else {
$csurname = getrandom(@slikely_candidates);
}
open(GIVEN, "givennames.b5") or die "Content-type: text/plain\n\nCan't find Given names file.";
while (<GIVEN>) {
next if m/^#/;
@info = split(/\t/);
# Select characters that match pronounciation, characteristics, and placement
if ($info[2] =~ m/^$fchar1/ and $info[4] =~ m/$type/ and $info[4] !~ m/2/) {
push @f1candidates, $info[0];
$given1uni{$info[0]} = $info[1];
$given1py{$info[0]} = $info[2];
$given1eng{$info[0]} = $info[3];
$given1type{$info[0]} = $info[4];
}
}
close(GIVEN);
$cgiven1 = getrandom(@f1candidates);
open(GIVEN, "givennames.b5") or die "Content-type: text/plain\n\nCan't find Given names file.";
while (<GIVEN>) {
next if m/^#/;
@info = split(/\t/);
# Select characters that match pronounciation, characteristics, and placement
if ($info[2] =~ m/^$fchar2/ and $info[4] =~ m/$type/ and $info[4] !~ m/1/) {
push @f2candidates, $info[0];
$given2uni{$info[0]} = $info[1];
$given2py{$info[0]} = $info[2];
$given2eng{$info[0]} = $info[3];
$given2type{$info[0]} = $info[4];
}
}
close(GIVEN);
$cgiven2 = getrandom(@f2candidates);
$chinname = $csurname . $cgiven1 . $cgiven2;
$csurpy = $surnamepy{$csurname};
$csurpy =~ s/^([a-z])/\U$1\E/;
$csurpy =~ s/[0-9]//;
$cgiv1py = $given1py{$cgiven1};
$cgiv1py =~ s/^([a-z])/\U$1\E/;
$cgiv1py =~ s/[0-9]//;
$cgiv2py = $given2py{$cgiven2};
$cgiv2py =~ s/[0-9]//;
$namepy = $surnamepy{$csurname} . $given1py{$cgiven1} . $given2py{$cgiven2};
$nicepy = $csurpy . " " . $cgiv1py . $cgiv2py;
#### Determine the Sign of the Person ####
$gday = $query->param("day");
$gmonth = $query->param("month");
$gyear = $query->param("year");
$gera = $query->param("era");
($jera, $jyear, $jmonth, $jday) =
Gregorian2Julian($gera, $gyear, $gmonth, $gday);
$juliandate = JulianPeriod($jera, $jyear, $jmonth, $jday);
# Get the Chinese Lunar Calendar Date
($dyn, $ruler, $title, $ryear, $cyear, $cmonthtype, $cmonthcycle, $cday) =
julian_day_to_chinese($juliandate);
$ystem = ($cyear % 10) - 1;
$ybranch = ($cyear % 12) - 1;
#### Print out the web page #####
print "Content-type: text/html\n\n";
print <<HEADER;
<HTML>
<HEAD>
<TITLE>$origfname $origsurname: Your Chinese Name is $nicepy</TITLE>
<BASE HREF="http://www.mandarintools.com/">
</HEAD>
<BODY BGCOLOR="gold">
HEADER
for ($m = 0; $m < length($chinname); $m++) {
$chinhex .= "\%" . sprintf("%x", vec($chinname, $m, 8));
}
## Print the GIF of the name
#print "<CENTER><A
#HREF=\"http://epsilon3.georgetown.edu/~petersee/cgi-bin/hangif.cgi?";
#print "ctext=" . $chinhex . "\&encoding=big5\&cfontname=kcm24";
#print "\&bgcolor=255,255,255\&fgcolor=0,0,0&width=24\&trans=yes\&inter=yes\">";
#print "<IMG HEIGHT=72 WIDTH=120
#SRC=\"http://epsilon3.georgetown.edu/~petersee/cgi-bin/hangif.cgi?";
#print "ctext=" . $chinhex . "\&encoding=big5\&cfontname=kcm24";
#print "\&bgcolor=255,255,255\&fgcolor=0,0,0&width=24\&trans=yes\&inter=yes\">";
#print "</A></CENTER><P>\n";
print <<NAME;
<CENTER>
<TABLE BORDER=5 BORDERCOLOR="red">
<TR>
<TD>
<IMG height=96 width=64 SRC="namegif/$surnameuni{$csurname}.gif" ALT="$surnamepy{$csurname}">
<IMG height=96 width=64 SRC="namegif/$given1uni{$cgiven1}.gif" ALT="$given1py{$cgiven1}">
<IMG height=96 width=64 SRC="namegif/$given2uni{$cgiven2}.gif" ALT="$given2py{$cgiven2}">
</TD></TR></TABLE>
</CENTER><P>
NAME
print <<MEANING;
<TABLE CELLSPACING=5 BORDER WIDTH="100%" BGCOLOR="red">
<TR>
<TD VALIGN=TOP width="33%">
<H3>Surname (first character)</H3>
<IMG ALIGN=LEFT SRC=\"http://www.mandarintools.com/cgi-bin/ugif/$surnameuni{$csurname}.gif\" ALT="$surnamepy{$csurname}">
<UL>
<LI><A HREF="http://www.mandarintools.com/sounds/$surnamepy{$csurname}.aif">$csurpy</A>
</UL>
</TD>
<TD width="33%">
<H3>Given Name (middle character)</H3>
<IMG ALIGN=LEFT SRC=\"http://www.mandarintools.com/cgi-bin/ugif/$given1uni{$cgiven1}.gif\" ALT="$given1py{$cgiven1}">
<UL>
<LI><A HREF="http://www.mandarintools.com/sounds/$given1py{$cgiven1}.aif">$cgiv1py</A>
<LI>$given1eng{$cgiven1}
</UL>
<P>
</TD>
<TD width="33%">
<H3>Given Name (last character):</H3>
<IMG ALIGN=LEFT SRC=\"http://www.mandarintools.com/cgi-bin/ugif/$given2uni{$cgiven2}.gif\" ALT="$given2py{$cgiven2}">
<UL>
<LI><A HREF="http://www.mandarintools.com/sounds/$given2py{$cgiven2}.aif">$cgiv2py</A>
<LI>$given2eng{$cgiven2}
</UL>
</TD>
</TR>
</TABLE>
<P>
MEANING
## Print URL to get the name pronounced
#print "<CENTER>";
#print "Hear the name pronounced: ";
#print "<A HREF=\"http://www.bell-labs.com/cgi-user/tts/mandarintts?";
#print "text=" . $surnamepy{$csurname} . $given1py{$cgiven1} . $given2py{$cgiven2} . "\&rate=slowest\&audio=.wav\">";
#print $nicepy . "</A></CENTER>\n";
#print "<HR>\n<H3>Chinese Date</H3>\n";
print "<P><CENTER>You were born in the Year of the $signs[$ybranch] " .
"<IMG ALIGN=ABSMIDDLE SRC=\"http://www.mandarintools.com/cgi-bin/ugif/$signuni[$ybranch].gif\"></CENTER>.";
print "<P><CENTER>Why is the zodiac sign <A HREF=\"http://www.mandarintools.com/faq.html#zodiac\">different than I expected</A>?</CENTER>\n";
print "<P><CENTER>Why do I keep getting <A HREF=\"http://www.mandarintools.com/faq.html#namer\">different names</A>?</CENTER>\n";
unless ($ENV{'HTTP_REFERER'} =~ /http:\/\/www.mandarintools.com\/chinesename.html/i or
$ENV{'HTTP_REFERER'} =~ /mandarintools/i or
$ENV{'HTTP_REFERER'} eq "" or
$ENV{'HTTP_REFERER'} =~ /mail/i) {
#if ($ENV{"SCRIPT_URI"} ne "http://www.mandarintools.com/cgi-bin/chinname.pl") {
print <<ADSENSE;
<BR>
<!-- Google -->
<center>
<script type="text/javascript"><!--
google_ad_client = "pub-1796608980793545";
/* Namer banner */
google_ad_slot = "5174430417";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</center>
<!-- Google -->
ADSENSE
}
print <<EXPLANATION;
<P>
<HR>
Hello, $origfname $origsurname! Above is the Chinese name which
was \"inspired\" by your English name. Chinese uses characters rather
than an alphabet, so names cannot be directly translated from English
to Chinese. However, Chinese characters can be chosen which approximate
the English pronounciation, which is what this program does.
<P>
Chinese names generally have 3 characters. The surname, which is
usually 1 character, comes first. Next are one or two characters which
are chosen by the parents (or the grandparents in traditional Chinese
culture). This program chooses the surname and given names according
to the spelling of your name and the characteristics you choose. The
selection is not unique though. Everytime you use this tool, you will
likely get a different name. So if you don\'t like the first name
you get, try again.
<P>
This page is mostly created for entertainment. Real Chinese names
should be chosen by someone who knows the nuances of Chinese language
and culture. Ask a native speaker if you want a Chinese name you will
actually use. Also, this tool will not translate Chinese names written
in English back to their original Chinese form.
<P>
If you came to this page directly, you might also enjoy visiting some
of my <A HREF="http://www.mandarintools.com" TARGET="_top">other tools</A> for learning and using Chinese. Please visit my <A HREF="http://www.mandarintools.com/contact.html">guestbook</A> if you have comments or
questions about this tool.
EXPLANATION
print <<FOOTER;
</BODY>
</HTML>
FOOTER
# foreach $env (keys %ENV) {
# print "$env\t" . $ENV{$env} . "\n";
# }
exit(0);
# Helper subroutines
sub getrandom {
(@larray) = @_;
srand;
if ($#larray == -1) {
return "";
} elsif ($#larray == 0) {
$choice = 0;
} else {
$choice = (rand ($#larray + 1)) % ($#larray + 1);
}
$larray[$choice];
}