3 # Copyright (C) 1989-2018 Free Software Foundation, Inc.
5 # This file is part of groff.
7 # groff is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # runs groff in safe mode, that seems to be the default
22 # installation now. That means that I have to fix all nice
23 # features outside groff. Sigh.
24 # I do agree however that the previous way opened a whole bunch
28 # check for -x and remove it
29 if (grep(/^-x$/, @ARGV)) {
31 @ARGV = grep(!/^-x$/, @ARGV);
34 # mmroff should always have -mm, but not twice
35 @ARGV = grep(!/^-mm$/, @ARGV);
36 my $check_macro = "groff -rRef=1 -z -mm @ARGV";
37 my $run_macro = "groff -mm @ARGV";
39 my (%cur, $rfilename, $max_height, $imacro, $max_width, @out, @indi);
40 open(MACRO, "$check_macro 2>&1 |") || die "run $check_macro:$!";
42 if (m#^\.\\" Rfilename: (\S+)#) {
43 # remove all directories just to be more secure
44 ($rfilename = $1) =~ s#.*/##;
47 if (m#^\.\\" Imacro: (\S+)#) {
48 # remove all directories just to be more secure
49 ($imacro = $1) =~ s#.*/##;
52 if (m#^\.\\" Index: (\S+)#) {
53 # remove all directories just to be more secure
56 &print_index($f, \@indi, $imacro);
62 if (($x) = m#^\.\\" IND (.+)#) {
64 my @x = split(/\t/, $x);
66 push(@indi, join("\t", @x));
69 if (m#^\.\\" PIC id (\d+)#) {
73 if (m#^\.\\" PIC file (\S+)#) {
78 if (m#^\.\\" PIC (\w+)\s+(\S+)#) {
79 eval "\$cur{'$1'} = '$2'";
89 push(@out, ".nr pict*max-height $max_height\n") if defined $max_height;
90 push(@out, ".nr pict*max-width $max_width\n") if defined $max_width;
92 open(OUT, ">$rfilename") || "create $rfilename:$!";
93 print OUT '.\" references', "\n";
102 exit system($run_macro);
105 my ($f, $ind, $macro) = @_;
107 open(OUT, ">$f") || "create $f:$!";
109 for $i (sort @$ind) {
111 $i = '.'.$macro.' "'.join('" "', split(/\t/, $i)).'"';
121 my $w = abs($cur{'llx'}-$cur{'urx'});
122 my $h = abs($cur{'lly'}-$cur{'ury'});
123 $max_width = $w if $w > $max_width;
124 $max_height = $h if $h > $max_height;
127 push(@out, ".ds pict*file!$id $f\n");
128 push(@out, ".ds pict*id!$f $id\n");
129 push(@out, ".nr pict*llx!$id $cur{'llx'}\n");
130 push(@out, ".nr pict*lly!$id $cur{'lly'}\n");
131 push(@out, ".nr pict*urx!$id $cur{'urx'}\n");
132 push(@out, ".nr pict*ury!$id $cur{'ury'}\n");
133 push(@out, ".nr pict*w!$id $w\n");
134 push(@out, ".nr pict*h!$id $h\n");
141 unless (open(IN, $f)) {
142 print STDERR "Warning: Postscript file $f:$!";
146 if (/^%%BoundingBox:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
158 ########################################################################