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