#!/usr/bin/perl # 注意: 入力ファイルのencodingはEUCで。 # 数字の全角-半角変換テーブル %z2h = qw(0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9); # ヘッダの生成 $part; # ヘッダ/期間/@番号 $period; # ヘッダ/期間 $year; # ヘッダ/期間/@年 $month; # ヘッダ/期間/@月 @comments; # ヘッダ/コメント * @pubinfo; # 新刊リスト/発売情報 * (生データ) $copyright; # ヘッダ/著作権 @authors; # ヘッダ/作成者 * (生データ) while(<>){ # 先頭セクションまで読みとばし last if(/^−.+−$/); } while(<>){ # タイトルセクションの読み込み last if(/^−.+−$/); if(/^(\d+)年(.+)(.+)月/) { $year=$1; $month=&convert_digit($2); }elsif (/その(.+)((.+))/){ $part=&convert_digit($1); $period=$2; } } $para = ""; while(<>){ # コメントセクションの読み込み if(/^−.+−$/){ push(@comments, $para) if($para ne ""); last; } if(/^・(.+)$/){ push(@comments, $para) if($para ne ""); $para = $1; }elsif(/^\s+(.*)$/){ $para = "$para$1"; } } while(<>){ # 凡例セクションの読みとばし last if(/^−.+−$/); } $lines = ""; while(<>){ # 発売情報リストの読み込み if(/^−.+−$/){ push(@pubinfo, $lines); last; } if(/^[^\s]+/){ push(@pubinfo, $lines) if($lines ne ""); $lines = $_; }elsif(/^\s+/){ $lines = "$lines$_"; } } while(<>){ # 著作権情報,作成者の読み込み last if(/^−.+−$/); if(/^\s+/){ push(@authors,$_); }else{ /^(.*)$/; $copyright = "$copyright$1"; } } while(<>){ # 作成者の読み込み last if(/^−.+−$/); push(@authors,$_) if(/^\s+/); } # 出力 ## ヘッダ部 $period = &convert_cdata($period); print <<_XML_; <新刊ニュース> <ヘッダ> <期間 年="$year" 月="$month" 番号="$part">$period _XML_ foreach(@authors){ # 作成者 /^\s+([^\s]+)\s+([^\s]+)$/; $author = &convert_cdata($1); print " <作成者 email=\"$2\">$author\n"; } foreach(@comments){ # コメント $comment = &convert_cdata($_); print " <コメント>$comment\n"; } $copyright = &convert_cdata($copyright); print <<_XML_; <著作権>$copyright <新刊リスト 通貨="円"> _XML_ ## リスト部 foreach(@pubinfo){ split("\n", $_); foreach(@_){ if(/^(\S+)・(.*)〈(.*)〉$/){ $day = &convert_digit($1); $ser = &convert_cdata($2); $pub = &convert_cdata($3); $ser =~ s/\s+$//; print " <発売情報 発売日=\"$day\">\n"; print " <シリーズ名>$ser\n" if($ser ne ""); print " <出版社>$pub\n"; }elsif(/^\s+(.+)[(.+)]\s+(\S+)/){ $title = &convert_cdata($1); $pubauthor = &convert_cdata($2); $price = &convert_digit($3); $title =~ s/\s+$//; print " <出版物>\n"; print " <タイトル>$title\n"; print " <著者>$pubauthor\n"; print " <予価>$price\n"; print " \n"; } } print " \n"; } print <<_XML_; _XML_ #### sub convert_cdata { my($str) = @_; $str =~ s/&/&/g; $str =~ s/