#!/usr/bin/perl # # dcnote-htms: # # ***.gif をくるむ ***.htm ファイルを作成する. # # ●Usage : dcnote-htms [ -s gif_source_dir ] [ -d output_dir ] # target directory ... # # ●作成されるファイル # # hogehoge/ : 作業ディレクトリ # 001.htm...: html ファイル # # 履歴 1998/05/11 豊田英司; bindnote.pl - make GFD Note's bottom directory # 1999/06/24 小高正嗣; dcnote-bindnote へ # 1999/12/20 杉山耕一朗; 注釈の追加 # ## スカラー変数の定義 $DESTDIR = "."; $LEFTICON = "left1.gif"; $RIGHTICON = "right1.gif"; $INDEXICON = "index.gif"; $DCLICON = "den.gif"; $DCUICON = "url.gif"; $INDEXLINK = "index.htm"; $SPICON = "sp.gif"; $SOURCEDIR = undef; # shift 関数を使って @ARGV の 0 番目の要素を抜きだし $_ に代入する # もし $_ が -s であれば @ARGV の 0 番目の要素を抜きだし $SOURCEDIR に代入する while ($_ = shift) { if (/^-s/) {$SOURCEDIR = shift; next;} if (/^-d/) {$DESTDIR = shift; next; } &bindnote($_); &install_gif($_) if defined $SOURCEDIR; } exit 0; # サブルーチン install_gif sub install_gif { local($dir) = @_; &install("$dir/$LEFTICON", "$SOURCEDIR/$LEFTICON"); &install("$dir/$RIGHTICON", "$SOURCEDIR/$RIGHTICON"); &install("$dir/$INDEXICON", "$SOURCEDIR/$INDEXICON"); &install("$dir/$DCLICON", "$SOURCEDIR/$DCLICON"); &install("$dir/$DCUICON", "$SOURCEDIR/$DCUICON"); &install("$dir/$SPICON", "$SOURCEDIR/$SPICON"); } # サブルーチン install ## gif イメージを gif_source_dir から output_dir にコピーする sub install { local($to, $from) = @_; return if (-f $to); local($cmd) = "cp $from $to"; print "! $cmd\n"; system $cmd; } # サブルーチン bindnote ## ディレクトリをオープンして, それぞれの gif イメージを張り込んだ ## html ファイル作成する. sub bindnote { local($dir) = @_; opendir($dir, $dir) || do { warn "cannot open $dir"; return; }; local(@gifs) = sort grep(/^[0-9][0-9][0-9]\.gif$/, readdir($dir)); local($a, $b, $c) = ("", "", ""); for (@gifs) { $a = $b; $b = $c; $c = $_; &gen_page($dir, $a, $b, $c) if $b; } &gen_page($dir, $b, $c, "") if $b; closedir($dir); } # サブルーチン gen_page ## 各ページの html ファイルを作成する sub gen_page { local($dir, $pre, $cur, $post) = @_; $pre =~ s/gif$/htm/; $post =~ s/gif$/htm/; local($output) = "$dir/$cur"; $output =~ s/gif$/htm/; local($preline) = $pre ? "" : ""; local($postline) = $post ? "" : ""; open(OUTPUT, ">$output") || do { warn "open $output"; return; }; print "writing $output\n"; print OUTPUT <<"EOF";
$preline $postline
$preline $postline
EOF }