8 |
|
|
9 |
Written by: Philip Hazel <ph10@cam.ac.uk> |
Written by: Philip Hazel <ph10@cam.ac.uk> |
10 |
|
|
11 |
Copyright (c) 1997-2001 University of Cambridge |
Copyright (c) 1997-2003 University of Cambridge |
12 |
|
|
13 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
14 |
Permission is granted to anyone to use this software for any purpose on any |
Permission is granted to anyone to use this software for any purpose on any |
50 |
#include "maketables.c" |
#include "maketables.c" |
51 |
|
|
52 |
|
|
53 |
int main(void) |
int main(int argc, char **argv) |
54 |
{ |
{ |
55 |
int i; |
int i; |
56 |
|
FILE *f; |
57 |
const unsigned char *tables = pcre_maketables(); |
const unsigned char *tables = pcre_maketables(); |
58 |
|
|
59 |
/* There are two printf() calls here, because gcc in pedantic mode complains |
if (argc != 2) |
60 |
|
{ |
61 |
|
fprintf(stderr, "dftables: one filename argument is required\n"); |
62 |
|
return 1; |
63 |
|
} |
64 |
|
|
65 |
|
f = fopen(argv[1], "w"); |
66 |
|
if (f == NULL) |
67 |
|
{ |
68 |
|
fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]); |
69 |
|
return 1; |
70 |
|
} |
71 |
|
|
72 |
|
/* There are two fprintf() calls here, because gcc in pedantic mode complains |
73 |
about the very long string otherwise. */ |
about the very long string otherwise. */ |
74 |
|
|
75 |
printf( |
fprintf(f, |
76 |
"/*************************************************\n" |
"/*************************************************\n" |
77 |
"* Perl-Compatible Regular Expressions *\n" |
"* Perl-Compatible Regular Expressions *\n" |
78 |
"*************************************************/\n\n" |
"*************************************************/\n\n" |
79 |
"/* This file is automatically written by the dftables auxiliary \n" |
"/* This file is automatically written by the dftables auxiliary \n" |
80 |
"program. If you edit it by hand, you might like to edit the Makefile to \n" |
"program. If you edit it by hand, you might like to edit the Makefile to \n" |
81 |
"prevent its ever being regenerated.\n\n"); |
"prevent its ever being regenerated.\n\n"); |
82 |
printf( |
fprintf(f, |
83 |
"This file is #included in the compilation of pcre.c to build the default\n" |
"This file is #included in the compilation of pcre.c to build the default\n" |
84 |
"character tables which are used when no tables are passed to the compile\n" |
"character tables which are used when no tables are passed to the compile\n" |
85 |
"function. */\n\n" |
"function. */\n\n" |
86 |
"static unsigned char pcre_default_tables[] = {\n\n" |
"static unsigned char pcre_default_tables[] = {\n\n" |
87 |
"/* This table is a lower casing table. */\n\n"); |
"/* This table is a lower casing table. */\n\n"); |
88 |
|
|
89 |
printf(" "); |
fprintf(f, " "); |
90 |
for (i = 0; i < 256; i++) |
for (i = 0; i < 256; i++) |
91 |
{ |
{ |
92 |
if ((i & 7) == 0 && i != 0) printf("\n "); |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
93 |
printf("%3d", *tables++); |
fprintf(f, "%3d", *tables++); |
94 |
if (i != 255) printf(","); |
if (i != 255) fprintf(f, ","); |
95 |
} |
} |
96 |
printf(",\n\n"); |
fprintf(f, ",\n\n"); |
97 |
|
|
98 |
printf("/* This table is a case flipping table. */\n\n"); |
fprintf(f, "/* This table is a case flipping table. */\n\n"); |
99 |
|
|
100 |
printf(" "); |
fprintf(f, " "); |
101 |
for (i = 0; i < 256; i++) |
for (i = 0; i < 256; i++) |
102 |
{ |
{ |
103 |
if ((i & 7) == 0 && i != 0) printf("\n "); |
if ((i & 7) == 0 && i != 0) fprintf(f, "\n "); |
104 |
printf("%3d", *tables++); |
fprintf(f, "%3d", *tables++); |
105 |
if (i != 255) printf(","); |
if (i != 255) fprintf(f, ","); |
106 |
} |
} |
107 |
printf(",\n\n"); |
fprintf(f, ",\n\n"); |
108 |
|
|
109 |
printf( |
fprintf(f, |
110 |
"/* This table contains bit maps for various character classes.\n" |
"/* This table contains bit maps for various character classes.\n" |
111 |
"Each map is 32 bytes long and the bits run from the least\n" |
"Each map is 32 bytes long and the bits run from the least\n" |
112 |
"significant end of each byte. The classes that have their own\n" |
"significant end of each byte. The classes that have their own\n" |
113 |
"maps are: space, xdigit, digit, upper, lower, word, graph\n" |
"maps are: space, xdigit, digit, upper, lower, word, graph\n" |
114 |
"print, punct, and cntrl. Other classes are built from combinations. */\n\n"); |
"print, punct, and cntrl. Other classes are built from combinations. */\n\n"); |
115 |
|
|
116 |
printf(" "); |
fprintf(f, " "); |
117 |
for (i = 0; i < cbit_length; i++) |
for (i = 0; i < cbit_length; i++) |
118 |
{ |
{ |
119 |
if ((i & 7) == 0 && i != 0) |
if ((i & 7) == 0 && i != 0) |
120 |
{ |
{ |
121 |
if ((i & 31) == 0) printf("\n"); |
if ((i & 31) == 0) fprintf(f, "\n"); |
122 |
printf("\n "); |
fprintf(f, "\n "); |
123 |
} |
} |
124 |
printf("0x%02x", *tables++); |
fprintf(f, "0x%02x", *tables++); |
125 |
if (i != cbit_length - 1) printf(","); |
if (i != cbit_length - 1) fprintf(f, ","); |
126 |
} |
} |
127 |
printf(",\n\n"); |
fprintf(f, ",\n\n"); |
128 |
|
|
129 |
printf( |
fprintf(f, |
130 |
"/* This table identifies various classes of character by individual bits:\n" |
"/* This table identifies various classes of character by individual bits:\n" |
131 |
" 0x%02x white space character\n" |
" 0x%02x white space character\n" |
132 |
" 0x%02x letter\n" |
" 0x%02x letter\n" |
137 |
ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word, |
ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word, |
138 |
ctype_meta); |
ctype_meta); |
139 |
|
|
140 |
printf(" "); |
fprintf(f, " "); |
141 |
for (i = 0; i < 256; i++) |
for (i = 0; i < 256; i++) |
142 |
{ |
{ |
143 |
if ((i & 7) == 0 && i != 0) |
if ((i & 7) == 0 && i != 0) |
144 |
{ |
{ |
145 |
printf(" /* "); |
fprintf(f, " /* "); |
146 |
if (isprint(i-8)) printf(" %c -", i-8); |
if (isprint(i-8)) fprintf(f, " %c -", i-8); |
147 |
else printf("%3d-", i-8); |
else fprintf(f, "%3d-", i-8); |
148 |
if (isprint(i-1)) printf(" %c ", i-1); |
if (isprint(i-1)) fprintf(f, " %c ", i-1); |
149 |
else printf("%3d", i-1); |
else fprintf(f, "%3d", i-1); |
150 |
printf(" */\n "); |
fprintf(f, " */\n "); |
151 |
} |
} |
152 |
printf("0x%02x", *tables++); |
fprintf(f, "0x%02x", *tables++); |
153 |
if (i != 255) printf(","); |
if (i != 255) fprintf(f, ","); |
154 |
} |
} |
155 |
|
|
156 |
printf("};/* "); |
fprintf(f, "};/* "); |
157 |
if (isprint(i-8)) printf(" %c -", i-8); |
if (isprint(i-8)) fprintf(f, " %c -", i-8); |
158 |
else printf("%3d-", i-8); |
else fprintf(f, "%3d-", i-8); |
159 |
if (isprint(i-1)) printf(" %c ", i-1); |
if (isprint(i-1)) fprintf(f, " %c ", i-1); |
160 |
else printf("%3d", i-1); |
else fprintf(f, "%3d", i-1); |
161 |
printf(" */\n\n/* End of chartables.c */\n"); |
fprintf(f, " */\n\n/* End of chartables.c */\n"); |
162 |
|
|
163 |
|
fclose(f); |
164 |
return 0; |
return 0; |
165 |
} |
} |
166 |
|
|