From: bg@dymaxion.ns.ca
Newsgroups: comp.os.vms,vmsnet.sources.d
Subject: Utility-Log session escape sequence filter
Date: 22 Jan 93 17:10:50 AST
Organization: Dymaxion Research Limited, NS, Canada

Freebie utility follows.

Here's what should be a fairly common problem.  Many packages log
sessions.  Few of them filter ANSI escape sequences so that the logs
may be printed.  Non-DEC printers are particularly awful at printing
such logs.  Many non-DEC printers do unpredictable things with the
escape sequences.  Some simply refuse to print further until someone
manually clears each invalid sequence using front-panel buttons. 
Manually editing the logs is cumbersome.

I'd like to see how people handle this situation.  I am aware of PHOTO
and its control-sequence filtering capability, but PHOTO cannot be
used in all situations (e.g. I don't believe it handles SET HOST
sessions).

Here is my first attempt at a solution which is written in a non-DEC
supported language, GAWK (GNU's version of Unix Awk for VMS).  I have
found this utility to be useful for converting logged sessions of
Digital's ESTORE Electronic Store service.  My co-worker is in the
process of checking to see if it is robust enough to also log DSIN
sessions.

To run it, you need GAWK (available at several ftp sites).  Type:

gawk -f unescape inputfile >outputfile

Ben.
--
#======
#======
#
# Procedure- UnEscape.Awk by B. Armstrong 22-Jan-93
#
# Inputs-
#
#	A logged DEC VT-xxx series terminal session.
#
# Outputs-
#
#	Filtered terminal session suitable for printing
#	on non-DEC devices.
#
#======
#======
BEGIN	{blank=0;

	 # CSI introduced escape sequences ending with the
	 # terminators listed below are considered to be
	 # newlines:
	 csinewlineseq="\033\\[[^a-zA-Z]*[HKm]";

	 # All other CSI introduced escape sequences:
	 # - matches a leading CSI followed by zero or more
	 #   non-alpha characters terminated by an alpha
	 #   character
	 csiseq="\033\\[[^a-zA-Z]*[a-zA-Z]";

	 # List all multi-character escape sequences here separated
	 # with alternation characters (|).  Any single character
	 # after an escape is considered to be part of an escape
	 # sequence (matches "\033.").
	 escapeseqs="\033( F|.)";

	 # The following control characters are considered newlines:
	 newlinechars="[\013-\015]";

	 # All other control characters (except tabs and newlines)
	 # and all eight-bit characters are considered invisible.
	 invisiblechars="[\000-\010\016-\037\177-\377]";
	}

# Default rule:
#   Perform escape sequnce/control character substitution
#   on all lines.
	{gsub(csinewlineseq,"\012",$0);
	 gsub(csiseq,"",$0);
	 gsub(escapeseqs,"",$0);
	 gsub(newlinechars,"\012",$0);
	 gsub(invisiblechars,"",$0);

	 # Split line delimited with newlines into separate
	 # lines.
	 n=split($0,line,"\012");

	 for (i=1;i<=n;i++) {
	   # Multiple consecutive newlines are considered
	   # to be a single blank line.
	   if (line[i]=="") {
	     if (blank==0) {
	       print line[i];
	       blank=1;
	     }
	   }
           else {
	     blank=0;
 	     print line[i];
	   }
	 }

	}

--
Ben Armstrong, Software Development                  bus: (902)422-1973
Dymaxion Research Ltd.,                              fax: (902)421-1267
Halifax, Nova Scotia, Canada B3J 1R2            Internet: bg@dymaxion.ns.ca