/[pcre]/code/trunk/dftables.c
ViewVC logotype

Contents of /code/trunk/dftables.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 65 - (hide annotations) (download)
Sat Feb 24 21:40:08 2007 UTC (7 years, 7 months ago) by nigel
File MIME type: text/plain
File size: 4766 byte(s)
Load pcre-4.1 into code/trunk.

1 nigel 27 /*************************************************
2     * Perl-Compatible Regular Expressions *
3     *************************************************/
4    
5     /*
6     PCRE is a library of functions to support regular expressions whose syntax
7     and semantics are as close as possible to those of the Perl 5 language.
8    
9     Written by: Philip Hazel <ph10@cam.ac.uk>
10    
11 nigel 53 Copyright (c) 1997-2001 University of Cambridge
12 nigel 27
13     -----------------------------------------------------------------------------
14     Permission is granted to anyone to use this software for any purpose on any
15     computer system, and to redistribute it freely, subject to the following
16     restrictions:
17    
18     1. This software is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21    
22     2. The origin of this software must not be misrepresented, either by
23     explicit claim or by omission.
24    
25     3. Altered versions must be plainly marked as such, and must not be
26     misrepresented as being the original software.
27 nigel 29
28     4. If PCRE is embedded in any software that is released under the GNU
29     General Purpose Licence (GPL), then the terms of that licence shall
30     supersede any condition above with which it is incompatible.
31 nigel 27 -----------------------------------------------------------------------------
32    
33     See the file Tech.Notes for some information on the internals.
34     */
35    
36    
37     /* This is a support program to generate the file chartables.c, containing
38     character tables of various kinds. They are built according to the default C
39     locale and used as the default tables by PCRE. Now that pcre_maketables is
40     a function visible to the outside world, we make use of its code from here in
41     order to be consistent. */
42    
43     #include <ctype.h>
44     #include <stdio.h>
45     #include <string.h>
46    
47     #include "internal.h"
48    
49     #define DFTABLES /* maketables.c notices this */
50     #include "maketables.c"
51    
52    
53     int main(void)
54     {
55     int i;
56 nigel 53 const unsigned char *tables = pcre_maketables();
57 nigel 27
58 nigel 65 /* There are two printf() calls here, because gcc in pedantic mode complains
59     about the very long string otherwise. */
60    
61 nigel 27 printf(
62     "/*************************************************\n"
63     "* Perl-Compatible Regular Expressions *\n"
64     "*************************************************/\n\n"
65 nigel 35 "/* This file is automatically written by the dftables auxiliary \n"
66 nigel 27 "program. If you edit it by hand, you might like to edit the Makefile to \n"
67 nigel 65 "prevent its ever being regenerated.\n\n");
68     printf(
69 nigel 27 "This file is #included in the compilation of pcre.c to build the default\n"
70     "character tables which are used when no tables are passed to the compile\n"
71     "function. */\n\n"
72     "static unsigned char pcre_default_tables[] = {\n\n"
73     "/* This table is a lower casing table. */\n\n");
74    
75     printf(" ");
76     for (i = 0; i < 256; i++)
77     {
78     if ((i & 7) == 0 && i != 0) printf("\n ");
79     printf("%3d", *tables++);
80     if (i != 255) printf(",");
81     }
82     printf(",\n\n");
83    
84     printf("/* This table is a case flipping table. */\n\n");
85    
86     printf(" ");
87     for (i = 0; i < 256; i++)
88     {
89     if ((i & 7) == 0 && i != 0) printf("\n ");
90     printf("%3d", *tables++);
91     if (i != 255) printf(",");
92     }
93     printf(",\n\n");
94    
95     printf(
96 nigel 43 "/* This table contains bit maps for various character classes.\n"
97     "Each map is 32 bytes long and the bits run from the least\n"
98     "significant end of each byte. The classes that have their own\n"
99     "maps are: space, xdigit, digit, upper, lower, word, graph\n"
100     "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
101 nigel 27
102     printf(" ");
103     for (i = 0; i < cbit_length; i++)
104     {
105     if ((i & 7) == 0 && i != 0)
106     {
107     if ((i & 31) == 0) printf("\n");
108     printf("\n ");
109     }
110     printf("0x%02x", *tables++);
111     if (i != cbit_length - 1) printf(",");
112     }
113 nigel 43 printf(",\n\n");
114 nigel 27
115     printf(
116     "/* This table identifies various classes of character by individual bits:\n"
117     " 0x%02x white space character\n"
118     " 0x%02x letter\n"
119     " 0x%02x decimal digit\n"
120     " 0x%02x hexadecimal digit\n"
121     " 0x%02x alphanumeric or '_'\n"
122     " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
123     ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
124     ctype_meta);
125    
126     printf(" ");
127     for (i = 0; i < 256; i++)
128     {
129     if ((i & 7) == 0 && i != 0)
130     {
131     printf(" /* ");
132     if (isprint(i-8)) printf(" %c -", i-8);
133     else printf("%3d-", i-8);
134     if (isprint(i-1)) printf(" %c ", i-1);
135     else printf("%3d", i-1);
136     printf(" */\n ");
137     }
138     printf("0x%02x", *tables++);
139     if (i != 255) printf(",");
140     }
141    
142     printf("};/* ");
143     if (isprint(i-8)) printf(" %c -", i-8);
144     else printf("%3d-", i-8);
145     if (isprint(i-1)) printf(" %c ", i-1);
146     else printf("%3d", i-1);
147     printf(" */\n\n/* End of chartables.c */\n");
148    
149     return 0;
150     }
151    
152     /* End of dftables.c */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12