/[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 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 391 by ph10, Tue Mar 17 21:16:01 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  ptype = ptype;    /* Avoid compiler warning */  /* It gets harder and harder to shut off unwanted compiler warnings. */
136  pvalue = pvalue;  ptype = ptype * pvalue;
137  return "??";  return (ptype == pvalue)? "??" : "??";
138  #endif  #endif
139  }  }
140    
# Line 124  return "??"; Line 145  return "??";
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 182  for(;;) Line 199  for(;;)
199      break;      break;
200    
201      case OP_CHAR:      case OP_CHAR:
202        fprintf(f, "    ");
203        do
204        {        {
205        fprintf(f, "    ");        code++;
206        do        code += 1 + print_char(f, code, utf8);
         {  
         code++;  
         code += 1 + print_char(f, code, utf8);  
         }  
       while (*code == OP_CHAR);  
       fprintf(f, "\n");  
       continue;  
207        }        }
208      break;      while (*code == OP_CHAR);
209        fprintf(f, "\n");
210        continue;
211    
212      case OP_CHARNC:      case OP_CHARNC:
213        fprintf(f, " NC ");
214        do
215        {        {
216        fprintf(f, " NC ");        code++;
217        do        code += 1 + print_char(f, code, utf8);
         {  
         code++;  
         code += 1 + print_char(f, code, utf8);  
         }  
       while (*code == OP_CHARNC);  
       fprintf(f, "\n");  
       continue;  
218        }        }
219        while (*code == OP_CHARNC);
220        fprintf(f, "\n");
221        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;      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 219  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_CREF:
250      printf("%3d %s", GET2(code, 1), OP_names[*code]);      fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);
251      break;      break;
252    
253      case OP_CREF:      case OP_RREF:
254      if (GET2(code, 1) == CREF_RECURSE)      c = GET2(code, 1);
255        fprintf(f, "    Cond recurse");      if (c == RREF_ANY)
256          fprintf(f, "    Cond recurse any");
257      else      else
258        fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);        fprintf(f, "    Cond recurse %d", c);
259        break;
260    
261        case OP_DEF:
262        fprintf(f, "    Cond def");
263      break;      break;
264    
265      case OP_STAR:      case OP_STAR:
266      case OP_MINSTAR:      case OP_MINSTAR:
267        case OP_POSSTAR:
268      case OP_PLUS:      case OP_PLUS:
269      case OP_MINPLUS:      case OP_MINPLUS:
270        case OP_POSPLUS:
271      case OP_QUERY:      case OP_QUERY:
272      case OP_MINQUERY:      case OP_MINQUERY:
273        case OP_POSQUERY:
274      case OP_TYPESTAR:      case OP_TYPESTAR:
275      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
276        case OP_TYPEPOSSTAR:
277      case OP_TYPEPLUS:      case OP_TYPEPLUS:
278      case OP_TYPEMINPLUS:      case OP_TYPEMINPLUS:
279        case OP_TYPEPOSPLUS:
280      case OP_TYPEQUERY:      case OP_TYPEQUERY:
281      case OP_TYPEMINQUERY:      case OP_TYPEMINQUERY:
282        case OP_TYPEPOSQUERY:
283      fprintf(f, "    ");      fprintf(f, "    ");
284      if (*code >= OP_TYPESTAR)      if (*code >= OP_TYPESTAR)
285        {        {
# Line 263  for(;;) Line 297  for(;;)
297      case OP_EXACT:      case OP_EXACT:
298      case OP_UPTO:      case OP_UPTO:
299      case OP_MINUPTO:      case OP_MINUPTO:
300        case OP_POSUPTO:
301      fprintf(f, "    ");      fprintf(f, "    ");
302      extra = print_char(f, code+3, utf8);      extra = print_char(f, code+3, utf8);
303      fprintf(f, "{");      fprintf(f, "{");
304      if (*code != OP_EXACT) fprintf(f, ",");      if (*code != OP_EXACT) fprintf(f, "0,");
305      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
306      if (*code == OP_MINUPTO) fprintf(f, "?");      if (*code == OP_MINUPTO) fprintf(f, "?");
307          else if (*code == OP_POSUPTO) fprintf(f, "+");
308      break;      break;
309    
310      case OP_TYPEEXACT:      case OP_TYPEEXACT:
311      case OP_TYPEUPTO:      case OP_TYPEUPTO:
312      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
313        case OP_TYPEPOSUPTO:
314      fprintf(f, "    %s", OP_names[code[3]]);      fprintf(f, "    %s", OP_names[code[3]]);
315      if (code[3] == OP_PROP || code[3] == OP_NOTPROP)      if (code[3] == OP_PROP || code[3] == OP_NOTPROP)
316        {        {
# Line 284  for(;;) Line 321  for(;;)
321      if (*code != OP_TYPEEXACT) fprintf(f, "0,");      if (*code != OP_TYPEEXACT) fprintf(f, "0,");
322      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
323      if (*code == OP_TYPEMINUPTO) fprintf(f, "?");      if (*code == OP_TYPEMINUPTO) fprintf(f, "?");
324          else if (*code == OP_TYPEPOSUPTO) fprintf(f, "+");
325      break;      break;
326    
327      case OP_NOT:      case OP_NOT:
328      if (isprint(c = code[1])) fprintf(f, "    [^%c]", c);      c = code[1];
329        if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);
330        else fprintf(f, "    [^\\x%02x]", c);        else fprintf(f, "    [^\\x%02x]", c);
331      break;      break;
332    
333      case OP_NOTSTAR:      case OP_NOTSTAR:
334      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
335        case OP_NOTPOSSTAR:
336      case OP_NOTPLUS:      case OP_NOTPLUS:
337      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
338        case OP_NOTPOSPLUS:
339      case OP_NOTQUERY:      case OP_NOTQUERY:
340      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
341      if (isprint(c = code[1])) fprintf(f, "    [^%c]", c);      case OP_NOTPOSQUERY:
342        c = code[1];
343        if (PRINTABLE(c)) fprintf(f, "    [^%c]", c);
344        else fprintf(f, "    [^\\x%02x]", c);        else fprintf(f, "    [^\\x%02x]", c);
345      fprintf(f, "%s", OP_names[*code]);      fprintf(f, "%s", OP_names[*code]);
346      break;      break;
# Line 305  for(;;) Line 348  for(;;)
348      case OP_NOTEXACT:      case OP_NOTEXACT:
349      case OP_NOTUPTO:      case OP_NOTUPTO:
350      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
351      if (isprint(c = code[3])) fprintf(f, "    [^%c]{", c);      case OP_NOTPOSUPTO:
352        c = code[3];
353        if (PRINTABLE(c)) fprintf(f, "    [^%c]{", c);
354        else fprintf(f, "    [^\\x%02x]{", c);        else fprintf(f, "    [^\\x%02x]{", c);
355      if (*code != OP_NOTEXACT) fprintf(f, "0,");      if (*code != OP_NOTEXACT) fprintf(f, "0,");
356      fprintf(f, "%d}", GET2(code,1));      fprintf(f, "%d}", GET2(code,1));
357      if (*code == OP_NOTMINUPTO) fprintf(f, "?");      if (*code == OP_NOTMINUPTO) fprintf(f, "?");
358          else if (*code == OP_NOTPOSUPTO) fprintf(f, "+");
359      break;      break;
360    
361      case OP_RECURSE:      case OP_RECURSE:
362      fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
363          else fprintf(f, "    ");
364        fprintf(f, "%s", OP_names[*code]);
365      break;      break;
366    
367      case OP_REF:      case OP_REF:
# Line 369  for(;;) Line 417  for(;;)
417              for (j = i+1; j < 256; j++)              for (j = i+1; j < 256; j++)
418                if ((ccode[j/8] & (1 << (j&7))) == 0) break;                if ((ccode[j/8] & (1 << (j&7))) == 0) break;
419              if (i == '-' || i == ']') fprintf(f, "\\");              if (i == '-' || i == ']') fprintf(f, "\\");
420              if (isprint(i)) fprintf(f, "%c", i); else fprintf(f, "\\x%02x", i);              if (PRINTABLE(i)) fprintf(f, "%c", i);
421                  else fprintf(f, "\\x%02x", i);
422              if (--j > i)              if (--j > i)
423                {                {
424                if (j != i + 1) fprintf(f, "-");                if (j != i + 1) fprintf(f, "-");
425                if (j == '-' || j == ']') fprintf(f, "\\");                if (j == '-' || j == ']') fprintf(f, "\\");
426                if (isprint(j)) fprintf(f, "%c", j); else fprintf(f, "\\x%02x", j);                if (PRINTABLE(j)) fprintf(f, "%c", j);
427                    else fprintf(f, "\\x%02x", j);
428                }                }
429              i = j;              i = j;
430              }              }

Legend:
Removed from v.87  
changed lines
  Added in v.391

  ViewVC Help
Powered by ViewVC 1.1.5