/[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 93 by nigel, Sat Feb 24 21:41:42 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 54  hexadecimal. We don't use isprint() beca Line 54  hexadecimal. We don't use isprint() beca
54  (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,
55  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. */
56    
57    #ifdef EBCDIC
58    #define PRINTABLE(c) ((c) >= 64 && (c) < 255)
59    #else
60  #define PRINTABLE(c) ((c) >= 32 && (c) < 127)  #define PRINTABLE(c) ((c) >= 32 && (c) < 127)
61    #endif
62    
63  /* The table of operator names. */  /* The table of operator names. */
64    
# Line 71  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 (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);    if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
# Line 102  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 115  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 134  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 168  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      else
188        fprintf(f, "    ");
189    
190    switch(*code)    switch(*code)
191      {      {
# Line 205  for(;;) Line 222  for(;;)
222    
223      case OP_CBRA:      case OP_CBRA:
224      case OP_SCBRA:      case OP_SCBRA:
225      fprintf(f, "%3d %s %d", GET(code, 1), OP_names[*code],      if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
226        GET2(code, 1+LINK_SIZE));        else fprintf(f, "    ");
227        fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE));
228      break;      break;
229    
230      case OP_BRA:      case OP_BRA:
# Line 223  for(;;) Line 241  for(;;)
241      case OP_COND:      case OP_COND:
242      case OP_SCOND:      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_CREF:      case OP_CREF:
# Line 339  for(;;) Line 359  for(;;)
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:

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

  ViewVC Help
Powered by ViewVC 1.1.5