bugzilla 612 - write recipients list in X-Envelope-To header of MBOX spool file
[exim.git] / src / src / pcre / pcre_printint.src
index e5407f81b9550d9b255ec1aac0d80ccfa5280e63..b32d3fbd168c3e3cc3ccdd964bdfcf6af4b2838a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Cambridge: exim/src/src/pcre/pcre_printint.src,v 1.2 2007/01/23 15:08:45 ph10 Exp $ */
+/* $Cambridge: exim/src/src/pcre/pcre_printint.src,v 1.4 2007/11/12 13:02:20 nm4 Exp $ */
 
 /*************************************************
 *      Perl-Compatible Regular Expressions       *
@@ -8,7 +8,7 @@
 and semantics are as close as possible to those of the Perl 5 language.
 
                        Written by Philip Hazel
-           Copyright (c) 1997-2005 University of Cambridge
+           Copyright (c) 1997-2007 University of Cambridge
 
 -----------------------------------------------------------------------------
 Redistribution and use in source and binary forms, with or without
@@ -73,6 +73,12 @@ print_char(FILE *f, uschar *ptr, BOOL utf8)
 {
 int c = *ptr;
 
+#ifndef SUPPORT_UTF8
+utf8 = utf8;  /* Avoid compiler warning */
+if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
+return 0;
+
+#else
 if (!utf8 || (c & 0xc0) != 0xc0)
   {
   if (PRINTABLE(c)) fprintf(f, "%c", c); else fprintf(f, "\\x%02x", c);
@@ -104,6 +110,7 @@ else
   if (c < 128) fprintf(f, "\\x%02x", c); else fprintf(f, "\\x{%x}", c);
   return a;
   }
+#endif
 }
 
 
@@ -117,11 +124,11 @@ get_ucpname(int ptype, int pvalue)
 {
 #ifdef SUPPORT_UCP
 int i;
-for (i = _pcre_utt_size; i >= 0; i--)
+for (i = _pcre_utt_size - 1; i >= 0; i--)
   {
   if (ptype == _pcre_utt[i].type && pvalue == _pcre_utt[i].value) break;
   }
-return (i >= 0)? _pcre_utt[i].name : "??";
+return (i >= 0)? _pcre_utt_names + _pcre_utt[i].name_offset : "??";
 #else
 /* It gets harder and harder to shut off unwanted compiler warnings. */
 ptype = ptype * pvalue;
@@ -136,10 +143,13 @@ return (ptype == pvalue)? "??" : "??";
 *************************************************/
 
 /* Make this function work for a regex with integers either byte order.
-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
+print_lengths flag controls whether offsets and lengths of items are printed.
+They can be turned off from pcretest so that automatic tests on bytecode can be
+written that do not depend on the value of LINK_SIZE. */
 
 static void
-pcre_printint(pcre *external_re, FILE *f)
+pcre_printint(pcre *external_re, FILE *f, BOOL print_lengths)
 {
 real_pcre *re = (real_pcre *)external_re;
 uschar *codestart, *code;
@@ -170,7 +180,10 @@ for(;;)
   int c;
   int extra = 0;
 
-  fprintf(f, "%3d ", (int)(code - codestart));
+  if (print_lengths)
+    fprintf(f, "%3d ", (int)(code - codestart));
+  else
+    fprintf(f, "    ");
 
   switch(*code)
     {
@@ -207,8 +220,9 @@ for(;;)
 
     case OP_CBRA:
     case OP_SCBRA:
-    fprintf(f, "%3d %s %d", GET(code, 1), OP_names[*code],
-      GET2(code, 1+LINK_SIZE));
+    if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
+      else fprintf(f, "    ");
+    fprintf(f, "%s %d", OP_names[*code], GET2(code, 1+LINK_SIZE));
     break;
 
     case OP_BRA:
@@ -225,7 +239,9 @@ for(;;)
     case OP_COND:
     case OP_SCOND:
     case OP_REVERSE:
-    fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);
+    if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
+      else fprintf(f, "    ");
+    fprintf(f, "%s", OP_names[*code]);
     break;
 
     case OP_CREF:
@@ -341,7 +357,9 @@ for(;;)
     break;
 
     case OP_RECURSE:
-    fprintf(f, "%3d %s", GET(code, 1), OP_names[*code]);
+    if (print_lengths) fprintf(f, "%3d ", GET(code, 1));
+      else fprintf(f, "    ");
+    fprintf(f, "%s", OP_names[*code]);
     break;
 
     case OP_REF: