| 1 |
#!/usr/bin/perl |
| 2 |
use strict; |
| 3 |
use CGI::Carp qw/fatalsToBrowser/; |
| 4 |
|
| 5 |
my $data_dir_name = q[data/]; |
| 6 |
my $map_file_name = $data_dir_name . q[_mapping.dat]; |
| 7 |
|
| 8 |
require Encode; |
| 9 |
|
| 10 |
sub decode_url ($) { |
| 11 |
my $s = shift; |
| 12 |
$s =~ tr/+/ /; |
| 13 |
$s =~ s/%([0-9A-Fa-f]{2})/pack 'C', hex $1/ge; |
| 14 |
return Encode::decode ('utf-8', $s); |
| 15 |
} # decode_url |
| 16 |
|
| 17 |
sub encode_url ($) { |
| 18 |
my $s = shift; |
| 19 |
$s = Encode::encode ('utf-8', $s); |
| 20 |
$s =~ s/([^0-9A-Za-z_~-])/sprintf '%%%02X', ord $1/ge; |
| 21 |
return $s; |
| 22 |
} # encode_url |
| 23 |
|
| 24 |
sub htescape ($) { |
| 25 |
my $s = shift; |
| 26 |
$s =~ s/&/&/g; |
| 27 |
$s =~ s/</</g; |
| 28 |
$s =~ s/>/>/g; |
| 29 |
$s =~ s/"/"/g; |
| 30 |
return $s; |
| 31 |
} # htescape |
| 32 |
|
| 33 |
if ($ENV{REQUEST_METHOD} eq 'POST') { |
| 34 |
my $param = {}; |
| 35 |
my $input = ''; |
| 36 |
read STDIN, $input, $ENV{CONTENT_LENGTH}; |
| 37 |
for (split /[&;]/, $input || '') { |
| 38 |
my ($name, $value) = split /=/, $_, 2; |
| 39 |
$param->{decode_url ($name)} = decode_url ($value); |
| 40 |
} |
| 41 |
|
| 42 |
if (length $param->{en}) { |
| 43 |
open my $map_file, '>>:utf8', $map_file_name or die "$0: $map_file_name: $!"; |
| 44 |
print $map_file join '%%', |
| 45 |
map {s/%%+/%/; s/\s+/ /; $_} |
| 46 |
($param->{en}, $param->{ja}, $param->{suffix}, $param->{note}); |
| 47 |
print $map_file "\n"; |
| 48 |
close $map_file; |
| 49 |
|
| 50 |
require 'common.pl'; |
| 51 |
system_ ('cvs', 'commit', -m => 'by remote user', $map_file_name); |
| 52 |
|
| 53 |
print q[Status: 202 Appended |
| 54 |
Content-Type: text/html ; charset = us-ascii |
| 55 |
|
| 56 |
<!DOCTYPE HTML> |
| 57 |
<html lang=en> |
| 58 |
<meta http-equiv=refresh content=0> |
| 59 |
<title>Appended</title> |
| 60 |
<p><a href="">Appended</a>]; |
| 61 |
|
| 62 |
exit; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
binmode STDOUT, ':utf8'; |
| 67 |
|
| 68 |
print q[Content-Type: text/html ; charset=utf-8 |
| 69 |
|
| 70 |
<!DOCTYPE HTML> |
| 71 |
<html lang=en> |
| 72 |
<head> |
| 73 |
<title>English-Japanese Word Mapping Table</title> |
| 74 |
<link rel=stylesheet href="/www/style/html/xhtml"> |
| 75 |
<link rel=license href="edit/#license" title="Same as HTML5 (except for copyright holder)"> |
| 76 |
<link rel=edit href="edit/_mapping"> |
| 77 |
<body> |
| 78 |
<h1>Word-to-Word Mapping</h1> |
| 79 |
|
| 80 |
<form action="words" accept-charset=utf-8 method=post> |
| 81 |
<table> |
| 82 |
<thead> |
| 83 |
<tr><th rowspan=2>English<th colspan=2>Japanese<th rowspan=2>Note |
| 84 |
<tr><th>Stem<th>Suffix<th> |
| 85 |
<tbody>]; |
| 86 |
|
| 87 |
my @map; |
| 88 |
open my $map_file, '<:utf8', $map_file_name or die "$0: $map_file_name: $!"; |
| 89 |
while (<$map_file>) { |
| 90 |
my ($en, $ja, $ja_suffix, $note) = split /%%/, $_, 4; |
| 91 |
push @map, [$en, $ja, $ja_suffix, $note]; |
| 92 |
} |
| 93 |
|
| 94 |
for (sort {$a->[0] cmp $b->[0]} @map) { |
| 95 |
print q[<tr>]; |
| 96 |
print q[<td><a href="find?word=] . encode_url ($_->[0]) . q[">], htescape ($_->[0]) . q[</a>]; |
| 97 |
print q[<td><a href="find?word=] . encode_url ($_->[1]) . q[;suffix=] . encode_url ($_->[2]) . q [">], htescape ($_->[1]) . q[</a>]; |
| 98 |
print q[<td>], htescape ($_->[2]); |
| 99 |
print q[<td>], htescape ($_->[3]); |
| 100 |
# print q[<td><a href="" onclick="edit (this.parentNode.parentNode); return false">Edit</a>]; |
| 101 |
} |
| 102 |
|
| 103 |
print q[<tfoot> |
| 104 |
<tr> |
| 105 |
<td><input type=text name=en> |
| 106 |
<td><input type=text name=ja> |
| 107 |
<td><select name=suffix><option value="none">No suffix<option value="ku">Ka-gyou Godan (-ku)<option value="su">Sa-gyou Godan (-su)<option value="tsu">Ta-gyou Godan (-tsu)<option value="nu">Na-gyou Godan (-nu)<option value="mu">Ma-gyou Godan (-mu)<option value="ru">Ra-gyou Godan (-ru)<option value="u">Wa/a-gyou Godan (-u)<option value="gu">Ga-gyou Godan (-gu)<option value="bu">Ba-gyou Godan (-bu)<option value="ichidan">Ichidan (-iru, -eru)<option value="suru">Sahen (-suru)<option value="kuru">Kahen (kuru)<option value="i">Keiyoushi (-i)<option value="da">Keiyou-doushi (-da)<option value="dasuru">Kei-dou-sahen (-da, -suru)</select> |
| 108 |
<td><textarea name=note></textarea> |
| 109 |
<td><input type=submit value=Add> |
| 110 |
</table> |
| 111 |
</form> |
| 112 |
]; |