3 # roff2* - transform roff files into other formats
5 # Source file position: <groff-source>/contrib/groffer/roff2.pl
6 # Installed position: <prefix>/bin/roff2*
8 # Copyright (C) 2006-2014 Free Software Foundation, Inc.
9 # Written by Bernd Warken <groff-bernd.warken-72@web.de>.
11 # This file is part of `groffer', which is part of `groff'.
13 # `groff' is free software; you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
18 # `groff' is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see
25 # <http://www.gnu.org/licenses/gpl-2.0.html>.
27 ########################################################################
35 # temporary dir and files
36 use File::Temp qw/ tempfile /;
38 my $Dev_Null = File::Spec->devnull();
43 ($v, $d, $Name) = File::Spec->splitpath($0);
44 die "wrong program name: $Name;"
45 if $Name !~ /^roff2[a-z]/;
50 my $Groff_Version = `groff --version 2>$Dev_Null`;
51 die "$Name error: groff does not work;" if $?;
52 my $Groffer_Version = `groffer --version 2>$Dev_Null`;
53 my $Has_Groffer = ! $?;
59 if ($_ eq '-v' || '--version' =~ m|^$_|) {
60 print $Name, ' in ', $Groffer_Version;
63 if ($_ eq '-h' || '--help' =~ m|^$_|) {
64 &usage_with_groffer();
68 system('groffer', '--to-stdout', "--$Mode", @ARGV);
86 if ($_ eq '-v' || '--version' =~ m|^$_|) {
87 print $Name, ' in ', $Groff_Version;
90 if ($_ eq '-h' || '--help' =~ m|^$_|) {
91 &usage_without_groffer();
103 print STDERR "$_ is not an existing, readable file.\n";
107 @filespec = ('-') unless @filespec;
109 foreach (@filespec) {
118 foreach ($ENV{'GROFF_TMPDIR'}, $ENV{'TMPDIR'}, $ENV{'TMP'},
119 $ENV{'TEMP'}, $ENV{'TEMPDIR'},
120 File::Spec->catfile($ENV{'HOME'}, 'tmp')) {
121 if ($_ && -d $_ && -w $_) {
126 my $template = $Name . '_XXXX';
129 ($fh, $stdin) = tempfile($template, UNLINK => 1, DIR => $tempdir) ||
130 die "$Name: could not create temporary file;";
132 ($fh, $stdin) = tempfile($template, UNLINK => 1) ||
133 die "$Name: could not create temporary file;";
136 print $fh $_ foreach <STDIN>;
138 foreach (@filespec) {
139 $_ = $stdin if $_ eq '-';
144 my $groff_options = "-T$Mode";
145 $groff_options = '-TX75-12 -Z' if $Mode eq 'x';
146 $groff_options = '-Tlatin1' if $Mode eq 'text';
147 if ($Mode eq 'pdf') {
149 my @path = File::Spec->path();
151 my $file = File::Spec->catfile($_, 'ps2pdf');
152 if (-f $file && -x $file) {
159 my $file = File::Spec->catfile($_, 'gs');
160 if (-f $file && -x $file) {
161 $ps2pdf = $file . ' -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite ' .
162 '-sOutputFile=- -c save pop -f -';
167 $grog = `grog -Tps @filespec`;
169 system("$grog | $ps2pdf");
172 $grog = `grog $groff_options @filespec`;
179 my $error_no_groffer;
180 sub error_no_groffer {
181 return 1 if $error_no_groffer;
182 $error_no_groffer = 1;
183 print STDERR "$Name: groffer is not available.\n";
186 my $error_no_options;
187 sub error_no_options {
188 return 1 if $error_no_options;
189 $error_no_groffer = 1;
190 print STDERR "$Name: groffer options are not allowed.\n";
193 sub usage_with_groffer {
195 usage: $Name [option]... [--] [filespec]...
197 -h | --help print usage information
198 -v | --version print version information
200 All other options are arbitrary options of `groffer'; the options
201 override the behavior of this program.
203 filespec's are the same as in `groffer': either the names of existing,
204 readable files or `-' for standard input or a search pattern for man
205 pages. No `filespec' assumes standard input automatically.
209 sub usage_without_groffer {
211 usage: $Name [option]... [--] [filespec]...
213 -h | --help print usage information
214 -v | --version print version information
216 No other options are allowed because `groffer' is not available.
218 The only `filespec's allowed are the names of existing, readable files
219 or `-' for standard input. No `filespec' assumes standard input
226 ########################################################################