| 1 |
nigel |
27 |
/************************************************* |
| 2 |
|
|
* Perl-Compatible Regular Expressions * |
| 3 |
|
|
*************************************************/ |
| 4 |
|
|
|
| 5 |
nigel |
77 |
/* PCRE is a library of functions to support regular expressions whose syntax |
| 6 |
nigel |
27 |
and semantics are as close as possible to those of the Perl 5 language. |
| 7 |
|
|
|
| 8 |
nigel |
77 |
Written by Philip Hazel |
| 9 |
ph10 |
117 |
Copyright (c) 1997-2007 University of Cambridge |
| 10 |
nigel |
27 |
|
| 11 |
|
|
----------------------------------------------------------------------------- |
| 12 |
nigel |
75 |
Redistribution and use in source and binary forms, with or without |
| 13 |
|
|
modification, are permitted provided that the following conditions are met: |
| 14 |
nigel |
27 |
|
| 15 |
nigel |
75 |
* Redistributions of source code must retain the above copyright notice, |
| 16 |
|
|
this list of conditions and the following disclaimer. |
| 17 |
nigel |
27 |
|
| 18 |
nigel |
75 |
* 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 |
nigel |
27 |
|
| 22 |
nigel |
75 |
* 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 |
nigel |
29 |
|
| 26 |
nigel |
75 |
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 |
nigel |
27 |
----------------------------------------------------------------------------- |
| 38 |
|
|
*/ |
| 39 |
|
|
|
| 40 |
|
|
|
| 41 |
ph10 |
128 |
/* 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 |
nigel |
77 |
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 |
nigel |
27 |
|
| 46 |
ph10 |
200 |
#ifdef HAVE_CONFIG_H |
| 47 |
ph10 |
199 |
#include <config.h> |
| 48 |
ph10 |
200 |
#endif |
| 49 |
ph10 |
199 |
|
| 50 |
nigel |
27 |
#include <ctype.h> |
| 51 |
|
|
#include <stdio.h> |
| 52 |
|
|
#include <string.h> |
| 53 |
ph10 |
128 |
#include <locale.h> |
| 54 |
nigel |
27 |
|
| 55 |
nigel |
77 |
#include "pcre_internal.h" |
| 56 |
nigel |
27 |
|
| 57 |
nigel |
77 |
#define DFTABLES /* pcre_maketables.c notices this */ |
| 58 |
|
|
#include "pcre_maketables.c" |
| 59 |
nigel |
27 |
|
| 60 |
|
|
|
| 61 |
nigel |
73 |
int main(int argc, char **argv) |
| 62 |
nigel |
27 |
{ |
| 63 |
nigel |
73 |
FILE *f; |
| 64 |
ph10 |
128 |
int i = 1; |
| 65 |
|
|
const unsigned char *tables; |
| 66 |
|
|
const unsigned char *base_of_tables; |
| 67 |
nigel |
27 |
|
| 68 |
ph10 |
128 |
/* By default, the default C locale is used rather than what the building user |
| 69 |
|
|
happens to have set. However, if the -L option is given, set the locale from |
| 70 |
|
|
the LC_xxx environment variables. */ |
| 71 |
|
|
|
| 72 |
|
|
if (argc > 1 && strcmp(argv[1], "-L") == 0) |
| 73 |
nigel |
73 |
{ |
| 74 |
ph10 |
128 |
setlocale(LC_ALL, ""); /* Set from environment variables */ |
| 75 |
|
|
i++; |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
if (argc < i + 1) |
| 79 |
|
|
{ |
| 80 |
nigel |
73 |
fprintf(stderr, "dftables: one filename argument is required\n"); |
| 81 |
|
|
return 1; |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
ph10 |
128 |
tables = pcre_maketables(); |
| 85 |
|
|
base_of_tables = tables; |
| 86 |
|
|
|
| 87 |
|
|
f = fopen(argv[i], "wb"); |
| 88 |
nigel |
73 |
if (f == NULL) |
| 89 |
|
|
{ |
| 90 |
|
|
fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]); |
| 91 |
|
|
return 1; |
| 92 |
|
|
} |
| 93 |
|
|
|
| 94 |
ph10 |
128 |
/* There are several fprintf() calls here, because gcc in pedantic mode |
| 95 |
|
|
complains about the very long string otherwise. */ |
| 96 |
nigel |
65 |
|
| 97 |
nigel |
73 |
fprintf(f, |
| 98 |
nigel |
27 |
"/*************************************************\n" |
| 99 |
|
|
"* Perl-Compatible Regular Expressions *\n" |
| 100 |
|
|
"*************************************************/\n\n" |
| 101 |
ph10 |
128 |
"/* 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 |
nigel |
73 |
fprintf(f, |
| 106 |
ph10 |
199 |
"The following #includes are present because without them gcc 4.x may remove\n" |
| 107 |
nigel |
93 |
"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 |
ph10 |
200 |
"#ifdef HAVE_CONFIG_H\n" |
| 113 |
|
|
"#include <config.h>\n" |
| 114 |
|
|
"#endif\n\n" |
| 115 |
nigel |
93 |
"#include \"pcre_internal.h\"\n\n"); |
| 116 |
|
|
fprintf(f, |
| 117 |
nigel |
77 |
"const unsigned char _pcre_default_tables[] = {\n\n" |
| 118 |
nigel |
27 |
"/* This table is a lower casing table. */\n\n"); |
| 119 |
|
|
|
| 120 |
nigel |
73 |
fprintf(f, " "); |
| 121 |
nigel |
27 |
for (i = 0; i < 256; i++) |
| 122 |
|
|
{ |
| 123 |
nigel |
73 |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
| 124 |
|
|
fprintf(f, "%3d", *tables++); |
| 125 |
|
|
if (i != 255) fprintf(f, ","); |
| 126 |
nigel |
27 |
} |
| 127 |
nigel |
73 |
fprintf(f, ",\n\n"); |
| 128 |
nigel |
27 |
|
| 129 |
nigel |
73 |
fprintf(f, "/* This table is a case flipping table. */\n\n"); |
| 130 |
nigel |
27 |
|
| 131 |
nigel |
73 |
fprintf(f, " "); |
| 132 |
nigel |
27 |
for (i = 0; i < 256; i++) |
| 133 |
|
|
{ |
| 134 |
nigel |
73 |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
| 135 |
|
|
fprintf(f, "%3d", *tables++); |
| 136 |
|
|
if (i != 255) fprintf(f, ","); |
| 137 |
nigel |
27 |
} |
| 138 |
nigel |
73 |
fprintf(f, ",\n\n"); |
| 139 |
nigel |
27 |
|
| 140 |
nigel |
73 |
fprintf(f, |
| 141 |
nigel |
43 |
"/* This table contains bit maps for various character classes.\n" |
| 142 |
|
|
"Each map is 32 bytes long and the bits run from the least\n" |
| 143 |
|
|
"significant end of each byte. The classes that have their own\n" |
| 144 |
|
|
"maps are: space, xdigit, digit, upper, lower, word, graph\n" |
| 145 |
|
|
"print, punct, and cntrl. Other classes are built from combinations. */\n\n"); |
| 146 |
nigel |
27 |
|
| 147 |
nigel |
73 |
fprintf(f, " "); |
| 148 |
nigel |
27 |
for (i = 0; i < cbit_length; i++) |
| 149 |
|
|
{ |
| 150 |
|
|
if ((i & 7) == 0 && i != 0) |
| 151 |
|
|
{ |
| 152 |
nigel |
73 |
if ((i & 31) == 0) fprintf(f, "\n"); |
| 153 |
|
|
fprintf(f, "\n "); |
| 154 |
nigel |
27 |
} |
| 155 |
nigel |
73 |
fprintf(f, "0x%02x", *tables++); |
| 156 |
|
|
if (i != cbit_length - 1) fprintf(f, ","); |
| 157 |
nigel |
27 |
} |
| 158 |
nigel |
73 |
fprintf(f, ",\n\n"); |
| 159 |
nigel |
27 |
|
| 160 |
nigel |
73 |
fprintf(f, |
| 161 |
nigel |
27 |
"/* This table identifies various classes of character by individual bits:\n" |
| 162 |
|
|
" 0x%02x white space character\n" |
| 163 |
|
|
" 0x%02x letter\n" |
| 164 |
|
|
" 0x%02x decimal digit\n" |
| 165 |
|
|
" 0x%02x hexadecimal digit\n" |
| 166 |
|
|
" 0x%02x alphanumeric or '_'\n" |
| 167 |
|
|
" 0x%02x regular expression metacharacter or binary zero\n*/\n\n", |
| 168 |
|
|
ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word, |
| 169 |
|
|
ctype_meta); |
| 170 |
|
|
|
| 171 |
nigel |
73 |
fprintf(f, " "); |
| 172 |
nigel |
27 |
for (i = 0; i < 256; i++) |
| 173 |
|
|
{ |
| 174 |
|
|
if ((i & 7) == 0 && i != 0) |
| 175 |
|
|
{ |
| 176 |
nigel |
73 |
fprintf(f, " /* "); |
| 177 |
|
|
if (isprint(i-8)) fprintf(f, " %c -", i-8); |
| 178 |
|
|
else fprintf(f, "%3d-", i-8); |
| 179 |
|
|
if (isprint(i-1)) fprintf(f, " %c ", i-1); |
| 180 |
|
|
else fprintf(f, "%3d", i-1); |
| 181 |
|
|
fprintf(f, " */\n "); |
| 182 |
nigel |
27 |
} |
| 183 |
nigel |
73 |
fprintf(f, "0x%02x", *tables++); |
| 184 |
|
|
if (i != 255) fprintf(f, ","); |
| 185 |
nigel |
27 |
} |
| 186 |
|
|
|
| 187 |
nigel |
73 |
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 |
ph10 |
128 |
fprintf(f, " */\n\n/* End of pcre_chartables.c */\n"); |
| 193 |
nigel |
27 |
|
| 194 |
nigel |
73 |
fclose(f); |
| 195 |
nigel |
77 |
free((void *)base_of_tables); |
| 196 |
nigel |
27 |
return 0; |
| 197 |
|
|
} |
| 198 |
|
|
|
| 199 |
|
|
/* End of dftables.c */ |