3 # Copyright (C) 1989, 2005
4 # Free Software Foundation, Inc.
6 # This file is part of groff.
8 # groff is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free
10 # Software Foundation; either version 2, or (at your option) any later
13 # groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 # You should have received a copy of the GNU General Public License along
19 # with groff; see the file COPYING. If not, write to the Free Software
20 # Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
23 # runs groff in safe mode, that seems to be the default
24 # installation now. That means that I have to fix all nice
25 # features outside groff. Sigh.
26 # I do agree however that the previous way opened a whole bunch
30 # check for -x and remove it
31 if (grep(/^-x$/, @ARGV)) {
33 @ARGV = grep(!/^-x$/, @ARGV);
36 # mmroff should always have -mm, but not twice
37 @ARGV = grep(!/^-mm$/, @ARGV);
38 my $check_macro = "groff -rRef=1 -z -mm @ARGV";
39 my $run_macro = "groff -mm @ARGV";
41 my (%cur, $rfilename, $max_height, $imacro, $max_width, @out, @indi);
42 open(MACRO
, "$check_macro 2>&1 |") || die "run $check_macro:$!";
44 if (m
#^\.\\" Rfilename: (\S+)#) {
45 # remove all directories just to be more secure
46 ($rfilename = $1) =~ s
#.*/##;
49 if (m
#^\.\\" Imacro: (\S+)#) {
50 # remove all directories just to be more secure
51 ($imacro = $1) =~ s
#.*/##;
54 if (m
#^\.\\" Index: (\S+)#) {
55 # remove all directories just to be more secure
58 &print_index
($f, \
@indi, $imacro);
64 if (($x) = m
#^\.\\" IND (.+)#) {
66 my @x = split(/\t/, $x);
68 push(@indi, join("\t", @x));
71 if (m
#^\.\\" PIC id (\d+)#) {
75 if (m
#^\.\\" PIC file (\S+)#) {
80 if (m
#^\.\\" PIC (\w+)\s+(\S+)#) {
81 eval "\$cur{'$1'} = '$2'";
91 push(@out, ".nr pict*max-height $max_height\n") if defined $max_height;
92 push(@out, ".nr pict*max-width $max_width\n") if defined $max_width;
94 open(OUT
, ">$rfilename") || "create $rfilename:$!";
95 print OUT
'.\" references', "\n";
104 exit system($run_macro);
107 my ($f, $ind, $macro) = @_;
109 open(OUT
, ">$f") || "create $f:$!";
111 for $i (sort @
$ind) {
113 $i = '.'.$macro.' "'.join('" "', split(/\t/, $i)).'"';
123 my $w = abs($cur{'llx'}-$cur{'urx'});
124 my $h = abs($cur{'lly'}-$cur{'ury'});
125 $max_width = $w if $w > $max_width;
126 $max_height = $h if $h > $max_height;
129 push(@out, ".ds pict*file!$id $f\n");
130 push(@out, ".ds pict*id!$f $id\n");
131 push(@out, ".nr pict*llx!$id $cur{'llx'}\n");
132 push(@out, ".nr pict*lly!$id $cur{'lly'}\n");
133 push(@out, ".nr pict*urx!$id $cur{'urx'}\n");
134 push(@out, ".nr pict*ury!$id $cur{'ury'}\n");
135 push(@out, ".nr pict*w!$id $w\n");
136 push(@out, ".nr pict*h!$id $h\n");
143 unless (open(IN
, $f)) {
144 print STDERR
"Warning: Postscript file $f:$!";
148 if (/^%%BoundingBox:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {