#!/usr/bin/perl use strict; use CGI::Carp qw/fatalsToBrowser/; my $data_dir_name = q[data/]; my $map_file_name = $data_dir_name . q[_mapping.dat]; require Encode; sub decode_url ($) { my $s = shift; $s =~ tr/+/ /; $s =~ s/%([0-9A-Fa-f]{2})/pack 'C', hex $1/ge; return Encode::decode ('utf-8', $s); } # decode_url sub encode_url ($) { my $s = shift; $s = Encode::encode ('utf-8', $s); $s =~ s/([^0-9A-Za-z_~-])/sprintf '%%%02X', ord $1/ge; return $s; } # encode_url sub htescape ($) { my $s = shift; $s =~ s/&/&/g; $s =~ s//>/g; $s =~ s/"/"/g; return $s; } # htescape if ($ENV{REQUEST_METHOD} eq 'POST') { my $param = {}; my $input = ''; read STDIN, $input, $ENV{CONTENT_LENGTH}; for (split /[&;]/, $input || '') { my ($name, $value) = split /=/, $_, 2; $param->{decode_url ($name)} = decode_url ($value); } if (length $param->{en}) { open my $map_file, '>>:utf8', $map_file_name or die "$0: $map_file_name: $!"; print $map_file join '%%', map {s/%%+/%/; s/\s+/ /; $_} ($param->{en}, $param->{ja}, $param->{suffix}, $param->{note}); print $map_file "\n"; close $map_file; require 'common.pl'; system_ ('cvs', 'commit', -m => 'by remote user', $map_file_name); print q[Status: 202 Appended Content-Type: text/html ; charset = us-ascii Appended

Appended]; exit; } } binmode STDOUT, ':utf8'; print q[Content-Type: text/html ; charset=utf-8 English-Japanese Word Mapping Table

Word-to-Word Mapping

]; my @map; open my $map_file, '<:utf8', $map_file_name or die "$0: $map_file_name: $!"; while (<$map_file>) { my ($en, $ja, $ja_suffix, $note) = split /%%/, $_, 4; push @map, [$en, $ja, $ja_suffix, $note]; } for (sort {$a->[0] cmp $b->[0]} @map) { print q[]; print q[
EnglishJapaneseNote
StemSuffix
], htescape ($_->[0]) . q[]; print q[], htescape ($_->[1]) . q[]; print q[], htescape ($_->[2]); print q[], htescape ($_->[3]); # print q[Edit]; } print q[
];