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

Contents of /code/trunk/dftables.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 75 - (hide annotations) (download)
Sat Feb 24 21:40:37 2007 UTC (7 years, 9 months ago) by nigel
File MIME type: text/plain
File size: 5808 byte(s)
Load pcre-5.0 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 75 Copyright (c) 1997-2004 University of Cambridge
12 nigel 27
13     -----------------------------------------------------------------------------
14 nigel 75 Redistribution and use in source and binary forms, with or without
15     modification, are permitted provided that the following conditions are met:
16 nigel 27
17 nigel 75 * Redistributions of source code must retain the above copyright notice,
18     this list of conditions and the following disclaimer.
19 nigel 27
20 nigel 75 * 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.
23 nigel 27
24 nigel 75 * 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.
27 nigel 29
28 nigel 75 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 nigel 27 -----------------------------------------------------------------------------
40     */
41    
42    
43     /* This is a support program to generate the file chartables.c, containing
44     character tables of various kinds. They are built according to the default C
45     locale and used as the default tables by PCRE. Now that pcre_maketables is
46     a function visible to the outside world, we make use of its code from here in
47     order to be consistent. */
48    
49     #include <ctype.h>
50     #include <stdio.h>
51     #include <string.h>
52    
53     #include "internal.h"
54    
55     #define DFTABLES /* maketables.c notices this */
56     #include "maketables.c"
57    
58    
59 nigel 73 int main(int argc, char **argv)
60 nigel 27 {
61     int i;
62 nigel 73 FILE *f;
63 nigel 53 const unsigned char *tables = pcre_maketables();
64 nigel 27
65 nigel 73 if (argc != 2)
66     {
67     fprintf(stderr, "dftables: one filename argument is required\n");
68     return 1;
69     }
70    
71     f = fopen(argv[1], "w");
72     if (f == NULL)
73     {
74     fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
75     return 1;
76     }
77    
78     /* There are two fprintf() calls here, because gcc in pedantic mode complains
79 nigel 65 about the very long string otherwise. */
80    
81 nigel 73 fprintf(f,
82 nigel 27 "/*************************************************\n"
83     "* Perl-Compatible Regular Expressions *\n"
84     "*************************************************/\n\n"
85 nigel 35 "/* This file is automatically written by the dftables auxiliary \n"
86 nigel 27 "program. If you edit it by hand, you might like to edit the Makefile to \n"
87 nigel 65 "prevent its ever being regenerated.\n\n");
88 nigel 73 fprintf(f,
89 nigel 27 "This file is #included in the compilation of pcre.c to build the default\n"
90     "character tables which are used when no tables are passed to the compile\n"
91     "function. */\n\n"
92     "static unsigned char pcre_default_tables[] = {\n\n"
93     "/* This table is a lower casing table. */\n\n");
94    
95 nigel 73 fprintf(f, " ");
96 nigel 27 for (i = 0; i < 256; i++)
97     {
98 nigel 73 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
99     fprintf(f, "%3d", *tables++);
100     if (i != 255) fprintf(f, ",");
101 nigel 27 }
102 nigel 73 fprintf(f, ",\n\n");
103 nigel 27
104 nigel 73 fprintf(f, "/* This table is a case flipping table. */\n\n");
105 nigel 27
106 nigel 73 fprintf(f, " ");
107 nigel 27 for (i = 0; i < 256; i++)
108     {
109 nigel 73 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
110     fprintf(f, "%3d", *tables++);
111     if (i != 255) fprintf(f, ",");
112 nigel 27 }
113 nigel 73 fprintf(f, ",\n\n");
114 nigel 27
115 nigel 73 fprintf(f,
116 nigel 43 "/* This table contains bit maps for various character classes.\n"
117     "Each map is 32 bytes long and the bits run from the least\n"
118     "significant end of each byte. The classes that have their own\n"
119     "maps are: space, xdigit, digit, upper, lower, word, graph\n"
120     "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
121 nigel 27
122 nigel 73 fprintf(f, " ");
123 nigel 27 for (i = 0; i < cbit_length; i++)
124     {
125     if ((i & 7) == 0 && i != 0)
126     {
127 nigel 73 if ((i & 31) == 0) fprintf(f, "\n");
128     fprintf(f, "\n ");
129 nigel 27 }
130 nigel 73 fprintf(f, "0x%02x", *tables++);
131     if (i != cbit_length - 1) fprintf(f, ",");
132 nigel 27 }
133 nigel 73 fprintf(f, ",\n\n");
134 nigel 27
135 nigel 73 fprintf(f,
136 nigel 27 "/* This table identifies various classes of character by individual bits:\n"
137     " 0x%02x white space character\n"
138     " 0x%02x letter\n"
139     " 0x%02x decimal digit\n"
140     " 0x%02x hexadecimal digit\n"
141     " 0x%02x alphanumeric or '_'\n"
142     " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
143     ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
144     ctype_meta);
145    
146 nigel 73 fprintf(f, " ");
147 nigel 27 for (i = 0; i < 256; i++)
148     {
149     if ((i & 7) == 0 && i != 0)
150     {
151 nigel 73 fprintf(f, " /* ");
152     if (isprint(i-8)) fprintf(f, " %c -", i-8);
153     else fprintf(f, "%3d-", i-8);
154     if (isprint(i-1)) fprintf(f, " %c ", i-1);
155     else fprintf(f, "%3d", i-1);
156     fprintf(f, " */\n ");
157 nigel 27 }
158 nigel 73 fprintf(f, "0x%02x", *tables++);
159     if (i != 255) fprintf(f, ",");
160 nigel 27 }
161    
162 nigel 73 fprintf(f, "};/* ");
163     if (isprint(i-8)) fprintf(f, " %c -", i-8);
164     else fprintf(f, "%3d-", i-8);
165     if (isprint(i-1)) fprintf(f, " %c ", i-1);
166     else fprintf(f, "%3d", i-1);
167     fprintf(f, " */\n\n/* End of chartables.c */\n");
168 nigel 27
169 nigel 73 fclose(f);
170 nigel 27 return 0;
171     }
172    
173     /* End of dftables.c */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12