../3rdparty/pcre/pcre_maketables.c

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/************************************************* -
2* Perl-Compatible Regular Expressions * -
3*************************************************/ -
4 -
5/* PCRE is a library of functions to support regular expressions whose syntax -
6and semantics are as close as possible to those of the Perl 5 language. -
7 -
8 Written by Philip Hazel -
9 Copyright (c) 1997-2012 University of Cambridge -
10 -
11----------------------------------------------------------------------------- -
12Redistribution and use in source and binary forms, with or without -
13modification, 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 -
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -
27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -
29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -
30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -
31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -
32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -
33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -
34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -
35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -
36POSSIBILITY OF SUCH DAMAGE. -
37----------------------------------------------------------------------------- -
38*/ -
39 -
40 -
41/* This module contains the external function pcre_maketables(), which builds -
42character tables for PCRE in the current locale. The file is compiled on its -
43own as part of the PCRE library. However, it is also included in the -
44compilation of dftables.c, in which case the macro DFTABLES is defined. */ -
45 -
46 -
47#ifndef DFTABLES -
48# ifdef PCRE_HAVE_CONFIG_H -
49# include "config.h" -
50# endif -
51# include "pcre_internal.h" -
52#endif -
53 -
54 -
55/************************************************* -
56* Create PCRE character tables * -
57*************************************************/ -
58 -
59/* This function builds a set of character tables for use by PCRE and returns -
60a pointer to them. They are build using the ctype functions, and consequently -
61their contents will depend upon the current locale setting. When compiled as -
62part of the library, the store is obtained via PUBL(malloc)(), but when -
63compiled inside dftables, use malloc(). -
64 -
65Arguments: none -
66Returns: pointer to the contiguous block of data -
67*/ -
68 -
69#ifdef COMPILE_PCRE8 -
70const unsigned char * -
71pcre_maketables(void) -
72#else -
73const unsigned char * -
74pcre16_maketables(void) -
75#endif -
76{ -
77unsigned char *yield, *p;
never executed (the execution status of this line is deduced): unsigned char *yield, *p;
-
78int i;
never executed (the execution status of this line is deduced): int i;
-
79 -
80#ifndef DFTABLES -
81yield = (unsigned char*)(PUBL(malloc))(tables_length);
never executed (the execution status of this line is deduced): yield = (unsigned char*)(pcre16_malloc)(((512 + 320) + 256));
-
82#else -
83yield = (unsigned char*)malloc(tables_length); -
84#endif -
85 -
86if (yield == NULL) return NULL;
never executed: return ((void *)0);
never evaluated: yield == ((void *)0)
0
87p = yield;
never executed (the execution status of this line is deduced): p = yield;
-
88 -
89/* First comes the lower casing table */ -
90 -
91for (i = 0; i < 256; i++) *p++ = tolower(i);
never executed: *p++ = (__extension__ ({ int __res; if (sizeof (i) > 1) { if (__builtin_constant_p (i)) { int __c = (i); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower (i); } else __res = (*__ctype_tolower_loc ())[(int) (i)]; __res; }));
never executed: }
never executed: __res = tolower (i);
never executed: __res = (*__ctype_tolower_loc ())[(int) (i)];
never evaluated: sizeof (i) > 1
never evaluated: __builtin_constant_p (i)
never evaluated: i < 256
never evaluated: __c < -128
never evaluated: __c > 255
0
92 -
93/* Next the case-flipping table */ -
94 -
95for (i = 0; i < 256; i++) *p++ = islower(i)? toupper(i) : tolower(i);
never executed: *p++ = ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISlower)? (__extension__ ({ int __res; if (sizeof (i) > 1) { if (__builtin_constant_p (i)) { int __c = (i); __res = __c < -128 || __c > 255 ? __c : (*__ctype_toupper_loc ())[__c]; } else __res = toupper (i); } else __res = (*__ctype_toupper_loc ())[(int) (i)]; __res; })) : (__extension__ ({ int __res; if (sizeof (i) > 1) { if (__builtin_constant_p (i)) { int __c = (i); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower (i); } else __res = (*__ctype_tolower_loc ())[(int) (i)]; __res; }));
never executed: }
never executed: __res = toupper (i);
never executed: __res = (*__ctype_toupper_loc ())[(int) (i)];
never executed: }
never executed: __res = tolower (i);
never executed: __res = (*__ctype_tolower_loc ())[(int) (i)];
never evaluated: sizeof (i) > 1
never evaluated: __builtin_constant_p (i)
never evaluated: sizeof (i) > 1
never evaluated: __builtin_constant_p (i)
never evaluated: i < 256
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISlower)
never evaluated: __c < -128
never evaluated: __c > 255
never evaluated: __c < -128
never evaluated: __c > 255
0
96 -
97/* Then the character class tables. Don't try to be clever and save effort on -
98exclusive ones - in some locales things may be different. Note that the table -
99for "space" includes everything "isspace" gives, including VT in the default -
100locale. This makes it work for the POSIX class [:space:]. Note also that it is -
101possible for a character to be alnum or alpha without being lower or upper, -
102such as "male and female ordinals" (\xAA and \xBA) in the fr_FR locale (at -
103least under Debian Linux's locales as of 12/2005). So we must test for alnum -
104specially. */ -
105 -
106memset(p, 0, cbit_length);
never executed (the execution status of this line is deduced): memset(p, 0, 320);
-
107for (i = 0; i < 256; i++)
never evaluated: i < 256
0
108 { -
109 if (isdigit(i)) p[cbit_digit + i/8] |= 1 << (i&7);
never executed: p[64 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISdigit)
0
110 if (isupper(i)) p[cbit_upper + i/8] |= 1 << (i&7);
never executed: p[96 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISupper)
0
111 if (islower(i)) p[cbit_lower + i/8] |= 1 << (i&7);
never executed: p[128 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISlower)
0
112 if (isalnum(i)) p[cbit_word + i/8] |= 1 << (i&7);
never executed: p[160 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISalnum)
0
113 if (i == '_') p[cbit_word + i/8] |= 1 << (i&7);
never executed: p[160 + i/8] |= 1 << (i&7);
never evaluated: i == '_'
0
114 if (isspace(i)) p[cbit_space + i/8] |= 1 << (i&7);
never executed: p[0 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISspace)
0
115 if (isxdigit(i))p[cbit_xdigit + i/8] |= 1 << (i&7);
never executed: p[32 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISxdigit)
0
116 if (isgraph(i)) p[cbit_graph + i/8] |= 1 << (i&7);
never executed: p[192 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISgraph)
0
117 if (isprint(i)) p[cbit_print + i/8] |= 1 << (i&7);
never executed: p[224 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISprint)
0
118 if (ispunct(i)) p[cbit_punct + i/8] |= 1 << (i&7);
never executed: p[256 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISpunct)
0
119 if (iscntrl(i)) p[cbit_cntrl + i/8] |= 1 << (i&7);
never executed: p[288 + i/8] |= 1 << (i&7);
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _IScntrl)
0
120 }
never executed: }
0
121p += cbit_length;
never executed (the execution status of this line is deduced): p += 320;
-
122 -
123/* Finally, the character type table. In this, we exclude VT from the white -
124space chars, because Perl doesn't recognize it as such for \s and for comments -
125within regexes. */ -
126 -
127for (i = 0; i < 256; i++)
never evaluated: i < 256
0
128 { -
129 int x = 0;
never executed (the execution status of this line is deduced): int x = 0;
-
130 if (i != 0x0b && isspace(i)) x += ctype_space;
never executed: x += 0x01;
never evaluated: i != 0x0b
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISspace)
0
131 if (isalpha(i)) x += ctype_letter;
never executed: x += 0x02;
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISalpha)
0
132 if (isdigit(i)) x += ctype_digit;
never executed: x += 0x04;
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISdigit)
0
133 if (isxdigit(i)) x += ctype_xdigit;
never executed: x += 0x08;
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISxdigit)
0
134 if (isalnum(i) || i == '_') x += ctype_word;
never executed: x += 0x10;
never evaluated: ((*__ctype_b_loc ())[(int) ((i))] & (unsigned short int) _ISalnum)
never evaluated: i == '_'
0
135 -
136 /* Note: strchr includes the terminating zero in the characters it considers. -
137 In this instance, that is ok because we want binary zero to be flagged as a -
138 meta-character, which in this sense is any character that terminates a run -
139 of data characters. */ -
140 -
141 if (strchr("\\*+?{^.$|()[", i) != 0) x += ctype_meta;
never executed: x += 0x80;
never evaluated: (__extension__ (__builtin_constant_p (i) && !__builtin_constant_p ("\\*+?{^.$|()[") && (i) == '\0' ? (char *) __rawmemchr ("\\*+?{^.$|()[", i) : __builtin_strchr ("\\*+?{^.$|()[", i))) != 0
never evaluated: __builtin_constant_p (i)
never evaluated: !__builtin_constant_p ("\\*+?{^.$|()[")
never evaluated: (i) == '\0'
0
142 *p++ = x;
never executed (the execution status of this line is deduced): *p++ = x;
-
143 }
never executed: }
0
144 -
145return yield;
never executed: return yield;
0
146} -
147 -
148/* End of pcre_maketables.c */ -
149 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial