#!/usr/local/bin/perl #Copyright (c) 2002 KAMICHI, Koichi(kamichi@sfc.keio.ac.jp) #Last updated: 25 June, 2002. $fullsp = pack("c", 0xe3).pack("c", 0x80).pack("c", 0x80); $page = pack("c", 0xe9).pack("c", 0xa0).pack("c", 0x81); $top = pack("c", 0xe5).pack("c", 0x88).pack("c", 0x9d); $prev = pack("c", 0xe5).pack("c", 0x89).pack("c", 0x8d); $next = pack("c", 0xe6).pack("c", 0xac).pack("c", 0xa1); $end = pack("c", 0xe7).pack("c", 0xb5).pack("c", 0x82); @number = (pack("c", 0xe5).pack("c", 0x8d).pack("c", 0x81), pack("c", 0xe4).pack("c", 0xb8).pack("c", 0x80), pack("c", 0xe4).pack("c", 0xba).pack("c", 0x8c), pack("c", 0xe4).pack("c", 0xb8).pack("c", 0x89), pack("c", 0xe5).pack("c", 0x9b).pack("c", 0x9b), pack("c", 0xe4).pack("c", 0xba).pack("c", 0x94), pack("c", 0xe5).pack("c", 0x85).pack("c", 0xad), pack("c", 0xe4).pack("c", 0xb8).pack("c", 0x83), pack("c", 0xe5).pack("c", 0x85).pack("c", 0xab), pack("c", 0xe4).pack("c", 0xb9).pack("c", 0x9d)); #ファイルからデータを読み込む sub getdata{ while(1){ #データが終わりであれば空白文字を返す if(eof FH || $eod eq "yes"){ $res = $fullsp; #EOFのときもeodを立てる $eod = "yes"; return; } else{ #本文が来るまで読む if($isstart eq "no"){ while($isstart eq "no"){ $res = ; if(not $res =~ m//i){ $beforebody = $beforebody.$res; next; } $res = $'; $beforebody = $beforebody.$`; $isstart = "yes"; #タイトルを探す $beforebody =~ m/(.+)<\/title>/i; $title = $1; } } #データを読み込む else{ $res = <FH>; #改行コードカット chomp($res); #</body>が来たら終わり if($res =~ m/<\/body>/i){ $res = $`; $eod = "yes"; } if(length($res) != 0){ return; } } } } } #小字データが何文字かをカウント sub countsmall{ $count = 0; $temp = $ressmall; while(length($temp) != 0){ if(unpack("C", substr($temp, 0, 1)) >= 0xe0){ $temp = substr($temp, 3); } elsif(unpack("C", substr($temp, 0, 1)) >= 0xc0){ $temp = substr($temp, 2); } else{ $temp = substr($temp, 1); } $count++; } } #小字データを1文字読み込む sub getdatasmall{ if(unpack("C", substr($ressmall, 0, 1)) >= 0xe0){ $ressmallchar = substr($ressmall, 0, 3); $ressmall = substr($ressmall, 3); } elsif(unpack("C", substr($ressmall, 0, 1)) >= 0xc0){ $ressmallchar = substr($ressmall, 0, 2); $ressmall = substr($ressmall, 2); } else{ $ressmallchar = substr($ressmall, 0, 1); $ressmall = substr($ressmall, 1); } } require 'cgi-lib.pl'; &ReadParse(*formdata); $filename = $formdata{"filename"}; if($filename eq ""){ $filename = "default"; } $filename = $filename.".html"; open FH,"<$filename" or die "cannot open $dbf : $!"; $isstart = "no"; $beforebody = ""; $title = ""; $eod = "no"; print <<'EOF'; Content-type: image/svg-xml <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg viewBox="0 0 1000 551" xmlns="http://www.w3.org/2000/svg"> <title>Hanpon CGI Hanpon CGI EOF $nowpage = 0; while($eod eq "no"){ $py = $nowpage * 551; print ""; $mode = "big"; $lastline = 20; $res = ""; $ressmall = ""; $lastbuf = ""; while($lastline >= 0){ $lastchar = 17; while($lastchar > 0){ #大字 if($mode eq "big"){ if(length($res) == 0){ &getdata; } if(substr($res,0,1) eq "<"){ #改行タグ if(substr($res,0,4) =~ m/
/i){ #終わり $res = substr($res,4); $lastchar = 0; next; } #小字タグ elsif(substr($res,0,7) =~ m//i){ $mode = "small"; $res = substr($res,7); #小字データの準備 $ressmall = $res; while(not $ressmall =~ m/<\/small>/i){ &getdata; $ressmall = $ressmall.$res; } #小字タグの整形 $ressmall =~ s/<\/small>/<\/small>/i; #小字データと残りデータの分割 $res = substr($ressmall, index($ressmall, "") + 8); $ressmall = substr($ressmall, 0, index($ressmall, "")); #タグは無視する $ressmall =~ s/<.+>//; next; } #その他のタグは無視する else{ $res =~ s/<.+>//; } } #文字の代入 $px = 40 + $lastline * 43; $py = 15 + (17 - $lastchar) * 30.4 + $nowpage * 551; if(unpack("C", substr($res, 0, 1)) >= 0xe0){ $lastbuf = $lastbuf."".substr($res,0,3).""; $res = substr($res,3); } elsif(unpack("C", substr($res, 0, 1)) >= 0xc0){ $lastbuf = $lastbuf."".substr($res,0,2).""; $res = substr($res,2); } else{ $lastbuf = $lastbuf."".substr($res,0,1).""; $res = substr($res,1); } $lastchar--; } #小字 else{ if(length($ressmall) == 0){ $mode = "big"; next; } #何文字入るか計算 &countsmall; $range = $count; if(int(($range + 3) / 4) > $lastchar){ $range = $lastchar * 4; } #左と右の文字数計算 $rangeleft = int($range / 2); $rangeright = int(($range + 1) / 2); #小字の始まり $plx = 40 + $lastline * 43 - 9; $prx = 40 + $lastline * 43 + 9; $py = 15 + (17 - $lastchar) * 30.4 + 2 + $nowpage * 551; $bufleft = ""; $bufright = ""; #代入(右側) while($rangeright > 0){ &getdatasmall; $bufright = $bufright."$ressmallchar"; $rangeright--; } #代入(左側) while($rangeleft > 0){ &getdatasmall; $bufleft = $bufleft."$ressmallchar"; $rangeleft--; } #htmlに出力 $lastbuf = $lastbuf.$bufright.""; $lastbuf = $lastbuf.$bufleft.""; $lastchar = $lastchar - int(($range + 3) / 4); } } $lastline--; #版心 if($lastline == 10){ if($nowpage+1 >= 20 && $nowpage % 10 != 0){ $numpages = $number[int(($nowpage+1) / 10)].$number[0].$number[($nowpage+1) % 10]; } elsif($nowpage+1 >= 20){ $numpages = $number[int(($nowpage+1) / 10)].$number[0]; } elsif($nowpage+1 > 10){ $numpages = $number[0].$number[($nowpage+1) % 10]; } elsif($nowpage+1 == 10){ $numpages = $number[0]; } else{ $numpages = $number[($nowpage+1) % 10]; } $py1 = $nowpage * 551 + 180; $py2 = $nowpage * 551 + 400; $lastbuf = $lastbuf."$title"; $lastbuf = $lastbuf."$numpages"; $lastline--; } } print $lastbuf; $nowpage++; } close FH; print <<'EOF';
EOF