/[suikacvs]/markup/html/html5/spec-ja/words.cgi
Suika

Contents of /markup/html/html5/spec-ja/words.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Thu Jul 24 13:17:16 2008 UTC (17 years, 8 months ago) by wakaba
Branch: MAIN
CVS Tags: before-new-ids, after-new-ids
*** empty log message ***

1 wakaba 1.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/</&lt;/g;
28     $s =~ s/>/&gt;/g;
29     $s =~ s/"/&quot;/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     print q[Status: 202 Appended
49     Content-Type: text/html ; charset = us-ascii
50    
51     <!DOCTYPE HTML>
52     <html lang=en>
53     <meta http-equiv=refresh content=0>
54     <title>Appended</title>
55     <p><a href="">Appended</a>];
56    
57     exit;
58     }
59     }
60    
61     binmode STDOUT, ':utf8';
62    
63     print q[Content-Type: text/html ; charset=utf-8
64    
65     <!DOCTYPE HTML>
66     <html lang=en>
67     <head>
68     <title>English-Japanese Word Mapping Table</title>
69     <link rel=stylesheet href="/www/style/html/xhtml">
70     <link rel=license href="edit/#license" title="Same as HTML5 (except for copyright holder)">
71     <link rel=edit href="edit/_mapping">
72     <body>
73     <h1>Word-to-Word Mapping</h1>
74    
75     <form action="words" accept-charset=utf-8 method=post>
76     <table>
77     <thead>
78     <tr><th rowspan=2>English<th colspan=2>Japanese<th rowspan=2>Note
79     <tr><th>Stem<th>Suffix<th>
80     <tbody>];
81    
82     my @map;
83     open my $map_file, '<:utf8', $map_file_name or die "$0: $map_file_name: $!";
84     while (<$map_file>) {
85     my ($en, $ja, $ja_suffix, $note) = split /%%/, $_, 4;
86     push @map, [$en, $ja, $ja_suffix, $note];
87     }
88    
89     for (sort {$a->[0] cmp $b->[0]} @map) {
90     print q[<tr>];
91     print q[<td><a href="find?word=] . encode_url ($_->[0]) . q[">], htescape ($_->[0]) . q[</a>];
92     print q[<td><a href="find?word=] . encode_url ($_->[1]) . q[;suffix=] . encode_url ($_->[2]) . q [">], htescape ($_->[1]) . q[</a>];
93     print q[<td>], htescape ($_->[2]);
94     print q[<td>], htescape ($_->[3]);
95     # print q[<td><a href="" onclick="edit (this.parentNode.parentNode); return false">Edit</a>];
96     }
97    
98     print q[<tfoot>
99     <tr>
100     <td><input type=text name=en>
101     <td><input type=text name=ja>
102     <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>
103     <td><textarea name=note></textarea>
104     <td><input type=submit value=Add>
105     </table>
106     </form>
107     ];

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24