/[pcre]/code/tags/pcre-8.10/pcre_printint.src
ViewVC logotype

Diff of /code/tags/pcre-8.10/pcre_printint.src

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

revision 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 461 by ph10, Mon Oct 5 10:59:35 2009 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-2005 University of Cambridge             Copyright (c) 1997-2009 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 49  local functions. This source file is use Line 49  local functions. This source file is use
49  compiled regex for debugging purposes. */  compiled regex for debugging purposes. */
50    
51    
52    /* Macro that decides whether a character should be output as a literal or in
53    hexadecimal. We don't use isprint() because that can vary from system to system
54    (even without the use of locales) and we want the output always to be the same,
55    for testing purposes. This macro is used in pcretest as well as in this file. */
56    
57    #ifdef EBCDIC
58    #define PRINTABLE(c) ((c) >= 64 && (c) < 255)
59    #else
60    #define PRINTABLE(c) ((c) >= 32 && (c) < 127)
61    #endif
62    
63    /* The table of operator names. */
64    
65  static const char *OP_names[] = { OP_NAME_LIST };  static const char *OP_names[] = { OP_NAME_LIST };
66    
67    
68    
69  /*************************************************  /*************************************************
70  *       Print single- or multi-byte character    *  *       Print single- or multi-byte character    *
71  *************************************************/  *************************************************/
# Line 61  print_char(FILE *f, uschar *ptr, BOOL ut Line 75  print_char(FILE *f, uschar *ptr, BOOL ut
75  {  {
76  int c = *ptr;  int c = *ptr;
77    
78    #ifndef SUPPORT_UTF8
79    utf8 = utf8;  /* Avoid compiler warning */
80    if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
81    return 0;
82    
83    #else
84  if (!utf8 || (c & 0xc0) != 0xc0)  if (!utf8 || (c & 0xc0) != 0xc0)
85    {    {
86    if (isprint(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);    if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
87    return 0;    return 0;
88    }    }
89  else  else
# Line 92  else Line 112  else
112    if (c < 128) fprintf(f, "\\x%02x", c); else fprintf(f, "\\x{%x}", c);    if (c < 128) fprintf(f, "\\x%02x", c); else fprintf(f, "\\x{%x}", c);
113    return a;    return a;
114    }    }
115    #endif
116  }  }
117    
118    
# Line 105  get_ucpname(int ptype, int pvalue) Line 126  get_ucpname(int ptype, int pvalue)
126  {  {
127  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
128  int i;  int i;
129  for (i = _pcre_utt_size; i >= 0; i--)  for (i = _pcre_utt_size - 1; i >= 0; i--)
130    {    {
131    if (ptype == _pcre_utt[i].type && pvalue == _pcre_utt[i].value) break;    if (ptype == _pcre_utt[i].type && pvalue == _pcre_utt[i].value) break;
132    }    }
133  return (i >= 0)? _pcre_utt[i].name : "??";  return (i >= 0)? _pcre_utt_names + _pcre_utt[i].name_offset : "??";
134  #else  #else
135  /* It gets harder and harder to shut off unwanted compiler warnings. */  /* It gets harder and harder to shut off unwanted compiler warnings. */
136  ptype = ptype * pvalue;  ptype = ptype * pvalue;
# Line 124  return (ptype == pvalue)? "??" : "??"; Line 145  return (ptype == pvalue)? "??" : "??";
145  *************************************************/  *************************************************/
146    
147  /* Make this function work for a regex with integers either byte order.  /* Make this function work for a regex with integers either byte order.
148  However, we assume that what we are passed is a compiled regex. */  However, we assume that what we are passed is a compiled regex. The
149    print_lengths flag controls whether offsets and lengths of items are printed.
150    They can be turned off from pcretest so that automatic tests on bytecode can be
151    written that do not depend on the value of LINK_SIZE. */
152    
153  static void  static void
154  pcre_printint(pcre *external_re, FILE *f)  pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths)
155  {  {
156  real_pcre *re = (real_pcre *)external_re;  real_pcre *re = (real_pcre *)external_re;
157  uschar *codestart, *code;  uschar *codestart, *code;
# Line 158  for(;;) Line 182  for(;;)
182    int c;    int c;
183    int extra = 0;    int extra = 0;
184    
185    fprintf(f, "%3d ", (int)(code - codestart));    if (print_lengths)
186        fprintf(f, "%3d ", (int)(code - codestart));
187    if (*code >= OP_BRA)    else
188      {      fprintf(f, "    ");
     if (*code - OP_BRA > EXTRACT_BASIC_MAX)  
       fprintf(f, "%3d Bra extra\n", GET(code, 1));  
     else  
       fprintf(f, "%3d Bra %d\n", GET(code, 1), *code - OP_BRA);  
     code += _pcre_OP_lengths[OP_BRA];  
     continue;  
     }  
189    
190    switch(*code)    switch(*code)
191      {      {
# Line 203  for(;;) Line 220  for(;;)
220      fprintf(f, "\n");      fprintf(f, "\n");
221      continue;      continue;
222    
223        case OP_CBRA:
224        case OP_SCBRA:
225        if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
226          else fprintf(f, "    ");
227        fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE));
228        break;
229    
230        case OP_BRA:
231        case OP_SBRA:
232      case OP_KETRMAX:      case OP_KETRMAX:
233      case OP_KETRMIN:      case OP_KETRMIN:
234      case OP_ALT:      case OP_ALT:
# Line 213  for(;;) Line 239  for(;;)
239      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
240      case OP_ONCE:      case OP_ONCE:
241      case OP_COND:      case OP_COND:
242        case OP_SCOND:
243      case OP_REVERSE:      case OP_REVERSE:
244      fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
245          else fprintf(f, "    ");
246        fprintf(f, "%s", OP_names[*code]);
247      break;      break;
248    
249      case OP_BRANUMBER:      case OP_CLOSE:
250      printf("%3d %s", GET2(code, 1), OP_names[*code]);      fprintf(f, "    %s %d", OP_names[*code], GET2(code, 1));
251      break;      break;
252    
253      case OP_CREF:      case OP_CREF:
254      if (GET2(code, 1) == CREF_RECURSE)      case OP_NCREF:
255        fprintf(f, "    Cond recurse");      fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);
256        break;
257    
258        case OP_RREF:
259        c = GET2(code, 1);
260        if (c == RREF_ANY)
261          fprintf(f, "    Cond recurse any");
262      else      else
263        fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);        fprintf(f, "    Cond recurse %d", c);
264        break;
265    
266        case OP_NRREF:
267        c = GET2(code, 1);
268        if (c == RREF_ANY)
269          fprintf(f, "    Cond nrecurse any");
270        else
271          fprintf(f, "    Cond nrecurse %d", c);
272        break;
273    
274        case OP_DEF:
275        fprintf(f, "    Cond def");
276      break;      break;
277    
278      case OP_STAR:      case OP_STAR:
279      case OP_MINSTAR:      case OP_MINSTAR:
280        case OP_POSSTAR:
281      case OP_PLUS:      case OP_PLUS:
282      case OP_MINPLUS:      case OP_MINPLUS:
283        case OP_POSPLUS:
284      case OP_QUERY:      case OP_QUERY:
285      case OP_MINQUERY:      case OP_MINQUERY:
286        case OP_POSQUERY:
287      case OP_TYPESTAR:      case OP_TYPESTAR:
288      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
289        case OP_TYPEPOSSTAR:
290      case OP_TYPEPLUS:      case OP_TYPEPLUS:
291      case OP_TYPEMINPLUS:      case OP_TYPEMINPLUS:
292        case OP_TYPEPOSPLUS:
293      case OP_TYPEQUERY:      case OP_TYPEQUERY:
294      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
295        case OP_TYPEPOSQUERY:
296      fprintf(f, "    ");      fprintf(f, "    ");
297      if (*code >= OP_TYPESTAR)      if (*code >= OP_TYPESTAR)
298        {        {
# Line 257  for(;;) Line 310  for(;;)
310      case OP_EXACT:      case OP_EXACT:
311      case OP_UPTO:      case OP_UPTO:
312      case OP_MINUPTO:      case OP_MINUPTO:
313        case OP_POSUPTO:
314      fprintf(f, "    ");      fprintf(f, "    ");
315      extra = print_char(f, code+3, utf8);      extra = print_char(f, code+3, utf8);
316      fprintf(f, "{");      fprintf(f, "{");
317      if (*code != OP_EXACT) fprintf(f, ",");      if (*code != OP_EXACT) fprintf(f, "0,");
318      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
319      if (*code == OP_MINUPTO) fprintf(f, "?");      if (*code == OP_MINUPTO) fprintf(f, "?");
320          else if (*code == OP_POSUPTO) fprintf(f, "+");
321      break;      break;
322    
323      case OP_TYPEEXACT:      case OP_TYPEEXACT:
324      case OP_TYPEUPTO:      case OP_TYPEUPTO:
325      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
326        case OP_TYPEPOSUPTO:
327      fprintf(f, "    %s", OP_names[code[3]]);      fprintf(f, "    %s", OP_names[code[3]]);
328      if (code[3] == OP_PROP || code[3] == OP_NOTPROP)      if (code[3] == OP_PROP || code[3] == OP_NOTPROP)
329        {        {
# Line 278  for(;;) Line 334  for(;;)
334      if (*code != OP_TYPEEXACT) fprintf(f, "0,");      if (*code != OP_TYPEEXACT) fprintf(f, "0,");
335      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
336      if (*code == OP_TYPEMINUPTO) fprintf(f, "?");      if (*code == OP_TYPEMINUPTO) fprintf(f, "?");
337          else if (*code == OP_TYPEPOSUPTO) fprintf(f, "+");
338      break;      break;
339    
340      case OP_NOT:      case OP_NOT:
341      if (isprint(c = code[1])) fprintf(f, "    [^%c]", c);      c = code[1];
342        if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);
343        else fprintf(f, "    [^\\x%02x]", c);        else fprintf(f, "    [^\\x%02x]", c);
344      break;      break;
345    
346      case OP_NOTSTAR:      case OP_NOTSTAR:
347      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
348        case OP_NOTPOSSTAR:
349      case OP_NOTPLUS:      case OP_NOTPLUS:
350      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
351        case OP_NOTPOSPLUS:
352      case OP_NOTQUERY:      case OP_NOTQUERY:
353      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
354      if (isprint(c = code[1])) fprintf(f, "    [^%c]", c);      case OP_NOTPOSQUERY:
355        c = code[1];
356        if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);
357        else fprintf(f, "    [^\\x%02x]", c);        else fprintf(f, "    [^\\x%02x]", c);
358      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", OP_names[*code]);
359      break;      break;
# Line 299  for(;;) Line 361  for(;;)
361      case OP_NOTEXACT:      case OP_NOTEXACT:
362      case OP_NOTUPTO:      case OP_NOTUPTO:
363      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
364      if (isprint(c = code[3])) fprintf(f, "    [^%c]{", c);      case OP_NOTPOSUPTO:
365        c = code[3];
366        if (PRINTABLE(c)) fprintf(f, "    [^%c]{", c);
367        else fprintf(f, "    [^\\x%02x]{", c);        else fprintf(f, "    [^\\x%02x]{", c);
368      if (*code != OP_NOTEXACT) fprintf(f, "0,");      if (*code != OP_NOTEXACT) fprintf(f, "0,");
369      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
370      if (*code == OP_NOTMINUPTO) fprintf(f, "?");      if (*code == OP_NOTMINUPTO) fprintf(f, "?");
371          else if (*code == OP_NOTPOSUPTO) fprintf(f, "+");
372      break;      break;
373    
374      case OP_RECURSE:      case OP_RECURSE:
375      fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
376          else fprintf(f, "    ");
377        fprintf(f, "%s", OP_names[*code]);
378      break;      break;
379    
380      case OP_REF:      case OP_REF:
# Line 363  for(;;) Line 430  for(;;)
430              for (j = i+1; j < 256; j++)              for (j = i+1; j < 256; j++)
431                if ((ccode[j/8] & (1 << (j&7))) == 0) break;                if ((ccode[j/8] & (1 << (j&7))) == 0) break;
432              if (i == '-' || i == ']') fprintf(f, "\\");              if (i == '-' || i == ']') fprintf(f, "\\");
433              if (isprint(i)) fprintf(f, "%c", i); else fprintf(f, "\\x%02x", i);              if (PRINTABLE(i)) fprintf(f, "%c", i);
434                  else fprintf(f, "\\x%02x", i);
435              if (--j > i)              if (--j > i)
436                {                {
437                if (j != i + 1) fprintf(f, "-");                if (j != i + 1) fprintf(f, "-");
438                if (j == '-' || j == ']') fprintf(f, "\\");                if (j == '-' || j == ']') fprintf(f, "\\");
439                if (isprint(j)) fprintf(f, "%c", j); else fprintf(f, "\\x%02x", j);                if (PRINTABLE(j)) fprintf(f, "%c", j);
440                    else fprintf(f, "\\x%02x", j);
441                }                }
442              i = j;              i = j;
443              }              }

Legend:
Removed from v.91  
changed lines
  Added in v.461

  ViewVC Help
Powered by ViewVC 1.1.5