home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************\
- * StripANSI v1.0 *
- * *
- * CLI Only Version *
- * *
- * Written by Syd L. Bolton *
- * Copyright ©1991 Legendary Design Technologies Inc. *
- * *
- * Revision: 001 Date: July 28, 1991 Time: 19:50:34 *
- \*********************************************************************/
-
- #include <stdio.h>
-
- #define ENTRIES 26
- #define BACKSPACE ENTRIES
- #define FORM_FEED ENTRIES+1
- #define CR_ONLY ENTRIES+2
-
- FILE *rf,*wf;
- int count=0,iterations[ENTRIES+3];
-
- int codes[] = {
- 99,64,65,66,67,68,69,70,72,74,75,76,77,80,83,84,104,108,109,110,
- 112,113,116,117,120,121
- };
-
- char *cnames[] = {
- "RESET TO INITIAL STATE",
- "INSERT [N] CHARACTERS",
- "CURSOR UP [N] CHARACTERS",
- "CURSOR DOWN [N] CHARACTERS",
- "CURSOR FWD [N] CHARACTERS",
- "CURSOR BKWD [N] CHARACTERS",
- "CURSOR NEXT LINE [N]",
- "CURSOR PRECEDING LINE [N]",
- "MOVE CURSOR TO ROW/COLUMN",
- "ERASE TO END OF DISPLAY",
- "ERASE TO END OF LINE",
- "INSERT LINE",
- "DELETE LINE",
- "DELETE CHARACTER [N]",
- "SCROLL UP [N] LINES",
- "SCROLL DOWN [N] LINES",
- "SET LINEFEED MODE",
- "RESET NEWLINE MODE",
- "SELECT GRAPHIC RENDITION",
- "DEVICE STATUS REPORT",
- "»SET CURSOR RENDITION",
- "»WINDOW STATUS REQUEST",
- "»SET PAGE LENGTH",
- "»SET LINE LENGTH",
- "»SET LEFT OFFSET",
- "»SET TOP OFFSET",
- "BACKSPACE",
- "FORM FEED",
- "CARRIAGE RETURN"
- };
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i;
- char c;
-
- if (argc < 3) {
- puts("StripANSI v1.0 ©1991 Legendary Design Technologies Inc.");
- puts("Written by Syd L. Bolton");
- puts(" ");
- puts("Usage: StripANSI inputfile outputfile [REPORT]");
- exit(1);
- }
-
- if (!(rf=fopen(argv[1],"rb"))) {
- puts("StripANSI: Couldn't open input file.");
- exit(1);
- }
-
- if (!(wf=fopen(argv[2],"wb"))) {
- puts("StripANSI: Couldn't open output file.");
- exit(1);
- }
-
- do {
- c=getc(rf);
- if(!(feof(rf))) {
- if (c=='\0x9b' || c==27) stripcode(); /* either CSI or ESC */
- else if (c == 8) {
- iterations[BACKSPACE]++;
- count++;
- }
- else if (c == 12) {
- iterations[FORM_FEED]++;
- count++;
- }
- else if (c == 13) {
- iterations[CR_ONLY]++;
- count++;
- }
- else fputc(c,wf);
- }
- } while(!(feof(rf)));
-
- fclose(rf);
- fclose(wf);
-
- if (argc > 3 && count > 0) {
- puts(" ANSI CODE NAME # %");
- puts("---------------------------------------------");
- for (i=0; i<ENTRIES+3; i++)
- if (iterations[i]) printf("%30s: %6d %3d%%\n",cnames[i],iterations[i],iterations[i]*100/count);
- puts("---------------------------------------------");
- }
- }
-
- stripcode()
- {
- int i,exit_flag=0;
- char c;
-
- do {
- c=getc(rf);
- for (i=0; i<ENTRIES; i++) {
- if (c==codes[i]) {
- exit_flag=1;
- iterations[i]++;
- count++;
- }
- }
- } while (exit_flag==0) ;
- }
-
-