version 1.1.1.1, 2012/02/21 23:50:25
|
version 1.1.1.4, 2014/06/15 19:46:04
|
Line 78 having a separate .h file just for this. */
|
Line 78 having a separate .h file just for this. */
|
#ifdef PCRE_INCLUDED |
#ifdef PCRE_INCLUDED |
static /* Keep the following function as private. */ |
static /* Keep the following function as private. */ |
#endif |
#endif |
#ifdef COMPILE_PCRE8 | |
| #if defined COMPILE_PCRE8 |
void pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths); |
void pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths); |
#else | #elif defined COMPILE_PCRE16 |
void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths); |
void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths); |
|
#elif defined COMPILE_PCRE32 |
|
void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths); |
#endif |
#endif |
|
|
/* Macro that decides whether a character should be output as a literal or in |
/* Macro that decides whether a character should be output as a literal or in |
Line 111 static const pcre_uint8 priv_OP_lengths[] = { OP_LENGT
|
Line 114 static const pcre_uint8 priv_OP_lengths[] = { OP_LENGT
|
* Print single- or multi-byte character * |
* Print single- or multi-byte character * |
*************************************************/ |
*************************************************/ |
|
|
static int | static unsigned int |
print_char(FILE *f, pcre_uchar *ptr, BOOL utf) |
print_char(FILE *f, pcre_uchar *ptr, BOOL utf) |
{ |
{ |
int c = *ptr; | pcre_uint32 c = *ptr; |
|
|
#ifndef SUPPORT_UTF |
#ifndef SUPPORT_UTF |
|
|
(void)utf; /* Avoid compiler warning */ |
(void)utf; /* Avoid compiler warning */ |
if (PRINTABLE(c)) fprintf(f, "%c", c); | if (PRINTABLE(c)) fprintf(f, "%c", (char)c); |
else if (c <= 0xff) fprintf(f, "\\x%02x", c); | else if (c <= 0x80) fprintf(f, "\\x%02x", c); |
else fprintf(f, "\\x{%x}", c); |
else fprintf(f, "\\x{%x}", c); |
return 0; |
return 0; |
|
|
#else |
#else |
|
|
#ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
|
|
if (!utf || (c & 0xc0) != 0xc0) |
if (!utf || (c & 0xc0) != 0xc0) |
{ |
{ |
if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c); | if (PRINTABLE(c)) fprintf(f, "%c", (char)c); |
| else if (c < 0x80) fprintf(f, "\\x%02x", c); |
| else fprintf(f, "\\x{%02x}", c); |
return 0; |
return 0; |
} |
} |
else |
else |
Line 160 else
|
Line 165 else
|
return a; |
return a; |
} |
} |
|
|
#else | #elif defined COMPILE_PCRE16 |
|
|
#ifdef COMPILE_PCRE16 |
|
|
|
if (!utf || (c & 0xfc00) != 0xd800) |
if (!utf || (c & 0xfc00) != 0xd800) |
{ |
{ |
if (PRINTABLE(c)) fprintf(f, "%c", c); | if (PRINTABLE(c)) fprintf(f, "%c", (char)c); |
else if (c <= 0xff) fprintf(f, "\\x%02x", c); | else if (c <= 0x80) fprintf(f, "\\x%02x", c); |
else fprintf(f, "\\x{%x}", c); | else fprintf(f, "\\x{%02x}", c); |
return 0; |
return 0; |
} |
} |
else |
else |
Line 188 else
|
Line 191 else
|
return 1; |
return 1; |
} |
} |
|
|
#endif /* COMPILE_PCRE16 */ | #elif defined COMPILE_PCRE32 |
|
|
#endif /* COMPILE_PCRE8 */ | if (!utf || (c & 0xfffff800u) != 0xd800u) |
| { |
| if (PRINTABLE(c)) fprintf(f, "%c", (char)c); |
| else if (c <= 0x80) fprintf(f, "\\x%02x", c); |
| else fprintf(f, "\\x{%x}", c); |
| return 0; |
| } |
| else |
| { |
| /* This is a check for malformed UTF-32; it should only occur if the sanity |
| check has been turned off. Rather than swallow a surrogate, just stop if |
| we hit one. Print it with \X instead of \x as an indication. */ |
| fprintf(f, "\\X{%x}", c); |
| return 0; |
| } |
|
|
|
#endif /* COMPILE_PCRE[8|16|32] */ |
|
|
#endif /* SUPPORT_UTF */ |
#endif /* SUPPORT_UTF */ |
} |
} |
|
|
Line 204 print_puchar(FILE *f, PCRE_PUCHAR ptr)
|
Line 223 print_puchar(FILE *f, PCRE_PUCHAR ptr)
|
{ |
{ |
while (*ptr != '\0') |
while (*ptr != '\0') |
{ |
{ |
register int c = *ptr++; | register pcre_uint32 c = *ptr++; |
if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x{%x}", c); |
if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x{%x}", c); |
} |
} |
} |
} |
Line 214 while (*ptr != '\0')
|
Line 233 while (*ptr != '\0')
|
*************************************************/ |
*************************************************/ |
|
|
static const char * |
static const char * |
get_ucpname(int ptype, int pvalue) | get_ucpname(unsigned int ptype, unsigned int pvalue) |
{ |
{ |
#ifdef SUPPORT_UCP |
#ifdef SUPPORT_UCP |
int i; |
int i; |
Line 231 return (ptype == pvalue)? "??" : "??";
|
Line 250 return (ptype == pvalue)? "??" : "??";
|
} |
} |
|
|
|
|
|
/************************************************* |
|
* Print Unicode property value * |
|
*************************************************/ |
|
|
|
/* "Normal" properties can be printed from tables. The PT_CLIST property is a |
|
pseudo-property that contains a pointer to a list of case-equivalent |
|
characters. This is used only when UCP support is available and UTF mode is |
|
selected. It should never occur otherwise, but just in case it does, have |
|
something ready to print. */ |
|
|
|
static void |
|
print_prop(FILE *f, pcre_uchar *code, const char *before, const char *after) |
|
{ |
|
if (code[1] != PT_CLIST) |
|
{ |
|
fprintf(f, "%s%s %s%s", before, priv_OP_names[*code], get_ucpname(code[1], |
|
code[2]), after); |
|
} |
|
else |
|
{ |
|
const char *not = (*code == OP_PROP)? "" : "not "; |
|
#ifndef SUPPORT_UCP |
|
fprintf(f, "%s%sclist %d%s", before, not, code[2], after); |
|
#else |
|
const pcre_uint32 *p = PRIV(ucd_caseless_sets) + code[2]; |
|
fprintf (f, "%s%sclist", before, not); |
|
while (*p < NOTACHAR) fprintf(f, " %04x", *p++); |
|
fprintf(f, "%s", after); |
|
#endif |
|
} |
|
} |
|
|
|
|
|
|
|
|
/************************************************* |
/************************************************* |
* Print compiled regex * |
* Print compiled regex * |
*************************************************/ |
*************************************************/ |
Line 245 written that do not depend on the value of LINK_SIZE.
|
Line 298 written that do not depend on the value of LINK_SIZE.
|
#ifdef PCRE_INCLUDED |
#ifdef PCRE_INCLUDED |
static /* Keep the following function as private. */ |
static /* Keep the following function as private. */ |
#endif |
#endif |
#ifdef COMPILE_PCRE8 | #if defined COMPILE_PCRE8 |
void |
void |
pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths) |
pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths) |
#else | #elif defined COMPILE_PCRE16 |
void |
void |
pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths) |
pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths) |
|
#elif defined COMPILE_PCRE32 |
|
void |
|
pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths) |
#endif |
#endif |
{ |
{ |
REAL_PCRE *re = (REAL_PCRE *)external_re; |
REAL_PCRE *re = (REAL_PCRE *)external_re; |
Line 274 if (re->magic_number != MAGIC_NUMBER)
|
Line 330 if (re->magic_number != MAGIC_NUMBER)
|
} |
} |
|
|
code = codestart = (pcre_uchar *)re + offset + count * size; |
code = codestart = (pcre_uchar *)re + offset + count * size; |
/* PCRE_UTF16 has the same value as PCRE_UTF8. */ | /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */ |
utf = (options & PCRE_UTF8) != 0; |
utf = (options & PCRE_UTF8) != 0; |
|
|
for(;;) |
for(;;) |
{ |
{ |
pcre_uchar *ccode; |
pcre_uchar *ccode; |
const char *flag = " "; |
const char *flag = " "; |
int c; | pcre_uint32 c; |
int extra = 0; | unsigned int extra = 0; |
|
|
if (print_lengths) |
if (print_lengths) |
fprintf(f, "%3d ", (int)(code - codestart)); |
fprintf(f, "%3d ", (int)(code - codestart)); |
Line 369 for(;;)
|
Line 425 for(;;)
|
break; |
break; |
|
|
case OP_CREF: |
case OP_CREF: |
case OP_NCREF: |
|
fprintf(f, "%3d %s", GET2(code,1), priv_OP_names[*code]); |
fprintf(f, "%3d %s", GET2(code,1), priv_OP_names[*code]); |
break; |
break; |
|
|
|
case OP_DNCREF: |
|
{ |
|
pcre_uchar *entry = (pcre_uchar *)re + offset + (GET2(code, 1) * size) + |
|
IMM2_SIZE; |
|
fprintf(f, " %s Cond ref <", flag); |
|
print_puchar(f, entry); |
|
fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); |
|
} |
|
break; |
|
|
case OP_RREF: |
case OP_RREF: |
c = GET2(code, 1); |
c = GET2(code, 1); |
if (c == RREF_ANY) |
if (c == RREF_ANY) |
Line 381 for(;;)
|
Line 446 for(;;)
|
fprintf(f, " Cond recurse %d", c); |
fprintf(f, " Cond recurse %d", c); |
break; |
break; |
|
|
case OP_NRREF: | case OP_DNRREF: |
c = GET2(code, 1); | { |
if (c == RREF_ANY) | pcre_uchar *entry = (pcre_uchar *)re + offset + (GET2(code, 1) * size) + |
fprintf(f, " Cond nrecurse any"); | IMM2_SIZE; |
else | fprintf(f, " %s Cond recurse <", flag); |
fprintf(f, " Cond nrecurse %d", c); | print_puchar(f, entry); |
| fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); |
| } |
break; |
break; |
|
|
case OP_DEF: |
case OP_DEF: |
Line 425 for(;;)
|
Line 492 for(;;)
|
fprintf(f, " %s ", flag); |
fprintf(f, " %s ", flag); |
if (*code >= OP_TYPESTAR) |
if (*code >= OP_TYPESTAR) |
{ |
{ |
fprintf(f, "%s", priv_OP_names[code[1]]); |
|
if (code[1] == OP_PROP || code[1] == OP_NOTPROP) |
if (code[1] == OP_PROP || code[1] == OP_NOTPROP) |
{ |
{ |
fprintf(f, " %s ", get_ucpname(code[2], code[3])); | print_prop(f, code + 1, "", " "); |
extra = 2; |
extra = 2; |
} |
} |
|
else fprintf(f, "%s", priv_OP_names[code[1]]); |
} |
} |
else extra = print_char(f, code+1, utf); |
else extra = print_char(f, code+1, utf); |
fprintf(f, "%s", priv_OP_names[*code]); |
fprintf(f, "%s", priv_OP_names[*code]); |
Line 459 for(;;)
|
Line 526 for(;;)
|
case OP_TYPEUPTO: |
case OP_TYPEUPTO: |
case OP_TYPEMINUPTO: |
case OP_TYPEMINUPTO: |
case OP_TYPEPOSUPTO: |
case OP_TYPEPOSUPTO: |
fprintf(f, " %s", priv_OP_names[code[1 + IMM2_SIZE]]); |
|
if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP) |
if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP) |
{ |
{ |
fprintf(f, " %s ", get_ucpname(code[1 + IMM2_SIZE + 1], | print_prop(f, code + IMM2_SIZE + 1, " ", " "); |
code[1 + IMM2_SIZE + 2])); | |
extra = 2; |
extra = 2; |
} |
} |
|
else fprintf(f, " %s", priv_OP_names[code[1 + IMM2_SIZE]]); |
fprintf(f, "{"); |
fprintf(f, "{"); |
if (*code != OP_TYPEEXACT) fprintf(f, "0,"); |
if (*code != OP_TYPEEXACT) fprintf(f, "0,"); |
fprintf(f, "%d}", GET2(code,1)); |
fprintf(f, "%d}", GET2(code,1)); |
Line 477 for(;;)
|
Line 543 for(;;)
|
flag = "/i"; |
flag = "/i"; |
/* Fall through */ |
/* Fall through */ |
case OP_NOT: |
case OP_NOT: |
c = code[1]; | fprintf(f, " %s [^", flag); |
if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c); | extra = print_char(f, code + 1, utf); |
else if (utf || c > 0xff) | fprintf(f, "]"); |
fprintf(f, " %s [^\\x{%02x}]", flag, c); | |
else | |
fprintf(f, " %s [^\\x%02x]", flag, c); | |
break; |
break; |
|
|
case OP_NOTSTARI: |
case OP_NOTSTARI: |
Line 506 for(;;)
|
Line 569 for(;;)
|
case OP_NOTQUERY: |
case OP_NOTQUERY: |
case OP_NOTMINQUERY: |
case OP_NOTMINQUERY: |
case OP_NOTPOSQUERY: |
case OP_NOTPOSQUERY: |
c = code[1]; | fprintf(f, " %s [^", flag); |
if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c); | extra = print_char(f, code + 1, utf); |
else fprintf(f, " %s [^\\x%02x]", flag, c); | fprintf(f, "]%s", priv_OP_names[*code]); |
fprintf(f, "%s", priv_OP_names[*code]); | |
break; |
break; |
|
|
case OP_NOTEXACTI: |
case OP_NOTEXACTI: |
Line 523 for(;;)
|
Line 585 for(;;)
|
case OP_NOTUPTO: |
case OP_NOTUPTO: |
case OP_NOTMINUPTO: |
case OP_NOTMINUPTO: |
case OP_NOTPOSUPTO: |
case OP_NOTPOSUPTO: |
c = code[1 + IMM2_SIZE]; | fprintf(f, " %s [^", flag); |
if (PRINTABLE(c)) fprintf(f, " %s [^%c]{", flag, c); | extra = print_char(f, code + 1 + IMM2_SIZE, utf); |
else fprintf(f, " %s [^\\x%02x]{", flag, c); | fprintf(f, "]{"); |
if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,"); |
if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,"); |
fprintf(f, "%d}", GET2(code,1)); |
fprintf(f, "%d}", GET2(code,1)); |
if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?"); |
if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?"); |
Line 547 for(;;)
|
Line 609 for(;;)
|
ccode = code + priv_OP_lengths[*code]; |
ccode = code + priv_OP_lengths[*code]; |
goto CLASS_REF_REPEAT; |
goto CLASS_REF_REPEAT; |
|
|
|
case OP_DNREFI: |
|
flag = "/i"; |
|
/* Fall through */ |
|
case OP_DNREF: |
|
{ |
|
pcre_uchar *entry = (pcre_uchar *)re + offset + (GET2(code, 1) * size) + |
|
IMM2_SIZE; |
|
fprintf(f, " %s \\k<", flag); |
|
print_puchar(f, entry); |
|
fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE)); |
|
} |
|
ccode = code + priv_OP_lengths[*code]; |
|
goto CLASS_REF_REPEAT; |
|
|
case OP_CALLOUT: |
case OP_CALLOUT: |
fprintf(f, " %s %d %d %d", priv_OP_names[*code], code[1], GET(code,2), |
fprintf(f, " %s %d %d %d", priv_OP_names[*code], code[1], GET(code,2), |
GET(code, 2 + LINK_SIZE)); |
GET(code, 2 + LINK_SIZE)); |
Line 554 for(;;)
|
Line 630 for(;;)
|
|
|
case OP_PROP: |
case OP_PROP: |
case OP_NOTPROP: |
case OP_NOTPROP: |
fprintf(f, " %s %s", priv_OP_names[*code], get_ucpname(code[1], code[2])); | print_prop(f, code, " ", ""); |
break; |
break; |
|
|
/* OP_XCLASS can only occur in UTF or PCRE16 modes. However, there's no | /* OP_XCLASS cannot occur in 8-bit, non-UTF mode. However, there's no harm |
harm in having this code always here, and it makes it less messy without | in having this code always here, and it makes it less messy without all |
all those #ifdefs. */ | those #ifdefs. */ |
|
|
case OP_CLASS: |
case OP_CLASS: |
case OP_NCLASS: |
case OP_NCLASS: |
case OP_XCLASS: |
case OP_XCLASS: |
{ |
{ |
int i, min, max; | int i; |
| unsigned int min, max; |
BOOL printmap; |
BOOL printmap; |
pcre_uint8 *map; |
pcre_uint8 *map; |
|
|
Line 616 for(;;)
|
Line 693 for(;;)
|
|
|
if (*code == OP_XCLASS) |
if (*code == OP_XCLASS) |
{ |
{ |
int ch; | pcre_uchar ch; |
while ((ch = *ccode++) != XCL_END) |
while ((ch = *ccode++) != XCL_END) |
{ |
{ |
if (ch == XCL_PROP) | BOOL not = FALSE; |
| const char *notch = ""; |
| |
| switch(ch) |
{ |
{ |
int ptype = *ccode++; | case XCL_NOTPROP: |
int pvalue = *ccode++; | not = TRUE; |
fprintf(f, "\\p{%s}", get_ucpname(ptype, pvalue)); | notch = "^"; |
} | /* Fall through */ |
else if (ch == XCL_NOTPROP) | |
{ | case XCL_PROP: |
int ptype = *ccode++; | { |
int pvalue = *ccode++; | unsigned int ptype = *ccode++; |
fprintf(f, "\\P{%s}", get_ucpname(ptype, pvalue)); | unsigned int pvalue = *ccode++; |
} | |
else | switch(ptype) |
{ | { |
| case PT_PXGRAPH: |
| fprintf(f, "[:%sgraph:]", notch); |
| break; |
| |
| case PT_PXPRINT: |
| fprintf(f, "[:%sprint:]", notch); |
| break; |
| |
| case PT_PXPUNCT: |
| fprintf(f, "[:%spunct:]", notch); |
| break; |
| |
| default: |
| fprintf(f, "\\%c{%s}", (not? 'P':'p'), |
| get_ucpname(ptype, pvalue)); |
| break; |
| } |
| } |
| break; |
| |
| default: |
ccode += 1 + print_char(f, ccode, utf); |
ccode += 1 + print_char(f, ccode, utf); |
if (ch == XCL_RANGE) |
if (ch == XCL_RANGE) |
{ |
{ |
fprintf(f, "-"); |
fprintf(f, "-"); |
ccode += 1 + print_char(f, ccode, utf); |
ccode += 1 + print_char(f, ccode, utf); |
} |
} |
|
break; |
} |
} |
} |
} |
} |
} |
Line 658 for(;;)
|
Line 760 for(;;)
|
case OP_CRMINPLUS: |
case OP_CRMINPLUS: |
case OP_CRQUERY: |
case OP_CRQUERY: |
case OP_CRMINQUERY: |
case OP_CRMINQUERY: |
|
case OP_CRPOSSTAR: |
|
case OP_CRPOSPLUS: |
|
case OP_CRPOSQUERY: |
fprintf(f, "%s", priv_OP_names[*ccode]); |
fprintf(f, "%s", priv_OP_names[*ccode]); |
extra += priv_OP_lengths[*ccode]; |
extra += priv_OP_lengths[*ccode]; |
break; |
break; |
|
|
case OP_CRRANGE: |
case OP_CRRANGE: |
case OP_CRMINRANGE: |
case OP_CRMINRANGE: |
|
case OP_CRPOSRANGE: |
min = GET2(ccode,1); |
min = GET2(ccode,1); |
max = GET2(ccode,1 + IMM2_SIZE); |
max = GET2(ccode,1 + IMM2_SIZE); |
if (max == 0) fprintf(f, "{%d,}", min); | if (max == 0) fprintf(f, "{%u,}", min); |
else fprintf(f, "{%d,%d}", min, max); | else fprintf(f, "{%u,%u}", min, max); |
if (*ccode == OP_CRMINRANGE) fprintf(f, "?"); |
if (*ccode == OP_CRMINRANGE) fprintf(f, "?"); |
|
else if (*ccode == OP_CRPOSRANGE) fprintf(f, "+"); |
extra += priv_OP_lengths[*ccode]; |
extra += priv_OP_lengths[*ccode]; |
break; |
break; |
|
|