| 2 |
* Perl-Compatible Regular Expressions * |
* Perl-Compatible Regular Expressions * |
| 3 |
*************************************************/ |
*************************************************/ |
| 4 |
|
|
| 5 |
/* |
/* PCRE is a library of functions to support regular expressions whose syntax |
|
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. |
and semantics are as close as possible to those of the Perl 5 language. |
| 7 |
|
|
| 8 |
Written by: Philip Hazel <ph10@cam.ac.uk> |
Written by Philip Hazel |
| 9 |
|
Copyright (c) 1997-2006 University of Cambridge |
| 10 |
|
|
|
Copyright (c) 1997-2001 University of Cambridge |
|
|
|
|
|
----------------------------------------------------------------------------- |
|
|
Permission is granted to anyone to use this software for any purpose on any |
|
|
computer system, and to redistribute it freely, subject to the following |
|
|
restrictions: |
|
|
|
|
|
1. This software is distributed in the hope that it will be useful, |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
|
|
|
|
2. The origin of this software must not be misrepresented, either by |
|
|
explicit claim or by omission. |
|
|
|
|
|
3. Altered versions must be plainly marked as such, and must not be |
|
|
misrepresented as being the original software. |
|
|
|
|
|
4. If PCRE is embedded in any software that is released under the GNU |
|
|
General Purpose Licence (GPL), then the terms of that licence shall |
|
|
supersede any condition above with which it is incompatible. |
|
| 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 |
See the file Tech.Notes for some information on the internals. |
* 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 support program to generate the file chartables.c, containing |
/* This is a freestanding support program to generate a file containing default |
| 42 |
character tables of various kinds. They are built according to the default C |
character tables for PCRE. The tables are built according to the default C |
| 43 |
locale and used as the default tables by PCRE. Now that pcre_maketables is |
locale. Now that pcre_maketables is a function visible to the outside world, we |
| 44 |
a function visible to the outside world, we make use of its code from here in |
make use of its code from here in order to be consistent. */ |
|
order to be consistent. */ |
|
| 45 |
|
|
| 46 |
#include <ctype.h> |
#include <ctype.h> |
| 47 |
#include <stdio.h> |
#include <stdio.h> |
| 48 |
#include <string.h> |
#include <string.h> |
| 49 |
|
|
| 50 |
#include "internal.h" |
#include "pcre_internal.h" |
| 51 |
|
|
| 52 |
#define DFTABLES /* maketables.c notices this */ |
#define DFTABLES /* pcre_maketables.c notices this */ |
| 53 |
#include "maketables.c" |
#include "pcre_maketables.c" |
| 54 |
|
|
| 55 |
|
|
| 56 |
int main(void) |
int main(int argc, char **argv) |
| 57 |
{ |
{ |
| 58 |
int i; |
int i; |
| 59 |
|
FILE *f; |
| 60 |
const unsigned char *tables = pcre_maketables(); |
const unsigned char *tables = pcre_maketables(); |
| 61 |
|
const unsigned char *base_of_tables = tables; |
| 62 |
|
|
| 63 |
|
if (argc != 2) |
| 64 |
|
{ |
| 65 |
|
fprintf(stderr, "dftables: one filename argument is required\n"); |
| 66 |
|
return 1; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
f = fopen(argv[1], "wb"); |
| 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 printf() calls here, because gcc in pedantic mode complains |
/* There are two fprintf() calls here, because gcc in pedantic mode complains |
| 77 |
about the very long string otherwise. */ |
about the very long string otherwise. */ |
| 78 |
|
|
| 79 |
printf( |
fprintf(f, |
| 80 |
"/*************************************************\n" |
"/*************************************************\n" |
| 81 |
"* Perl-Compatible Regular Expressions *\n" |
"* Perl-Compatible Regular Expressions *\n" |
| 82 |
"*************************************************/\n\n" |
"*************************************************/\n\n" |
| 83 |
"/* This file is automatically written by the dftables auxiliary \n" |
"/* This file is automatically written by the dftables auxiliary \n" |
| 84 |
"program. If you edit it by hand, you might like to edit the Makefile to \n" |
"program. If you edit it by hand, you might like to edit the Makefile to \n" |
| 85 |
"prevent its ever being regenerated.\n\n"); |
"prevent its ever being regenerated.\n\n"); |
| 86 |
printf( |
fprintf(f, |
| 87 |
"This file is #included in the compilation of pcre.c to build the default\n" |
"This file contains the default tables for characters with codes less than\n" |
| 88 |
"character tables which are used when no tables are passed to the compile\n" |
"128 (ASCII characters). These tables are used when no external tables are\n" |
| 89 |
"function. */\n\n" |
"passed to PCRE. */\n\n" |
| 90 |
"static unsigned char pcre_default_tables[] = {\n\n" |
"const unsigned char _pcre_default_tables[] = {\n\n" |
| 91 |
"/* This table is a lower casing table. */\n\n"); |
"/* This table is a lower casing table. */\n\n"); |
| 92 |
|
|
| 93 |
printf(" "); |
fprintf(f, " "); |
| 94 |
for (i = 0; i < 256; i++) |
for (i = 0; i < 256; i++) |
| 95 |
{ |
{ |
| 96 |
if ((i & 7) == 0 && i != 0) printf("\n "); |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
| 97 |
printf("%3d", *tables++); |
fprintf(f, "%3d", *tables++); |
| 98 |
if (i != 255) printf(","); |
if (i != 255) fprintf(f, ","); |
| 99 |
} |
} |
| 100 |
printf(",\n\n"); |
fprintf(f, ",\n\n"); |
| 101 |
|
|
| 102 |
printf("/* This table is a case flipping table. */\n\n"); |
fprintf(f, "/* This table is a case flipping table. */\n\n"); |
| 103 |
|
|
| 104 |
printf(" "); |
fprintf(f, " "); |
| 105 |
for (i = 0; i < 256; i++) |
for (i = 0; i < 256; i++) |
| 106 |
{ |
{ |
| 107 |
if ((i & 7) == 0 && i != 0) printf("\n "); |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
| 108 |
printf("%3d", *tables++); |
fprintf(f, "%3d", *tables++); |
| 109 |
if (i != 255) printf(","); |
if (i != 255) fprintf(f, ","); |
| 110 |
} |
} |
| 111 |
printf(",\n\n"); |
fprintf(f, ",\n\n"); |
| 112 |
|
|
| 113 |
printf( |
fprintf(f, |
| 114 |
"/* This table contains bit maps for various character classes.\n" |
"/* 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" |
"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" |
"significant end of each byte. The classes that have their own\n" |
| 117 |
"maps are: space, xdigit, digit, upper, lower, word, graph\n" |
"maps are: space, xdigit, digit, upper, lower, word, graph\n" |
| 118 |
"print, punct, and cntrl. Other classes are built from combinations. */\n\n"); |
"print, punct, and cntrl. Other classes are built from combinations. */\n\n"); |
| 119 |
|
|
| 120 |
printf(" "); |
fprintf(f, " "); |
| 121 |
for (i = 0; i < cbit_length; i++) |
for (i = 0; i < cbit_length; i++) |
| 122 |
{ |
{ |
| 123 |
if ((i & 7) == 0 && i != 0) |
if ((i & 7) == 0 && i != 0) |
| 124 |
{ |
{ |
| 125 |
if ((i & 31) == 0) printf("\n"); |
if ((i & 31) == 0) fprintf(f, "\n"); |
| 126 |
printf("\n "); |
fprintf(f, "\n "); |
| 127 |
} |
} |
| 128 |
printf("0x%02x", *tables++); |
fprintf(f, "0x%02x", *tables++); |
| 129 |
if (i != cbit_length - 1) printf(","); |
if (i != cbit_length - 1) fprintf(f, ","); |
| 130 |
} |
} |
| 131 |
printf(",\n\n"); |
fprintf(f, ",\n\n"); |
| 132 |
|
|
| 133 |
printf( |
fprintf(f, |
| 134 |
"/* This table identifies various classes of character by individual bits:\n" |
"/* This table identifies various classes of character by individual bits:\n" |
| 135 |
" 0x%02x white space character\n" |
" 0x%02x white space character\n" |
| 136 |
" 0x%02x letter\n" |
" 0x%02x letter\n" |
| 141 |
ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word, |
ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word, |
| 142 |
ctype_meta); |
ctype_meta); |
| 143 |
|
|
| 144 |
printf(" "); |
fprintf(f, " "); |
| 145 |
for (i = 0; i < 256; i++) |
for (i = 0; i < 256; i++) |
| 146 |
{ |
{ |
| 147 |
if ((i & 7) == 0 && i != 0) |
if ((i & 7) == 0 && i != 0) |
| 148 |
{ |
{ |
| 149 |
printf(" /* "); |
fprintf(f, " /* "); |
| 150 |
if (isprint(i-8)) printf(" %c -", i-8); |
if (isprint(i-8)) fprintf(f, " %c -", i-8); |
| 151 |
else printf("%3d-", i-8); |
else fprintf(f, "%3d-", i-8); |
| 152 |
if (isprint(i-1)) printf(" %c ", i-1); |
if (isprint(i-1)) fprintf(f, " %c ", i-1); |
| 153 |
else printf("%3d", i-1); |
else fprintf(f, "%3d", i-1); |
| 154 |
printf(" */\n "); |
fprintf(f, " */\n "); |
| 155 |
} |
} |
| 156 |
printf("0x%02x", *tables++); |
fprintf(f, "0x%02x", *tables++); |
| 157 |
if (i != 255) printf(","); |
if (i != 255) fprintf(f, ","); |
| 158 |
} |
} |
| 159 |
|
|
| 160 |
printf("};/* "); |
fprintf(f, "};/* "); |
| 161 |
if (isprint(i-8)) printf(" %c -", i-8); |
if (isprint(i-8)) fprintf(f, " %c -", i-8); |
| 162 |
else printf("%3d-", i-8); |
else fprintf(f, "%3d-", i-8); |
| 163 |
if (isprint(i-1)) printf(" %c ", i-1); |
if (isprint(i-1)) fprintf(f, " %c ", i-1); |
| 164 |
else printf("%3d", i-1); |
else fprintf(f, "%3d", i-1); |
| 165 |
printf(" */\n\n/* End of chartables.c */\n"); |
fprintf(f, " */\n\n/* End of chartables.c */\n"); |
| 166 |
|
|
| 167 |
|
fclose(f); |
| 168 |
|
free((void *)base_of_tables); |
| 169 |
return 0; |
return 0; |
| 170 |
} |
} |
| 171 |
|
|