/[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

code/branches/pcre16/pcre_printint.c revision 810 by ph10, Mon Dec 19 13:34:10 2011 UTC code/trunk/pcre_printint.c revision 1046 by ph10, Tue Sep 25 16:27:58 2012 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2010 University of Cambridge             Copyright (c) 1997-2012 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# 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 114  print_char(FILE *f, pcre_uchar *ptr, BOO Line 117  print_char(FILE *f, pcre_uchar *ptr, BOO
117  int c = *ptr;  int c = *ptr;
118    
119  #ifndef SUPPORT_UTF  #ifndef SUPPORT_UTF
120    
121  (void)utf;  /* Avoid compiler warning */  (void)utf;  /* Avoid compiler warning */
122  if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);  if (PRINTABLE(c)) fprintf(f, "%c", c);
123    else if (c <= 0x80) fprintf(f, "\\x%02x", c);
124    else fprintf(f, "\\x{%x}", c);
125  return 0;  return 0;
126    
127  #else  #else
# Line 124  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 161  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 225  return (ptype == pvalue)? "??" : "??"; Line 233  return (ptype == pvalue)? "??" : "??";
233  }  }
234    
235    
236    /*************************************************
237    *       Print Unicode property value             *
238    *************************************************/
239    
240    /* "Normal" properties can be printed from tables. The PT_CLIST property is a
241    pseudo-property that contains a pointer to a list of case-equivalent
242    characters. This is used only when UCP support is available and UTF mode is
243    selected. It should never occur otherwise, but just in case it does, have
244    something ready to print. */
245    
246    static void
247    print_prop(FILE *f, pcre_uchar *code, const char *before, const char *after)
248    {
249    if (code[1] != PT_CLIST)
250      {
251      fprintf(f, "%s%s %s%s", before, priv_OP_names[*code], get_ucpname(code[1],
252        code[2]), after);
253      }
254    else
255      {
256      const char *not = (*code == OP_PROP)? "" : "not ";
257    #ifndef SUPPORT_UCP
258      fprintf(f, "%s%sclist %d%s", before, not, code[2], after);
259    #else
260      const pcre_uint32 *p = PRIV(ucd_caseless_sets) + code[2];
261      fprintf (f, "%s%sclist", before, not);
262      while (*p < NOTACHAR) fprintf(f, " %04x", *p++);
263      fprintf(f, "%s", after);
264    #endif
265      }
266    }
267    
268    
269    
270    
271  /*************************************************  /*************************************************
272  *         Print compiled regex                   *  *         Print compiled regex                   *
# Line 247  void Line 289  void
289  pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths)  pcre16_printint(pcre *external_re, FILE *f, BOOL print_lengths)
290  #endif  #endif
291  {  {
292  real_pcre *re = (real_pcre *)external_re;  REAL_PCRE *re = (REAL_PCRE *)external_re;
293  pcre_uchar *codestart, *code;  pcre_uchar *codestart, *code;
294  BOOL utf;  BOOL utf;
295    
# Line 294  for(;;) Line 336  for(;;)
336    
337        case OP_TABLE_LENGTH:        case OP_TABLE_LENGTH:
338        case OP_TABLE_LENGTH +        case OP_TABLE_LENGTH +
339          ((sizeof(OP_names)/sizeof(const char *) == OP_TABLE_LENGTH) &&          ((sizeof(priv_OP_names)/sizeof(const char *) == OP_TABLE_LENGTH) &&
340          (sizeof(OP_lengths) == OP_TABLE_LENGTH)):          (sizeof(priv_OP_lengths) == OP_TABLE_LENGTH)):
341        break;        break;
342  /* ========================================================================== */  /* ========================================================================== */
343    
344      case OP_END:      case OP_END:
345      fprintf(f, "    %s\n", OP_names[*code]);      fprintf(f, "    %s\n", priv_OP_names[*code]);
346      fprintf(f, "------------------------------------------------------------------\n");      fprintf(f, "------------------------------------------------------------------\n");
347      return;      return;
348    
# Line 332  for(;;) Line 374  for(;;)
374      case OP_SCBRAPOS:      case OP_SCBRAPOS:
375      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
376        else fprintf(f, "    ");        else fprintf(f, "    ");
377      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));
378      break;      break;
379    
380      case OP_BRA:      case OP_BRA:
# Line 355  for(;;) Line 397  for(;;)
397      case OP_REVERSE:      case OP_REVERSE:
398      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
399        else fprintf(f, "    ");        else fprintf(f, "    ");
400      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", priv_OP_names[*code]);
401      break;      break;
402    
403      case OP_CLOSE:      case OP_CLOSE:
404      fprintf(f, "    %s %d", OP_names[*code], GET2(code, 1));      fprintf(f, "    %s %d", priv_OP_names[*code], GET2(code, 1));
405      break;      break;
406    
407      case OP_CREF:      case OP_CREF:
408      case OP_NCREF:      case OP_NCREF:
409      fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);      fprintf(f, "%3d %s", GET2(code,1), priv_OP_names[*code]);
410      break;      break;
411    
412      case OP_RREF:      case OP_RREF:
# Line 419  for(;;) Line 461  for(;;)
461      fprintf(f, " %s ", flag);      fprintf(f, " %s ", flag);
462      if (*code >= OP_TYPESTAR)      if (*code >= OP_TYPESTAR)
463        {        {
       fprintf(f, "%s", OP_names[code[1]]);  
464        if (code[1] == OP_PROP || code[1] == OP_NOTPROP)        if (code[1] == OP_PROP || code[1] == OP_NOTPROP)
465          {          {
466          fprintf(f, " %s ", get_ucpname(code[2], code[3]));          print_prop(f, code + 1, "", " ");
467          extra = 2;          extra = 2;
468          }          }
469          else fprintf(f, "%s", priv_OP_names[code[1]]);
470        }        }
471      else extra = print_char(f, code+1, utf);      else extra = print_char(f, code+1, utf);
472      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", priv_OP_names[*code]);
473      break;      break;
474    
475      case OP_EXACTI:      case OP_EXACTI:
# Line 453  for(;;) Line 495  for(;;)
495      case OP_TYPEUPTO:      case OP_TYPEUPTO:
496      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
497      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
     fprintf(f, "    %s", OP_names[code[1 + IMM2_SIZE]]);  
498      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)
499        {        {
500        fprintf(f, " %s ", get_ucpname(code[1 + IMM2_SIZE + 1],        print_prop(f, code + IMM2_SIZE + 1, "    ", " ");
         code[1 + IMM2_SIZE + 2]));  
501        extra = 2;        extra = 2;
502        }        }
503        else fprintf(f, "    %s", priv_OP_names[code[1 + IMM2_SIZE]]);
504      fprintf(f, "{");      fprintf(f, "{");
505      if (*code != OP_TYPEEXACT) fprintf(f, "0,");      if (*code != OP_TYPEEXACT) fprintf(f, "0,");
506      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
# Line 471  for(;;) Line 512  for(;;)
512      flag = "/i";      flag = "/i";
513      /* Fall through */      /* Fall through */
514      case OP_NOT:      case OP_NOT:
515      c = code[1];      fprintf(f, " %s [^", flag);
516      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);      extra = print_char(f, code + 1, utf);
517      else if (utf || c > 0xff)      fprintf(f, "]");
       fprintf(f, " %s [^\\x{%02x}]", flag, c);  
     else  
       fprintf(f, " %s [^\\x%02x]", flag, c);  
518      break;      break;
519    
520      case OP_NOTSTARI:      case OP_NOTSTARI:
# Line 500  for(;;) Line 538  for(;;)
538      case OP_NOTQUERY:      case OP_NOTQUERY:
539      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
540      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
541      c = code[1];      fprintf(f, " %s [^", flag);
542      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);      extra = print_char(f, code + 1, utf);
543        else fprintf(f, " %s [^\\x%02x]", flag, c);      fprintf(f, "]%s", priv_OP_names[*code]);
     fprintf(f, "%s", OP_names[*code]);  
