| 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 |
|
|
Copyright (c) 1997-2005 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 |
nigel |
77 |
/* This is a freestanding support program to generate a file containing default |
| 42 |
|
|
character tables for PCRE. The tables are built according to the default C |
| 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 |
nigel |
27 |
|
| 46 |
|
|
#include <ctype.h> |
| 47 |
|
|
#include <stdio.h> |
| 48 |
|
|
#include <string.h> |
| 49 |
|
|
|
| 50 |
nigel |
77 |
#include "pcre_internal.h" |
| 51 |
nigel |
27 |
|
| 52 |
nigel |
77 |
#define DFTABLES /* pcre_maketables.c notices this */ |
| 53 |
|
|
#include "pcre_maketables.c" |
| 54 |
nigel |
27 |
|
| 55 |
|
|
|
| 56 |
nigel |
73 |
int main(int argc, char **argv) |
| 57 |
nigel |
27 |
{ |
| 58 |
|
|
int i; |
| 59 |
nigel |
73 |
FILE *f; |
| 60 |
nigel |
53 |
const unsigned char *tables = pcre_maketables(); |
| 61 |
nigel |
77 |
const unsigned char *base_of_tables = tables; |
| 62 |
nigel |
27 |
|
| 63 |
nigel |
73 |
if (argc != 2) |
| 64 |
|
|
{ |
| 65 |
|
|
fprintf(stderr, "dftables: one filename argument is required\n"); |
| 66 |
|
|
return 1; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
|
f = fopen(argv[1], "w"); |
| 70 |
|
|
if (f == NULL) |
| 71 |
|
|
{ |
| 72 |
|
|
fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]); |
| 73 |
|
|
return 1; |
| 74 |
|
|
} |
| 75 |
|
|
|
| 76 |
|
|
/* There are two fprintf() calls here, because gcc in pedantic mode complains |
| 77 |
nigel |
65 |
about the very long string otherwise. */ |
| 78 |
|
|
|
| 79 |
nigel |
73 |
fprintf(f, |
| 80 |
nigel |
27 |
"/*************************************************\n" |
| 81 |
|
|
"* Perl-Compatible Regular Expressions *\n" |
| 82 |
|
|
"*************************************************/\n\n" |
| 83 |
nigel |
35 |
"/* This file is automatically written by the dftables auxiliary \n" |
| 84 |
nigel |
27 |
"program. If you edit it by hand, you might like to edit the Makefile to \n" |
| 85 |
nigel |
65 |
"prevent its ever being regenerated.\n\n"); |
| 86 |
nigel |
73 |
fprintf(f, |
| 87 |
nigel |
77 |
"This file contains the default tables for characters with codes less than\n" |
| 88 |
|
|
"128 (ASCII characters). These tables are used when no external tables are\n" |
| 89 |
|
|
"passed to PCRE. */\n\n" |
| 90 |
|
|
"const unsigned char _pcre_default_tables[] = {\n\n" |
| 91 |
nigel |
27 |
"/* This table is a lower casing table. */\n\n"); |
| 92 |
|
|
|
| 93 |
nigel |
73 |
fprintf(f, " "); |
| 94 |
nigel |
27 |
for (i = 0; i < 256; i++) |
| 95 |
|
|
{ |
| 96 |
nigel |
73 |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
| 97 |
|
|
fprintf(f, "%3d", *tables++); |
| 98 |
|
|
if (i != 255) fprintf(f, ","); |
| 99 |
nigel |
27 |
} |
| 100 |
nigel |
73 |
fprintf(f, ",\n\n"); |
| 101 |
nigel |
27 |
|
| 102 |
nigel |
73 |
fprintf(f, "/* This table is a case flipping table. */\n\n"); |
| 103 |
nigel |
27 |
|
| 104 |
nigel |
73 |
fprintf(f, " "); |
| 105 |
nigel |
27 |
for (i = 0; i < 256; i++) |
| 106 |
|
|
{ |
| 107 |
nigel |
73 |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
| 108 |
|
|
fprintf(f, "%3d", *tables++); |
| 109 |
|
|
if (i != 255) fprintf(f, ","); |
| 110 |
nigel |
27 |
} |
| 111 |
nigel |
73 |
fprintf(f, ",\n\n"); |
| 112 |
nigel |
27 |
|
| 113 |
nigel |
73 |
fprintf(f, |
| 114 |
nigel |
43 |
"/* This table contains bit maps for various character classes.\n" |
| 115 |
|
|
"Each map is 32 bytes long and the bits run from the least\n" |
| 116 |
|
|
"significant end of each byte. The classes that have their own\n" |
| 117 |
|
|
"maps are: space, xdigit, digit, upper, lower, word, graph\n" |
| 118 |
|
|
"print, punct, and cntrl. Other classes are built from combinations. */\n\n"); |
| 119 |
nigel |
27 |
|
| 120 |
nigel |
73 |
fprintf(f, " "); |
| 121 |
nigel |
27 |
for (i = 0; i < cbit_length; i++) |
| 122 |
|
|
{ |
| 123 |
|
|
if ((i & 7) == 0 && i != 0) |
| 124 |
|
|
{ |
| 125 |
nigel |
73 |
if ((i & 31) == 0) fprintf(f, "\n"); |
| 126 |
|
|
fprintf(f, "\n "); |
| 127 |
nigel |
27 |
} |
| 128 |
nigel |
73 |
fprintf(f, "0x%02x", *tables++); |
| 129 |
|
|
if (i != cbit_length - 1) fprintf(f, ","); |
| 130 |
nigel |
27 |
} |
| 131 |
nigel |
73 |
fprintf(f, ",\n\n"); |
| 132 |
nigel |
27 |
|
| 133 |
nigel |
73 |
fprintf(f, |
| 134 |
nigel |
27 |
"/* This table identifies various classes of character by individual bits:\n" |
| 135 |
|
|
" 0x%02x white space character\n" |
| 136 |
|
|
" 0x%02x letter\n" |
| 137 |
|
|
" 0x%02x decimal digit\n" |
| 138 |
|
|
" 0x%02x hexadecimal digit\n" |
| 139 |
|
|
" 0x%02x alphanumeric or '_'\n" |
| 140 |
|
|
" 0x%02x regular expression metacharacter or binary zero\n*/\n\n", |
| 141 |
|
|
ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word, |
| 142 |
|
|
ctype_meta); |
| 143 |
|
|
|
| 144 |
nigel |
73 |
fprintf(f, " "); |
| 145 |
nigel |
27 |
for (i = 0; i < 256; i++) |
| 146 |
|
|
{ |
| 147 |
|
|
if ((i & 7) == 0 && i != 0) |
| 148 |
|
|
{ |
| 149 |
nigel |
73 |
fprintf(f, " /* "); |
| 150 |
|
|
if (isprint(i-8)) fprintf(f, " %c -", i-8); |
| 151 |
|
|
else fprintf(f, "%3d-", i-8); |
| 152 |
|
|
if (isprint(i-1)) fprintf(f, " %c ", i-1); |
| 153 |
|
|
else fprintf(f, "%3d", i-1); |
| 154 |
|
|
fprintf(f, " */\n "); |
| 155 |
nigel |
27 |
} |
| 156 |
nigel |
73 |
fprintf(f, "0x%02x", *tables++); |
| 157 |
|
|
if (i != 255) fprintf(f, ","); |
| 158 |
nigel |
27 |
} |
| 159 |
|
|
|
| 160 |
nigel |
73 |
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\n/* End of chartables.c */\n"); |
| 166 |
nigel |
27 |
|
| 167 |
nigel |
73 |
fclose(f); |
| 168 |
nigel |
77 |
free((void *)base_of_tables); |
| 169 |
nigel |
27 |
return 0; |
| 170 |
|
|
} |
| 171 |
|
|
|
| 172 |
|
|
/* End of dftables.c */ |