home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / main / gen_test_char.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-08  |  1.5 KB  |  63 lines

  1. /* we need some of the portability definitions... for strchr */
  2. #include "httpd.h"
  3.  
  4. /* A bunch of functions in util.c scan strings looking for certain characters.
  5.  * To make that more efficient we encode a lookup table.
  6.  */
  7. #define T_ESCAPE_SHELL_CMD    (0x01)
  8. #define T_ESCAPE_PATH_SEGMENT    (0x02)
  9. #define T_OS_ESCAPE_PATH    (0x04)
  10. #define T_HTTP_TOKEN_STOP    (0x08)
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     unsigned c;
  15.     unsigned char flags;
  16.  
  17.     printf(
  18. "/* this file is automatically generated by gen_test_char, do not edit */\n"
  19. "#define T_ESCAPE_SHELL_CMD    (%u)\n"
  20. "#define T_ESCAPE_PATH_SEGMENT    (%u)\n"
  21. "#define T_OS_ESCAPE_PATH    (%u)\n"
  22. "#define T_HTTP_TOKEN_STOP    (%u)\n"
  23. "\n"
  24. "static const unsigned char test_char_table[256] = {\n"
  25. "    0,",
  26.     T_ESCAPE_SHELL_CMD,
  27.     T_ESCAPE_PATH_SEGMENT,
  28.     T_OS_ESCAPE_PATH,
  29.     T_HTTP_TOKEN_STOP);
  30.  
  31.     /* we explicitly dealt with NUL above
  32.      * in case some strchr() do bogosity with it */
  33.  
  34.     for (c = 1; c < 256; ++c) {
  35.     flags = 0;
  36.     if (c % 20 == 0)
  37.         printf("\n    ");
  38.  
  39.     /* escape_shell_cmd */
  40.     if (strchr("&;`'\"|*?~<>^()[]{}$\\\n", c)) {
  41.         flags |= T_ESCAPE_SHELL_CMD;
  42.     }
  43.  
  44.     if (!ap_isalnum(c) && !strchr("$-_.+!*'(),:@&=~", c)) {
  45.         flags |= T_ESCAPE_PATH_SEGMENT;
  46.     }
  47.  
  48.     if (!ap_isalnum(c) && !strchr("$-_.+!*'(),:@&=/~", c)) {
  49.         flags |= T_OS_ESCAPE_PATH;
  50.     }
  51.  
  52.     /* these are the "tspecials" from RFC2068 */
  53.     if (ap_iscntrl(c) || strchr(" \t()<>@,;:\\/[]?={}", c)) {
  54.         flags |= T_HTTP_TOKEN_STOP;
  55.     }
  56.     printf("%u%c", flags, (c < 255) ? ',' : ' ');
  57.  
  58.     }
  59.     printf("\n};\n");
  60.  
  61.     return 0;
  62. }
  63.