/[pcre]/code/tags/pcre-7.2/dftables.c
ViewVC logotype

Contents of /code/tags/pcre-7.2/dftables.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 186 - (show annotations) (download)
Tue Jun 19 13:41:40 2007 UTC (7 years, 4 months ago) by ph10
File MIME type: text/plain
File size: 6649 byte(s)
Created "tagged" 7.2 version.

1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
4
5 /* PCRE is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language.
7
8 Written by Philip Hazel
9 Copyright (c) 1997-2007 University of Cambridge
10
11 -----------------------------------------------------------------------------
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
17
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21
22 * Neither the name of the University of Cambridge nor the names of its
23 contributors may be used to endorse or promote products derived from
24 this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37 -----------------------------------------------------------------------------
38 */
39
40
41 /* This is a freestanding support program to generate a file containing
42 character tables for PCRE. The tables are built according to the current
43 locale. Now that pcre_maketables is a function visible to the outside world, we
44 make use of its code from here in order to be consistent. */
45
46 #include <ctype.h>
47 #include <stdio.h>
48 #include <string.h>
49 #include <locale.h>
50
51 #include "pcre_internal.h"
52
53 #define DFTABLES /* pcre_maketables.c notices this */
54 #include "pcre_maketables.c"
55
56
57 int main(int argc, char **argv)
58 {
59 FILE *f;
60 int i = 1;
61 const unsigned char *tables;
62 const unsigned char *base_of_tables;
63
64 /* By default, the default C locale is used rather than what the building user
65 happens to have set. However, if the -L option is given, set the locale from
66 the LC_xxx environment variables. */
67
68 if (argc > 1 && strcmp(argv[1], "-L") == 0)
69 {
70 setlocale(LC_ALL, ""); /* Set from environment variables */
71 i++;
72 }
73
74 if (argc < i + 1)
75 {
76 fprintf(stderr, "dftables: one filename argument is required\n");
77 return 1;
78 }
79
80 tables = pcre_maketables();
81 base_of_tables = tables;
82
83 f = fopen(argv[i], "wb");
84 if (f == NULL)
85 {
86 fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
87 return 1;
88 }
89
90 /* There are several fprintf() calls here, because gcc in pedantic mode
91 complains about the very long string otherwise. */
92
93 fprintf(f,
94 "/*************************************************\n"
95 "* Perl-Compatible Regular Expressions *\n"
96 "*************************************************/\n\n"
97 "/* This file was automatically written by the dftables auxiliary\n"
98 "program. It contains character tables that are used when no external\n"
99 "tables are passed to PCRE by the application that calls it. The tables\n"
100 "are used only for characters whose code values are less than 256.\n\n");
101 fprintf(f,
102 "The following #include is present because without it gcc 4.x may remove\n"
103 "the array definition from the final binary if PCRE is built into a static\n"
104 "library and dead code stripping is activated. This leads to link errors.\n"
105 "Pulling in the header ensures that the array gets flagged as \"someone\n"
106 "outside this compilation unit might reference this\" and so it will always\n"
107 "be supplied to the linker. */\n\n"
108 "#include \"pcre_internal.h\"\n\n");
109 fprintf(f,
110 "const unsigned char _pcre_default_tables[] = {\n\n"
111 "/* This table is a lower casing table. */\n\n");
112
113 fprintf(f, " ");
114 for (i = 0; i < 256; i++)
115 {
116 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
117 fprintf(f, "%3d", *tables++);
118 if (i != 255) fprintf(f, ",");
119 }
120 fprintf(f, ",\n\n");
121
122 fprintf(f, "/* This table is a case flipping table. */\n\n");
123
124 fprintf(f, " ");
125 for (i = 0; i < 256; i++)
126 {
127 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
128 fprintf(f, "%3d", *tables++);
129 if (i != 255) fprintf(f, ",");
130 }
131 fprintf(f, ",\n\n");
132
133 fprintf(f,
134 "/* This table contains bit maps for various character classes.\n"
135 "Each map is 32 bytes long and the bits run from the least\n"
136 "significant end of each byte. The classes that have their own\n"
137 "maps are: space, xdigit, digit, upper, lower, word, graph\n"
138 "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
139
140 fprintf(f, " ");
141 for (i = 0; i < cbit_length; i++)
142 {
143 if ((i & 7) == 0 && i != 0)
144 {
145 if ((i & 31) == 0) fprintf(f, "\n");
146 fprintf(f, "\n ");
147 }
148 fprintf(f, "0x%02x", *tables++);
149 if (i != cbit_length - 1) fprintf(f, ",");
150 }
151 fprintf(f, ",\n\n");
152
153 fprintf(f,
154 "/* This table identifies various classes of character by individual bits:\n"
155 " 0x%02x white space character\n"
156 " 0x%02x letter\n"
157 " 0x%02x decimal digit\n"
158 " 0x%02x hexadecimal digit\n"
159 " 0x%02x alphanumeric or '_'\n"
160 " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
161 ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
162 ctype_meta);
163
164 fprintf(f, " ");
165 for (i = 0; i < 256; i++)
166 {
167 if ((i & 7) == 0 && i != 0)
168 {
169 fprintf(f, " /* ");
170 if (isprint(i-8)) fprintf(f, " %c -", i-8);
171 else fprintf(f, "%3d-", i-8);
172 if (isprint(i-1)) fprintf(f, " %c ", i-1);
173 else fprintf(f, "%3d", i-1);
174 fprintf(f, " */\n ");
175 }
176 fprintf(f, "0x%02x", *tables++);
177 if (i != 255) fprintf(f, ",");
178 }
179
180 fprintf(f, "};/* ");
181 if (isprint(i-8)) fprintf(f, " %c -", i-8);
182 else fprintf(f, "%3d-", i-8);
183 if (isprint(i-1)) fprintf(f, " %c ", i-1);
184 else fprintf(f, "%3d", i-1);
185 fprintf(f, " */\n\n/* End of pcre_chartables.c */\n");
186
187 fclose(f);
188 free((void *)base_of_tables);
189 return 0;
190 }
191
192 /* End of dftables.c */

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12