#!/usr/local/bin/perl #$CPU_start = (times)[0]; # title viewer - SisterSystem # 使用方法。 # HTMLを一覧表示させたいディレクトリにコレを入れる。それだけ。 # titleタグの部分とcommentタグのコメントを解釈して表示してくれます。 # Extend:1 # ?lastをつけて起動する事によりファイルソート順で一番上の物が表示されます。 # その記事にを入れると?allへのリンクが自動的に生成されます。 # で取り出した時に表示する件数。 $gh = 3; # エラヨウ。 print "Content-type: text/html\n\n"; if ($ENV{'SCRIPT_NAME'} =~ /^(.*)\/(.*)\/(\w{1,24}).cgi$/i) { $alpha = $2; } if ($alpha) { $beta = "../$alpha/"; } if (!$beta) { print "ディレクトリ設定が不正だよ?"; exit; } if (!opendir DIR, $beta) { print "そんなディレクトリは見つからなかったよ?"; exit; } @files = grep { /^(.*)\.(htm|html|shtm|shtml)$/ } readdir DIR; close DIR; $line = 1; $naiyo = ''; @files = sort { $b cmp $a; } @files; if ($ENV{'QUERY_STRING'} eq 'last') { &last; }; if ($ENV{'QUERY_STRING'} ne 'all') { &index; }; foreach $file (@files) { &cores; $title_count = &hex_chenge($title); $comment_count = &hex_chenge($comment); $blank = ' ' x (100 - ($title_count + $comment_count)); &tag; $naiyo.= "$ctime $title<\/A>$blank$comment\n"; } $naiyo =~ s/\r$|\n$//g; print <<"_HTML_"; dir /w $alpha
$naiyo

title viewer - SisterSystem
_HTML_ $CPU_end = (times)[0]; printf("cpu time %.3f secs.
\n",$CPU_end-$CPU_start); print <<"_HTML_";

_HTML_ exit; sub index { $beta =~ s/^\.\.\//.\//g; foreach $file (@files) { &cores; &tag; $naiyo.= "
$ctime
$title<\/A>\n"; if ($line > $gh) { last; } } $naiyo =~ s/\r$|\n$//g; print "\n"; print $naiyo; print "\n

[and_more]

"; print "\n
"; exit; } # コア部分 sub cores { $title = ''; $comment = ''; if (!open(DATA,"$file")) { print "そんなファイルは無いよ?"; exit; } flock (DATA, 1); $data = join('',); close(DATA); if ($data =~ s/(.*)/i) { $title = $1; } if ($data =~ s/(.*)/i) { $comment = $1; } $ctime = ''; $mtime = ''; ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat $file; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($ctime + 32400); $moon = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dev")[$mon]; $ctime = sprintf("%02d-$moon-%04d %02d:%02d", $mday, $year + 1900, $hour, $min); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($mtime + 32400); $moon = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dev")[$mon]; $mtime = sprintf("%02d-$moon-%04d %02d:%02d", $mday, $year + 1900, $hour, $min); $line++; } #タグつぶし sub tag { $title =~ s/&/&/g; $title =~ s/\"/"/g; $title =~ s//>/g; $title =~ s/\,/,/g; $comment =~ s/&/&/g; $comment =~ s/\"/"/g; $comment =~ s//>/g; $comment =~ s/\,/,/g; } # 0x80以降は2byteとして扱うあれ sub hex_chenge { $bin = unpack("H*", $_[0]); $bin =~ s/([0-9a-f]{2})/$1\t/g; @hex = split(/\t/,$bin); $count = 0; foreach (@hex) { if ($next) { $next--; next; } if ($hex = m/^([8-9a-f]{1})([0-9a-f]{1})$/i) { $next = 2; $count++; } $count++; } return $count; } sub last { if (!open(DATA,"@files[0]")) { print "そんなファイルは無いよ?"; exit; } flock (DATA, 1); $data = join('',); close(DATA); ($headder,$preview,$foot) = split(//, $data); $data =~ s//\n[and_more<\/A>]\n/g; print $data; exit; }