1 |
# |
2 |
# -*- Perl -*- |
3 |
# $Id: man.pl,v 1.26 2000/03/15 11:52:03 satoru 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 man; |
27 |
use strict; |
28 |
require 'util.pl'; |
29 |
require 'gfilter.pl'; |
30 |
|
31 |
my $roffpath = undef; |
32 |
my $roffargs = undef; |
33 |
|
34 |
sub mediatype() { |
35 |
return ('text/x-roff'); |
36 |
} |
37 |
|
38 |
sub status() { |
39 |
$roffpath = util::checkcmd('jgroff'); |
40 |
unless (defined $roffpath) { |
41 |
$roffpath = util::checkcmd('groff'); |
42 |
} |
43 |
unless (defined $roffpath) { |
44 |
$roffpath = util::checkcmd('nroff'); |
45 |
} |
46 |
unless (defined $roffpath) { |
47 |
return 'no'; |
48 |
} |
49 |
|
50 |
if (util::islang("ja") && $roffpath =~ /\bj?groff$/) { |
51 |
# Check wheter -Tnippon is valid. |
52 |
if (($mknmz::SYSTEM eq "MSWin32") || ($mknmz::SYSTEM eq "os2")){ |
53 |
`echo ''| $roffpath -Tnippon 1>nul 2>&1`; |
54 |
} else { |
55 |
`echo ''| $roffpath -Tnippon 1>/dev/null 2>&1`; |
56 |
} |
57 |
if ($? == 0) { |
58 |
$roffargs = '-Wall -Tnippon' ; |
59 |
} else { |
60 |
$roffargs = '-Wall -Tascii'; |
61 |
} |
62 |
# print "// $roffargs\n"; |
63 |
} elsif ($roffpath =~ /\bj?groff$/) { |
64 |
$roffargs = '-Tascii'; |
65 |
} elsif ($roffpath =~ /nroff$/) { |
66 |
$roffargs = ''; |
67 |
} else { |
68 |
die; |
69 |
} |
70 |
return 'yes'; |
71 |
} |
72 |
|
73 |
sub recursive() { |
74 |
return 0; |
75 |
} |
76 |
|
77 |
sub pre_codeconv() { |
78 |
return 0; |
79 |
} |
80 |
|
81 |
sub post_codeconv () { |
82 |
return 0; |
83 |
} |
84 |
|
85 |
sub add_magic ($) { |
86 |
return; |
87 |
} |
88 |
|
89 |
sub filter ($$$$$) { |
90 |
my ($orig_cfile, $cont, $weighted_str, $headings, $fields) |
91 |
= @_; |
92 |
my $cfile = defined $orig_cfile ? $$orig_cfile : ''; |
93 |
|
94 |
my $tmpfile = util::tmpnam('NMZ.man'); |
95 |
|
96 |
{ |
97 |
util::vprint("Processing man file ... (using '$roffpath -man $roffargs')\n"); |
98 |
my $fh = util::efopen("|$roffpath -man $roffargs > $tmpfile"); |
99 |
|
100 |
# Make groff output one paragraph per one line. |
101 |
# Thanks to Tatsuo SEKINE <tsekine@isoternet.org> for his suggestion. |
102 |
print $fh ".ll 100i\n"; |
103 |
|
104 |
print $fh $$cont; |
105 |
} |
106 |
{ |
107 |
my $fh = util::efopen("$tmpfile"); |
108 |
$$cont = util::readfile($fh); |
109 |
unlink($tmpfile); |
110 |
} |
111 |
|
112 |
codeconv::toeuc($cont); |
113 |
|
114 |
man_filter($cont, $weighted_str, $fields); |
115 |
|
116 |
gfilter::line_adjust_filter($cont); |
117 |
gfilter::line_adjust_filter($weighted_str); |
118 |
gfilter::white_space_adjust_filter($cont); |
119 |
gfilter::show_filter_debug_info($cont, $weighted_str, |
120 |
$fields, $headings); |
121 |
return undef; |
122 |
} |
123 |
|
124 |
# This is not perfect but works not bad. |
125 |
sub man_filter ($$$) { |
126 |
my ($contref, $weighted_str, $fields) = @_; |
127 |
my $name = ""; |
128 |
|
129 |
# processing like col -b (2byte character acceptable) |
130 |
$$contref =~ s/_\x08//g; |
131 |
$$contref =~ s/\x08{1,2}([\x20-\x7e]|[\xa1-\xfe]{2})//g; |
132 |
|
133 |
$$contref =~ s/^\s+//gs; |
134 |
|
135 |
$$contref =~ /^(.*?)\s*\S*$/m; |
136 |
my $title = "$1"; |
137 |
$fields->{'title'} = $title; |
138 |
my $weight = $conf::Weight{'html'}->{'title'}; |
139 |
$$weighted_str .= "\x7f$weight\x7f$title\x7f/$weight\x7f\n"; |
140 |
|
141 |
if ($$contref =~ /^(?:NAME|名前|名称)\s*\n(.*?)\n\n/ms) { |
142 |
$name = "$1::\n"; |
143 |
$weight = $conf::Weight{'html'}->{'h1'}; |
144 |
$$weighted_str .= "\x7f$weight\x7f$1\x7f/$weight\x7f\n"; |
145 |
} |
146 |
|
147 |
if ($$contref =~ |
148 |
s/\A(.+^(?:DESCRIPTION 解説|DESCRIPTIONS?|SHELL GRAMMAR|INTRODUCTION|【概要】|解説|説明|機能説明|基本機能説明)\s*\n)//ims) |
149 |
{ |
150 |
$$contref = $name . $$contref; |
151 |
$$weighted_str .= "\x7f1\x7f$1\x7f/1\x7f\n"; |
152 |
} |
153 |
} |
154 |
|
155 |
1; |