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