/* stripcomments.c - Don Yang (uguu.org) Remove non-BF characters from stream. 09/03/04 */ #include #define BUFSIZE 0x10000 int main(int argc, char **argv) { static char buffer[BUFSIZE], *p; FILE *infile, *outfile; size_t s; if( argc > 1 ) { if( (infile = fopen(argv[1], "rb")) == NULL ) return printf("Can not open %s\n", argv[1]); if( argc > 2 ) { if( (outfile = fopen(argv[2], "wb+")) == NULL ) { (void)fclose(infile); return printf("Can not create %s\n", argv[2]); } } else { outfile = stdout; } } else { infile = stdin; outfile = stdout; } while( (s = fread(buffer, 1, BUFSIZE, infile)) > 0 ) { for(p = buffer; s-- > 0; p++) { if( *p == '[' || *p == ']' || *p == '<' || *p == '>' || *p == '-' || *p == '+' || *p == ',' || *p == '.' ) (void)fputc(*p, outfile); } if( s < BUFSIZE ) break; } (void)fputc('\n', outfile); (void)fclose(infile); (void)fclose(outfile); return 0; }