]>
git.saurik.com Git - apple/javascriptcore.git/blob - pcre/dftables
3 # This is JavaScriptCore's variant of the PCRE library. While this library
4 # started out as a copy of PCRE, many of the features of PCRE have been
5 # removed. This library now supports only the regular expression features
6 # required by the JavaScript language specification, and has only the functions
7 # needed by JavaScriptCore and the rest of WebKit.
9 # Originally written by Philip Hazel
10 # Copyright (c) 1997-2006 University of Cambridge
11 # Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
13 # -----------------------------------------------------------------------------
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions are met:
17 # * Redistributions of source code must retain the above copyright notice,
18 # this list of conditions and the following disclaimer.
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.
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.
28 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 # POSSIBILITY OF SUCH DAMAGE.
39 # -----------------------------------------------------------------------------
41 # This is a freestanding support program to generate a file containing
42 # character tables. The tables are built according to the default C
49 use File
::Temp
qw(tempfile);
52 sub readHeaderValues
();
56 if (scalar(@ARGV) < 1) {
57 print STDERR
"Usage: ", basename
($0), " [--preprocessor=program] output-file\n";
63 GetOptions
('preprocessor=s' => \
$preprocessor);
64 if (not $preprocessor) {
65 $preprocessor = "cpp";
68 $outputFile = $ARGV[0];
69 die('Must specify output file.') unless defined($outputFile);
73 open(OUT
, ">", $outputFile) or die "$!";
77 "/*************************************************\n" .
78 "* Perl-Compatible Regular Expressions *\n" .
79 "*************************************************/\n\n" .
80 "/* This file is automatically written by the dftables auxiliary \n" .
81 "program. If you edit it by hand, you might like to edit the Makefile to \n" .
82 "prevent its ever being regenerated.\n\n");
84 "This file contains the default tables for characters with codes less than\n" .
85 "128 (ASCII characters). These tables are used when no external tables are\n" .
86 "passed to PCRE. */\n\n" .
87 "const unsigned char jsc_pcre_default_tables[%d] = {\n\n" .
88 "/* This table is a lower casing table. */\n\n", $pcre_internal{tables_length
});
90 if ($pcre_internal{lcc_offset
} != 0) {
91 die "lcc_offset != 0";
95 for (my $i = 0; $i < 128; $i++) {
96 if (($i & 7) == 0 && $i != 0) {
99 printf(OUT
"0x%02X", ord(lc(chr($i))));
106 printf(OUT
"/* This table is a case flipping table. */\n\n");
108 if ($pcre_internal{fcc_offset
} != 128) {
109 die "fcc_offset != 128";
113 for (my $i = 0; $i < 128; $i++) {
114 if (($i & 7) == 0 && $i != 0) {
118 printf(OUT
"0x%02X", $c =~ /[[:lower:]]/ ? ord(uc($c)) : ord(lc($c)));
126 "/* This table contains bit maps for various character classes.\n" .
127 "Each map is 32 bytes long and the bits run from the least\n" .
128 "significant end of each byte. The classes are: space, digit, word. */\n\n");
130 if ($pcre_internal{cbits_offset
} != $pcre_internal{fcc_offset
} + 128) {
131 die "cbits_offset != fcc_offset + 128";
134 my @cbit_table = (0) x
$pcre_internal{cbit_length
};
135 for (my $i = ord('0'); $i <= ord('9'); $i++) {
136 $cbit_table[$pcre_internal{cbit_digit
} + $i / 8] |= 1 << ($i & 7);
138 $cbit_table[$pcre_internal{cbit_word
} + ord('_') / 8] |= 1 << (ord('_') & 7);
139 for (my $i = 0; $i < 128; $i++) {
141 if ($c =~ /[[:alnum:]]/) {
142 $cbit_table[$pcre_internal{cbit_word
} + $i / 8] |= 1 << ($i & 7);
144 if ($c =~ /[[:space:]]/) {
145 $cbit_table[$pcre_internal{cbit_space
} + $i / 8] |= 1 << ($i & 7);
150 for (my $i = 0; $i < $pcre_internal{cbit_length
}; $i++) {
151 if (($i & 7) == 0 && $i != 0) {
152 if (($i & 31) == 0) {
157 printf(OUT
"0x%02X", $cbit_table[$i]);
158 if ($i != $pcre_internal{cbit_length
} - 1) {
165 "/* This table identifies various classes of character by individual bits:\n" .
166 " 0x%02x white space character\n" .
167 " 0x%02x hexadecimal digit\n" .
168 " 0x%02x alphanumeric or '_'\n*/\n\n",
169 $pcre_internal{ctype_space
}, $pcre_internal{ctype_xdigit
}, $pcre_internal{ctype_word
});
171 if ($pcre_internal{ctypes_offset
} != $pcre_internal{cbits_offset
} + $pcre_internal{cbit_length
}) {
172 die "ctypes_offset != cbits_offset + cbit_length";
176 for (my $i = 0; $i < 128; $i++) {
179 if ($c =~ /[[:space:]]/) {
180 $x += $pcre_internal{ctype_space
};
182 if ($c =~ /[[:xdigit:]]/) {
183 $x += $pcre_internal{ctype_xdigit
};
185 if ($c =~ /[[:alnum:]_]/) {
186 $x += $pcre_internal{ctype_word
};
188 printf(OUT
"0x%02X", $x);
197 if ($d =~ /[[:print:]]/) {
198 printf(OUT
" %c -", $i - 7);
200 printf(OUT
"%3d-", $i - 7);
202 if ($c =~ m/[[:print:]]/) {
203 printf(OUT
" %c ", $i);
205 printf(OUT
"%3d", $i);
214 if ($pcre_internal{tables_length
} != $pcre_internal{ctypes_offset
} + 128) {
215 die "tables_length != ctypes_offset + 128";
218 printf(OUT
"\n\n/* End of chartables.c */\n");
224 sub readHeaderValues
()
243 my $headerPath = File
::Spec-
>catfile(dirname
($0), "pcre_internal.h");
245 my ($fh, $tempFile) = tempfile
(
246 basename
($0) . "-XXXXXXXX",
247 DIR
=> File
::Spec-
>tmpdir,
252 print $fh "#define DFTABLES\n\n";
254 open(HEADER
, "<", $headerPath) or die "$!";
260 for my $v (@variables) {
261 print $fh "\$pcre_internal{\"$v\"} = $v;\n";
266 open(CPP
, "$preprocessor \"$tempFile\" |") or die "$!";