1 |
# |
2 |
# -*- Perl -*- |
3 |
# $Id: rfc.pl,v 1.1.1.1 2001/10/20 14:09:01 ェイ Exp $ |
4 |
# Copyright (C) 1997-2000 Satoru Takabayashi , |
5 |
# 1999 NOKUBI Takatsugu All rights reserved. |
6 |
# This is free software with ABSOLUTELY NO WARRANTY. |
7 |
# |
8 |
# This program is free software; you can redistribute it and/or modify |
9 |
# it under the terms of the GNU General Public License as published by |
10 |
# the Free Software Foundation; either versions 2, or (at your option) |
11 |
# any later version. |
12 |
# |
13 |
# This program is distributed in the hope that it will be useful |
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
# GNU General Public License for more details. |
17 |
# |
18 |
# You should have received a copy of the GNU General Public License |
19 |
# along with this program; if not, write to the Free Software |
20 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
21 |
# 02111-1307, USA |
22 |
# |
23 |
# This file must be encoded in EUC-JP encoding |
24 |
# |
25 |
|
26 |
package rfc; |
27 |
use strict; |
28 |
require 'util.pl'; |
29 |
require 'gfilter.pl'; |
30 |
|
31 |
sub mediatype() { |
32 |
return ('text/plain; x-type=rfc'); |
33 |
} |
34 |
|
35 |
sub status() { |
36 |
return 'yes'; |
37 |
} |
38 |
|
39 |
sub recursive() { |
40 |
return 0; |
41 |
} |
42 |
|
43 |
sub pre_codeconv() { |
44 |
return 1; # For translated documents. |
45 |
} |
46 |
|
47 |
sub post_codeconv () { |
48 |
return 0; |
49 |
} |
50 |
|
51 |
sub add_magic ($) { |
52 |
my ($magic) = @_; |
53 |
|
54 |
$magic->addSpecials("text/plain; x-type=rfc", |
55 |
"^Network Working Group", |
56 |
"^Request [fF]or Comments", |
57 |
"^Obsoletes:", |
58 |
"^Category:", |
59 |
"^Updates:", |
60 |
"^INTERNET[- ]DRAFT", "^Internet[- ]Draft", |
61 |
"^draft-[A-Za-z0-9-]+\\.txt", |
62 |
"^<draft-[A-Za-z0-9-]+(?:\\.txt)?>", |
63 |
"^Expires", |
64 |
"^Status of this Memo"); |
65 |
$magic->addFileExts('^rfc\d+\.txt$' => 'text/plain; x-type=rfc'); |
66 |
$magic->addFileExts('^draft-[A-Za-z0-9-]+\.txt$' => 'text/plain; x-type=rfc'); |
67 |
$magic->addFileExts('^fyi\d+\.txt$' => 'text/plain; x-type=rfc'); |
68 |
$magic->addFileExts('^bcp\d+\.txt$' => 'text/plain; x-type=rfc'); |
69 |
$magic->addFileExts('^std\d+\.txt$' => 'text/plain; x-type=rfc'); |
70 |
$magic->addFileExts('^rfc\d+-\w+\.txt$', 'text/plain; x-type=rfc'); |
71 |
|
72 |
return; |
73 |
} |
74 |
|
75 |
sub filter ($$$$$) { |
76 |
my ($orig_cfile, $cont, $weighted_str, $headings, $fields) |
77 |
= @_; |
78 |
my $cfile = defined $orig_cfile ? $$orig_cfile : ''; |
79 |
|
80 |
util::vprint("Processing rfc file ...\n"); |
81 |
|
82 |
rfc_filter($cont, $weighted_str, $fields); |
83 |
|
84 |
gfilter::line_adjust_filter($cont); |
85 |
gfilter::line_adjust_filter($weighted_str); |
86 |
gfilter::white_space_adjust_filter($cont); |
87 |
gfilter::show_filter_debug_info($cont, $weighted_str, |
88 |
$fields, $headings); |
89 |
return undef; |
90 |
} |
91 |
|
92 |
# It's not perfect because of fuzziness in RFC documents. |
93 |
sub rfc_filter ($$$) { |
94 |
my ($contref, $weighted_str, $fields) = @_; |
95 |
|
96 |
$$contref =~ s/^\s+//s; |
97 |
|
98 |
# Get an author name first. |
99 |
if ($$contref =~ /^Network Working Group\s+(\S.*\S)\s*$/m) { |
100 |
$fields->{'author'} = $1; |
101 |
} elsif ($$contref =~ /^INTERNET[- ]DRAFT\s+(\S.*\S)\s*$/mi) { |
102 |
$fields->{'author'} = $1; |
103 |
} |
104 |
|
105 |
# Handle the header. |
106 |
if ($$contref =~ s/((.+\n)+)\s+(.*)//) { |
107 |
$$weighted_str .= "\x7f1\x7f$1\x7f/1\x7f\n" if defined $1; |
108 |
|
109 |
# Get the title. |
110 |
my $title = $3 if defined $3; |
111 |
$fields->{'title'} = $title; |
112 |
|
113 |
my $weight = $conf::Weight{'html'}->{'title'}; |
114 |
$$weighted_str .= "\x7f$weight\x7f$title\x7f/$weight\x7f\n"; |
115 |
} |
116 |
|
117 |
# Get Summary or Introduction and put it at the beginning |
118 |
# for summarization. |
119 |
# $$contref =~ s/\A(.+?^(\d+\.\s*)?(Abstract|Introduction)\n\n)//ims; |
120 |
# $$contref =~ s/(^[\w\.\s]*(?:Abstract|Introduction|Scope|概要|要約|(?:はじ|始|初)めに|導入|序論|摘要|梗概|イントロダクション|適用範囲))//im; |
121 |
# $$contref =~ s/([\s\S]+^(\d+\.\s*)?(Abstract|Introduction)\n\n)//im; |
122 |
$$contref =~ s/([\s\S]+^[\w\.\s]*?(?:Abstract|Introduction|Scope|概要|要約|摘要|梗概|(?:はじ|始|初)めに|導入|序論|イントロダクション|適用範囲).*\n\n)//im; |
123 |
$$weighted_str .= "\x7f1\x7f$1\x7f/1\x7f\n" if defined $1; |
124 |
} |
125 |
|
126 |
1; |