This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 #ifdef HAVE_CONFIG_H
47 #include "config.h"
48 #endif
49
50 #include <ctype.h>
51 #include <stdio.h>
52 #include <string.h>
53 #include <locale.h>
54
55 #include "pcre_internal.h"
56
57 #define DFTABLES
58 #include "pcre_maketables.c"
59
60
61 int main(int argc, char **argv)
62 {
63 FILE *f;
64 int i = 1;
65 const unsigned char *tables;
66 const unsigned char *base_of_tables;
67
68
69
70
71
72 if (argc > 1 && strcmp(argv[1], "-L") == 0)
73 {
74 setlocale(LC_ALL, "");
75 i++;
76 }
77
78 if (argc < i + 1)
79 {
80 fprintf(stderr, "dftables: one filename argument is required\n");
81 return 1;
82 }
83
84 tables = pcre_maketables();
85 base_of_tables = tables;
86
87 f = fopen(argv[i], "wb");
88 if (f == NULL)
89 {
90 fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
91 return 1;
92 }
93
94
95
96
97 fprintf(f,
98 "/*************************************************\n"
99 "* Perl-Compatible Regular Expressions *\n"
100 "*************************************************/\n\n"
101 "/* This file was automatically written by the dftables auxiliary\n"
102 "program. It contains character tables that are used when no external\n"
103 "tables are passed to PCRE by the application that calls it. The tables\n"
104 "are used only for characters whose code values are less than 256.\n\n");
105 fprintf(f,
106 "The following #includes are present because without them gcc 4.x may remove\n"
107 "the array definition from the final binary if PCRE is built into a static\n"
108 "library and dead code stripping is activated. This leads to link errors.\n"
109 "Pulling in the header ensures that the array gets flagged as \"someone\n"
110 "outside this compilation unit might reference this\" and so it will always\n"
111 "be supplied to the linker. */\n\n");
112
113
114
115 #if defined NATIVE_ZOS
116 fprintf(f,
117 "/* For z/OS, config.h is forced */\n"
118 "#ifndef HAVE_CONFIG_H\n"
119 "#define HAVE_CONFIG_H 1\n"
120 "#endif\n\n");
121 #endif
122
123 fprintf(f,
124 "#ifdef HAVE_CONFIG_H\n"
125 "#include \"config.h\"\n"
126 "#endif\n\n"
127 "#include \"pcre_internal.h\"\n\n");
128
129 fprintf(f,
130 "const pcre_uint8 PRIV(default_tables)[] = {\n\n"
131 "/* This table is a lower casing table. */\n\n");
132
133 fprintf(f, " ");
134 for (i = 0; i < 256; i++)
135 {
136 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
137 fprintf(f, "%3d", *tables++);
138 if (i != 255) fprintf(f, ",");
139 }
140 fprintf(f, ",\n\n");
141
142 fprintf(f, "/* This table is a case flipping table. */\n\n");
143
144 fprintf(f, " ");
145 for (i = 0; i < 256; i++)
146 {
147 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
148 fprintf(f, "%3d", *tables++);
149 if (i != 255) fprintf(f, ",");
150 }
151 fprintf(f, ",\n\n");
152
153 fprintf(f,
154 "/* This table contains bit maps for various character classes.\n"
155 "Each map is 32 bytes long and the bits run from the least\n"
156 "significant end of each byte. The classes that have their own\n"
157 "maps are: space, xdigit, digit, upper, lower, word, graph\n"
158 "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
159
160 fprintf(f, " ");
161 for (i = 0; i < cbit_length; i++)
162 {
163 if ((i & 7) == 0 && i != 0)
164 {
165 if ((i & 31) == 0) fprintf(f, "\n");
166 fprintf(f, "\n ");
167 }
168 fprintf(f, "0x%02x", *tables++);
169 if (i != cbit_length - 1) fprintf(f, ",");
170 }
171 fprintf(f, ",\n\n");
172
173 fprintf(f,
174 "/* This table identifies various classes of character by individual bits:\n"
175 " 0x%02x white space character\n"
176 " 0x%02x letter\n"
177 " 0x%02x decimal digit\n"
178 " 0x%02x hexadecimal digit\n"
179 " 0x%02x alphanumeric or '_'\n"
180 " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
181 ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
182 ctype_meta);
183
184 fprintf(f, " ");
185 for (i = 0; i < 256; i++)
186 {
187 if ((i & 7) == 0 && i != 0)
188 {
189 fprintf(f, " /* ");
190 if (isprint(i-8)) fprintf(f, " %c -", i-8);
191 else fprintf(f, "%3d-", i-8);
192 if (isprint(i-1)) fprintf(f, " %c ", i-1);
193 else fprintf(f, "%3d", i-1);
194 fprintf(f, " */\n ");
195 }
196 fprintf(f, "0x%02x", *tables++);
197 if (i != 255) fprintf(f, ",");
198 }
199
200 fprintf(f, "};/* ");
201 if (isprint(i-8)) fprintf(f, " %c -", i-8);
202 else fprintf(f, "%3d-", i-8);
203 if (isprint(i-1)) fprintf(f, " %c ", i-1);
204 else fprintf(f, "%3d", i-1);
205 fprintf(f, " */\n\n/* End of pcre_chartables.c */\n");
206
207 fclose(f);
208 free((void *)base_of_tables);
209 return 0;
210 }
211
212