/[pcre]/code/trunk/pcre_printint.c
ViewVC logotype

Diff of /code/trunk/pcre_printint.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 906 by zherczeg, Tue Jan 24 09:55:16 2012 UTC revision 1137 by chpe, Thu Oct 18 19:08:11 2012 UTC
# Line 78  having a separate .h file just for this. Line 78  having a separate .h file just for this.
78  #ifdef PCRE_INCLUDED  #ifdef PCRE_INCLUDED
79  static /* Keep the following function as private. */  static /* Keep the following function as private. */
80  #endif  #endif
81  #ifdef COMPILE_PCRE8  
82    #if defined COMPILE_PCRE8
83  void pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths);
84  #else  #elif defined COMPILE_PCRE16
85  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);  void pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths);
86    #elif defined COMPILE_PCRE32
87    void pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths);
88  #endif  #endif
89    
90  /* 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[ Line 114  static const pcre_uint8 priv_OP_lengths[
114  *       Print single- or multi-byte character    *  *       Print single- or multi-byte character    *
115  *************************************************/  *************************************************/
116    
117  static int  static unsigned int
118  print_char(FILE *f, pcre_uchar *ptr, BOOL utf)  print_char(FILE *f, pcre_uchar *ptr, BOOL utf)
119  {  {
120  int c = *ptr;  pcre_uint32 c = *ptr;
121    
122  #ifndef SUPPORT_UTF  #ifndef SUPPORT_UTF
123    
124  (void)utf;  /* Avoid compiler warning */  (void)utf;  /* Avoid compiler warning */
125  if (PRINTABLE(c)) fprintf(f, "%c", c);  if (PRINTABLE(c)) fprintf(f, "%c", (char)c);
126  else if (c <= 0xff) fprintf(f, "\\x%02x", c);  else if (c <= 0x80) fprintf(f, "\\x%02x", c);
127  else fprintf(f, "\\x{%x}", c);  else fprintf(f, "\\x{%x}", c);
128  return 0;  return 0;
129    
130  #else  #else
131    
132  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
133    
134  if (!utf || (c & 0xc0) != 0xc0)  if (!utf || (c & 0xc0) != 0xc0)
135    {    {
136    if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);    if (PRINTABLE(c)) fprintf(f, "%c", (char)c);
137      else if (c < 0x80) fprintf(f, "\\x%02x", c);
138      else fprintf(f, "\\x{%02x}", c);
139    return 0;    return 0;
140    }    }
141  else  else
# Line 160  else Line 165  else
165    return a;    return a;
166    }    }
167    
168  #else  #elif defined COMPILE_PCRE16
   
 #ifdef COMPILE_PCRE16  
