サブディレクトリ内も一覧(その2)

                             <p>ソースコード</p>

初期設定

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";
&amp;Jprint("親ディレクトリ以下にあるファイルの一覧(HTMLファイルのみ)","n");
print "<ul>n";
&amp;Jconv ("<li><a href="$searchdir">", &amp;indexSearch($searchdir), "</a>n");
&amp;dirlist($searchdir);
print "</ul>n";
print "</div>n";

&amp;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 = &amp;getHTMLTitle("$dir/$&amp;");
        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 = &amp;getHTMLTitle($filename);
            &amp;Jconv ("<li><a href="$filename">$file(", $ftitle, ")</a>n");
        }
    }
}
foreach $filename (@dirs){
    if($filename =~ /[w-]+$/){
        $file = $&amp;;
    }
    $ftitle = &amp;indexSearch($filename);
    &amp;Jconv ("<li><a href="$filename/">$file(", $ftitle, ")</a>n");
    &amp;dirlist($filename);
}
if(!$fileflg){print "</ul>n";}

}

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

sub printHeader{ print “Content-type: text/htmlnn”; &Jprint ("$g_titlen”); foreach (@g_styles){ print “n”; } print “n”; print “n”; &Jprint ("$g_titlen”); &printlinks; print “n”; }

sub printFooter{ print “n”; &printlinks; print “n”; open(IN, “../../sig.txt”); while (){ print; } close(IN); print “n”; print “n”; }

sub printlinks{ print “Homen”; print “/nPerln”; print “/nTestCGI Indexn”; if($linkfile){ &Jprint ("/n$g_titleの解説n”); } }

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

sub Jconv{ foreach (@) { print &Jconvert($, $cut_code, &Jgetcode($_)); } }

                              </div>
    	

Comments

comments powered by Disqus