3 # Copyright (C) 1989, 2005, 2009
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 3 of the License, or
11 # (at your option) any later version.
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
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # runs groff in safe mode, that seems to be the default
23 # installation now. That means that I have to fix all nice
24 # features outside groff. Sigh.
25 # I do agree however that the previous way opened a whole bunch
29 # check for -x and remove it
30 if (grep(/^-x$/, @ARGV)) {
32 @ARGV = grep(!/^-x$/, @ARGV);
35 # mmroff should always have -mm, but not twice
36 @ARGV = grep(!/^-mm$/, @ARGV);
37 my $check_macro = "groff -rRef=1 -z -mm @ARGV";
38 my $run_macro = "groff -mm @ARGV";
40 my (%cur, $rfilename, $max_height, $imacro, $max_width, @out, @indi);
41 open(MACRO, "$check_macro 2>&1 |") || die "run $check_macro:$!";
43 if (m#^\.\\" Rfilename: (\S+)#) {
44 # remove all directories just to be more secure
45 ($rfilename = $1) =~ s#.*/##;
48 if (m#^\.\\" Imacro: (\S+)#) {
49 # remove all directories just to be more secure
50 ($imacro = $1) =~ s#.*/##;
53 if (m#^\.\\" Index: (\S+)#) {
54 # remove all directories just to be more secure
57 &print_index($f, \@indi, $imacro);
63 if (($x) = m#^\.\\" IND (.+)#) {
65 my @x = split(/\t/, $x);
67 push(@indi, join("\t", @x));
70 if (m#^\.\\" PIC id (\d+)#) {
74 if (m#^\.\\" PIC file (\S+)#) {
79 if (m#^\.\\" PIC (\w+)\s+(\S+)#) {
80 eval "\$cur{'$1'} = '$2'";
90 push(@out, ".nr pict*max-height $max_height\n") if defined $max_height;
91 push(@out, ".nr pict*max-width $max_width\n") if defined $max_width;
93 open(OUT, ">$rfilename") || "create $rfilename:$!";
94 print OUT '.\" references', "\n";
103 exit system($run_macro);
106 my ($f, $ind, $macro) = @_;
108 open(OUT, ">$f") || "create $f:$!";
110 for $i (sort @$ind) {
112 $i = '.'.$macro.' "'.join('" "', split(/\t/, $i)).'"';
122 my $w = abs($cur{'llx'}-$cur{'urx'});
123 my $h = abs($cur{'lly'}-$cur{'ury'});
124 $max_width = $w if $w > $max_width;
125 $max_height = $h if $h > $max_height;
128 push(@out, ".ds pict*file!$id $f\n");
129 push(@out, ".ds pict*id!$f $id\n");
130 push(@out, ".nr pict*llx!$id $cur{'llx'}\n");
131 push(@out, ".nr pict*lly!$id $cur{'lly'}\n");
132 push(@out, ".nr pict*urx!$id $cur{'urx'}\n");
133 push(@out, ".nr pict*ury!$id $cur{'ury'}\n");
134 push(@out, ".nr pict*w!$id $w\n");
135 push(@out, ".nr pict*h!$id $h\n");
142 unless (open(IN, $f)) {
143 print STDERR "Warning: Postscript file $f:$!";
147 if (/^%%BoundingBox:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {