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
157
158
159
160
161
162
163
164
165
166
167
|
#!/usr/bin/perl
# 初期設定
# require Jcode;
# *Jgetcode = &Jcode::getcode;
# *Jconvert = &Jcode::convert;
require "../../../cgi-bin/jcode.pl";
*Jgetcode = &jcode::getcode;
*Jconvert = sub { &jcode::to($_[1], $_[0], $_[2]); };
@g_styles = ("../../ipp.css", "../test.css");
$g_title = "テスト14";
$my_code = &Jgetcode("漢字");
$cut_code = "jis";
$htmlfile = "html?|[ps]ht(ml)?";
$scrname = $ENV{'SCRIPT_NAME'};
$scrname =~ s/_1|_u// ;
if($scrname =~ /ts[0-9]{4}.cgi$/){
$linkfile = $& ;
$linkfile =~ s/.cgi/.htm/ ;
}
# 固有設定
$searchdir = "..";
$searchfile = "\.$htmlfile";
$indexfile = "index\.($htmlfile)";
{
&printHeader;
print "<div class=test>\n";
&Jprint("親ディレクトリ以下にあるファイルの一覧(HTMLファイルのみ)","\n");
print "<ul>\n";
&Jconv ("<li><a href=\"$searchdir\">", &indexSearch($searchdir), "</a>\n");
&dirlist($searchdir);
print "</ul>\n";
print "</div>\n";
&printFooter;
exit;
}
sub indexSearch{
local($dir) = $_[0];
local($result, @filelist);
opendir(DIR, $dir);
@filelist = readdir(DIR);
closedir(DIR);
@filelist = sort @filelist;
$result = "インデックス無し";
foreach(@filelist){
if(/$indexfile/){
$result = &getHTMLTitle("$dir/$&");
last;
}
}
return $result;
}
sub dirlist{
local($dir)=$_[0];
local(@filelist,@dirs, $file, $filename, $ftitle, $fileflg);
@dirs = ();
$fileflg = 1;
opendir(DIR, $dir);
@filelist = readdir(DIR);
closedir(DIR);
@filelist = sort @filelist;
foreach $file(@filelist){
if($file eq "."){ next; }
if($file eq ".."){ next; }
$filename = "$dir/$file";
if(-d $filename){
push(@dirs, $filename);
}elsif($filename =~ /$searchfile/){
if($filename !~ /$indexfile/){
if($fileflg){
print "<ul>\n";
$fileflg = 0;
}
$ftitle = &getHTMLTitle($filename);
&Jconv ("<li><a href=\"$filename\">$file(", $ftitle, ")</a>\n");
}
}
}
foreach $filename (@dirs){
if($filename =~ /[\w-]+$/){
$file = $&;
}
$ftitle = &indexSearch($filename);
&Jconv ("<li><a href=\"$filename/\">$file(", $ftitle, ")</a>\n");
&dirlist($filename);
}
if(!$fileflg){print "</ul>\n";}
}
sub getHTMLTitle{
local($file)=$_[0];
local($ttl, $result);
$result = "タイトル無し";
if($file =~ /$htmlfile/){
open(IN, $file);
while(<IN>){
if(/<title>/){
if($' =~ /<\/title>/){
$ttl = $`;
if($ttl =~ /\S/){$result = $ttl;}
last;
}
}
}
close(IN);
}
return $result;
}
sub printHeader{
print "Content-type: text/html\n\n";
&Jprint ("<html lang=ja><head><title>$g_title</title>\n");
foreach (@g_styles){
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"$_\">\n";
}
print "</head><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";
open(IN, "../../sig.txt");
while (<IN>){
print;
}
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($linkfile){
&Jprint ("/\n<a href=\"../$linkfile\">$g_titleの解説</a>\n");
}
}
sub Jprint{
foreach (@_) {
print &Jconvert($_, $cut_code, $my_code);
}
}
sub Jconv{
foreach (@_) {
print &Jconvert($_, $cut_code, &Jgetcode($_));
}
}
|