home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Creative Computers
/
CreativeComputers.iso
/
shareware
/
text
/
stripansi_v1.2
/
source
/
source.lzh
/
prog.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-15
|
4KB
|
165 lines
/*********************************************************************\
* StripANSI v1.2 *
* *
* CLI Only Version *
* *
* Written by Syd L. Bolton *
* Copyright ⌐1991 Legendary Design Technologies Inc. *
* *
* Revision: 001 Date: July 28, 1991 Time: 19:50:34 *
* Revision: 002 Date: Sept 18, 1992 Time: 20:01:00 *
\*********************************************************************/
#include <stdio.h>
#define ENTRIES 26
#define EXTENTRIES 11
FILE *rf,*wf;
int count=0,iterations[ENTRIES+EXTENTRIES];
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"
};
int extcodes[] = {
7,8,12,13,14,15,17,18,19,20,24
};
char *extcnames[] = {
"BELL",
"BACKSPACE",
"FORM FEED",
"CARRIAGE RETURN",
"DOUBLE WIDTH MODE",
"CONDENSED MODE",
"SELECT PRINTER",
"CANCEL CONDENSED",
"DESELECT PRINTER",
"CANCEL DOUBLE WIDTH",
"CANCEL LINE"
};
main(argc,argv)
int argc;
char *argv[];
{
register short i,rv;
int report=0,true=0;
char c;
if (argc < 3) {
puts("StripANSI v1.2 ⌐1991,92 Legendary Design Technologies Inc.");
puts("Written by Syd L. Bolton");
puts(" ");
puts("Usage: StripANSI inputfile outputfile [REPORT,TRUE]");
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);
}
if (argc > 3) {
for (i=3; i<argc; i++) {
if (!(strcmp("REPORT",argv[i])) || !(strcmp("report",argv[i]))) report=1;
if (!(strcmp("TRUE",argv[i])) || !(strcmp("true",argv[i]))) true=1;
}
}
do {
c=getc(rf);
if (!(feof(rf))) {
if (c=='\0x9b' || c==27) stripcode(); /* either CSI or ESC */
else {
if (true==0) rv=checkextended(c); else rv=0;
if (rv==0) fputc(c,wf);
}
}
} while(!(feof(rf)));
fclose(rf);
fclose(wf);
if (report==1 && count > 0) {
puts(" ANSI CODE NAME # %");
puts("---------------------------------------------");
for (i=0; i<ENTRIES; i++)
if (iterations[i]) printf("%30s: %6d %3d%%\n",cnames[i],iterations[i],iterations[i]*100/count);
if (true==0) {
for (i=0; i<EXTENTRIES; i++)
if (iterations[ENTRIES+i]) printf("%30s: %6d %3d%%\n",extcnames[i],iterations[ENTRIES+i],iterations[ENTRIES+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) ;
}
checkextended(c)
char c;
{
register short i;
int rv=0;
for (i=0; i<EXTENTRIES; i++) {
if (c==extcodes[i]) {
count++;
iterations[ENTRIES+i]++;
rv=1;
}
}
return(rv);
}