From ac82fcdd23907ac40b0024921cfcbd3072b25c6c Mon Sep 17 00:00:00 2001 From: John Fieber Date: Sun, 29 Sep 1996 19:42:51 +0000 Subject: [PATCH] Add a signal handler to clean up files if an INT, HUP, or QUIT is received. --- usr.bin/sgmlfmt/sgmlfmt.pl | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/usr.bin/sgmlfmt/sgmlfmt.pl b/usr.bin/sgmlfmt/sgmlfmt.pl index 383bb85a7b38..e9ea98245ea0 100755 --- a/usr.bin/sgmlfmt/sgmlfmt.pl +++ b/usr.bin/sgmlfmt/sgmlfmt.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# $Id: sgmlfmt.pl,v 1.13 1996/09/29 17:34:05 jfieber Exp $ +# $Id: sgmlfmt.pl,v 1.14 1996/09/29 18:27:12 jfieber Exp $ # Copyright (C) 1996 # John R. Fieber. All rights reserved. @@ -50,6 +50,30 @@ $dtdbase = "/usr/share/sgml/FreeBSD"; $dtd = "$dtdbase/linuxdoc.dtd"; $decl = "$dtdbase/linuxdoc.dcl"; +# +# Things to clean up if we exit abnormally +# + +@cleanfiles = (); + +# +# Interrupt handler, remove scratch files. +# + +sub sighandler { + local($sig) = @_; + unlink @cleanfiles; + exit(1); +} + +$SIG{'HUP'} = 'sighandler'; +$SIG{'INT'} = 'sighandler'; +$SIG{'QUIT'} = 'sighandler'; + +# +# Display a usage message. +# + sub usage { print "Usage:\n"; print "sgmlfmt -f [-i ...] [-links] [-ssi] file\n"; @@ -105,6 +129,7 @@ sub sgmlparse { # sub gen_roff { + @cleanfiles = (@cleanfiles, "${fileroot}.roff"); open (outfile, ">$fileroot.roff"); &sgmlparse(infile, "roff"); while () { @@ -120,6 +145,8 @@ sub gen_roff { sub do_groff { local($driver, $postproc) = @_; + @cleanfiles = (@cleanfiles, "${fileroot}.trf", "${fileroot}.tmp", + "${fileroot}.qrf", "${fileroot}.${driver}"); open (outfile, ">$fileroot.trf"); &sgmlparse(infile, "roff"); while () { @@ -144,6 +171,7 @@ sub do_groff { # sub gen_latex { + @cleanfiles = (@cleanfiles, "${fileroot}.latex"); open(outfile, ">$fileroot.latex"); &sgmlparse(infile, "latex"); while () { @@ -205,6 +233,8 @@ sub gen_html { local($i, $sl); $tmpfile = "/tmp/sgmlf.$$"; + @cleanfiles = (@cleanfiles, "$tmpfile", "${fileroot}.html", + "${fileroot}_toc.html", "${fileroot}.ln"); open(bar, ">$tmpfile"); # print STDERR "(Pass 1..."; &sgmlparse(foo, "html"); @@ -237,6 +267,7 @@ sub gen_html { if ($sl <= $maxlevel) { $filecount++; $st_ol[$sc] = $sl; + @cleanfiles = (@cleanfiles, "${fileroot}${filecount}.html"); } else { $st_ol[$sc] = $maxlevel;