169    
170  if (!utf || (c & 0xfc00) != 0xd800)  if (!utf || (c & 0xfc00) != 0xd800)
171    {    {
172    if (PRINTABLE(c)) fprintf(f, "%c", c);    if (PRINTABLE(c)) fprintf(f, "%c", (char)c);
173    else if (c <= 0xff) fprintf(f, "\\x%02x", c);    else if (c <= 0x80) fprintf(f, "\\x%02x", c);
174    else fprintf(f, "\\x{%x}", c);    else fprintf(f, "\\x{%02x}", c);
175    return 0;    return 0;
176    }    }
177  else  else
# Line 188  else Line 191  else
191    return 1;    return 1;
192    }    }
193    
194  #endif /* COMPILE_PCRE16 */  #elif defined COMPILE_PCRE32
195    
196  #endif /* COMPILE_PCRE8 */  if (!utf || (c & 0xfffff800u) != 0xd800u)
197      {
198      if (PRINTABLE(c)) fprintf(f, "%c", (char)c);
199      else if (c <= 0x80) fprintf(f, "\\x%02x", c);
200      else fprintf(f, "\\x{%x}", c);
201      return 0;
202      }
203    else
204      {
205      /* This is a check for malformed UTF-32; it should only occur if the sanity
206      check has been turned off. Rather than swallow a surrogate, just stop if
207      we hit one. Print it with \X instead of \x as an indication. */
208      fprintf(f, "\\X{%x}", c);
209      return 0;
210      }
211    
212    #endif /* COMPILE_PCRE[8|16|32] */
213    
214  #endif /* SUPPORT_UTF */  #endif /* SUPPORT_UTF */
215  }  }
# Line 204  print_puchar(FILE *f, PCRE_PUCHAR ptr) Line 223  print_puchar(FILE *f, PCRE_PUCHAR ptr)
223  {  {
224  while (*ptr != '\0')  while (*ptr != '\0')
225    {    {
226    register int c = *ptr++;    register pcre_uint32 c = *ptr++;
227    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);
228    }    }
229  }  }
# Line 214  while (*ptr != '\0') Line 233  while (*ptr != '\0')
233  *************************************************/  *************************************************/
234    
235  static const char *  static const char *
236  get_ucpname(int ptype, int pvalue)  get_ucpname(unsigned int ptype, unsigned int pvalue)
237  {  {
238  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
239  int i;  int i;
# Line 231  return (ptype == pvalue)? "??" : "??"; Line 250  return (ptype == pvalue)? "??" : "??";
250  }  }
251    
252    
253    /*************************************************
254    *       Print Unicode property value             *
255    *************************************************/
256    
257    /* "Normal" properties can be printed from tables. The PT_CLIST property is a
258    pseudo-property that contains a pointer to a list of case-equivalent
259    characters. This is used only when UCP support is available and UTF mode is
260    selected. It should never occur otherwise, but just in case it does, have
261    something ready to print. */
262    
263    static void
264    print_prop(FILE *f, pcre_uchar *code, const char *before, const char *after)
265    {
266    if (code[1] != PT_CLIST)
267      {
268      fprintf(f, "%s%s %s%s", before, priv_OP_names[*code], get_ucpname(code[1],
269        code[2]), after);
270      }
271    else
272      {
273      const char *not = (*code == OP_PROP)? "" : "not ";
274    #ifndef SUPPORT_UCP
275      fprintf(f, "%s%sclist %d%s", before, not, code[2], after);
276    #else
277      const pcre_uint32 *p = PRIV(ucd_caseless_sets) + code[2];
278      fprintf (f, "%s%sclist", before, not);
279      while (*p < NOTACHAR) fprintf(f, " %04x", *p++);
280      fprintf(f, "%s", after);
281    #endif
282      }
283    }
284    
285    
286    
287    
288  /*************************************************  /*************************************************
289  *         Print compiled regex                   *  *         Print compiled regex                   *
# Line 245  written that do not depend on the value Line 298  written that do not depend on the value
298  #ifdef PCRE_INCLUDED  #ifdef PCRE_INCLUDED
299  static /* Keep the following function as private. */  static /* Keep the following function as private. */
300  #endif  #endif
301  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
302  void  void
303  pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths)  pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths)
304  #else  #elif defined COMPILE_PCRE16
305  void  void
306  pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths)  pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths)
307    #elif defined COMPILE_PCRE32
308    void
309    pcre32_printint(pcre *external_re, FILE *f, BOOL print_lengths)
310  #endif  #endif
311  {  {
312  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)
330    }    }
331    
332  code = codestart = (pcre_uchar *)re + offset + count * size;  code = codestart = (pcre_uchar *)re + offset + count * size;
333  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */
334  utf = (options & PCRE_UTF8) != 0;  utf = (options & PCRE_UTF8) != 0;
335    
336  for(;;)  for(;;)
337    {    {
338    pcre_uchar *ccode;    pcre_uchar *ccode;
339    const char *flag = "  ";    const char *flag = "  ";
340    int c;    pcre_uint32 c;
341    int extra = 0;    unsigned int extra = 0;
342    
343    if (print_lengths)    if (print_lengths)
344      fprintf(f, "%3d ", (int)(code - codestart));      fprintf(f, "%3d ", (int)(code - codestart));
# Line 425  for(;;) Line 481  for(;;)
481      fprintf(f, " %s ", flag);      fprintf(f, " %s ", flag);
482      if (*code >= OP_TYPESTAR)      if (*code >= OP_TYPESTAR)
483        {        {
       fprintf(f, "%s", priv_OP_names[code[1]]);  
484        if (code[1] == OP_PROP || code[1] == OP_NOTPROP)        if (code[1] == OP_PROP || code[1] == OP_NOTPROP)
485          {          {
486          fprintf(f, " %s ", get_ucpname(code[2], code[3]));          print_prop(f, code + 1, "", " ");
487          extra = 2;          extra = 2;
488          }          }
489          else fprintf(f, "%s", priv_OP_names[code[1]]);
490        }        }
491      else extra = print_char(f, code+1, utf);      else extra = print_char(f, code+1, utf);
492      fprintf(f, "%s", priv_OP_names[*code]);      fprintf(f, "%s", priv_OP_names[*code]);
# Line 459  for(;;) Line 515  for(;;)
515      case OP_TYPEUPTO:      case OP_TYPEUPTO:
516      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
517      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
     fprintf(f, "    %s", priv_OP_names[code[1 + IMM2_SIZE]]);  
518      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)
519        {        {
520        fprintf(f, " %s ", get_ucpname(code[1 + IMM2_SIZE + 1],        print_prop(f, code + IMM2_SIZE + 1, "    ", " ");
         code[1 + IMM2_SIZE + 2]));  
521        extra = 2;        extra = 2;
522        }        }
523        else fprintf(f, "    %s", priv_OP_names[code[1 + IMM2_SIZE]]);
524      fprintf(f, "{");      fprintf(f, "{");
525      if (*code != OP_TYPEEXACT) fprintf(f, "0,");      if (*code != OP_TYPEEXACT) fprintf(f, "0,");
526      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
# Line 477  for(;;) Line 532  for(;;)
532      flag = "/i";      flag = "/i";
533      /* Fall through */      /* Fall through */
534      case OP_NOT:      case OP_NOT:
535      c = code[1];      fprintf(f, " %s [^", flag);
536      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);      extra = print_char(f, code + 1, utf);
537      else if (utf || c > 0xff)      fprintf(f, "]");
       fprintf(f, " %s [^\\x{%02x}]", flag, c);  
     else  
       fprintf(f, " %s [^\\x%02x]", flag, c);  
