Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #define COMPILE_PARSE_RULES
00025 
00026 #include "ParseRules.h"
00027 
00028 const unsigned int parseRulesCType[256] = { 0 };
00029 const char parseRulesCTypeToUpper[256] = { 0 };
00030 const char parseRulesCTypeToLower[256] = { 0 };
00031 
00032 unsigned int tparseRulesCType[256];
00033 char tparseRulesCTypeToUpper[256];
00034 char tparseRulesCTypeToLower[256];
00035 
00036 
00037 #include <stdio.h>
00038 #include <ctype.h>
00039 #include "ink_string.h"
00040 
00041 static char *
00042 uint_to_binary(unsigned int u)
00043 {
00044   int i;
00045   static char buf[33];
00046   for (i = 0; i < 32; i++) {
00047     buf[i] = ((u & (1 << (31 - i))) ? '1' : '0');
00048   }
00049   buf[32] = '\0';
00050   return (buf);
00051 }
00052 
00053 int
00054 main()
00055 {
00056   int c;
00057   for (c = 0; c < 256; c++) {
00058     tparseRulesCType[c] = 0;
00059     tparseRulesCTypeToLower[c] = ParseRules::ink_tolower(c);
00060     tparseRulesCTypeToUpper[c] = ParseRules::ink_toupper(c);
00061 
00062     if (ParseRules::is_char(c))
00063       tparseRulesCType[c] |= is_char_BIT;
00064     if (ParseRules::is_upalpha(c))
00065       tparseRulesCType[c] |= is_upalpha_BIT;
00066     if (ParseRules::is_loalpha(c))
00067       tparseRulesCType[c] |= is_loalpha_BIT;
00068     if (ParseRules::is_alpha(c))
00069       tparseRulesCType[c] |= is_alpha_BIT;
00070     if (ParseRules::is_digit(c))
00071       tparseRulesCType[c] |= is_digit_BIT;
00072     if (ParseRules::is_ctl(c))
00073       tparseRulesCType[c] |= is_ctl_BIT;
00074     if (ParseRules::is_ws(c))
00075       tparseRulesCType[c] |= is_ws_BIT;
00076     if (ParseRules::is_hex(c))
00077       tparseRulesCType[c] |= is_hex_BIT;
00078     char cc = c;
00079     if (ParseRules::is_pchar(&cc))
00080       tparseRulesCType[c] |= is_pchar_BIT;
00081     if (ParseRules::is_extra(c))
00082       tparseRulesCType[c] |= is_extra_BIT;
00083     if (ParseRules::is_safe(c))
00084       tparseRulesCType[c] |= is_safe_BIT;
00085     if (ParseRules::is_unsafe(c))
00086       tparseRulesCType[c] |= is_unsafe_BIT;
00087     if (ParseRules::is_national(c))
00088       tparseRulesCType[c] |= is_national_BIT;
00089     if (ParseRules::is_reserved(c))
00090       tparseRulesCType[c] |= is_reserved_BIT;
00091     if (ParseRules::is_unreserved(c))
00092       tparseRulesCType[c] |= is_unreserved_BIT;
00093     if (ParseRules::is_punct(c))
00094       tparseRulesCType[c] |= is_punct_BIT;
00095     if (ParseRules::is_end_of_url(c))
00096       tparseRulesCType[c] |= is_end_of_url_BIT;
00097     if (ParseRules::is_tspecials(c))
00098       tparseRulesCType[c] |= is_tspecials_BIT;
00099     if (ParseRules::is_spcr(c))
00100       tparseRulesCType[c] |= is_spcr_BIT;
00101     if (ParseRules::is_splf(c))
00102       tparseRulesCType[c] |= is_splf_BIT;
00103     if (ParseRules::is_wslfcr(c))
00104       tparseRulesCType[c] |= is_wslfcr_BIT;
00105     if (ParseRules::is_eow(c))
00106       tparseRulesCType[c] |= is_eow_BIT;
00107     if (ParseRules::is_token(c))
00108       tparseRulesCType[c] |= is_token_BIT;
00109     if (ParseRules::is_wildmat(c))
00110       tparseRulesCType[c] |= is_wildmat_BIT;
00111     if (ParseRules::is_sep(c))
00112       tparseRulesCType[c] |= is_sep_BIT;
00113     if (ParseRules::is_empty(c))
00114       tparseRulesCType[c] |= is_empty_BIT;
00115     if (ParseRules::is_alnum(c))
00116       tparseRulesCType[c] |= is_alnum_BIT;
00117     if (ParseRules::is_space(c))
00118       tparseRulesCType[c] |= is_space_BIT;
00119     if (ParseRules::is_control(c))
00120       tparseRulesCType[c] |= is_control_BIT;
00121     if (ParseRules::is_mime_sep(c))
00122       tparseRulesCType[c] |= is_mime_sep_BIT;
00123     if (ParseRules::is_http_field_name(c))
00124       tparseRulesCType[c] |= is_http_field_name_BIT;
00125     if (ParseRules::is_http_field_value(c))
00126       tparseRulesCType[c] |= is_http_field_value_BIT;
00127   }
00128 
00129   FILE *fp = fopen("ParseRulesCType", "w");
00130   for (c = 0; c < 256; c++) {
00131     fprintf(fp, "/* %3d (%c) */\t", c, (isprint(c) ? c : '?'));
00132     fprintf(fp, "0x%08X%c\t\t", tparseRulesCType[c], (c != 255 ? ',' : ' '));
00133     fprintf(fp, "/* [%s] */\n", uint_to_binary((unsigned int) (tparseRulesCType[c])));
00134   }
00135   fclose(fp);
00136   fp = fopen("ParseRulesCTypeToUpper", "w");
00137   for (c = 0; c < 256; c++)
00138     fprintf(fp, "%d%c\n", tparseRulesCTypeToUpper[c], c != 255 ? ',' : ' ');
00139   fclose(fp);
00140   fp = fopen("ParseRulesCTypeToLower", "w");
00141   for (c = 0; c < 256; c++)
00142     fprintf(fp, "%d%c\n", tparseRulesCTypeToLower[c], c != 255 ? ',' : ' ');
00143   fclose(fp);
00144 
00145   return (0);
00146 }