サブディレクトリ内も一覧

                             <p>ソースコード</p>
  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
#!/usr/bin/perl

# 初期設定
# require Jcode;
# *Jgetcode = &amp;Jcode::getcode;
# *Jconvert = &amp;Jcode::convert;

require "../../../cgi-bin/jcode.pl";
*Jgetcode = &amp;jcode::getcode;
*Jconvert = sub { &amp;jcode::to($_[1], $_[0], $_[2]); };

@g_styles = ("../../ipp.css","../test.css");
$g_title = "テスト13";
$my_code = &amp;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 = $&amp; ;
    $linkfile =~ s/.cgi/.htm/ ;
}

# 固有設定
$searchdir = "..";
$searchfile = $htmlfile;

{
    &amp;printHeader;

    print "<div class=test>n";
    &amp;Jprint("親ディレクトリ以下にあるファイルの一覧(HTMLファイルのみ)","n");
    &amp;dirlist($searchdir);
    print "</div>n";

    &amp;printFooter;

    exit;
}

sub dirlist{
    local($dir)=$_[0];
    local(@filelist, $file, $filename, $ftitle);
    opendir(DIR, $dir);
    @filelist = readdir(DIR);
    closedir(DIR);
    @filelist = sort @filelist;
    print "<ul>n";

    foreach $file(@filelist){
        if($file eq "."){ next; }
        if($file eq ".."){ next; }
        $filename = "$dir/$file";
        if(-d $filename){
            print "<li><a href="$filename/">$file</a>n";
            &amp;dirlist($filename);
        }elsif($filename =~ /.$searchfile/){
            $ftitle = &amp;getHTMLTitle($filename);
            &amp;Jconv ("<li><a href="$filename">$file(", $ftitle, ")</a>n");
        }
    }
    print "</ul>n";
}

sub getHTMLTitle{
    local($file)=$_[0];
    local($result);
    $result = "タイトル無し";
    if($file =~ /$htmlfile/){
        open(IN, $file);
        while(<IN>){
            if(/<title>/){
                if($' =~ /</title>/){
                    $result = $`;
                    last;
                }
            }
        }
        close(IN);
    }
    return $result;
}

sub printHeader{
    print "Content-type: text/htmlnn";
    &amp;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";
    &amp;Jprint ("<h1>$g_title</h1><hr>n");
    &amp;printlinks;
    print "<hr></div>n";
}

sub printFooter{
    print "<div class=foot><hr>n";
    &amp;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){
        &amp;Jprint ("/n<a href="../$linkfile">$g_titleの解説</a>n");
    }
}

sub Jprint{
    foreach (@_) {
        print &amp;Jconvert($_, $cut_code, $my_code);
    }
}

sub Jconv{
    foreach (@_) {
        print &amp;Jconvert($_, $cut_code, &amp;Jgetcode($_));
    }
}
                          </div>
comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。