[net.sources] script post processor

perlman@wanginst.UUCP (Gary Perlman) (01/16/85)

On our UNIX, the script command keeps all errors and corrections
in the typescript.  This looks bad on the lineprinter, so here
is a program that cleans up typescripts.

#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	postscript.1
#	postscript.c
# This archive created: Wed Jan 16 00:00:29 1985
# By:	Gary Perlman (Wang Institute, Tyngsboro, MA 01879 USA)
echo shar: extracting postscript.1 '(820 characters)'
sed 's/^X//' << \SHAR_EOF > postscript.1
X.TH POSTSCRIPT 1WI "January 16, 1985"
X.SH NAME
Xpostscript \- remove errors from script record of session
X.SH SYNOPSIS
X.B postscript
X[script file]
X.SH DESCRIPTION
X.I postscript
Xis a postprocessor for transcripts created with the
X.I script
Xcommand.
XScripts created with
X.I script
Xcontain all the text of a session,
Xincluding corrections.
XThese corrections make hardcopy printing of scripts a mess,
Xso this program is meant to remove only what you don't want.
XOptionally, the name of the script file can be supplied,
Xor the file ``typescript'' is used;
Xthis is the same convention as used by
X.I script.
X.SH EXAMPLE
X$ script
X ...
X$ postscript | lpr
X.SH AUTHOR
XGary Perlman
X.SH BUGS
X.I postscript
Xmay only work with the 4.2 version of UNIX.
XIt may not work well if you correct characters with
Xsomething other than backspace.
SHAR_EOF
if test 820 -ne "`wc -c postscript.1`"
then
echo shar: error transmitting postscript.1 '(should have been 820 characters)'
fi
echo shar: extracting postscript.c '(921 characters)'
sed 's/^X//' << \SHAR_EOF > postscript.c
X#include <stdio.h>
X
X#define	BS  8    /* back space */
X#define	CR 13    /* carriage return */
X
Xmain (argc, argv) char **argv;
X	{
X	char	inline[BUFSIZ];
X	char	outline[BUFSIZ];
X	char	*iptr, *optr;
X	FILE	*ioptr;
X	int 	linekill;
X	char	*typescript = argc > 1 ? argv[1] : "typescript";
X	if (ioptr = fopen (typescript, "r"))
X		{
X		while (fgets (iptr = inline, BUFSIZ, ioptr))
X			{
X			linekill = 0;
X			for (optr = outline; *iptr; iptr++)
X				switch (*iptr)
X					{
X					case '^': /* ignore control char */
X						iptr++;
X						if (*iptr == '?') linekill++;
X						break;
X					case BS:
X						if (optr > outline) optr--;
X						break;
X					case CR: /* ^M */
X					case 4:  /* ^D */
X						break;
X					default:
X						*optr++ = *iptr;
X						break;
X					}
X			if (!linekill)
X				{
X				*optr = '\0';
X				fputs (outline, stdout);
X				}
X			}
X		fclose (ioptr);
X		}
X	else
X		fprintf (stderr, "%s: can't open script '%s'\n", argv[0], typescript);
X	}
SHAR_EOF
if test 921 -ne "`wc -c postscript.c`"
then
echo shar: error transmitting postscript.c '(should have been 921 characters)'
fi
#	End of shell archive
exit 0