Annotation of embedaddon/php/ext/pcre/pcrelib/dftables.c, revision 1.1.1.1

1.1       misho       1: /*************************************************
                      2: *      Perl-Compatible Regular Expressions       *
                      3: *************************************************/
                      4: 
                      5: /* 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.
                      7: 
                      8:                        Written by Philip Hazel
                      9:            Copyright (c) 1997-2008 University of Cambridge
                     10: 
                     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:     * 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 freestanding support program to generate a file containing
                     42: character tables for PCRE. The tables are built according to the current
                     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: 
                     46: #include "config.h"
                     47: 
                     48: #include <ctype.h>
                     49: #include <stdio.h>
                     50: #include <string.h>
                     51: #include <locale.h>
                     52: 
                     53: #include "pcre_internal.h"
                     54: 
                     55: #define DFTABLES          /* pcre_maketables.c notices this */
                     56: #include "pcre_maketables.c"
                     57: 
                     58: 
                     59: int main(int argc, char **argv)
                     60: {
                     61: FILE *f;
                     62: int i = 1;
                     63: const unsigned char *tables;
                     64: const unsigned char *base_of_tables;
                     65: 
                     66: /* By default, the default C locale is used rather than what the building user
                     67: happens to have set. However, if the -L option is given, set the locale from
                     68: the LC_xxx environment variables. */
                     69: 
                     70: if (argc > 1 && strcmp(argv[1], "-L") == 0)
                     71:   {
                     72:   setlocale(LC_ALL, "");        /* Set from environment variables */
                     73:   i++;
                     74:   }
                     75: 
                     76: if (argc < i + 1)
                     77:   {
                     78:   fprintf(stderr, "dftables: one filename argument is required\n");
                     79:   return 1;
                     80:   }
                     81: 
                     82: tables = pcre_maketables();
                     83: base_of_tables = tables;
                     84: 
                     85: f = fopen(argv[i], "wb");
                     86: if (f == NULL)
                     87:   {
                     88:   fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
                     89:   return 1;
                     90:   }
                     91: 
                     92: /* There are several fprintf() calls here, because gcc in pedantic mode
                     93: complains about the very long string otherwise. */
                     94: 
                     95: fprintf(f,
                     96:   "/*************************************************\n"
                     97:   "*      Perl-Compatible Regular Expressions       *\n"
                     98:   "*************************************************/\n\n"
                     99:   "/* This file was automatically written by the dftables auxiliary\n"
                    100:   "program. It contains character tables that are used when no external\n"
                    101:   "tables are passed to PCRE by the application that calls it. The tables\n"
                    102:   "are used only for characters whose code values are less than 256.\n\n");
                    103: fprintf(f,
                    104:   "The following #includes are present because without them gcc 4.x may remove\n"
                    105:   "the array definition from the final binary if PCRE is built into a static\n"
                    106:   "library and dead code stripping is activated. This leads to link errors.\n"
                    107:   "Pulling in the header ensures that the array gets flagged as \"someone\n"
                    108:   "outside this compilation unit might reference this\" and so it will always\n"
                    109:   "be supplied to the linker. */\n\n"
                    110:   "#ifdef HAVE_CONFIG_H\n"
                    111:   "#include \"config.h\"\n"
                    112:   "#endif\n\n"
                    113:   "#include \"pcre_internal.h\"\n\n");
                    114: fprintf(f,
                    115:   "const unsigned char _pcre_default_tables[] = {\n\n"
                    116:   "/* This table is a lower casing table. */\n\n");
                    117: 
                    118: fprintf(f, "  ");
                    119: for (i = 0; i < 256; i++)
                    120:   {
                    121:   if ((i & 7) == 0 && i != 0) fprintf(f, "\n  ");
                    122:   fprintf(f, "%3d", *tables++);
                    123:   if (i != 255) fprintf(f, ",");
                    124:   }
                    125: fprintf(f, ",\n\n");
                    126: 
                    127: fprintf(f, "/* This table is a case flipping table. */\n\n");
                    128: 
                    129: fprintf(f, "  ");
                    130: for (i = 0; i < 256; i++)
                    131:   {
                    132:   if ((i & 7) == 0 && i != 0) fprintf(f, "\n  ");
                    133:   fprintf(f, "%3d", *tables++);
                    134:   if (i != 255) fprintf(f, ",");
                    135:   }
                    136: fprintf(f, ",\n\n");
                    137: 
                    138: fprintf(f,
                    139:   "/* This table contains bit maps for various character classes.\n"
                    140:   "Each map is 32 bytes long and the bits run from the least\n"
                    141:   "significant end of each byte. The classes that have their own\n"
                    142:   "maps are: space, xdigit, digit, upper, lower, word, graph\n"
                    143:   "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
                    144: 
                    145: fprintf(f, "  ");
                    146: for (i = 0; i < cbit_length; i++)
                    147:   {
                    148:   if ((i & 7) == 0 && i != 0)
                    149:     {
                    150:     if ((i & 31) == 0) fprintf(f, "\n");
                    151:     fprintf(f, "\n  ");
                    152:     }
                    153:   fprintf(f, "0x%02x", *tables++);
                    154:   if (i != cbit_length - 1) fprintf(f, ",");
                    155:   }
                    156: fprintf(f, ",\n\n");
                    157: 
                    158: fprintf(f,
                    159:   "/* This table identifies various classes of character by individual bits:\n"
                    160:   "  0x%02x   white space character\n"
                    161:   "  0x%02x   letter\n"
                    162:   "  0x%02x   decimal digit\n"
                    163:   "  0x%02x   hexadecimal digit\n"
                    164:   "  0x%02x   alphanumeric or '_'\n"
                    165:   "  0x%02x   regular expression metacharacter or binary zero\n*/\n\n",
                    166:   ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
                    167:   ctype_meta);
                    168: 
                    169: fprintf(f, "  ");
                    170: for (i = 0; i < 256; i++)
                    171:   {
                    172:   if ((i & 7) == 0 && i != 0)
                    173:     {
                    174:     fprintf(f, " /* ");
                    175:     if (isprint(i-8)) fprintf(f, " %c -", i-8);
                    176:       else fprintf(f, "%3d-", i-8);
                    177:     if (isprint(i-1)) fprintf(f, " %c ", i-1);
                    178:       else fprintf(f, "%3d", i-1);
                    179:     fprintf(f, " */\n  ");
                    180:     }
                    181:   fprintf(f, "0x%02x", *tables++);
                    182:   if (i != 255) fprintf(f, ",");
                    183:   }
                    184: 
                    185: fprintf(f, "};/* ");
                    186: if (isprint(i-8)) fprintf(f, " %c -", i-8);
                    187:   else fprintf(f, "%3d-", i-8);
                    188: if (isprint(i-1)) fprintf(f, " %c ", i-1);
                    189:   else fprintf(f, "%3d", i-1);
                    190: fprintf(f, " */\n\n/* End of pcre_chartables.c */\n");
                    191: 
                    192: fclose(f);
                    193: free((void *)base_of_tables);
                    194: return 0;
                    195: }
                    196: 
                    197: /* End of dftables.c */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>