| 9 |
|
|
| 10 |
Written by: Philip Hazel <ph10@cam.ac.uk> |
Written by: Philip Hazel <ph10@cam.ac.uk> |
| 11 |
|
|
| 12 |
Copyright (c) 1997-2003 University of Cambridge |
Copyright (c) 1997-2004 University of Cambridge |
| 13 |
|
|
| 14 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 15 |
Permission is granted to anyone to use this software for any purpose on any |
Redistribution and use in source and binary forms, with or without |
| 16 |
computer system, and to redistribute it freely, subject to the following |
modification, are permitted provided that the following conditions are met: |
| 17 |
restrictions: |
|
| 18 |
|
* Redistributions of source code must retain the above copyright notice, |
| 19 |
1. This software is distributed in the hope that it will be useful, |
this list of conditions and the following disclaimer. |
| 20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
* Redistributions in binary form must reproduce the above copyright |
| 22 |
|
notice, this list of conditions and the following disclaimer in the |
| 23 |
2. The origin of this software must not be misrepresented, either by |
documentation and/or other materials provided with the distribution. |
| 24 |
explicit claim or by omission. |
|
| 25 |
|
* Neither the name of the University of Cambridge nor the names of its |
| 26 |
3. Altered versions must be plainly marked as such, and must not be |
contributors may be used to endorse or promote products derived from |
| 27 |
misrepresented as being the original software. |
this software without specific prior written permission. |
| 28 |
|
|
| 29 |
4. If PCRE is embedded in any software that is released under the GNU |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 30 |
General Purpose Licence (GPL), then the terms of that licence shall |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 31 |
supersede any condition above with which it is incompatible. |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 32 |
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 33 |
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 34 |
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 35 |
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 36 |
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 37 |
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 38 |
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 39 |
|
POSSIBILITY OF SUCH DAMAGE. |
| 40 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
| 41 |
*/ |
*/ |
| 42 |
|
|
| 84 |
c = (c & utf8_t3[a]) << s; |
c = (c & utf8_t3[a]) << s; |
| 85 |
for (i = 1; i <= a; i++) |
for (i = 1; i <= a; i++) |
| 86 |
{ |
{ |
| 87 |
|
/* This is a check for malformed UTF-8; it should only occur if the sanity |
| 88 |
|
check has been turned off. Rather than swallow random bytes, just stop if |
| 89 |
|
we hit a bad one. Print it with \X instead of \x as an indication. */ |
| 90 |
|
|
| 91 |
|
if ((ptr[i] & 0xc0) != 0x80) |
| 92 |
|
{ |
| 93 |
|
fprintf(f, "\\X{%x}", c); |
| 94 |
|
return i - 1; |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
/* The byte is OK */ |
| 98 |
|
|
| 99 |
s -= 6; |
s -= 6; |
| 100 |
c |= (ptr[i] & 0x3f) << s; |
c |= (ptr[i] & 0x3f) << s; |
| 101 |
} |
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
/************************************************* |
/************************************************* |
| 111 |
|
* Find Unicode property name * |
| 112 |
|
*************************************************/ |
| 113 |
|
|
| 114 |
|
static const char * |
| 115 |
|
get_ucpname(int property) |
| 116 |
|
{ |
| 117 |
|
int i; |
| 118 |
|
for (i = sizeof(utt)/sizeof(ucp_type_table); i >= 0; i--) |
| 119 |
|
{ |
| 120 |
|
if (property == utt[i].value) break; |
| 121 |
|
} |
| 122 |
|
return (i >= 0)? utt[i].name : "??"; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
/************************************************* |
| 128 |
* Print compiled regex * |
* Print compiled regex * |
| 129 |
*************************************************/ |
*************************************************/ |
| 130 |
|
|
| 131 |
|
/* Make this function work for a regex with integers either byte order. |
| 132 |
|
However, we assume that what we are passed is a compiled regex. */ |
| 133 |
|
|
| 134 |
static void |
static void |
| 135 |
print_internals(pcre *external_re, FILE *f) |
print_internals(pcre *external_re, FILE *f) |
| 136 |
{ |
{ |
| 137 |
real_pcre *re = (real_pcre *)external_re; |
real_pcre *re = (real_pcre *)external_re; |
| 138 |
uschar *codestart = |
uschar *codestart, *code; |
| 139 |
(uschar *)re + sizeof(real_pcre) + re->name_count * re->name_entry_size; |
BOOL utf8; |
| 140 |
uschar *code = codestart; |
|
| 141 |
BOOL utf8 = (re->options & PCRE_UTF8) != 0; |
unsigned int options = re->options; |
| 142 |
|
int offset = re->name_table_offset; |
| 143 |
|
int count = re->name_count; |
| 144 |
|
int size = re->name_entry_size; |
| 145 |
|
|
| 146 |
|
if (re->magic_number != MAGIC_NUMBER) |
| 147 |
|
{ |
| 148 |
|
offset = ((offset << 8) & 0xff00) | ((offset >> 8) & 0xff); |
| 149 |
|
count = ((count << 8) & 0xff00) | ((count >> 8) & 0xff); |
| 150 |
|
size = ((size << 8) & 0xff00) | ((size >> 8) & 0xff); |
| 151 |
|
options = ((options << 24) & 0xff000000) | |
| 152 |
|
((options << 8) & 0x00ff0000) | |
| 153 |
|
((options >> 8) & 0x0000ff00) | |
| 154 |
|
((options >> 24) & 0x000000ff); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
code = codestart = (uschar *)re + offset + count * size; |
| 158 |
|
utf8 = (options & PCRE_UTF8) != 0; |
| 159 |
|
|
| 160 |
for(;;) |
for(;;) |
| 161 |
{ |
{ |
| 186 |
fprintf(f, " %.2x %s", code[1], OP_names[*code]); |
fprintf(f, " %.2x %s", code[1], OP_names[*code]); |
| 187 |
break; |
break; |
| 188 |
|
|
| 189 |
case OP_CHARS: |
case OP_CHAR: |
| 190 |
{ |
{ |
| 191 |
int charlength = code[1]; |
fprintf(f, " "); |
| 192 |
ccode = code + 2; |
do |
|
extra = charlength; |
|
|
fprintf(f, "%3d ", charlength); |
|
|
while (charlength > 0) |
|
| 193 |
{ |
{ |
| 194 |
int extrabytes = print_char(f, ccode, utf8); |
code++; |
| 195 |
ccode += 1 + extrabytes; |
code += 1 + print_char(f, code, utf8); |
|
charlength -= 1 + extrabytes; |
|
| 196 |
} |
} |
| 197 |
|
while (*code == OP_CHAR); |
| 198 |
|
fprintf(f, "\n"); |
| 199 |
|
continue; |
| 200 |
|
} |
| 201 |
|
break; |
| 202 |
|
|
| 203 |
|
case OP_CHARNC: |
| 204 |
|
{ |
| 205 |
|
fprintf(f, " NC "); |
| 206 |
|
do |
| 207 |
|
{ |
| 208 |
|
code++; |
| 209 |
|
code += 1 + print_char(f, code, utf8); |
| 210 |
|
} |
| 211 |
|
while (*code == OP_CHARNC); |
| 212 |
|
fprintf(f, "\n"); |
| 213 |
|
continue; |
| 214 |
} |
} |
| 215 |
break; |
break; |
| 216 |
|
|
| 252 |
case OP_TYPEQUERY: |
case OP_TYPEQUERY: |
| 253 |
case OP_TYPEMINQUERY: |
case OP_TYPEMINQUERY: |
| 254 |
fprintf(f, " "); |
fprintf(f, " "); |
| 255 |
if (*code >= OP_TYPESTAR) fprintf(f, "%s", OP_names[code[1]]); |
if (*code >= OP_TYPESTAR) |
| 256 |
else extra = print_char(f, code+1, utf8); |
{ |
| 257 |
|
fprintf(f, "%s", OP_names[code[1]]); |
| 258 |
|
if (code[1] == OP_PROP || code[1] == OP_NOTPROP) |
| 259 |
|
{ |
| 260 |
|
fprintf(f, " %s ", get_ucpname(code[2])); |
| 261 |
|
extra = 1; |
| 262 |
|
} |
| 263 |
|
} |
| 264 |
|
else extra = print_char(f, code+1, utf8); |
| 265 |
fprintf(f, "%s", OP_names[*code]); |
fprintf(f, "%s", OP_names[*code]); |
| 266 |
break; |
break; |
| 267 |
|
|
| 279 |
case OP_TYPEEXACT: |
case OP_TYPEEXACT: |
| 280 |
case OP_TYPEUPTO: |
case OP_TYPEUPTO: |
| 281 |
case OP_TYPEMINUPTO: |
case OP_TYPEMINUPTO: |
| 282 |
fprintf(f, " %s{", OP_names[code[3]]); |
fprintf(f, " %s", OP_names[code[3]]); |
| 283 |
|
if (code[3] == OP_PROP || code[3] == OP_NOTPROP) |
| 284 |
|
{ |
| 285 |
|
fprintf(f, " %s ", get_ucpname(code[4])); |
| 286 |
|
extra = 1; |
| 287 |
|
} |
| 288 |
|
fprintf(f, "{"); |
| 289 |
if (*code != OP_TYPEEXACT) fprintf(f, "0,"); |
if (*code != OP_TYPEEXACT) fprintf(f, "0,"); |
| 290 |
fprintf(f, "%d}", GET2(code,1)); |
fprintf(f, "%d}", GET2(code,1)); |
| 291 |
if (*code == OP_TYPEMINUPTO) fprintf(f, "?"); |
if (*code == OP_TYPEMINUPTO) fprintf(f, "?"); |
| 327 |
goto CLASS_REF_REPEAT; |
goto CLASS_REF_REPEAT; |
| 328 |
|
|
| 329 |
case OP_CALLOUT: |
case OP_CALLOUT: |
| 330 |
fprintf(f, " %s %d", OP_names[*code], code[1]); |
fprintf(f, " %s %d %d %d", OP_names[*code], code[1], GET(code,2), |
| 331 |
|
GET(code, 2 + LINK_SIZE)); |
| 332 |
|
break; |
| 333 |
|
|
| 334 |
|
case OP_PROP: |
| 335 |
|
case OP_NOTPROP: |
| 336 |
|
fprintf(f, " %s %s", OP_names[*code], get_ucpname(code[1])); |
| 337 |
break; |
break; |
| 338 |
|
|
| 339 |
/* OP_XCLASS can only occur in UTF-8 mode. However, there's no harm in |
/* OP_XCLASS can only occur in UTF-8 mode. However, there's no harm in |
| 377 |
if (isprint(i)) fprintf(f, "%c", i); else fprintf(f, "\\x%02x", i); |
if (isprint(i)) fprintf(f, "%c", i); else fprintf(f, "\\x%02x", i); |
| 378 |
if (--j > i) |
if (--j > i) |
| 379 |
{ |
{ |
| 380 |
fprintf(f, "-"); |
if (j != i + 1) fprintf(f, "-"); |
| 381 |
if (j == '-' || j == ']') fprintf(f, "\\"); |
if (j == '-' || j == ']') fprintf(f, "\\"); |
| 382 |
if (isprint(j)) fprintf(f, "%c", j); else fprintf(f, "\\x%02x", j); |
if (isprint(j)) fprintf(f, "%c", j); else fprintf(f, "\\x%02x", j); |
| 383 |
} |
} |
| 394 |
int ch; |
int ch; |
| 395 |
while ((ch = *ccode++) != XCL_END) |
while ((ch = *ccode++) != XCL_END) |
| 396 |
{ |
{ |
| 397 |
ccode += 1 + print_char(f, ccode, TRUE); |
if (ch == XCL_PROP) |
| 398 |
if (ch == XCL_RANGE) |
{ |
| 399 |
|
fprintf(f, "\\p{%s}", get_ucpname(*ccode++)); |
| 400 |
|
} |
| 401 |
|
else if (ch == XCL_NOTPROP) |
| 402 |
|
{ |
| 403 |
|
fprintf(f, "\\P{%s}", get_ucpname(*ccode++)); |
| 404 |
|
} |
| 405 |
|
else |
| 406 |
{ |
{ |
|
fprintf(f, "-"); |
|
| 407 |
ccode += 1 + print_char(f, ccode, TRUE); |
ccode += 1 + print_char(f, ccode, TRUE); |
| 408 |
|
if (ch == XCL_RANGE) |
| 409 |
|
{ |
| 410 |
|
fprintf(f, "-"); |
| 411 |
|
ccode += 1 + print_char(f, ccode, TRUE); |
| 412 |
|
} |
| 413 |
} |
} |
| 414 |
} |
} |
| 415 |
} |
} |
| 430 |
case OP_CRQUERY: |
case OP_CRQUERY: |
| 431 |
case OP_CRMINQUERY: |
case OP_CRMINQUERY: |
| 432 |
fprintf(f, "%s", OP_names[*ccode]); |
fprintf(f, "%s", OP_names[*ccode]); |
| 433 |
extra = OP_lengths[*ccode]; |
extra += OP_lengths[*ccode]; |
| 434 |
break; |
break; |
| 435 |
|
|
| 436 |
case OP_CRRANGE: |
case OP_CRRANGE: |
| 440 |
if (max == 0) fprintf(f, "{%d,}", min); |
if (max == 0) fprintf(f, "{%d,}", min); |
| 441 |
else fprintf(f, "{%d,%d}", min, max); |
else fprintf(f, "{%d,%d}", min, max); |
| 442 |
if (*ccode == OP_CRMINRANGE) fprintf(f, "?"); |
if (*ccode == OP_CRMINRANGE) fprintf(f, "?"); |
| 443 |
extra = OP_lengths[*ccode]; |
extra += OP_lengths[*ccode]; |
| 444 |
break; |
break; |
| 445 |
} |
} |
| 446 |
} |
} |