"Fossies" - the Fresh Open Source Software Archive 
Member "tin-2.6.2/pcre/dftables.c" (23 Aug 2021, 6369 Bytes) of package /linux/misc/tin-2.6.2.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "dftables.c":
2.4.3_vs_2.4.4.
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-2006 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 default
42 character tables for PCRE. The tables are built according to the default C
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 <ctype.h>
47 #include <stdio.h>
48 #include <string.h>
49
50 #include "pcre_internal.h"
51
52 #define DFTABLES /* pcre_maketables.c notices this */
53 #include "pcre_maketables.c"
54
55
56 int main(int argc, char **argv)
57 {
58 int i;
59 FILE *f;
60 const unsigned char *tables = pcre_maketables();
61 const unsigned char *base_of_tables = tables;
62
63 if (argc != 2)
64 {
65 fprintf(stderr, "dftables: one filename argument is required\n");
66 return 1;
67 }
68
69 f = fopen(argv[1], "w+");
70 if (f == NULL)
71 {
72 fprintf(stderr, "dftables: failed to open %s for writing\n", argv[1]);
73 return 1;
74 }
75
76 /* There are two fprintf() calls here, because gcc in pedantic mode complains
77 about the very long string otherwise. */
78
79 fprintf(f,
80 "/*************************************************\n"
81 "* Perl-Compatible Regular Expressions *\n"
82 "*************************************************/\n\n"
83 "/* This file is automatically written by the dftables auxiliary \n"
84 "program. If you edit it by hand, you might like to edit the Makefile to \n"
85 "prevent its ever being regenerated.\n\n");
86 fprintf(f,
87 "This file contains the default tables for characters with codes less than\n"
88 "128 (ASCII characters). These tables are used when no external tables are\n"
89 "passed to PCRE.\n\n");
90 fprintf(f,
91 "The following #include is present because without it gcc 4.x may remove\n"
92 "the array definition from the final binary if PCRE is built into a static\n"
93 "library and dead code stripping is activated. This leads to link errors.\n"
94 "Pulling in the header ensures that the array gets flagged as \"someone\n"
95 "outside this compilation unit might reference this\" and so it will always\n"
96 "be supplied to the linker. */\n\n"
97 "#include \"pcre_internal.h\"\n\n");
98 fprintf(f,
99 "const unsigned char _pcre_default_tables[] = {\n\n"
100 "/* This table is a lower casing table. */\n\n");
101
102 fprintf(f, " ");
103 for (i = 0; i < 256; i++)
104 {
105 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
106 fprintf(f, "%3d", *tables++);
107 if (i != 255) fprintf(f, ",");
108 }
109 fprintf(f, ",\n\n");
110
111 fprintf(f, "/* This table is a case flipping table. */\n\n");
112
113 fprintf(f, " ");
114 for (i = 0; i < 256; i++)
115 {
116 if ((i & 7) == 0 && i != 0) fprintf(f, "\n ");
117 fprintf(f, "%3d", *tables++);
118 if (i != 255) fprintf(f, ",");
119 }
120 fprintf(f, ",\n\n");
121
122 fprintf(f,
123 "/* This table contains bit maps for various character classes.\n"
124 "Each map is 32 bytes long and the bits run from the least\n"
125 "significant end of each byte. The classes that have their own\n"
126 "maps are: space, xdigit, digit, upper, lower, word, graph\n"
127 "print, punct, and cntrl. Other classes are built from combinations. */\n\n");
128
129 fprintf(f, " ");
130 for (i = 0; i < cbit_length; i++)
131 {
132 if ((i & 7) == 0 && i != 0)
133 {
134 if ((i & 31) == 0) fprintf(f, "\n");
135 fprintf(f, "\n ");
136 }
137 fprintf(f, "0x%02x", *tables++);
138 if (i != cbit_length - 1) fprintf(f, ",");
139 }
140 fprintf(f, ",\n\n");
141
142 fprintf(f,
143 "/* This table identifies various classes of character by individual bits:\n"
144 " 0x%02x white space character\n"
145 " 0x%02x letter\n"
146 " 0x%02x decimal digit\n"
147 " 0x%02x hexadecimal digit\n"
148 " 0x%02x alphanumeric or '_'\n"
149 " 0x%02x regular expression metacharacter or binary zero\n*/\n\n",
150 ctype_space, ctype_letter, ctype_digit, ctype_xdigit, ctype_word,
151 ctype_meta);
152
153 fprintf(f, " ");
154 for (i = 0; i < 256; i++)
155 {
156 if ((i & 7) == 0 && i != 0)
157 {
158 fprintf(f, " /* ");
159 if (isprint(i-8)) fprintf(f, " %c -", i-8);
160 else fprintf(f, "%3d-", i-8);
161 if (isprint(i-1)) fprintf(f, " %c ", i-1);
162 else fprintf(f, "%3d", i-1);
163 fprintf(f, " */\n ");
164 }
165 fprintf(f, "0x%02x", *tables++);
166 if (i != 255) fprintf(f, ",");
167 }
168
169 fprintf(f, "};/* ");
170 if (isprint(i-8)) fprintf(f, " %c -", i-8);
171 else fprintf(f, "%3d-", i-8);
172 if (isprint(i-1)) fprintf(f, " %c ", i-1);
173 else fprintf(f, "%3d", i-1);
174 fprintf(f, " */\n\n/* End of chartables.c */\n");
175
176 fclose(f);
177 free((void *)base_of_tables);
178 return 0;
179 }
180
181 /* End of dftables.c */