544      break;      break;
545    
546      case OP_NOTEXACTI:      case OP_NOTEXACTI:
# Line 517  for(;;) Line 554  for(;;)
554      case OP_NOTUPTO:      case OP_NOTUPTO:
555      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
556      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
557      c = code[1 + IMM2_SIZE];      fprintf(f, " %s [^", flag);
558      if (PRINTABLE(c)) fprintf(f, " %s [^%c]{", flag, c);      extra = print_char(f, code + 1 + IMM2_SIZE, utf);
559        else fprintf(f, " %s [^\\x%02x]{", flag, c);      fprintf(f, "]{");
560      if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,");      if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,");
561      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
562      if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");      if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");
# Line 530  for(;;) Line 567  for(;;)
567      case OP_RECURSE:      case OP_RECURSE:
568      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
569        else fprintf(f, "    ");        else fprintf(f, "    ");
570      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", priv_OP_names[*code]);
571      break;      break;
572    
573      case OP_REFI:      case OP_REFI:
# Line 538  for(;;) Line 575  for(;;)
575      /* Fall through */      /* Fall through */
576      case OP_REF:      case OP_REF:
577      fprintf(f, " %s \\%d", flag, GET2(code,1));      fprintf(f, " %s \\%d", flag, GET2(code,1));
578      ccode = code + PRIV(OP_lengths)[*code];      ccode = code + priv_OP_lengths[*code];
579      goto CLASS_REF_REPEAT;      goto CLASS_REF_REPEAT;
580    
581      case OP_CALLOUT:      case OP_CALLOUT:
582      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),
583        GET(code, 2 + LINK_SIZE));        GET(code, 2 + LINK_SIZE));
584      break;      break;
585    
586      case OP_PROP:      case OP_PROP:
587      case OP_NOTPROP:      case OP_NOTPROP:
588      fprintf(f, "    %s %s", OP_names[*code], get_ucpname(code[1], code[2]));      print_prop(f, code, "    ", "");
589      break;      break;
590    
591      /* 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 627  for(;;) Line 664  for(;;)
664              }              }
665            else            else
666              {              {
667              ccode += 1 + print_char(f, ccode, TRUE);              ccode += 1 + print_char(f, ccode, utf);
668              if (ch == XCL_RANGE)              if (ch == XCL_RANGE)
669                {                {
670                fprintf(f, "-");                fprintf(f, "-");
671                ccode += 1 + print_char(f, ccode, TRUE);                ccode += 1 + print_char(f, ccode, utf);
672                }                }
673              }              }
674            }            }
# Line 652  for(;;) Line 689  for(;;)
689          case OP_CRMINPLUS:          case OP_CRMINPLUS:
690          case OP_CRQUERY:          case OP_CRQUERY:
691          case OP_CRMINQUERY:          case OP_CRMINQUERY:
692          fprintf(f, "%s", OP_names[*ccode]);          fprintf(f, "%s", priv_OP_names[*ccode]);
693          extra += PRIV(OP_lengths)[*ccode];          extra += priv_OP_lengths[*ccode];
694          break;          break;
695    
696          case OP_CRRANGE:          case OP_CRRANGE:
# Line 663  for(;;) Line 700  for(;;)
700          if (max == 0) fprintf(f, "{%d,}", min);          if (max == 0) fprintf(f, "{%d,}", min);
701          else fprintf(f, "{%d,%d}", min, max);          else fprintf(f, "{%d,%d}", min, max);
702          if (*ccode == OP_CRMINRANGE) fprintf(f, "?");          if (*ccode == OP_CRMINRANGE) fprintf(f, "?");
703          extra += PRIV(OP_lengths)[*ccode];          extra += priv_OP_lengths[*ccode];
704          break;          break;
705    
706          /* 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 679  for(;;) Line 716  for(;;)
716      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
717      case OP_SKIP_ARG:      case OP_SKIP_ARG:
718      case OP_THEN_ARG:      case OP_THEN_ARG:
719      fprintf(f, "    %s ", OP_names[*code]);      fprintf(f, "    %s ", priv_OP_names[*code]);
720      print_puchar(f, code + 2);      print_puchar(f, code + 2);
721      extra += code[1];      extra += code[1];
722      break;      break;
723    
724      case OP_THEN:      case OP_THEN:
725      fprintf(f, "    %s", OP_names[*code]);      fprintf(f, "    %s", priv_OP_names[*code]);
726      break;      break;
727    
728      case OP_CIRCM:      case OP_CIRCM:
# Line 696  for(;;) Line 733  for(;;)
733      /* 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. */
734    
735      default:      default:
736      fprintf(f, " %s %s", flag, OP_names[*code]);      fprintf(f, " %s %s", flag, priv_OP_names[*code]);
737      break;      break;
738      }      }
739    
740    code += PRIV(OP_lengths)[*code] + extra;    code += priv_OP_lengths[*code] + extra;
741    fprintf(f, "\n");    fprintf(f, "\n");
742    }    }
743  }  }

Legend:
Removed from v.810  
changed lines
  Added in v.1046

  ViewVC Help
Powered by ViewVC 1.1.5