1 /** @file
2
3 A brief file description
4
5 @section license License
6
7 Licensed to the Apache Software Foundation (ASF) under one
8 or more contributor license agreements. See the NOTICE file
9 distributed with this work for additional information
10 regarding copyright ownership. The ASF licenses this file
11 to you under the Apache License, Version 2.0 (the
12 "License"); you may not use this file except in compliance
13 with the License. You may obtain a copy of the License at
14
15 http://www.apache.org/licenses/LICENSE-2.0
16
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
23
24 #define COMPILE_PARSE_RULES
25
26 #include "tscore/ParseRules.h"
27
28 const unsigned int parseRulesCType[256] = {0};
29 const char parseRulesCTypeToUpper[256] = {0};
30 const char parseRulesCTypeToLower[256] = {0};
31
32 unsigned int tparseRulesCType[256];
33 char tparseRulesCTypeToUpper[256];
34 char tparseRulesCTypeToLower[256];
35
36 #include <cstdio>
37 #include <cctype>
38 #include "tscore/ink_string.h"
39
40 static char *
uint_to_binary(unsigned int u)41 uint_to_binary(unsigned int u)
42 {
43 int i;
44 static char buf[33];
45 for (i = 0; i < 32; i++) {
46 buf[i] = ((u & (1 << (31 - i))) ? '1' : '0');
47 }
48 buf[32] = '\0';
49 return (buf);
50 }
51
52 int
main()53 main()
54 {
55 int c;
56 for (c = 0; c < 256; c++) {
57 tparseRulesCType[c] = 0;
58 tparseRulesCTypeToLower[c] = ParseRules::ink_tolower(c);
59 tparseRulesCTypeToUpper[c] = ParseRules::ink_toupper(c);
60
61 if (ParseRules::is_char(c)) {
62 tparseRulesCType[c] |= is_char_BIT;
63 }
64 if (ParseRules::is_upalpha(c)) {
65 tparseRulesCType[c] |= is_upalpha_BIT;
66 }
67 if (ParseRules::is_loalpha(c)) {
68 tparseRulesCType[c] |= is_loalpha_BIT;
69 }
70 if (ParseRules::is_alpha(c)) {
71 tparseRulesCType[c] |= is_alpha_BIT;
72 }
73 if (ParseRules::is_digit(c)) {
74 tparseRulesCType[c] |= is_digit_BIT;
75 }
76 if (ParseRules::is_ctl(c)) {
77 tparseRulesCType[c] |= is_ctl_BIT;
78 }
79 if (ParseRules::is_ws(c)) {
80 tparseRulesCType[c] |= is_ws_BIT;
81 }
82 if (ParseRules::is_hex(c)) {
83 tparseRulesCType[c] |= is_hex_BIT;
84 }
85 char cc = c;
86 if (ParseRules::is_pchar(&cc)) {
87 tparseRulesCType[c] |= is_pchar_BIT;
88 }
89 if (ParseRules::is_extra(c)) {
90 tparseRulesCType[c] |= is_extra_BIT;
91 }
92 if (ParseRules::is_safe(c)) {
93 tparseRulesCType[c] |= is_safe_BIT;
94 }
95 if (ParseRules::is_unsafe(c)) {
96 tparseRulesCType[c] |= is_unsafe_BIT;
97 }
98 if (ParseRules::is_national(c)) {
99 tparseRulesCType[c] |= is_national_BIT;
100 }
101 if (ParseRules::is_reserved(c)) {
102 tparseRulesCType[c] |= is_reserved_BIT;
103 }
104 if (ParseRules::is_unreserved(c)) {
105 tparseRulesCType[c] |= is_unreserved_BIT;
106 }
107 if (ParseRules::is_punct(c)) {
108 tparseRulesCType[c] |= is_punct_BIT;
109 }
110 if (ParseRules::is_end_of_url(c)) {
111 tparseRulesCType[c] |= is_end_of_url_BIT;
112 }
113 if (ParseRules::is_tspecials(c)) {
114 tparseRulesCType[c] |= is_tspecials_BIT;
115 }
116 if (ParseRules::is_spcr(c)) {
117 tparseRulesCType[c] |= is_spcr_BIT;
118 }
119 if (ParseRules::is_splf(c)) {
120 tparseRulesCType[c] |= is_splf_BIT;
121 }
122 if (ParseRules::is_wslfcr(c)) {
123 tparseRulesCType[c] |= is_wslfcr_BIT;
124 }
125 if (ParseRules::is_eow(c)) {
126 tparseRulesCType[c] |= is_eow_BIT;
127 }
128 if (ParseRules::is_token(c)) {
129 tparseRulesCType[c] |= is_token_BIT;
130 }
131 if (ParseRules::is_uri(c)) {
132 tparseRulesCType[c] |= is_uri_BIT;
133 }
134 if (ParseRules::is_sep(c)) {
135 tparseRulesCType[c] |= is_sep_BIT;
136 }
137 if (ParseRules::is_empty(c)) {
138 tparseRulesCType[c] |= is_empty_BIT;
139 }
140 if (ParseRules::is_alnum(c)) {
141 tparseRulesCType[c] |= is_alnum_BIT;
142 }
143 if (ParseRules::is_space(c)) {
144 tparseRulesCType[c] |= is_space_BIT;
145 }
146 if (ParseRules::is_control(c)) {
147 tparseRulesCType[c] |= is_control_BIT;
148 }
149 if (ParseRules::is_mime_sep(c)) {
150 tparseRulesCType[c] |= is_mime_sep_BIT;
151 }
152 if (ParseRules::is_http_field_name(c)) {
153 tparseRulesCType[c] |= is_http_field_name_BIT;
154 }
155 if (ParseRules::is_http_field_value(c)) {
156 tparseRulesCType[c] |= is_http_field_value_BIT;
157 }
158 }
159
160 FILE *fp = fopen("ParseRulesCType", "w");
161 for (c = 0; c < 256; c++) {
162 fprintf(fp, "/* %3d (%c) */\t", c, (isprint(c) ? c : '?'));
163 fprintf(fp, "0x%08X%c\t\t", tparseRulesCType[c], (c != 255 ? ',' : ' '));
164 fprintf(fp, "/* [%s] */\n", uint_to_binary((tparseRulesCType[c])));
165 }
166 fclose(fp);
167 fp = fopen("ParseRulesCTypeToUpper", "w");
168 for (c = 0; c < 256; c++) {
169 fprintf(fp, "%d%c\n", tparseRulesCTypeToUpper[c], c != 255 ? ',' : ' ');
170 }
171 fclose(fp);
172 fp = fopen("ParseRulesCTypeToLower", "w");
173 for (c = 0; c < 256; c++) {
174 fprintf(fp, "%d%c\n", tparseRulesCTypeToLower[c], c != 255 ? ',' : ' ');
175 }
176 fclose(fp);
177
178 return (0);
179 }
180