#!/usr/bin/perl # # dcnote-latex2desc : # # tex 及びその aux ファイルから目次記述ファイル desc.txt を生成する. # # ●Usage : dcnote-aux2desc hogehoge.tex # # ●作成されるファイル # # hogehoge/ : 作業ディレクトリ. # desc.txt : 目次記述ファイル. botscan で使用される. # # ●必要な小道具 # untex # # 履歴 1998/11/24 竹広真一 # 1999/05/10 林祥介 # 1999/05/20 小高正嗣; perl スクリプトに変更 # 1999/07/17 小高正嗣; des ファイル作成プログラムと marge # 1999/12/20 杉山耕一朗; 注釈や細かい修正の追加 # ###################################################################### $desc="desc.txt" ; # 前処理: # 引数に file 名が与えられないとエラーを返す. ## @ARGV は引数を保持する特殊な配列. ## 実行する際に tex ファイルが与えられなかった場合はプログラムを停止する. die "Usage: dcnote-latex2desc [tex file].\n" if @ARGV == 0 ; # すでに $desc が存在していたら終了する. ## -e オプションによってファイルが存在するかどうかを判定. if ( -e $desc ) { print "Warning: $desc is already exist.\n" ; exit ; } # メインループ; # サブルーチン tex2desc, aux2desc を呼ぶ. ## 引数の末尾の .tex という文字列を削除し, $file に代入する. ## $desc を出力先としてオープンし, サブルーチンを実行する. foreach $file (@ARGV) { $file =~ s/\.tex$// ; open(STDOUT, ">$desc"); &tex2desc($file) ; &aux2desc($file) ; close(STDOUT) ; } exit 0; ###################################################################### # サブルーチン tex2desc # desc.txt の作成: tex ファイルから # sub tex2desc{ local($file) = @_ ; # ローカル変数の定義 $tex="$file.tex" ; $pdf="$file.pdf" ; # tex ファイルがない場合, サブルーチンを抜ける. if ( ! -e $tex ) { print "Warning: $tex not found.\n" ; return ; } # $desc の作成 # \?title, \?author, \?date の存在している行のみ処理. # 複数行にまたがっていると処理できない. # # \?title[...]{...} での [] の中身を取り出す. # 空なら \?title[...]{...} での {} の中身を取り出す. # ## (m/^\\.?title\[(.*)\]/) は文頭が \Dtitle もしくは \title で, すぐ後に ## カギカッコ([])が続く文字列にマッチする. open(F,$tex) ; while () { if (m/^\\.?title\[(.*)\]/) { s/^\\.?title\[// ; s/\].*$// ; $title = $_ ; } elsif (m/^\\.?title(\[(.*)\])*\{(.*)\}/) { s/^\\.?title(\[(.*)\])*\{// ; s/\}$// ; $title = $_ ; } if (m/^\\.?author\[(.*)\]/) { s/^\\.?author\[// ; s/\].*$// ; $author = $_ ; } elsif (m/^\\.?author(\[(.*)\])*\{(.*)\}/) { s/^\\.?author(\[(.*)\])*\{// ; s/\}$// ; $author = $_ ; } if (m/^\\.?date\[(.*)\]/) { s/^\\.?date\[// ; s/\].*$// ; $date = $_ ; } elsif (m/^\\.?date(\[(.*)\])*\{(.*)\}/) { s/^\\.?date(\[(.*)\])*\{// ; s/\}$// ; $date = $_ ; } } # \?date[...]{...} の []{}の中身が空なら # date コマンドを実行してそれを日付とする. if ( $date =\ ~ m/.+/ ) { $date=`date +%Y/%m/%d` ; } print "Subject: ", $title ; print "From: ", $author ; print "Date: ", $date ; print "Pdf: ", $pdf ,"\n"; close(F) ; } ###################################################################### # desc.txt の作成: aux ファイルから # # aux file 処理後の出力 # カラム 4 : セクション番号 # カラム 5 : セクションタイトル # カラム 6 : ページ番号. convert は 000 からスタートするので 1 引く. # sub aux2desc{ local($file) = @_ ; # ローカル変数の定義 local($temp) = "temp" ; $aux="$file.aux" ; # aux ファイルがない場合, サブルーチンを抜ける. if ( ! -e $aux ) { print "Warning: $aux not found.\n" ; return ; } # $desc の作成 ## ここで作成される desc.txt には section 項目しか ## 保持されていないことに注意. system ("grep section $aux | untex - > $temp") ; open(F, $temp); while () { @_=split(/\s+/, $_) ; print STDOUT sprintf("%03d: %s. %s\n", @_[6]-1, @_[4], @_[5]) ; } close(F) ; system ("rm -f $temp") ; }