3 # pdfmom : Frontend to run groff -mom to produce PDFs
4 # Deri James : Friday 16 Mar 2012
7 # Copyright (C) 2012-2018 Free Software Foundation, Inc.
8 # Written by Deri James <deri@chuzzlewit.demon.co.uk>
10 # This file is part of groff.
12 # groff is free software; you can redistribute it and/or modify it under
13 # the terms of the GNU General Public License as published by the Free
14 # Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # groff is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 use File::Temp qw/tempfile/;
31 my $RT_SEP='@RT_SEP@';
33 $ENV{PATH}=$ENV{GROFF_BIN_PATH}.$RT_SEP.$ENV{PATH} if exists($ENV{GROFF_BIN_PATH});
34 $ENV{TMPDIR}=$ENV{GROFF_TMPDIR} if exists($ENV{GROFF_TMPDIR});
40 if (substr($c,0,2) eq '-T')
52 elsif (substr($c,0,2) eq '-K')
65 elsif (substr($c,0,2) eq '-k')
70 elsif ($c eq '-z' or $c eq '-Z')
77 print "GNU pdfmom (groff) version @VERSION@\n";
80 elsif (substr($c,0,1) eq '-')
85 push(@cmd,"'".(shift)."'") if length($c)==2 and index('dDfFIKLmMnoPrwW',substr($c,-1)) >= 0;
100 $readstdin=0 if $readstdin == 1;
106 my $cmdstring=' '.join(' ',@cmd).' ';
110 my ($fh,$tmpfn)=tempfile('pdfmom-XXXXX', UNLINK=>1);
119 $cmdstring=~s/ - / $tmpfn / if $readstdin == 2;
120 $cmdstring.=" $tmpfn " if $readstdin == 1;
125 system("groff -Tpdf -dLABEL.REFS=1 -mom -z $cmdstring 2>&1 | LC_ALL=C grep '^\\. *ds' | groff -Tpdf -dPDF.EXPORT=1 -dLABEL.REFS=1 -mom -z - $cmdstring 2>&1 | LC_ALL=C grep '^\\. *ds' | groff -Tpdf -mom $preconv - $cmdstring");
129 system("groff -Tpdf -dLABEL.REFS=1 -mom -z $cmdstring 2>&1 | LC_ALL=C grep '^\\. *ds' | pdfroff -mpdfmark -mom --no-toc - $preconv $cmdstring");
131 elsif ($dev eq '-z') # pseudo dev - just compile for warnings
133 system("groff -Tpdf -mom -z $cmdstring");
135 elsif ($dev eq '-Z') # pseudo dev - produce troff output
137 system("groff -Tpdf -mom -Z $cmdstring");
141 print STDERR "Not compatible with device '-T $dev'\n";