[Pcre-svn] [1030] code/trunk/pcretest.c: Fix -C option in pc…

Página superior
Eliminar este mensaje
Autor: Subversion repository
Fecha:  
A: pcre-svn
Asunto: [Pcre-svn] [1030] code/trunk/pcretest.c: Fix -C option in pcretest for EBCDIC environments.
Revision: 1030
          http://vcs.pcre.org/viewvc?view=rev&revision=1030
Author:   ph10
Date:     2012-09-08 16:58:38 +0100 (Sat, 08 Sep 2012)


Log Message:
-----------
Fix -C option in pcretest for EBCDIC environments.

Modified Paths:
--------------
    code/trunk/pcretest.c


Modified: code/trunk/pcretest.c
===================================================================
--- code/trunk/pcretest.c    2012-09-07 09:50:59 UTC (rev 1029)
+++ code/trunk/pcretest.c    2012-09-08 15:58:38 UTC (rev 1030)
@@ -1097,7 +1097,40 @@
 #endif /* HAVE_STRERROR */



+
 /*************************************************
+*       Print newline configuration              *
+*************************************************/
+
+/* 
+Argument: the return code from PCRE_CONFIG_NEWLINE
+Returns:  nothing
+*/
+
+static void
+print_newline_config(int rc)
+{
+const char *s = NULL;
+printf("  Newline sequence is ");
+switch(rc)
+  {
+  case CHAR_CR: s = "CR"; break;
+  case CHAR_LF: s = "LF"; break;
+  case (CHAR_CR<<8 | CHAR_LF): s = "CRLF"; break;
+  case -1: s = "ANY"; break;
+  case -2: s = "ANYCRLF"; break;
+  
+  default:
+  printf("a non-standard value: 0x%04x\n", rc);    
+  return;
+  }  
+
+printf("%s\n", s);
+}
+
+
+
+/*************************************************
 *         JIT memory callback                    *
 *************************************************/


@@ -2428,12 +2461,7 @@
       if (strcmp(argv[op + 1], "newline") == 0)
         {
         (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
-        /* Note that these values are always the ASCII values, even
-        in EBCDIC environments. CR is 13 and NL is 10. */
-        printf("%s\n", (rc == 13)? "CR" :
-          (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :
-          (rc == -2)? "ANYCRLF" :
-          (rc == -1)? "ANY" : "???");
+        print_newline_config(rc); 
         goto EXIT;
         }
       printf("Unknown -C option: %s\n", argv[op + 1]);
@@ -2442,6 +2470,10 @@


     printf("PCRE version %s\n", version);
     printf("Compiled with\n");
+    
+#ifdef EBCDIC
+    printf("  EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
+#endif 


 /* At least one of SUPPORT_PCRE8 and SUPPORT_PCRE16 will be set. If both
 are set, either both UTFs are supported or both are not supported. */
@@ -2475,12 +2507,7 @@
     else
       printf("  No just-in-time compiler support\n");
     (void)PCRE_CONFIG(PCRE_CONFIG_NEWLINE, &rc);
-    /* Note that these values are always the ASCII values, even
-    in EBCDIC environments. CR is 13 and NL is 10. */
-    printf("  Newline sequence is %s\n", (rc == 13)? "CR" :
-      (rc == 10)? "LF" : (rc == (13<<8 | 10))? "CRLF" :
-      (rc == -2)? "ANYCRLF" :
-      (rc == -1)? "ANY" : "???");
+    print_newline_config(rc); 
     (void)PCRE_CONFIG(PCRE_CONFIG_BSR, &rc);
     printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
                                      "all Unicode newlines");