4 # runs groff in safe mode, that seems to be the default
5 # installation now. That means that I have to fix all nice
6 # features outside groff. Sigh.
7 # I do agree however that the previous way opened a whole bunch
11 # check for -x and remove it
12 if (grep(/^-x$/, @ARGV)) {
14 @ARGV = grep(!/^-x$/, @ARGV);
17 # mmroff should always have -mm, but not twice
18 @ARGV = grep(!/^-mm$/, @ARGV);
19 my $check_macro = "groff -rRef=1 -z -mm @ARGV";
20 my $run_macro = "groff -mm @ARGV";
22 my (%cur, $rfilename, $max_height, $imacro, $max_width, @out, @indi);
23 open(MACRO
, "$check_macro 2>&1 |") || die "run $check_macro:$!";
25 if (m
#^\.\\" Rfilename: (\S+)#) {
26 # remove all directories just to be more secure
27 ($rfilename = $1) =~ s
#.*/##;
30 if (m
#^\.\\" Imacro: (\S+)#) {
31 # remove all directories just to be more secure
32 ($imacro = $1) =~ s
#.*/##;
35 if (m
#^\.\\" Index: (\S+)#) {
36 # remove all directories just to be more secure
39 &print_index
($f, \
@indi, $imacro);
45 if (($x) = m
#^\.\\" IND (.+)#) {
47 my @x = split(/\t/, $x);
49 push(@indi, join("\t", @x));
52 if (m
#^\.\\" PIC id (\d+)#) {
56 if (m
#^\.\\" PIC file (\S+)#) {
61 if (m
#^\.\\" PIC (\w+)\s+(\S+)#) {
62 eval "\$cur{'$1'} = '$2'";
72 push(@out, ".nr pict*max-height $max_height\n") if defined $max_height;
73 push(@out, ".nr pict*max-width $max_width\n") if defined $max_width;
75 open(OUT
, ">$rfilename") || "create $rfilename:$!";
76 print OUT
'.\" references', "\n";
85 exit system($run_macro);
88 my ($f, $ind, $macro) = @_;
90 open(OUT
, ">$f") || "create $f:$!";
94 $i = '.'.$macro.' "'.join('" "', split(/\t/, $i)).'"';
104 my $w = abs($cur{'llx'}-$cur{'urx'});
105 my $h = abs($cur{'lly'}-$cur{'ury'});
106 $max_width = $w if $w > $max_width;
107 $max_height = $h if $h > $max_height;
110 push(@out, ".ds pict*file!$id $f\n");
111 push(@out, ".ds pict*id!$f $id\n");
112 push(@out, ".nr pict*llx!$id $cur{'llx'}\n");
113 push(@out, ".nr pict*lly!$id $cur{'lly'}\n");
114 push(@out, ".nr pict*urx!$id $cur{'urx'}\n");
115 push(@out, ".nr pict*ury!$id $cur{'ury'}\n");
116 push(@out, ".nr pict*w!$id $w\n");
117 push(@out, ".nr pict*h!$id $h\n");
124 unless (open(IN
, $f)) {
125 print STDERR
"Warning: Postscript file $f:$!";
129 if (/^%%BoundingBox:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {