%{ int indent= 0, pre= 0, chars= 0, last_is_nl= 1; static void tabs(int i) { while(i>0){ putchar('\t'); i--; chars+=8; last_is_nl= 0; } } static void newlines(int i) { if (chars<=indent*8) i--; if (!last_is_nl) { while(i>0){ putchar('\n'); i--; } } chars= 0; last_is_nl= 1; if (!pre) tabs(indent); } static void space(void) { if (!pre && (chars + 1 >= 80)) newlines(1); else { if (chars>indent*8) { chars++; printf(" "); last_is_nl= 0; } } } static void word(char text[]) { int leng= strlen(text); if (!pre && (chars + leng >= 80)) newlines(1); chars+= leng; printf("%s", text); last_is_nl= 0; if (text[leng-1]=='\n') {chars= 0; /*last_is_nl= 1;*/} } static void unknown(char text[]) { printf("\n[unknown:%s]", text); newlines(1); } %} %e 1500 tail (" "[^>]*)?">"(\n)? %% "]*">" ; "<"HTML{tail} ; "]*">" {unknown(yytext);} "<" {word("<");} ">" {word(">");} "&" {word("&");} """ {word("\"");} " " {word(" "); /* oops! */ } "&"[^;]*";" {unknown(yytext);} [ \t\n]+ {if (pre) word(yytext); else space();} [^ \t\n&<]+ {word(yytext);} . {unknown(yytext);} %% int yywrap() {return 1;} int main () { yy_flex_debug= 0; yylex(); putchar('\n'); return 0; }