/[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 842 by ph10, Sat Dec 31 15:19:04 2011 UTC revision 1045 by ph10, Sun Sep 23 16:50:00 2012 UTC
# Line 55  asked to print out a compiled regex for Line 55  asked to print out a compiled regex for
55  #include "config.h"  #include "config.h"
56  #endif  #endif
57    
58    /* For pcretest program. */
59    #define PRIV(name) name
60    
61  /* We have to include pcre_internal.h because we need the internal info for  /* We have to include pcre_internal.h because we need the internal info for
62  displaying the results of pcre_study() and we also need to know about the  displaying the results of pcre_study() and we also need to know about the
63  internal macros, structures, and other internal data values; pcretest has  internal macros, structures, and other internal data values; pcretest has
# Line 94  for testing purposes. */ Line 97  for testing purposes. */
97    
98  /* The table of operator names. */  /* The table of operator names. */
99    
100  static const char *OP_names[] = { OP_NAME_LIST };  static const char *priv_OP_names[] = { OP_NAME_LIST };
101    
102  /* This table of operator lengths is not actually used by the working code,  /* This table of operator lengths is not actually used by the working code,
103  but its size is needed for a check that ensures it is the correct size for the  but its size is needed for a check that ensures it is the correct size for the
104  number of opcodes (thus catching update omissions). */  number of opcodes (thus catching update omissions). */
105    
106  static const pcre_uint8 OP_lengths[] = { OP_LENGTHS };  static const pcre_uint8 priv_OP_lengths[] = { OP_LENGTHS };
107    
108    
109    
# Line 127  return 0; Line 130  return 0;
130    
131  if (!utf || (c & 0xc0) != 0xc0)  if (!utf || (c & 0xc0) != 0xc0)
132    {    {
133    if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);    if (PRINTABLE(c)) fprintf(f, "%c", c);
134      else if (c < 0x80) fprintf(f, "\\x%02x", c);
135      else fprintf(f, "\\x{%02x}", c);
136    return 0;    return 0;
137    }    }
138  else  else
# Line 164  else Line 169  else
169  if (!utf || (c & 0xfc00) != 0xd800)  if (!utf || (c & 0xfc00) != 0xd800)
170    {    {
171    if (PRINTABLE(c)) fprintf(f, "%c", c);    if (PRINTABLE(c)) fprintf(f, "%c", c);
172    else if (c <= 0xff) fprintf(f, "\\x%02x", c);    else if (c <= 0x80) fprintf(f, "\\x%02x", c);
173    else fprintf(f, "\\x{%x}", c);    else fprintf(f, "\\x{%02x}", c);
174    return 0;    return 0;
175    }    }
176  else  else
# Line 250  void Line 255  void
255  pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths)  pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths)
256  #endif  #endif
257  {  {
258  real_pcre *re = (real_pcre *)external_re;  REAL_PCRE *re = (REAL_PCRE *)external_re;
259  pcre_uchar *codestart, *code;  pcre_uchar *codestart, *code;
260  BOOL utf;  BOOL utf;
261    
# Line 297  for(;;) Line 302  for(;;)
302    
303        case OP_TABLE_LENGTH:        case OP_TABLE_LENGTH:
304        case OP_TABLE_LENGTH +        case OP_TABLE_LENGTH +
305          ((sizeof(OP_names)/sizeof(const char *) == OP_TABLE_LENGTH) &&          ((sizeof(priv_OP_names)/sizeof(const char *) == OP_TABLE_LENGTH) &&
306          (sizeof(OP_lengths) == OP_TABLE_LENGTH)):          (sizeof(priv_OP_lengths) == OP_TABLE_LENGTH)):
307        break;        break;
308  /* ========================================================================== */  /* ========================================================================== */
309    
310      case OP_END:      case OP_END:
311      fprintf(f, "    %s\n", OP_names[*code]);      fprintf(f, "    %s\n", priv_OP_names[*code]);
312      fprintf(f, "------------------------------------------------------------------\n");      fprintf(f, "------------------------------------------------------------------\n");
313      return;      return;
314    
# Line 335  for(;;) Line 340  for(;;)
340      case OP_SCBRAPOS:      case OP_SCBRAPOS:
341      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
342        else fprintf(f, "    ");        else fprintf(f, "    ");
343      fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE));      fprintf(f, "%s %d", priv_OP_names[*code], GET2(code, 1+LINK_SIZE));
344      break;      break;
345    
346      case OP_BRA:      case OP_BRA:
# Line 358  for(;;) Line 363  for(;;)
363      case OP_REVERSE:      case OP_REVERSE:
364      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
365        else fprintf(f, "    ");        else fprintf(f, "    ");
366      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", priv_OP_names[*code]);
367      break;      break;
368    
369      case OP_CLOSE:      case OP_CLOSE:
370      fprintf(f, "    %s %d", OP_names[*code], GET2(code, 1));      fprintf(f, "    %s %d", priv_OP_names[*code], GET2(code, 1));
371      break;      break;
372    
373      case OP_CREF:      case OP_CREF:
374      case OP_NCREF:      case OP_NCREF:
375      fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);      fprintf(f, "%3d %s", GET2(code,1), priv_OP_names[*code]);
376      break;      break;
377    
378      case OP_RREF:      case OP_RREF:
# Line 422  for(;;) Line 427  for(;;)
427      fprintf(f, " %s ", flag);      fprintf(f, " %s ", flag);
428      if (*code >= OP_TYPESTAR)      if (*code >= OP_TYPESTAR)
429        {        {
430        fprintf(f, "%s", OP_names[code[1]]);        fprintf(f, "%s", priv_OP_names[code[1]]);
431        if (code[1] == OP_PROP || code[1] == OP_NOTPROP)        if (code[1] == OP_PROP || code[1] == OP_NOTPROP)
432          {          {
433          fprintf(f, " %s ", get_ucpname(code[2], code[3]));          fprintf(f, " %s ", get_ucpname(code[2], code[3]));
# Line 430  for(;;) Line 435  for(;;)
435          }          }
436        }        }
437      else extra = print_char(f, code+1, utf);      else extra = print_char(f, code+1, utf);
438      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", priv_OP_names[*code]);
439      break;      break;
440    
441      case OP_EXACTI:      case OP_EXACTI:
# Line 456  for(;;) Line 461  for(;;)
461      case OP_TYPEUPTO:      case OP_TYPEUPTO:
462      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
463      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
464      fprintf(f, "    %s", OP_names[code[1 + IMM2_SIZE]]);      fprintf(f, "    %s", priv_OP_names[code[1 + IMM2_SIZE]]);
465      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)
466        {        {
467        fprintf(f, " %s ", get_ucpname(code[1 + IMM2_SIZE + 1],        fprintf(f, " %s ", get_ucpname(code[1 + IMM2_SIZE + 1],
# Line 474  for(;;) Line 479  for(;;)
479      flag = "/i";      flag = "/i";
480      /* Fall through */      /* Fall through */
481      case OP_NOT:      case OP_NOT:
482      c = code[1];      fprintf(f, " %s [^", flag);
483      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);      extra = print_char(f, code + 1, utf);
484      else if (utf || c > 0xff)      fprintf(f, "]");
       fprintf(f, " %s [^\\x{%02x}]", flag, c);  
     else  
       fprintf(f, " %s [^\\x%02x]", flag, c);  
485      break;      break;
486    
487      case OP_NOTSTARI:      case OP_NOTSTARI:
# Line 503  for(;;) Line 505  for(;;)
505      case OP_NOTQUERY:      case OP_NOTQUERY:
506      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
507      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
508      c = code[1];      fprintf(f, " %s [^", flag);
509      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);      extra = print_char(f, code + 1, utf);
510        else fprintf(f, " %s [^\\x%02x]", flag, c);      fprintf(f, "]%s", priv_OP_names[*code]);
     fprintf(f, "%s", OP_names[*code]);  
511      break;      break;
512    
513      case OP_NOTEXACTI:      case OP_NOTEXACTI:
# Line 520  for(;;) Line 521  for(;;)
521      case OP_NOTUPTO:      case OP_NOTUPTO:
522      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
523      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
524      c = code[1 + IMM2_SIZE];      fprintf(f, " %s [^", flag);
525      if (PRINTABLE(c)) fprintf(f, " %s [^%c]{", flag, c);      extra = print_char(f, code + 1 + IMM2_SIZE, utf);
526        else fprintf(f, " %s [^\\x%02x]{", flag, c);      fprintf(f, "]{");
527      if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,");      if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,");
528      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
529      if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");      if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");
# Line 533  for(;;) Line 534  for(;;)
534      case OP_RECURSE:      case OP_RECURSE:
535      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
536        else fprintf(f, "    ");        else fprintf(f, "    ");
537      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", priv_OP_names[*code]);
538      break;      break;
539    
540      case OP_REFI:      case OP_REFI:
# Line 541  for(;;) Line 542  for(;;)
542      /* Fall through */      /* Fall through */
543      case OP_REF:      case OP_REF:
544      fprintf(f, " %s \\%d", flag, GET2(code,1));      fprintf(f, " %s \\%d", flag, GET2(code,1));
545      ccode = code + PRIV(OP_lengths)[*code];      ccode = code + priv_OP_lengths[*code];
546      goto CLASS_REF_REPEAT;      goto CLASS_REF_REPEAT;
547    
548      case OP_CALLOUT:      case OP_CALLOUT:
549      fprintf(f, "    %s %d %d %d", OP_names[*code], code[1], GET(code,2),      fprintf(f, "    %s %d %d %d", priv_OP_names[*code], code[1], GET(code,2),
550        GET(code, 2 + LINK_SIZE));        GET(code, 2 + LINK_SIZE));
551      break;      break;
552    
553      case OP_PROP:      case OP_PROP:
554      case OP_NOTPROP:      case OP_NOTPROP:
555      fprintf(f, "    %s %s", OP_names[*code], get_ucpname(code[1], code[2]));      fprintf(f, "    %s %s", priv_OP_names[*code], get_ucpname(code[1], code[2]));
556      break;      break;
557    
558      /* 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 655  for(;;) Line 656  for(;;)
656          case OP_CRMINPLUS:          case OP_CRMINPLUS:
657          case OP_CRQUERY:          case OP_CRQUERY:
658          case OP_CRMINQUERY:          case OP_CRMINQUERY:
659          fprintf(f, "%s", OP_names[*ccode]);          fprintf(f, "%s", priv_OP_names[*ccode]);
660          extra += PRIV(OP_lengths)[*ccode];          extra += priv_OP_lengths[*ccode];
661          break;          break;
662    
663          case OP_CRRANGE:          case OP_CRRANGE:
# Line 666  for(;;) Line 667  for(;;)
667          if (max == 0) fprintf(f, "{%d,}", min);          if (max == 0) fprintf(f, "{%d,}", min);
668          else fprintf(f, "{%d,%d}", min, max);          else fprintf(f, "{%d,%d}", min, max);
669          if (*ccode == OP_CRMINRANGE) fprintf(f, "?");          if (*ccode == OP_CRMINRANGE) fprintf(f, "?");
670          extra += PRIV(OP_lengths)[*ccode];          extra += priv_OP_lengths[*ccode];
671          break;          break;
672    
673          /* Do nothing if it's not a repeat; this code stops picky compilers          /* Do nothing if it's not a repeat; this code stops picky compilers
# Line 682  for(;;) Line 683  for(;;)
683      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
684      case OP_SKIP_ARG:      case OP_SKIP_ARG:
685      case OP_THEN_ARG:      case OP_THEN_ARG:
686      fprintf(f, "    %s ", OP_names[*code]);      fprintf(f, "    %s ", priv_OP_names[*code]);
687      print_puchar(f, code + 2);      print_puchar(f, code + 2);
688      extra += code[1];      extra += code[1];
689      break;      break;
690    
691      case OP_THEN:      case OP_THEN:
692      fprintf(f, "    %s", OP_names[*code]);      fprintf(f, "    %s", priv_OP_names[*code]);
693      break;      break;
694    
695      case OP_CIRCM:      case OP_CIRCM:
# Line 699  for(;;) Line 700  for(;;)
700      /* Anything else is just an item with no data, but possibly a flag. */      /* Anything else is just an item with no data, but possibly a flag. */
701    
702      default:      default:
703      fprintf(f, " %s %s", flag, OP_names[*code]);      fprintf(f, " %s %s", flag, priv_OP_names[*code]);
704      break;      break;
705      }      }
706    
707    code += PRIV(OP_lengths)[*code] + extra;    code += priv_OP_lengths[*code] + extra;
708    fprintf(f, "\n");    fprintf(f, "\n");
709    }    }
710  }  }

Legend:
Removed from v.842  
changed lines
  Added in v.1045

  ViewVC Help
Powered by ViewVC 1.1.5