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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations) (download)
Sat Feb 24 21:38:49 2007 UTC (7 years, 7 months ago) by nigel
Original Path: code/trunk/maketables.c
File MIME type: text/plain
File size: 3132 byte(s)
Load pcre-2.02 into code/trunk.

1 nigel 3 /*************************************************
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 27 Copyright (c) 1997-1999 University of Cambridge
12 nigel 3
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 nigel 25 /* This file is compiled on its own as part of the PCRE library. However,
34 nigel 27 it is also included in the compilation of dftables.c, in which case the macro
35     DFTABLES is defined. */
36 nigel 3
37 nigel 27 #ifndef DFTABLES
38 nigel 3 #include "internal.h"
39 nigel 25 #endif
40 nigel 3
41 nigel 25
42    
43     /*************************************************
44     * Create PCRE character tables *
45     *************************************************/
46    
47     /* This function builds a set of character tables for use by PCRE and returns
48     a pointer to them. They are build using the ctype functions, and consequently
49     their contents will depend upon the current locale setting. When compiled as
50     part of the library, the store is obtained via pcre_malloc(), but when compiled
51 nigel 27 inside dftables, use malloc().
52 nigel 25
53     Arguments: none
54     Returns: pointer to the contiguous block of data
55     */
56    
57     unsigned const char *
58     pcre_maketables(void)
59 nigel 3 {
60 nigel 25 unsigned char *yield, *p;
61 nigel 3 int i;
62    
63 nigel 27 #ifndef DFTABLES
64 nigel 25 yield = (pcre_malloc)(tables_length);
65     #else
66     yield = malloc(tables_length);
67     #endif
68 nigel 3
69 nigel 25 if (yield == NULL) return NULL;
70     p = yield;
71 nigel 3
72 nigel 25 /* First comes the lower casing table */
73 nigel 3
74 nigel 25 for (i = 0; i < 256; i++) *p++ = tolower(i);
75 nigel 3
76 nigel 25 /* Next the case-flipping table */
77 nigel 3
78 nigel 25 for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i);
79 nigel 3
80 nigel 25 /* Then the character class tables */
81    
82     memset(p, 0, cbit_length);
83 nigel 3 for (i = 0; i < 256; i++)
84     {
85 nigel 25 if (isdigit(i)) p[cbit_digit + i/8] |= 1 << (i&7);
86 nigel 3 if (isalnum(i) || i == '_')
87 nigel 25 p[cbit_word + i/8] |= 1 << (i&7);
88     if (isspace(i)) p[cbit_space + i/8] |= 1 << (i&7);
89 nigel 3 }
90 nigel 25 p += cbit_length;
91 nigel 3
92 nigel 25 /* Finally, the character type table */
93 nigel 3
94     for (i = 0; i < 256; i++)
95     {
96     int x = 0;
97     if (isspace(i)) x += ctype_space;
98     if (isalpha(i)) x += ctype_letter;
99     if (isdigit(i)) x += ctype_digit;
100     if (isxdigit(i)) x += ctype_xdigit;
101     if (isalnum(i) || i == '_') x += ctype_word;
102     if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta;
103 nigel 25 *p++ = x;
104 nigel 3 }
105    
106 nigel 25 return yield;
107 nigel 3 }
108    
109     /* End of maketables.c */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12