]>
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 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 
  51 sub readHeaderValues
(); 
  55 if (scalar(@ARGV) != 1) { 
  56     print STDERR 
"Usage: ", basename
($0), " output-file\n"; 
  60 my $outputFile = shift @ARGV; 
  64 open(OUT
, ">", $outputFile) or die "$!"; 
  68     "/*************************************************\n" . 
  69     "*      Perl-Compatible Regular Expressions       *\n" . 
  70     "*************************************************/\n\n" . 
  71     "/* This file is automatically written by the dftables auxiliary \n" . 
  72     "program. If you edit it by hand, you might like to edit the Makefile to \n" . 
  73     "prevent its ever being regenerated.\n\n"); 
  75     "This file contains the default tables for characters with codes less than\n" . 
  76     "128 (ASCII characters). These tables are used when no external tables are\n" . 
  77     "passed to PCRE. */\n\n" . 
  78     "const unsigned char kjs_pcre_default_tables[%d] = {\n\n" . 
  79     "/* This table is a lower casing table. */\n\n", $pcre_internal{tables_length
}); 
  81 if ($pcre_internal{lcc_offset
} != 0) { 
  82     die "lcc_offset != 0"; 
  86 for (my $i = 0; $i < 128; $i++) { 
  87     if (($i & 7) == 0 && $i != 0) { 
  90     printf(OUT 
"0x%02X", ord(lc(chr($i)))); 
  97 printf(OUT 
"/* This table is a case flipping table. */\n\n"); 
  99 if ($pcre_internal{fcc_offset
} != 128) { 
 100   die "fcc_offset != 128"; 
 104 for (my $i = 0; $i < 128; $i++) { 
 105     if (($i & 7) == 0 && $i != 0) { 
 109     printf(OUT 
"0x%02X", $c =~ /[[:lower:]]/ ? ord(uc($c)) : ord(lc($c))); 
 117     "/* This table contains bit maps for various character classes.\n" . 
 118     "Each map is 32 bytes long and the bits run from the least\n" . 
 119     "significant end of each byte. The classes are: space, digit, word. */\n\n"); 
 121 if ($pcre_internal{cbits_offset
} != $pcre_internal{fcc_offset
} + 128) { 
 122     die "cbits_offset != fcc_offset + 128"; 
 125 my @cbit_table = (0) x 
$pcre_internal{cbit_length
}; 
 126 for (my $i = ord('0'); $i <= ord('9'); $i++) { 
 127     $cbit_table[$pcre_internal{cbit_digit
} + $i / 8] |= 1 << ($i & 7); 
 129 $cbit_table[$pcre_internal{cbit_word
} + ord('_') / 8] |= 1 << (ord('_') & 7); 
 130 for (my $i = 0; $i < 128; $i++) { 
 132     if ($c =~ /[[:alnum:]]/) { 
 133         $cbit_table[$pcre_internal{cbit_word
} + $i / 8] |= 1 << ($i & 7); 
 135     if ($c =~ /[[:space:]]/) { 
 136         $cbit_table[$pcre_internal{cbit_space
} + $i / 8] |= 1 << ($i & 7); 
 141 for (my $i = 0; $i < $pcre_internal{cbit_length
}; $i++) { 
 142     if (($i & 7) == 0 && $i != 0) { 
 143         if (($i & 31) == 0) { 
 148     printf(OUT 
"0x%02X", $cbit_table[$i]); 
 149     if ($i != $pcre_internal{cbit_length
} - 1) { 
 156     "/* This table identifies various classes of character by individual bits:\n" . 
 157     "  0x%02x   white space character\n" . 
 158     "  0x%02x   hexadecimal digit\n" . 
 159     "  0x%02x   alphanumeric or '_'\n*/\n\n", 
 160     $pcre_internal{ctype_space
}, $pcre_internal{ctype_xdigit
}, $pcre_internal{ctype_word
}); 
 162 if ($pcre_internal{ctypes_offset
} != $pcre_internal{cbits_offset
} + $pcre_internal{cbit_length
}) { 
 163     die "ctypes_offset != cbits_offset + cbit_length"; 
 167 for (my $i = 0; $i < 128; $i++) { 
 170     if ($c =~ /[[:space:]]/) { 
 171         $x += $pcre_internal{ctype_space
}; 
 173     if ($c =~ /[[:xdigit:]]/) { 
 174         $x += $pcre_internal{ctype_xdigit
}; 
 176     if ($c =~ /[[:alnum:]_]/) { 
 177         $x += $pcre_internal{ctype_word
}; 
 179     printf(OUT 
"0x%02X", $x); 
 188         if ($d =~ /[[:print:]]/) { 
 189             printf(OUT 
" %c -", $i - 7); 
 191             printf(OUT 
"%3d-", $i - 7); 
 193         if ($c =~ m/[[:print:]]/) { 
 194             printf(OUT 
" %c ", $i); 
 196             printf(OUT 
"%3d", $i); 
 205 if ($pcre_internal{tables_length
} != $pcre_internal{ctypes_offset
} + 128) { 
 206     die "tables_length != ctypes_offset + 128"; 
 209 printf(OUT 
"\n\n/* End of chartables.c */\n"); 
 215 sub readHeaderValues
() 
 234     my $headerPath = File
::Spec-
>catfile(dirname
($0), "pcre_internal.h"); 
 236     my $fh = new File
::Temp
( 
 237         DIR 
=> ($ENV{'TMPDIR'} || "/tmp"), 
 239         TEMPLATE 
=> basename
($0) . "-XXXXXXXX", 
 242     my $tempFile = $fh->filename(); 
 244     print $fh "#define DFTABLES\n\n"; 
 246     open(HEADER
, "<", $headerPath) or die "$!"; 
 252     for my $v (@variables) { 
 253         print $fh "\$pcre_internal{\"$v\"} = $v;\n"; 
 258     open(CPP
, "cpp '$tempFile' |") or die "$!";