home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vile-src.zip / vile-8.1 / c-filt.flx < prev    next >
Text File  |  1995-02-19  |  2KB  |  97 lines

  1. %x COMMENT
  2.  
  3. %{
  4. /* Filter to add vile "attribution" sequences to selected bits of C/C++ */
  5. /* input text. */
  6.  
  7. /* You gotta use flex for this beast - hence the COMMENT start state */
  8. /* written by Alistair G. Crooks (agc@uts.amdahl.com) */
  9.  
  10. #include <stdio.h>
  11.  
  12.  
  13. #define BOLD    "B"
  14. #define ULINE    "U"
  15. #define ITALIC    "I"
  16. #define COLOR1    "C1"
  17. #define COLOR2    "C2"
  18. #define COLOR3    "C3"
  19. #define COLOR4    "C4"
  20.  
  21. /* customize here, using the above set of defines... */
  22.  
  23. char keyword_attr[] = BOLD;
  24. char preproc_attr[] = BOLD;
  25. char comment_attr[] = ULINE;
  26.  
  27. /* ...end customization */
  28.  
  29. #define CTL_A    '\001'
  30.  
  31. int
  32. #ifdef __STDC__
  33. main(int argc, char **argv)
  34. #else
  35. main(argc, argv)
  36. int    argc;
  37. char    **argv;
  38. #endif
  39. {
  40.     extern FILE    *yyin;
  41.  
  42.     if (argc == 1) {
  43.         yyin = stdin;
  44.     } else if ((yyin = fopen(argv[1], "r")) == (FILE *) NULL) {
  45.         (void) fprintf(stderr, "can't open %s\n", argv[1]);
  46.         exit(1);
  47.     }
  48.     while (yylex() > 0) {
  49.     }
  50.     exit(0);
  51. }
  52.  
  53. %}
  54.  
  55. %%
  56.  
  57. #[ \t]*if    |
  58. #[ \t]*if(n)?def    |
  59. #[ \t]*else    |
  60. #[ \t]*endif    |
  61. #[ \t]*define    |
  62. #[ \t]*error    |
  63. #[ \t]*include    |
  64. #[ \t]*undef    { printf("%c%i%s:%s", CTL_A, yyleng, preproc_attr, yytext); }
  65.  
  66. break        |
  67. case        |
  68. continue    |
  69. default        |
  70. do        |
  71. else        |
  72. extern        |
  73. for        |
  74. goto        |
  75. if        |
  76. return        |
  77. sizeof        |
  78. static        |
  79. struct        |
  80. switch        |
  81. typedef        |
  82. union        |
  83. while        { printf("%c%i%s:%s", CTL_A, yyleng, keyword_attr, yytext); }
  84.  
  85.  
  86. "/*"        { printf("%c2%s:/*", CTL_A, comment_attr); BEGIN(COMMENT); }
  87. <COMMENT>[^*]*    { printf("%c%i%s:%s", CTL_A, yyleng, comment_attr, yytext); }
  88. <COMMENT>"*"+[^*/]*    { printf("%c%i%s:%s", CTL_A, yyleng, comment_attr, yytext); }
  89. <COMMENT>"*"+"/"    { printf("%c%i%s:%s", CTL_A, yyleng, comment_attr, yytext); BEGIN(0); }
  90.  
  91. "//".*$        { printf("%c%i%s:%s", CTL_A, yyleng, comment_attr, yytext); }
  92.  
  93. [a-zA-Z_][a-zA-Z_0-9]*    |
  94. \"(\\\.|[^\"])*\"    { printf("%s", yytext); }
  95.  
  96.  
  97.