1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
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.
8 Written by Philip Hazel
9 Original API code Copyright (c) 1997-2012 University of Cambridge
10 New API code Copyright (c) 2016-2018 University of Cambridge
12 -----------------------------------------------------------------------------
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright notice,
17 this list of conditions and the following disclaimer.
19 * Redistributions in binary form must reproduce the above copyright
20 notice, this list of conditions and the following disclaimer in the
21 documentation and/or other materials provided with the distribution.
23 * Neither the name of the University of Cambridge nor the names of its
24 contributors may be used to endorse or promote products derived from
25 this software without specific prior written permission.
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 POSSIBILITY OF SUCH DAMAGE.
38 -----------------------------------------------------------------------------
42 /* This is a freestanding support program to generate a file containing
43 character tables for PCRE2. The tables are built according to the current
44 locale using the pcre2_maketables() function, which is part of the PCRE2 API.
56 #define PCRE2_CODE_UNIT_WIDTH 0 /* Must be set, but not relevant here */
57 #include "pcre2_internal.h"
59 #define DFTABLES /* pcre2_maketables.c notices this */
60 #include "pcre2_maketables.c"
62 int main(int argc, char **argv)
66 const unsigned char *tables;
67 const unsigned char *base_of_tables;
69 /* By default, the default C locale is used rather than what the building user
70 happens to have set. However, if the -L option is given, set the locale from
71 the LC_xxx environment variables. */
73 if (argc > 1 && strcmp(argv[1], "-L") == 0)
75 setlocale(LC_ALL, ""); /* Set from environment variables */
81 fprintf(stderr, "dftables: one filename argument is required\n");
85 tables = maketables();
86 base_of_tables = tables;
88 f = fopen(argv[i], "wb");
91 fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
95 /* There are several fprintf() calls here, because gcc in pedantic mode
96 complains about the very long string otherwise. */
99 "/*************************************************\n"
100 "* Perl-Compatible Regular Expressions *\n"
101 "*************************************************/\n\n"
102 "/* This file was automatically written by the dftables auxiliary\n"
103 "program. It contains character tables that are used when no external\n"
104 "tables are passed to PCRE2 by the application that calls it. The tables\n"
105 "are used only for characters whose code values are less than 256. */\n\n");
108 "/*The dftables program (which is distributed with PCRE2) can be used to\n"
109 "build alternative versions of this file. This is necessary if you are\n"
110 "running in an EBCDIC environment, or if you want to default to a different\n"
111 "encoding, for example ISO-8859-1. When dftables is run, it creates these\n"
112 "tables in the current locale. This happens automatically if PCRE2 is\n"
113 "configured with --enable-rebuild-chartables. */\n\n");
115 /* Force config.h in z/OS */
117 #if defined NATIVE_ZOS
119 "/* For z/OS, config.h is forced */\n"
120 "#ifndef HAVE_CONFIG_H\n"
121 "#define HAVE_CONFIG_H 1\n"
126 "/* The following #include is present because without it gcc 4.x may remove\n"
127 "the array definition from the final binary if PCRE2 is built into a static\n"
128 "library and dead code stripping is activated. This leads to link errors.\n"
129 "Pulling in the header ensures that the array gets flagged as \"someone\n"
130 "outside this compilation unit might reference this\" and so it will always\n"
131 "be supplied to the linker. */\n\n");
134 "#ifdef HAVE_CONFIG_H\n"
135 "#include \"config.h\"\n"
137 "#include \"pcre2_internal.h\"\n\n");
140 "const uint8_t PRIV(default_tables)[] = {\n\n"
141 "/* This table is a lower casing table. */\n\n");
144 for (i = 0; i < 256; i++)
146 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
147 fprintf(f, "%3d", *tables++);
148 if (i != 255) fprintf(f, ",");
152 fprintf(f, "/* This table is a case flipping table. */\n\n");
155 for (i = 0; i < 256; i++)
157 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
158 fprintf(f, "%3d", *tables++);
159 if (i != 255) fprintf(f, ",");
164 "/* This table contains bit maps for various character classes. Each map is 32\n"
165 "bytes long and the bits run from the least significant end of each byte. The\n"
166 "classes that have their own maps are: space, xdigit, digit, upper, lower, word,\n"
167 "graph print, punct, and cntrl. Other classes are built from combinations. */\n\n");
170 for (i = 0; i < cbit_length; i++)
172 if ((i & 7) == 0 && i != 0)
174 if ((i & 31) == 0) fprintf(f, "\n");
177 fprintf(f, "0x%02x", *tables++);
178 if (i != cbit_length - 1) fprintf(f, ",");
183 "/* This table identifies various classes of character by individual bits:\n"
184 " 0x%02x white space character\n"
186 " 0x%02x decimal digit\n"
187 " 0x%02x hexadecimal digit\n"
188 " 0x%02x alphanumeric or '_'\n*/\n\n",
189 ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word);
192 for (i = 0; i < 256; i++)
194 if ((i & 7) == 0 && i != 0)
197 if (isprint(i-8)) fprintf(f, " %c -", i-8);
198 else fprintf(f, "%3d-", i-8);
199 if (isprint(i-1)) fprintf(f, " %c ", i-1);
200 else fprintf(f, "%3d", i-1);
201 fprintf(f, " */\n ");
203 fprintf(f, "0x%02x", *tables++);
204 if (i != 255) fprintf(f, ",");
208 if (isprint(i-8)) fprintf(f, " %c -", i-8);
209 else fprintf(f, "%3d-", i-8);
210 if (isprint(i-1)) fprintf(f, " %c ", i-1);
211 else fprintf(f, "%3d", i-1);
212 fprintf(f, " */\n\n/* End of pcre2_chartables.c */\n");
215 free((void *)base_of_tables);
219 /* End of dftables.c */