538      break;      break;
539    
540      case OP_NOTSTARI:      case OP_NOTSTARI:
# Line 506  for(;;) Line 558  for(;;)
558      case OP_NOTQUERY:      case OP_NOTQUERY:
559      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
560      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
561      c = code[1];      fprintf(f, " %s [^", flag);
562      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);      extra = print_char(f, code + 1, utf);
563        else fprintf(f, " %s [^\\x%02x]", flag, c);      fprintf(f, "]%s", priv_OP_names[*code]);
     fprintf(f, "%s", priv_OP_names[*code]);  
564      break;      break;
565    
566      case OP_NOTEXACTI:      case OP_NOTEXACTI:
# Line 523  for(;;) Line 574  for(;;)
574      case OP_NOTUPTO:      case OP_NOTUPTO:
575      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
576      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
577      c = code[1 + IMM2_SIZE];      fprintf(f, " %s [^", flag);
578      if (PRINTABLE(c)) fprintf(f, " %s [^%c]{", flag, c);      extra = print_char(f, code + 1 + IMM2_SIZE, utf);
579        else fprintf(f, " %s [^\\x%02x]{", flag, c);      fprintf(f, "]{");
580      if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,");      if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,");
581      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
582      if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");      if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");
# Line 554  for(;;) Line 605  for(;;)
605    
606      case OP_PROP:      case OP_PROP:
607      case OP_NOTPROP:      case OP_NOTPROP:
608      fprintf(f, "    %s %s", priv_OP_names[*code], get_ucpname(code[1], code[2]));      print_prop(f, code, "    ", "");
609      break;      break;
610    
611      /* 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 565  for(;;) Line 616  for(;;)
616      case OP_NCLASS:      case OP_NCLASS:
617      case OP_XCLASS:      case OP_XCLASS:
618        {        {
619        int i, min, max;        int i;
620          unsigned int min, max;
621        BOOL printmap;        BOOL printmap;
622        pcre_uint8 *map;        pcre_uint8 *map;
623    
# Line 616  for(;;) Line 668  for(;;)
668    
669        if (*code == OP_XCLASS)        if (*code == OP_XCLASS)
670          {          {
671          int ch;          pcre_uchar ch;
672          while ((ch = *ccode++) != XCL_END)          while ((ch = *ccode++) != XCL_END)
673            {            {
674            if (ch == XCL_PROP)            if (ch == XCL_PROP)
675              {              {
676              int ptype = *ccode++;              unsigned int ptype = *ccode++;
677              int pvalue = *ccode++;              unsigned int pvalue = *ccode++;
678              fprintf(f, "\\p{%s}", get_ucpname(ptype, pvalue));              fprintf(f, "\\p{%s}", get_ucpname(ptype, pvalue));
679              }              }
680            else if (ch == XCL_NOTPROP)            else if (ch == XCL_NOTPROP)
681              {              {
682              int ptype = *ccode++;              unsigned int ptype = *ccode++;
683              int pvalue = *ccode++;              unsigned int pvalue = *ccode++;
684              fprintf(f, "\\P{%s}", get_ucpname(ptype, pvalue));              fprintf(f, "\\P{%s}", get_ucpname(ptype, pvalue));
685              }              }
686            else            else
# Line 666  for(;;) Line 718  for(;;)
718          case OP_CRMINRANGE:          case OP_CRMINRANGE:
719          min = GET2(ccode,1);          min = GET2(ccode,1);
720          max = GET2(ccode,1 + IMM2_SIZE);          max = GET2(ccode,1 + IMM2_SIZE);
721          if (max == 0) fprintf(f, "{%d,}", min);          if (max == 0) fprintf(f, "{%u,}", min);
722          else fprintf(f, "{%d,%d}", min, max);          else fprintf(f, "{%u,%u}", min, max);
723          if (*ccode == OP_CRMINRANGE) fprintf(f, "?");          if (*ccode == OP_CRMINRANGE) fprintf(f, "?");
724          extra += priv_OP_lengths[*ccode];          extra += priv_OP_lengths[*ccode];
725          break;          break;

Legend:
Removed from v.906  
changed lines
  Added in v.1137

  ViewVC Help
Powered by ViewVC 1.1.5