--- sgmlfmt/sgmlfmt.pl.orig	Sat Feb 21 22:48:24 1998
+++ sgmlfmt/sgmlfmt.pl	Mon Apr 13 11:58:14 1998
@@ -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 <jfieber@freebsd.org> for the FreeBSD documentation
@@ -68,13 +69,25 @@
 $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 <doctype>] -f <format> [-i <namea> ...] [-links]\n";
-    print "    [-e encoding] [-hdr file] [-ftr file] file\n";
+    print "    [-e encoding] [-hdr file] [-ftr file] [-b] file\n";
     print "where <doctype> is one of: linuxdoc (default), docbook.\n";
     print "and <format> is one of: ascii, html, koi8-r, latin1, ps, roff\n";
 }
@@ -119,6 +132,7 @@
     if ($defines ne "") {
 	$defines = "-i $defines";
     }
+
     open($ifhandle, "$sgmls $defines $decl $file | " . 
     	"sed -e 's/^f\<OSFILE\>/f/' | " .
     	"$instant -Dfilename=$fileroot $instantopts " .
@@ -138,6 +152,7 @@
     }
     close(infile);
     close(outfile);
+    &exitiferror($?);
 }
 
 #
@@ -155,16 +170,22 @@
     }
     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 @@
 	}
     }
     close(bar);
+    close(foo);
+    &exitiferror($?);
 
     open(foofile, $tmpfile);
     &html2html(foofile, "boo");
@@ -623,6 +646,7 @@
     }
     close(infile);
     close(outfile);
+    &exitiferror($?);
 }
 
 # extlink
@@ -655,7 +679,8 @@
 
 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 @@
     	$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 @@
 	&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", "");
