%x NORMAL LIT_TEXT HEX_TEXT B85_TEXT %o6000 %{ /* * $Header: /usr/build/vile/vile/filters/RCS/ps-filt.l,v 1.3 2003/05/20 20:38:41 tom Exp $ * * Filter to add vile "attribution" sequences to selected bits of PostScript * files. */ #include DefineFilter("ps"); #define isQuote(ch) (ch != 0 && strchr("\\'\"", ch) != 0) static char *Action_attr; static char *Comment_attr; static char *Error_attr; static char *Ident_attr; static char *Number_attr; static char *String_attr; %} NAME [a-zA-Z$_!@#&*_+=|:";',.?] ACTION [/{}[\]] IDENT {NAME}({NAME}|[0-9])* SIGN [-+] INTEGER {SIGN}?([0-9]+) REAL {SIGN}?[0-9]+\.[0-9]*|{SIGN}?\.[0-9]+ RADIX ([0-9]+)"#"([0-9A-Fa-f]+) NUMBER {INTEGER}|{REAL}|{RADIX} %% {IDENT} { WriteToken(keyword_attr(yytext)); } "%"[^\n]* { WriteToken(Comment_attr); } {ACTION} { WriteToken(Action_attr); } {NUMBER} { WriteToken(Number_attr); } "(" { BeginQuote(LIT_TEXT, String_attr); } \\[nrtbf\\()] { flt_bfr_embed(yytext, yyleng, Ident_attr); } \\[0-7]+ { flt_bfr_embed(yytext, yyleng, Ident_attr); } \\\n { flt_bfr_embed(yytext, yyleng, Ident_attr); } [^\\)] { flt_bfr_append(yytext, yyleng); } ")" { FinishQuote(NORMAL); } "<<" | ">>" { WriteToken(Action_attr); } "<" { BeginQuote(HEX_TEXT, String_attr); } [0-9A-Fa-f]+ { flt_bfr_append(yytext, yyleng); } [^>0-9A-Fa-f]+ { flt_bfr_embed(yytext, yyleng, Error_attr); } ">" { FinishQuote(NORMAL); } %% static void init_filter(int before GCC_UNUSED) { } static void do_filter(FILE *inputs) { yyin = inputs; Action_attr = class_attr(NAME_ACTION); Comment_attr = class_attr(NAME_COMMENT); Error_attr = class_attr(NAME_ERROR); Ident_attr = class_attr(NAME_IDENT2); Number_attr = class_attr(NAME_NUMBER); String_attr = class_attr(NAME_LITERAL); BEGIN(NORMAL); while (yylex() > 0) { } flt_bfr_error(); }