/[pcre]/code/branches/pcre16/pcre_printint.src
ViewVC logotype

Diff of /code/branches/pcre16/pcre_printint.src

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

revision 117 by ph10, Fri Mar 9 15:59:06 2007 UTC revision 602 by ph10, Wed May 25 08:29:03 2011 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-2007 University of Cambridge             Copyright (c) 1997-2010 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 43  internal form of a compiled regular expr Line 43  internal form of a compiled regular expr
43  local functions. This source file is used in two places:  local functions. This source file is used in two places:
44    
45  (1) It is #included by pcre_compile.c when it is compiled in debugging mode  (1) It is #included by pcre_compile.c when it is compiled in debugging mode
46  (DEBUG defined in pcre_internal.h). It is not included in production compiles.  (PCRE_DEBUG defined in pcre_internal.h). It is not included in production
47    compiles.
48    
49  (2) It is always #included by pcretest.c, which can be asked to print out a  (2) It is always #included by pcretest.c, which can be asked to print out a
50  compiled regex for debugging purposes. */  compiled regex for debugging purposes. */
# Line 54  hexadecimal. We don't use isprint() beca Line 55  hexadecimal. We don't use isprint() beca
55  (even without the use of locales) and we want the output always to be the same,  (even without the use of locales) and we want the output always to be the same,
56  for testing purposes. This macro is used in pcretest as well as in this file. */  for testing purposes. This macro is used in pcretest as well as in this file. */
57    
58    #ifdef EBCDIC
59    #define PRINTABLE(c) ((c) >= 64 && (c) < 255)
60    #else
61  #define PRINTABLE(c) ((c) >= 32 && (c) < 127)  #define PRINTABLE(c) ((c) >= 32 && (c) < 127)
62    #endif
63    
64  /* The table of operator names. */  /* The table of operator names. */
65    
# Line 122  get_ucpname(int ptype, int pvalue) Line 127  get_ucpname(int ptype, int pvalue)
127  {  {
128  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
129  int i;  int i;
130  for (i = _pcre_utt_size; i >= 0; i--)  for (i = _pcre_utt_size - 1; i >= 0; i--)
131    {    {
132    if (ptype == _pcre_utt[i].type && pvalue == _pcre_utt[i].value) break;    if (ptype == _pcre_utt[i].type && pvalue == _pcre_utt[i].value) break;
133    }    }
134  return (i >= 0)? _pcre_utt[i].name : "??";  return (i >= 0)? _pcre_utt_names + _pcre_utt[i].name_offset : "??";
135  #else  #else
136  /* It gets harder and harder to shut off unwanted compiler warnings. */  /* It gets harder and harder to shut off unwanted compiler warnings. */
137  ptype = ptype * pvalue;  ptype = ptype * pvalue;
# Line 142  return (ptype == pvalue)? "??" : "??"; Line 147  return (ptype == pvalue)? "??" : "??";
147    
148  /* Make this function work for a regex with integers either byte order.  /* Make this function work for a regex with integers either byte order.
149  However, we assume that what we are passed is a compiled regex. The  However, we assume that what we are passed is a compiled regex. The
150  print_lengths flag controls whether offsets and lengths of items are printed.  print_lengths flag controls whether offsets and lengths of items are printed.
151  They can be turned off from pcretest so that automatic tests on bytecode can be  They can be turned off from pcretest so that automatic tests on bytecode can be
152  written that do not depend on the value of LINK_SIZE. */  written that do not depend on the value of LINK_SIZE. */
153    
# Line 175  utf8 = (options & PCRE_UTF8) != 0; Line 180  utf8 = (options & PCRE_UTF8) != 0;
180  for(;;)  for(;;)
181    {    {
182    uschar *ccode;    uschar *ccode;
183      const char *flag = "  ";
184    int c;    int c;
185    int extra = 0;    int extra = 0;
186    
187    if (print_lengths)    if (print_lengths)
188      fprintf(f, "%3d ", (int)(code - codestart));      fprintf(f, "%3d ", (int)(code - codestart));
189    else    else
190      fprintf(f, "    ");      fprintf(f, "    ");
191    
192    switch(*code)    switch(*code)
193      {      {
194    /* ========================================================================== */
195          /* These cases are never obeyed. This is a fudge that causes a compile-
196          time error if the vectors OP_names or _pcre_OP_lengths, which are indexed
197          by opcode, are not the correct length. It seems to be the only way to do
198          such a check at compile time, as the sizeof() operator does not work in
199          the C preprocessor. We do this while compiling pcretest, because that
200          #includes pcre_tables.c, which holds _pcre_OP_lengths. We can't do this
201          when building pcre_compile.c with PCRE_DEBUG set, because it doesn't then
202          know the size of _pcre_OP_lengths. */
203    
204    #ifdef COMPILING_PCRETEST
205          case OP_TABLE_LENGTH:
206          case OP_TABLE_LENGTH +
207            ((sizeof(OP_names)/sizeof(const char *) == OP_TABLE_LENGTH) &&
208            (sizeof(_pcre_OP_lengths) == OP_TABLE_LENGTH)):
209          break;
210    #endif
211    /* ========================================================================== */
212    
213      case OP_END:      case OP_END:
214      fprintf(f, "    %s\n", OP_names[*code]);      fprintf(f, "    %s\n", OP_names[*code]);
215      fprintf(f, "------------------------------------------------------------------\n");      fprintf(f, "------------------------------------------------------------------\n");
216      return;      return;
217    
     case OP_OPT:  
     fprintf(f, " %.2x %s", code[1], OP_names[*code]);  
     break;  
   
218      case OP_CHAR:      case OP_CHAR:
219      fprintf(f, "    ");      fprintf(f, "    ");
220      do      do
# Line 205  for(;;) Line 226  for(;;)
226      fprintf(f, "\n");      fprintf(f, "\n");
227      continue;      continue;
228    
229      case OP_CHARNC:      case OP_CHARI:
230      fprintf(f, " NC ");      fprintf(f, " /i ");
231      do      do
232        {        {
233        code++;        code++;
234        code += 1 + print_char(f, code, utf8);        code += 1 + print_char(f, code, utf8);
235        }        }
236      while (*code == OP_CHARNC);      while (*code == OP_CHARI);
237      fprintf(f, "\n");      fprintf(f, "\n");
238      continue;      continue;
239    
240      case OP_CBRA:      case OP_CBRA:
241      case OP_SCBRA:      case OP_SCBRA:
242      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
243        else fprintf(f, "    ");        else fprintf(f, "    ");
244      fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE));      fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE));
245      break;      break;
246    
# Line 238  for(;;) Line 259  for(;;)
259      case OP_SCOND:      case OP_SCOND:
260      case OP_REVERSE:      case OP_REVERSE:
261      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
262        else fprintf(f, "    ");        else fprintf(f, "    ");
263      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", OP_names[*code]);
264      break;      break;
265    
266        case OP_CLOSE:
267        fprintf(f, "    %s %d", OP_names[*code], GET2(code, 1));
268        break;
269    
270      case OP_CREF:      case OP_CREF:
271        case OP_NCREF:
272      fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);      fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);
273      break;      break;
274    
# Line 254  for(;;) Line 280  for(;;)
280        fprintf(f, "    Cond recurse %d", c);        fprintf(f, "    Cond recurse %d", c);
281      break;      break;
282    
283        case OP_NRREF:
284        c = GET2(code, 1);
285        if (c == RREF_ANY)
286          fprintf(f, "    Cond nrecurse any");
287        else
288          fprintf(f, "    Cond nrecurse %d", c);
289        break;
290    
291      case OP_DEF:      case OP_DEF:
292      fprintf(f, "    Cond def");      fprintf(f, "    Cond def");
293      break;      break;
294    
295        case OP_STARI:
296        case OP_MINSTARI:
297        case OP_POSSTARI:
298        case OP_PLUSI:
299        case OP_MINPLUSI:
300        case OP_POSPLUSI:
301        case OP_QUERYI:
302        case OP_MINQUERYI:
303        case OP_POSQUERYI:
304        flag = "/i";
305        /* Fall through */
306      case OP_STAR:      case OP_STAR:
307      case OP_MINSTAR:      case OP_MINSTAR:
308      case OP_POSSTAR:      case OP_POSSTAR:
# Line 276  for(;;) Line 321  for(;;)
321      case OP_TYPEQUERY:      case OP_TYPEQUERY:
322      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
323      case OP_TYPEPOSQUERY:      case OP_TYPEPOSQUERY:
324      fprintf(f, "    ");      fprintf(f, " %s ", flag);
325      if (*code >= OP_TYPESTAR)      if (*code >= OP_TYPESTAR)
326        {        {
327        fprintf(f, "%s", OP_names[code[1]]);        fprintf(f, "%s", OP_names[code[1]]);
# Line 290  for(;;) Line 335  for(;;)
335      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", OP_names[*code]);
336      break;      break;
337    
338        case OP_EXACTI:
339        case OP_UPTOI:
340        case OP_MINUPTOI:
341        case OP_POSUPTOI:
342        flag = "/i";
343        /* Fall through */
344      case OP_EXACT:      case OP_EXACT:
345      case OP_UPTO:      case OP_UPTO:
346      case OP_MINUPTO:      case OP_MINUPTO:
347      case OP_POSUPTO:      case OP_POSUPTO:
348      fprintf(f, "    ");      fprintf(f, " %s ", flag);
349      extra = print_char(f, code+3, utf8);      extra = print_char(f, code+3, utf8);
350      fprintf(f, "{");      fprintf(f, "{");
351      if (*code != OP_EXACT) fprintf(f, "0,");      if (*code != OP_EXACT && *code != OP_EXACTI) fprintf(f, "0,");
352      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
353      if (*code == OP_MINUPTO) fprintf(f, "?");      if (*code == OP_MINUPTO || *code == OP_MINUPTOI) fprintf(f, "?");
354        else if (*code == OP_POSUPTO) fprintf(f, "+");        else if (*code == OP_POSUPTO || *code == OP_POSUPTOI) fprintf(f, "+");
355      break;      break;
356    
357      case OP_TYPEEXACT:      case OP_TYPEEXACT:
# Line 320  for(;;) Line 371  for(;;)
371        else if (*code == OP_TYPEPOSUPTO) fprintf(f, "+");        else if (*code == OP_TYPEPOSUPTO) fprintf(f, "+");
372      break;      break;
373    
374        case OP_NOTI:
375        flag = "/i";
376        /* Fall through */
377      case OP_NOT:      case OP_NOT:
378      c = code[1];      c = code[1];
379      if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);
380        else fprintf(f, "    [^\\x%02x]", c);        else fprintf(f, " %s [^\\x%02x]", flag, c);
381      break;      break;
382    
383        case OP_NOTSTARI:
384        case OP_NOTMINSTARI:
385        case OP_NOTPOSSTARI:
386        case OP_NOTPLUSI:
387        case OP_NOTMINPLUSI:
388        case OP_NOTPOSPLUSI:
389        case OP_NOTQUERYI:
390        case OP_NOTMINQUERYI:
391        case OP_NOTPOSQUERYI:
392        flag = "/i";
393        /* Fall through */
394    
395      case OP_NOTSTAR:      case OP_NOTSTAR:
396      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
397      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
# Line 336  for(;;) Line 402  for(;;)
402      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
403      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
404      c = code[1];      c = code[1];
405      if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);      if (PRINTABLE(c)) fprintf(f, " %s [^%c]", flag, c);
406        else fprintf(f, "    [^\\x%02x]", c);        else fprintf(f, " %s [^\\x%02x]", flag, c);
407      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", OP_names[*code]);
408      break;      break;
409    
410        case OP_NOTEXACTI:
411        case OP_NOTUPTOI:
412        case OP_NOTMINUPTOI:
413        case OP_NOTPOSUPTOI:
414        flag = "/i";
415        /* Fall through */
416    
417      case OP_NOTEXACT:      case OP_NOTEXACT:
418      case OP_NOTUPTO:      case OP_NOTUPTO:
419      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
420      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
421      c = code[3];      c = code[3];
422      if (PRINTABLE(c)) fprintf(f, "    [^%c]{", c);      if (PRINTABLE(c)) fprintf(f, " %s [^%c]{", flag, c);
423        else fprintf(f, "    [^\\x%02x]{", c);        else fprintf(f, " %s [^\\x%02x]{", flag, c);
424      if (*code != OP_NOTEXACT) fprintf(f, "0,");      if (*code != OP_NOTEXACT && *code != OP_NOTEXACTI) fprintf(f, "0,");
425      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
426      if (*code == OP_NOTMINUPTO) fprintf(f, "?");      if (*code == OP_NOTMINUPTO || *code == OP_NOTMINUPTOI) fprintf(f, "?");
427        else if (*code == OP_NOTPOSUPTO) fprintf(f, "+");        else
428        if (*code == OP_NOTPOSUPTO || *code == OP_NOTPOSUPTOI) fprintf(f, "+");
429      break;      break;
430    
431      case OP_RECURSE:      case OP_RECURSE:
432      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
433        else fprintf(f, "    ");        else fprintf(f, "    ");
434      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", OP_names[*code]);
435      break;      break;
436    
437        case OP_REFI:
438        flag = "/i";
439        /* Fall through */
440      case OP_REF:      case OP_REF:
441      fprintf(f, "    \\%d", GET2(code,1));      fprintf(f, " %s \\%d", flag, GET2(code,1));
442      ccode = code + _pcre_OP_lengths[*code];      ccode = code + _pcre_OP_lengths[*code];
443      goto CLASS_REF_REPEAT;      goto CLASS_REF_REPEAT;
444    
# Line 497  for(;;) Line 574  for(;;)
574        }        }
575      break;      break;
576    
577      /* Anything else is just an item with no data*/      case OP_MARK:
578        case OP_PRUNE_ARG:
579        case OP_SKIP_ARG:
580        fprintf(f, "    %s %s", OP_names[*code], code + 2);
581        extra += code[1];
582        break;
583    
584        case OP_THEN:
585        if (print_lengths)
586          fprintf(f, "    %s %d", OP_names[*code], GET(code, 1));
587        else
588          fprintf(f, "    %s", OP_names[*code]);
589        break;
590    
591        case OP_THEN_ARG:
592        if (print_lengths)
593          fprintf(f, "    %s %d %s", OP_names[*code], GET(code, 1),
594            code + 2 + LINK_SIZE);
595        else
596          fprintf(f, "    %s %s", OP_names[*code], code + 2 + LINK_SIZE);
597        extra += code[1+LINK_SIZE];
598        break;
599    
600        case OP_CIRCM:
601        case OP_DOLLM:
602        flag = "/m";
603        /* Fall through */
604    
605        /* Anything else is just an item with no data, but possibly a flag. */
606    
607      default:      default:
608      fprintf(f, "    %s", OP_names[*code]);      fprintf(f, " %s %s", flag, OP_names[*code]);
609      break;      break;
610      }      }
611    

Legend:
Removed from v.117  
changed lines
  Added in v.602

  ViewVC Help
Powered by ViewVC 1.1.5