--- sgmlfmt/sgmlfmt.pl.orig Sat Feb 21 22:48:24 1998 +++ sgmlfmt/sgmlfmt.pl Sat Jun 10 02:22:37 2000 @@ -26,6 +26,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. +# $XFree86: doctools/sgmlformat/sgmlfmt/sgmlfmt.pl,v 1.4 1998/04/12 03:13:03 dawes Exp $ # Format an sgml document tagged according to the linuxdoc DTD. # by John Fieber for the FreeBSD documentation @@ -68,13 +69,25 @@ $SIG{'INT'} = 'sighandler'; $SIG{'QUIT'} = 'sighandler'; # +# Check if a command we've run returned an error status. If so, remove +# scratch files and exit. +# +sub exitiferror { + local($ret) = @_; + if ($ret >> 8 != 0) { + unlink @cleanfiles; + exit($ret >> 8); + } +} + +# # Display a usage message. # sub usage { print "Usage:\n"; print "sgmlfmt [-d ] -f [-i ...] [-links]\n"; - print " [-e encoding] [-hdr file] [-ftr file] file\n"; + print " [-e encoding] [-hdr file] [-ftr file] [-b] file\n"; print "where is one of: linuxdoc (default), docbook.\n"; print "and is one of: ascii, html, koi8-r, latin1, ps, roff\n"; } @@ -119,6 +132,7 @@ sub sgmlparse { if ($defines ne "") { $defines = "-i $defines"; } + open($ifhandle, "$sgmls $defines $decl $file | " . "sed -e 's/^f\/f/' | " . "$instant -Dfilename=$fileroot $instantopts " . @@ -138,6 +152,7 @@ sub gen_roff { } close(infile); close(outfile); + &exitiferror($?); } # @@ -155,16 +170,22 @@ sub do_groff { } close(infile); close(outfile); - system("groff -T ${driver} -t ${fileroot}.trf ${postproc} > ${fileroot}.${driver}"); + &exitiferror($?); + + system("groff -T ${driver} -t -M ${sgmldir}/tmac ${fileroot}.trf" . + " ${postproc} > ${fileroot}.${driver}"); + &exitiferror($?); # If foo.tmp has been created, then there are cross references # in the file and we need a second pass to resolve them correctly. if (stat("${fileroot}.tmp")) { - system("groff -T ${driver} -t ${fileroot}.trf ${postproc} > ${fileroot}.${driver}"); + system("groff -T ${driver} -t -M ${sgmldir}/tmac ${fileroot}.trf" . + " ${postproc} > ${fileroot}.${driver}"); unlink("${fileroot}.qrf"); } unlink("${fileroot}.trf"); + &exitiferror($?); } # @@ -303,6 +324,8 @@ sub gen_html { } } close(bar); + close(foo); + &exitiferror($?); open(foofile, $tmpfile); &html2html(foofile, "boo"); @@ -623,6 +646,7 @@ sub docbook_html { } close(infile); close(outfile); + &exitiferror($?); } # extlink @@ -655,7 +679,8 @@ sub extlink { sub main { # Check arguments - if (!&NGetOpt('d=s', 'f=s', 'links', 'i:s@', 'hdr=s', 'ftr=s', 'e=s')) { + if (!&NGetOpt('d=s', 'f=s', 'links', 'i:s@', 'hdr=s', 'ftr=s', 'e=s', + 'b')) { &usage; exit 1; } @@ -681,6 +706,12 @@ sub main { $decl = "-c " . $sgmldir . "/linuxdoc/catalog"; } + if ($opt_b) { + $colcmd = "col -b"; + } + else { + $colcmd = "col"; + } # Generate the output if ($opt_f eq 'html') { # Set the character encoding @@ -705,13 +736,13 @@ sub main { &gen_roff(); } elsif ($opt_f eq 'ascii') { - &do_groff("ascii", "| col"); + &do_groff("ascii", "| $colcmd"); } elsif ($opt_f eq 'latin1') { - &do_groff("latin1", "| col"); + &do_groff("latin1", "| $colcmd"); } elsif ($opt_f eq 'koi8-r') { - &do_groff("koi8-r", "| col"); + &do_groff("koi8-r", "| $colcmd"); } elsif ($opt_f eq 'ps') { &do_groff("ps", "");