#!/usr/bin/perl -w
use Cwd;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Encode qw/encode/;
use Encode 'decode';
#use strict;
my $cgi = CGI->new;
#$cgi->charset("utf8");
$cgi->charset("sjis");
my $keyword = $cgi->param("keyword");
#$keyword = decode('utf8', $keyword);
$keyword = decode('sjis', $keyword);
my %result;
#print $cgi->header(-charset=>"utf8");
print $cgi->header(-charset=>"sjis");
my $keyword_sjis = encode('sjis', $keyword);
print "<form method=GET action=\"search.cgi\">\n";
print "<input type=text name=\"keyword\" value=\"$keyword_sjis\"></input>\n";
print "<input type=submit value=\"検索\"></input>\n";
print "</form>\n";
my $filepath = "/homepage/doc";
if( $keyword ne "" )
{
my $phrase = $keyword;
chdir($filepath);
my @filelist = glob "*";
foreach my $filename (@filelist)
{
my @lines;
open(IN,$filename);
@lines = <IN>;
close(IN);
foreach $line (@lines)
{
$line = decode('sjis', $line);
if( $line =~ m/$phrase/ )
{
$result{$filename} = 1;
}
}
}
print "<ul>\n";
foreach my $key ( keys(%result) )
{
my @lines;
open(IN,$key);
@lines = <IN>;
close(IN);
my $title = $key;
foreach $line (@lines)
{
$line = decode('sjis', $line);
if( $line =~ m/<title>(.+)<\/title>/ )
{
$title = $1;
}
}
$title = encode('sjis', $title);
print "<li><a href=\"/doc/$key\">$title</a></li>\n";
}
print "</ul>\n";
}
(setq org-html-preamble-format '(("en" "
<div align=right>
最終更新日: %C
</div>
<div align=right>
<a href=\"http://cha.la.coocan.jp/\">ホーム</a> |
<a href=\"index.html\">文書トップ</a> | <a href=\"sitemap.html\">目次</a>
</div>
<div align=right>
<form method=GET action=\"/cgi-bin/search/search.cgi\">
<input type=text name=\"keyword\" value=\"\"></input>
<input type=submit value=\"検索\"></input>
</form>
</div>
")))