home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / stripansi2.lha / StripANSI2 / StripANSI.l < prev    next >
Encoding:
Lex Description  |  1994-01-26  |  2.9 KB  |  104 lines

  1. %{
  2. /*****************************************************************************
  3.  **
  4.  *        File:   StripANSI.l - Strip ANSI files of ANSI codes
  5.  **
  6.  *     Project:   JMA Utilities
  7.  *
  8.  *     Created:   Wednesday 26-Jan-94 00:24:02
  9.  *
  10.  *      Author:   Jon M. Armstrong
  11.  *                315 Dale Drive
  12.  *                Farmington, New York 14425
  13.  *
  14.  *                (c) Copyright 1994
  15.  *
  16.  *  Notes:
  17.  *
  18.  *   I'm tired of picking up text/documentation files that contain
  19.  *   ANSI escape codes and other helpful character sequences.
  20.  *   Personally,  I like using my favorite text editor, as opposed
  21.  *   to a 'More' or 'Less' reader.
  22.  *
  23.  *   This huge utility strips a few ANSI-ish sequences from any file.
  24.  *
  25.  *   This file, if you haven't guessed, is the source code for this
  26.  *   very complex utility :).
  27.  *
  28.  *   To rebuild this utility, try the following:
  29.  *
  30.  *     flex -8 StripANSI.l
  31.  *     gcc -o StripANSI2 -O2 -s lex.yy.c
  32.  *
  33.  *   I used flex version 2.3 and gcc version 2.3.3 to generate the
  34.  *   included Amiga executable.  The ixemul.library is probably
  35.  *   required to run this program.  If you have gcc for the Amiga,
  36.  *   you are likely to also have ixemul.library.  If you rebuild this
  37.  *   with another compiler, you may not have this restriction.
  38.  *
  39.  *   This archive contains at least one (1) sample file containing
  40.  *   character sequences that the utility will strip and a script
  41.  *   that shows how the utility is used to strip the file.  The
  42.  *   resulting output file is also included.
  43.  *
  44.  *   Usage: StripANSI2 < Input.file > Output.file
  45.  *
  46.  *   It almost took longer for me to type this short description
  47.  *   than it took to write the code.  I didn't use a formal ANSI
  48.  *   reference to write this, so I'm sure there are a few sequences
  49.  *   that aren't covered, as well as a few invalid sequences that
  50.  *   are covered.
  51.  *
  52.  *   Feel free to drop me a line, if you have any questions.
  53.  *   I try to listen in on the FIDO Amiga programming echo.
  54.  *
  55.  *   Have fun.
  56.  *
  57.  *    $Log: StripANSI.l,v $
  58.  *
  59.  *****************************************************************************/
  60.  
  61. static int lines=0;
  62. static int chars=0;
  63. static int kills=0;
  64. %}
  65.  
  66.  
  67. Digit       [0-9]
  68. Ps          [0-9;]*
  69. Pn          [0-9]*
  70. OverStrike  (.\b)
  71. ESC         (\x1b)
  72. CSI0        (\x9b)
  73. CSI         (({CSI0})|({ESC}\[))
  74. TMode1      ({Pn}[ ][@ACE])
  75. TMode2      (([?]?){Pn}([a-zA-Z@\`]|(\"q)|(!p)))
  76. TMode3      ({Pn}[;]{Pn}[frHR])
  77. TMode4      ({Pn}[;]{Pn}[ ][BDG])
  78. TMode5      ({Ps}[a-zA-Z])
  79. TMode6      ({Ps}[ ][FH])
  80. TermModes   ({TMode1}|{TMode2}|{TMode3}|{TMode4}|{TMode5}|{TMode6})
  81. ESCCODES    ([abcD-W78\\\]\^]|([#]{Digit}))
  82. CSICODES    ({TermModes})
  83. ANSI        ({OverStrike}|({CSI}{CSICODES})|({ESC}{ESCCODES}))
  84. NPrintable  ([^\n\t \-\xadA-Za-z0-9!@#$\%^&*()_+|=`,./<>/?;':"~{}\\\[\]])
  85.  
  86. %%
  87. {ANSI}          {kills++;}
  88. {NPrintable}    {kills++;}
  89.  
  90. "\n"{2,}    {printf("\n\n");chars+=2;lines+=2;}
  91. "\n"        {ECHO;chars++;lines++;}
  92. .        {ECHO;chars++;}
  93.  
  94. %%
  95. int yyerror(s)
  96. char *s ;
  97. {
  98. }
  99.  
  100. main()
  101. {
  102.   yylex();
  103. }
  104.