Diff for /embedaddon/pcre/pcre_printint.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2012/10/09 09:19:17 version 1.1.1.3, 2013/07/22 08:25:56
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 intstatic 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 425  for(;;) Line 481  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 515  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 550  for(;;) Line 605  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 can only occur in UTF or PCRE16 modes. However, there's no
Line 561  for(;;) Line 616  for(;;)
     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 612  for(;;) Line 668  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)            if (ch == XCL_PROP)
             {              {
            int ptype = *ccode++;            unsigned int ptype = *ccode++;
            int pvalue = *ccode++;            unsigned int pvalue = *ccode++;
             fprintf(f, "\\p{%s}", get_ucpname(ptype, pvalue));              fprintf(f, "\\p{%s}", get_ucpname(ptype, pvalue));
             }              }
           else if (ch == XCL_NOTPROP)            else if (ch == XCL_NOTPROP)
             {              {
            int ptype = *ccode++;            unsigned int ptype = *ccode++;
            int pvalue = *ccode++;            unsigned int pvalue = *ccode++;
             fprintf(f, "\\P{%s}", get_ucpname(ptype, pvalue));              fprintf(f, "\\P{%s}", get_ucpname(ptype, pvalue));
             }              }
           else            else
Line 662  for(;;) Line 718  for(;;)
         case OP_CRMINRANGE:          case OP_CRMINRANGE:
         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, "?");
         extra += priv_OP_lengths[*ccode];          extra += priv_OP_lengths[*ccode];
         break;          break;

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>