/[pcre]/code/tags/pcre-1.08/maketables.c
ViewVC logotype

Contents of /code/tags/pcre-1.08/maketables.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations) (download)
Sat Feb 24 21:38:35 2007 UTC (7 years, 8 months ago) by nigel
File MIME type: text/plain
File size: 4557 byte(s)
Tag code/trunk as code/tags/pcre-1.08.

1 /*************************************************
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 Copyright (c) 1998 University of Cambridge
12
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 -----------------------------------------------------------------------------
28
29 See the file Tech.Notes for some information on the internals.
30 */
31
32
33 /* This is a support program to generate the file chartables.c, containing
34 character tables of various kinds. They are built according to the local C
35 locale. */
36
37 #include <ctype.h>
38 #include <stdio.h>
39 #include <string.h>
40
41 #include "internal.h"
42
43 int main(void)
44 {
45 int i;
46 unsigned char cbits[cbit_length];
47
48 printf(
49 "/*************************************************\n"
50 "* Perl-Compatible Regular Expressions *\n"
51 "*************************************************/\n\n"
52 "/* This file is automatically written by the makechartables auxiliary \n"
53 "program. If you edit it by hand, you might like to edit the Makefile to \n"
54 "prevent its ever being regenerated. */\n\n"
55 "/* This table is a lower casing table. */\n\n"
56 "unsigned char pcre_lcc[] = {\n");
57
58 printf(" ");
59 for (i = 0; i < 256; i++)
60 {
61 if ((i & 7) == 0 && i != 0) printf("\n ");
62 printf("%3d", tolower(i));
63 if (i != 255) printf(",");
64 }
65 printf(" };\n\n");
66
67 printf(
68 "/* This table is a case flipping table. */\n\n"
69 "unsigned char pcre_fcc[] = {\n");
70
71 printf(" ");
72 for (i = 0; i < 256; i++)
73 {
74 if ((i & 7) == 0 && i != 0) printf("\n ");
75 printf("%3d", islower(i)? toupper(i) : tolower(i));
76 if (i != 255) printf(",");
77 }
78 printf(" };\n\n");
79
80 printf(
81 "/* This table contains bit maps for digits, letters, 'word' chars, and\n"
82 "white space. Each map is 32 bytes long and the bits run from the least\n"
83 "significant end of each byte. */\n\n"
84 "unsigned char pcre_cbits[] = {\n");
85
86 memset(cbits, 0, sizeof(cbits));
87
88 for (i = 0; i < 256; i++)
89 {
90 if (isdigit(i)) cbits[cbit_digit + i/8] |= 1 << (i&7);
91 if (isalpha(i)) cbits[cbit_letter + i/8] |= 1 << (i&7);
92 if (isalnum(i) || i == '_')
93 cbits[cbit_word + i/8] |= 1 << (i&7);
94 if (isspace(i)) cbits[cbit_space + i/8] |= 1 << (i&7);
95 }
96
97 printf(" ");
98 for (i = 0; i < cbit_length; i++)
99 {
100 if ((i & 7) == 0 && i != 0)
101 {
102 if ((i & 31) == 0) printf("\n");
103 printf("\n ");
104 }
105 printf("0x%02x", cbits[i]);
106 if (i != cbit_length - 1) printf(",");
107 }
108 printf(" };\n\n");
109
110 printf(
111 "/* This table identifies various classes of character by individual bits:\n"
112 " 0x%02x white space character\n"
113 " 0x%02x letter\n"
114 " 0x%02x decimal digit\n"
115 " 0x%02x hexadecimal digit\n"
116 " 0x%02x alphanumeric or '_'\n"
117 " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
118 ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
119 ctype_meta);
120
121 printf("unsigned char pcre_ctypes[] = {\n");
122
123 printf(" ");
124 for (i = 0; i < 256; i++)
125 {
126 int x = 0;
127 if (isspace(i)) x += ctype_space;
128 if (isalpha(i)) x += ctype_letter;
129 if (isdigit(i)) x += ctype_digit;
130 if (isxdigit(i)) x += ctype_xdigit;
131 if (isalnum(i) || i == '_') x += ctype_word;
132 if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta;
133
134 if ((i & 7) == 0 && i != 0)
135 {
136 printf(" /* ");
137 if (isprint(i-8)) printf(" %c -", i-8);
138 else printf("%3d-", i-8);
139 if (isprint(i-1)) printf(" %c ", i-1);
140 else printf("%3d", i-1);
141 printf(" */\n ");
142 }
143 printf("0x%02x", x);
144 if (i != 255) printf(",");
145 }
146
147 printf("};/* ");
148 if (isprint(i-8)) printf(" %c -", i-8);
149 else printf("%3d-", i-8);
150 if (isprint(i-1)) printf(" %c ", i-1);
151 else printf("%3d", i-1);
152 printf(" */\n\n/* End of chartables.c */\n");
153
154 return 0;
155 }
156
157 /* End of maketables.c */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12