summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjfieber <jfieber@FreeBSD.org>1996-09-29 19:42:51 +0000
committerjfieber <jfieber@FreeBSD.org>1996-09-29 19:42:51 +0000
commit4c255f1f69ca9c6ad57c01a58805d760b83b75ac (patch)
treed06ef4c0a1a79e84b1b1ae8db497eca78cba4411
parent3d1181fd338e3fbe84c2c4723620b040adb01bb8 (diff)
downloadFreeBSD-src-4c255f1f69ca9c6ad57c01a58805d760b83b75ac.zip
FreeBSD-src-4c255f1f69ca9c6ad57c01a58805d760b83b75ac.tar.gz
Add a signal handler to clean up files if an INT, HUP, or QUIT
is received.
-rwxr-xr-xusr.bin/sgmlfmt/sgmlfmt.pl33
1 files changed, 32 insertions, 1 deletions
diff --git a/usr.bin/sgmlfmt/sgmlfmt.pl b/usr.bin/sgmlfmt/sgmlfmt.pl
index 383bb85..e9ea982 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 <format> [-i <namea> ...] [-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 (<infile>) {
@@ -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 (<infile>) {
@@ -144,6 +171,7 @@ sub do_groff {
#
sub gen_latex {
+ @cleanfiles = (@cleanfiles, "${fileroot}.latex");
open(outfile, ">$fileroot.latex");
&sgmlparse(infile, "latex");
while (<infile>) {
@@ -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;
OpenPOWER on IntegriCloud