KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/mandarintools/cgi-bin/cnamexml.pl
#!/usr/bin/perl -- # -*- perl -*-

use CGI;
$query = new CGI;

$surname = lc($query->param('surname'));
$fname = lc($query->param('fname'));

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.u8") 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.u8") 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/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.u8") 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/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;
$csurpytone = $surnamepy{$csurname};
$csurpy = $surnamepy{$csurname};
$csurpy =~ s/^([a-z])/\U$1\E/;
$csurpy =~ s/[0-9]//;
$cgiv1pytone = $given1py{$cgiven1};
$cgiv1py = $given1py{$cgiven1};
$cgiv1py =~ s/^([a-z])/\U$1\E/;
$cgiv1py =~ s/[0-9]//;
$cgiv2pytone = $given2py{$cgiven2};
$cgiv2py = $given2py{$cgiven2};
$cgiv2py =~ s/[0-9]//;
$namepy = $surnamepy{$csurname} . $given1py{$cgiven1} . $given2py{$cgiven2};

$nicepy = $csurpy . " " . $cgiv1py . $cgiv2py;


#### Print out xml file #####

print "Content-type: text/xml\n\n";

print <<HEADER;
<?xml version="1.0" encoding="utf-8"?>
<xml>
  <content name="$chinname">
    <names img="path/$surnameuni{$csurname}.png" talk="$csurpy" pron="">$csurname</names>
    <names img="path/$given1uni{$cgiven1}.png" talk="$cgiv1py" pron="$given1eng{$cgiven1}">$cgiven1</names>
    <names img="path/$given2uni{$cgiven2}.png" talk="$cgiv2py" pron="$given2eng{$cgiven2}">$cgiven2</names>
  </content>
</xml>
HEADER


exit(0);

# Helper subroutines

sub getrandom {
    (@larray) = @_;
    srand;
    if ($#larray == -1) {
	return "";
    } elsif ($#larray == 0) {
	$choice = 0;
    } else {
	$choice = (rand ($#larray + 1)) % ($#larray + 1);
    }
    return $larray[$choice];
}


Anon7 - 2021