/* $Id: filter.c,v 1.2 1996/09/17 04:54:40 connolly Exp $ */ #include #include #include #include "sgml_lex.h" /* * This is a the trivial SGML_LexFunc. */ static void transparent(void *rock, SGML_Lexer *l, int qty, SGML_TokType *types, SGML_String *strings, size_t *lengths) { int i; for(i = 0; i < qty; i++){ if(types[i] < SGML_LIMITATION){ fwrite(strings[i], 1, lengths[i], stdout); } } } #define BIG 16000 int main(int argc, char **argv) { char buf[BIG]; const char *p = buf; int qty; SGML_Lexer *lexer = SGML_createLexer(); assert(lexer); /*@@ malloc() -> 0? */ while(1){ qty = fread(buf, 1, sizeof(buf)-1, stdin); if (qty <= 0) break; while(qty > 0){ /* pick wierd-sized chunks to stress-test lexer.*/ int chunk = *p % 23; if(chunk == 0) chunk = 1; if(chunk > qty) chunk = qty; SGML_lex(lexer, p, chunk, transparent, 0, transparent, 0, transparent, 0); qty -= chunk; p += chunk; } p = buf; }; /* final step... */ SGML_lex(lexer, NULL, 0, transparent, 0, transparent, 0, transparent, 0); SGML_delLexer(lexer); return 0; }