home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / vms / 21782 < prev    next >
Encoding:
Text File  |  1993-01-27  |  3.4 KB  |  116 lines

  1. Xref: sparky comp.os.vms:21782 vmsnet.sources.d:785
  2. Path: sparky!uunet!newsflash.concordia.ca!nstn.ns.ca!dymaxion.ns.ca!bg
  3. From: bg@dymaxion.ns.ca
  4. Newsgroups: comp.os.vms,vmsnet.sources.d
  5. Subject: Utility-Log session escape sequence filter
  6. Message-ID: <1993Jan22.171051.581@dymaxion.ns.ca>
  7. Date: 22 Jan 93 17:10:50 AST
  8. Organization: Dymaxion Research Limited, NS, Canada
  9. Lines: 105
  10.  
  11. Freebie utility follows.
  12.  
  13. Here's what should be a fairly common problem.  Many packages log
  14. sessions.  Few of them filter ANSI escape sequences so that the logs
  15. may be printed.  Non-DEC printers are particularly awful at printing
  16. such logs.  Many non-DEC printers do unpredictable things with the
  17. escape sequences.  Some simply refuse to print further until someone
  18. manually clears each invalid sequence using front-panel buttons. 
  19. Manually editing the logs is cumbersome.
  20.  
  21. I'd like to see how people handle this situation.  I am aware of PHOTO
  22. and its control-sequence filtering capability, but PHOTO cannot be
  23. used in all situations (e.g. I don't believe it handles SET HOST
  24. sessions).
  25.  
  26. Here is my first attempt at a solution which is written in a non-DEC
  27. supported language, GAWK (GNU's version of Unix Awk for VMS).  I have
  28. found this utility to be useful for converting logged sessions of
  29. Digital's ESTORE Electronic Store service.  My co-worker is in the
  30. process of checking to see if it is robust enough to also log DSIN
  31. sessions.
  32.  
  33. To run it, you need GAWK (available at several ftp sites).  Type:
  34.  
  35. gawk -f unescape inputfile >outputfile
  36.  
  37. Ben.
  38. --
  39. #======
  40. #======
  41. #
  42. # Procedure- UnEscape.Awk by B. Armstrong 22-Jan-93
  43. #
  44. # Inputs-
  45. #
  46. #    A logged DEC VT-xxx series terminal session.
  47. #
  48. # Outputs-
  49. #
  50. #    Filtered terminal session suitable for printing
  51. #    on non-DEC devices.
  52. #
  53. #======
  54. #======
  55. BEGIN    {blank=0;
  56.  
  57.      # CSI introduced escape sequences ending with the
  58.      # terminators listed below are considered to be
  59.      # newlines:
  60.      csinewlineseq="\033\\[[^a-zA-Z]*[HKm]";
  61.  
  62.      # All other CSI introduced escape sequences:
  63.      # - matches a leading CSI followed by zero or more
  64.      #   non-alpha characters terminated by an alpha
  65.      #   character
  66.      csiseq="\033\\[[^a-zA-Z]*[a-zA-Z]";
  67.  
  68.      # List all multi-character escape sequences here separated
  69.      # with alternation characters (|).  Any single character
  70.      # after an escape is considered to be part of an escape
  71.      # sequence (matches "\033.").
  72.      escapeseqs="\033( F|.)";
  73.  
  74.      # The following control characters are considered newlines:
  75.      newlinechars="[\013-\015]";
  76.  
  77.      # All other control characters (except tabs and newlines)
  78.      # and all eight-bit characters are considered invisible.
  79.      invisiblechars="[\000-\010\016-\037\177-\377]";
  80.     }
  81.  
  82. # Default rule:
  83. #   Perform escape sequnce/control character substitution
  84. #   on all lines.
  85.     {gsub(csinewlineseq,"\012",$0);
  86.      gsub(csiseq,"",$0);
  87.      gsub(escapeseqs,"",$0);
  88.      gsub(newlinechars,"\012",$0);
  89.      gsub(invisiblechars,"",$0);
  90.  
  91.      # Split line delimited with newlines into separate
  92.      # lines.
  93.      n=split($0,line,"\012");
  94.  
  95.      for (i=1;i<=n;i++) {
  96.        # Multiple consecutive newlines are considered
  97.        # to be a single blank line.
  98.        if (line[i]=="") {
  99.          if (blank==0) {
  100.            print line[i];
  101.            blank=1;
  102.          }
  103.        }
  104.            else {
  105.          blank=0;
  106.           print line[i];
  107.        }
  108.      }
  109.  
  110.     }
  111.  
  112. --
  113. Ben Armstrong, Software Development                  bus: (902)422-1973
  114. Dymaxion Research Ltd.,                              fax: (902)421-1267
  115. Halifax, Nova Scotia, Canada B3J 1R2            Internet: bg@dymaxion.ns.ca
  116.