Namazu-devel-ja(旧)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
rtf2html 対応 filter/rtf.pl
- From: Tadamasa Teranishi <yw3t-trns@xxxxxxxxxxxxxxx>
- Date: Wed, 26 Mar 2003 04:12:56 +0900
- X-ml-name: namazu-devel-ja
- X-mail-count: 02834
寺西です。
以下の rtf2html に対応した HEAD の filter/rtf.pl の差分です。
http://www.45.free.net/~vitus/ice/misc/rtf2html.tar.gz
Index: filter/rtf.pl
===================================================================
RCS file: /storage/cvsroot/namazu/filter/rtf.pl,v
retrieving revision 1.2
diff -r1.2 rtf.pl
27a28
> use File::Basename;
39,40c40,43
< $rtfconvpath = util::checkcmd('doccat');
< @rtfconvopts = ("-o", "e");
---
> #
> # http://www.45.free.net/~vitus/ice/misc/rtf2html.tar.gz
> #
> $rtfconvpath = util::checkcmd('rtf2html');
42,48c45,59
< my $fh_cmd = util::efopen("$rtfconvpath -V |");
< while (<$fh_cmd>) {
< if (/TF Library *: *Version *: *(\d*)\.(\d*)/i) {
< my $major = $1;
< my $minor = $2 . "000";
< if ($major >= 1 && substr($minor, 0, 2) >= 42) {
< return 'yes';
---
> @rtfconvopts = ();
> return 'yes';
> }
> else {
> $rtfconvpath = util::checkcmd('doccat');
> @rtfconvopts = ("-o", "e");
> if (defined $rtfconvpath) {
> my $fh_cmd = util::efopen("$rtfconvpath -V |");
> while (<$fh_cmd>) {
> if (/TF Library *: *Version *: *(\d*)\.(\d*)/i) {
> my $major = $1;
> my $minor = $2 . "000";
> if ($major >= 1 && substr($minor, 0, 2) >= 42) {
> return 'yes';
> }
51a63
> return 'no';
53d64
< return 'no';
81c92,96
< $err = filter_doccat($orig_cfile, $cont, $weighted_str, $headings,
$fields);
---
> if (basename($rtfconvpath) =~ /rtf2html/i) {
> $err = filter_rtf2html($orig_cfile, $cont, $weighted_str, $headings, $fields);
> } else {
> $err = filter_doccat($orig_cfile, $cont, $weighted_str, $headings, $fields);
> }
84a100,144
>
> sub filter_rtf2html ($$$$$) {
> my ($orig_cfile, $cont, $weighted_str, $headings, $fields)
> = @_;
> my $cfile = defined $orig_cfile ? $$orig_cfile : '';
>
> util::vprint("Processing rtf file ... (using '$rtfconvpath')\n");
>
> my $tmpfile = util::tmpnam('NMZ.rtf');
> {
> my $fh = util::efopen("> $tmpfile");
> print $fh $$cont;
> }
> {
> my @cmd = ($rtfconvpath, @rtfconvopts, $tmpfile);
> my ($status, $fh_out, $fh_err) = util::systemcmd(@cmd);
> my $size = util::filesize($fh_out);
> if ($size == 0) {
> return "Unable to convert file ($rtfconvpath error occurred).";
> }
> if ($size > $conf::TEXT_SIZE_MAX) {
> return 'Too large rtf file.';
> }
> $$cont = util::readfile($fh_out);
> }
> unlink $tmpfile;
>
> if (util::islang("ja")) {
> codeconv::toeuc($cont);
> }
>
> # Title shoud be removed.
> $$cont =~ s!<TITLE>.+</TITLE>!!;
>
> html::html_filter($cont, $weighted_str, $fields, $headings);
>
> gfilter::line_adjust_filter($cont);
> gfilter::line_adjust_filter($weighted_str);
> gfilter::white_space_adjust_filter($cont);
> $fields->{'title'} = gfilter::filename_to_title($cfile, $weighted_str)
> unless $fields->{'title'};
> gfilter::show_filter_debug_info($cont, $weighted_str,
> $fields, $headings);
> return undef;
> }
--
=====================================================================
寺西 忠勝(TADAMASA TERANISHI) yw3t-trns@xxxxxxxxxxxxxxx
http://www.asahi-net.or.jp/~yw3t-trns/index.htm
Key fingerprint = 474E 4D93 8E97 11F6 662D 8A42 17F5 52F4 10E7 D14E