1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#!/usr/bin/perl
# 初期設定
# require Jcode;
# $JcodeVer = "Jcode $Jcode::VERSION";
# *Jgetcode = &Jcode::getcode;
# *Jconvert = &Jcode::convert;
require "../../../cgi-bin/jcode.pl";
$JcodeVer = "jcode.pl $jcode::version";
*Jgetcode = &jcode::getcode;
*Jconvert = sub { &jcode::to($_[1], $_[0], $_[2]); };
@G_styles = ('../../ipp.css','../test.css');
$G_title = 'テスト17';
$G_myCode = &Jgetcode('漢字');
$G_Code = 'jis';
$G_Charset = 'iso-2022-jp';
%G_form=();
$G_scrName = $ENV{'SCRIPT_NAME'};
if($G_scrName =~ /ts[0-9]{4}/){
$G_scrName = $&;
$G_linkFile = "../$G_scrName.htm";
}
{
&printHeader;
print "<div class=test>n";
if($#ARGV == -1){
&printMethodtype;
}elsif($ARGV[0] eq "output"){
&formRead;
&formWrite;
}elsif($ARGV[0] eq "post"){
&printForm("post");
}elsif($ARGV[0] eq "get"){
&printForm("get");
}else{
&error('<h2>無効なコマンドが渡されました。</h2>');
}
print "</div>n";
&printFooter;
exit;
}
sub printMethodtype{
&Jprint("<form method=post action="$ENV{'SCRIPT_NAME'}?post"><input type=submit value="POSTでの送信フォーム"></form>n");
&Jprint("<form method=post action="$ENV{'SCRIPT_NAME'}?get"><input type=submit value="GETでの送信フォーム"></form>n");
}
sub error{
&Jprint(@_);
print "</div>n";
&printFooter;
exit;
}
sub formWrite{
local($name, $value);
print "<table border=1>n";
&Jprint("<tr><th>エレメントの名前<th>エレメントの中身</tr>n");
while (($name, $value) = each(%G_form)){
&JconvPrint("<tr><td>$name<td>$value</tr>n");
}
print "</table>n";
}
sub formRead{
local($query_string, @elements, $elm, $name, $value, $code, $method);
$method = $ENV{'REQUEST_METHOD'};
if($method eq "POST"){
read(STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
}elsif($method eq "GET"){
$query_string = $ENV{'QUERY_STRING'};
}else{
&error('methodは「post」か「get」にしてください。');
}
@elements = split(/&/, $query_string); # 中身はpostもgetも同じ
foreach $elm (@elements){
($name, $value) = split(/=/, $elm);
$value =~ s/+/ /g; # =~ tr/+/ /; と書くのが普通なのか?
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
$code = &Jgetcode($value);
if($code ne 'euc'){ $value = &Jconvert($value, 'euc', $code); } # とりあえずEUCに変換
$value =~ s/&/&amp;/g; # メタ文字(?)を無効化
$value =~ s/</&lt;/g; # タグを無効化
$value =~ s/>/&gt;/g; # タグを無効化
$value =~ s/rn?/n/g; # 改行を統一
$value =~ s/n/<br>/g; # 改行を<br>に変換
$G_form{$name} = $value;
}
}
sub printForm{
print "<form method=$_[0] action="$ENV{'SCRIPT_NAME'}?output">n";
print "<input type=text name=tx1 value="tx1"><br>n";
print "<input type=text name=tx2 value="tx2"><br>n";
&Jprint("<textarea name=tx3 cols=40 rows=4>tx3 日本語 英語 どちらでもnタグなどは無効になります。</textarea><br>n");
print "<input type=submit value="Submit!">n";
print "</form>n";
}
sub printHeader{
if($G_Charset){
print "Content-type: text/html; charset=$G_Charsetnn";
}else{
print "Content-type: text/htmlnn";
}
print '<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">'."n";
print "<html lang=ja>n<head>n";
if($G_Charset){ print "<meta http-equiv="Content-Type" content="text/html; charset=$G_Charset">n"; }
print '<meta http-equiv="Content-Script-Type" content="text/javascript">',"n";
print '<meta http-equiv="Content-Style-Type" content="text/css">'."n";
&Jprint ("<title>$G_title</title>n");
foreach (@G_styles){ print "<link rel="stylesheet" type="text/css" href="$_">n"; }
print "</head>n<body>n";
print "<div class=head>n";
&Jprint ("<h1>$G_title</h1><hr>n");
&printlinks;
print "<hr></div>n";
}
sub printFooter{
print "<div class=foot><hr>n";
&printlinks;
print "<hr>n";
&Jprint("漢字コード変換 : $JcodeVer<br>n");
open(IN, '../../sig.txt');
print while (<IN>);
close(IN);
print "</div>n";
print "</body></html>n";
}
sub printlinks{
print "<a href="../../../index.htm">Home</a>n";
print "/n<a href="../../">Perl</a>n";
print "/n<a href="../">TestCGI Index</a>n";
if($G_linkFile){ &Jprint ("/n<a href="$G_linkFile">$G_titleの解説</a>n"); }
}
sub Jprint{
if($G_Code eq $G_myCode){
foreach (@_){ print; }
}else{
foreach (@_){ print &Jconvert($_, $G_Code, $G_myCode); }
}
}
sub JconvPrint{
foreach (@_){ print &Jconvert($_, $G_Code, &Jgetcode($_)); }
}
|