You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/09/08 09:24:30 UTC

svn commit: r812356 - in /commons/sandbox/runtime/trunk/src/main/native: ./ include/ include/arch/darwin/ include/arch/hpux/ include/arch/linux/ include/arch/solaris/ include/arch/windows/ os/win32/ test/

Author: mturk
Date: Tue Sep  8 07:24:29 2009
New Revision: 812356

URL: http://svn.apache.org/viewvc?rev=812356&view=rev
Log:
Add crc32 and pmatch API

Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
    commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Tue Sep  8 07:24:29 2009
@@ -83,6 +83,7 @@
 	$(SRCDIR)/shared/bzip2.$(OBJ) \
 	$(SRCDIR)/shared/clazz.$(OBJ) \
 	$(SRCDIR)/shared/constp.$(OBJ) \
+	$(SRCDIR)/shared/crc32.$(OBJ) \
 	$(SRCDIR)/shared/descriptor.$(OBJ) \
 	$(SRCDIR)/shared/db.$(OBJ) \
 	$(SRCDIR)/shared/error.$(OBJ) \
@@ -211,6 +212,7 @@
 PPORT_OBJS=\
 	$(SRCDIR)/port/fnmatch.$(OBJ) \
 	$(SRCDIR)/port/rijndael.$(OBJ) \
+	$(SRCDIR)/port/pmatch.$(OBJ) \
 	$(SRCDIR)/port/strlcat.$(OBJ) \
 	$(SRCDIR)/port/strlcpy.$(OBJ) \
 	$(SRCDIR)/port/wcslcat.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Tue Sep  8 07:24:29 2009
@@ -72,6 +72,7 @@
 	$(SRCDIR)/shared/bzip2.$(OBJ) \
 	$(SRCDIR)/shared/clazz.$(OBJ) \
 	$(SRCDIR)/shared/constp.$(OBJ) \
+	$(SRCDIR)/shared/crc32.$(OBJ) \
 	$(SRCDIR)/shared/descriptor.$(OBJ) \
 	$(SRCDIR)/shared/db.$(OBJ) \
 	$(SRCDIR)/shared/error.$(OBJ) \
@@ -129,6 +130,7 @@
 PPORT_OBJS=\
 	$(SRCDIR)/port/fnmatch.$(OBJ) \
 	$(SRCDIR)/port/rijndael.$(OBJ) \
+	$(SRCDIR)/port/pmatch.$(OBJ) \
 	$(SRCDIR)/port/strlcat.$(OBJ) \
 	$(SRCDIR)/port/strlcpy.$(OBJ) \
 	$(SRCDIR)/port/wcslcat.$(OBJ) \

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_crypto.h Tue Sep  8 07:24:29 2009
@@ -75,6 +75,14 @@
     acr_byte_t     buffer[ACR_SHA512_BLOCK_LENGTH];
 };
 
+/**
+ * Calculate CRC32 value for the given buffer.
+ * @param crc Initial crc seed.
+ * @param buf Input buffer to use.
+ * @param len Input buffer length.
+ */
+ACR_DECLARE(acr_uint32_t) ACR_CRC32(acr_uint32_t crc, const acr_byte_t *buf,
+                                    size_t len);
 
 /**
  * Size of the SHA1 DIGEST

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h Tue Sep  8 07:24:29 2009
@@ -59,6 +59,26 @@
 size_t wcslcpy(wchar_t *, const wchar_t *, size_t);
 #endif
 
+/**
+ * pmatch():
+ *  Return 2 on exact match.
+ *  Return 1 on substring match.
+ *  Return 0 on no match.
+ *  Return -1 on error.
+ * *estr will point to the end of the longest exact or substring match.
+ */
+#define ACR_PMATCH_NONE     0
+#define ACR_PMATCH_SUBSTR   1
+#define ACR_PMATCH_EXACT    2
+#define ACR_PMATCH_ERROR   -1
+
+#if defined(ACR_WANT_PMATCH)
+int pmatch(const char*, const char*, const char**);
+#endif
+int wmatch(const wchar_t *, const wchar_t *, const wchar_t **);
+int pimatch(const char*, const char*, const char**);
+int wimatch(const wchar_t *, const wchar_t *, const wchar_t **);
+
 #if defined(ACR_WANT_ISBLANK)
 static ACR_INLINE int isblank(int c)
 {

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/darwin/acr_arch_private.h Tue Sep  8 07:24:29 2009
@@ -45,6 +45,11 @@
 #define NOTREACHED(X)    return (X)
 
 /**
+ * Include needed functions from portable layer
+ */
+#define ACR_WANT_PMATCH                     1
+
+/**
  * Temporary APR flags
  */
 #define APR_USE_SHMEM_SHMGET                1

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/hpux/acr_arch_private.h Tue Sep  8 07:24:29 2009
@@ -43,6 +43,7 @@
 /**
  * Include needed functions from portable layer
  */
+#define ACR_WANT_PMATCH                     1
 #define ACR_WANT_STRSIGNAL                  1
 #define ACR_WANT_STRLCAT                    1
 #define ACR_WANT_STRLCPY                    1

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/linux/acr_arch_private.h Tue Sep  8 07:24:29 2009
@@ -43,6 +43,7 @@
 /**
  * Include needed functions from portable layer
  */
+#define ACR_WANT_PMATCH                     1
 #define ACR_WANT_STRLCAT                    1
 #define ACR_WANT_STRLCPY                    1
 #define ACR_WANT_WCSLCAT                    1

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/solaris/acr_arch_private.h Tue Sep  8 07:24:29 2009
@@ -42,6 +42,7 @@
 /**
  * Include needed functions from portable layer
  */
+#define ACR_WANT_PMATCH                     1
 #define ACR_WANT_STRLCAT                    1
 #define ACR_WANT_STRLCPY                    1
 #define ACR_WANT_WCSLCAT                    1

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h Tue Sep  8 07:24:29 2009
@@ -101,6 +101,7 @@
 /**
  * Include needed functions from portable layer
  */
+#define ACR_WANT_PMATCH                     1
 #define ACR_WANT_STRSIGNAL                  1
 #define ACR_WANT_STRLCAT                    1
 #define ACR_WANT_STRLCPY                    1

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Tue Sep  8 07:24:29 2009
@@ -18,6 +18,7 @@
 #include "acr_private.h"
 #include "acr_error.h"
 #include "acr_memory.h"
+#include "acr_port.h"
 #include "acr_string.h"
 #include "acr_descriptor.h"
 #include "acr_file.h"
@@ -82,7 +83,7 @@
              */
             wchar_t  tmpname[ACR_HBUFF_SIZ];
             wchar_t *tmpoff = NULL;
-            if (!ACR_StrMatchW(fname, L"\\\\.\\PIPE\\*", NULL, 1))
+            if (wimatch(fname, L"\\\\.\\PIPE\\*", NULL) == ACR_PMATCH_EXACT)
                 type = ACR_FT_PIPE;
             else if (GetFullPathNameW(fname, ACR_HBUFF_LEN,
                                       tmpname, &tmpoff)) {
@@ -369,7 +370,7 @@
                         nlen = repb->SymbolicLinkReparseBuffer.PrintNameLength / sizeof(WCHAR);
                         noff = repb->SymbolicLinkReparseBuffer.PrintNameOffset;
                         wb   = (wchar_t *)(pb + noff);
-                        if (!ACR_StrMatchW(wb, L"\\\\.\\PIPE\\*", NULL, 1)) {
+                        if (wimatch(wb, L"\\\\.\\PIPE\\*", NULL) == ACR_PMATCH_EXACT) {
                             rv = (*_E)->NewString(_E, (const jchar *)wb, (jsize)nlen);
                         }
                         else {

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c?rev=812356&r1=812355&r2=812356&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testsuite.c Tue Sep  8 07:24:29 2009
@@ -25,6 +25,7 @@
 #include "acr_tables.h"
 #include "acr_vm.h"
 #include "acr_clazz.h"
+#include "acr_port.h"
 #include "acr_pointer.h"
 #include "acr_descriptor.h"
 #include "acr_file.h"
@@ -404,6 +405,26 @@
     return 0;
 }
 
+static int test_pmatch(int argc, const char *const argv[])
+{
+    int i;
+    size_t mp = 0;
+    const char *end = NULL;
+
+    if (argc < 2) {
+
+        return -1;
+    }
+    i = pimatch(argv[0], argv[1], &end);
+    printf("pmatch returned  %d\n", i);
+    printf("pmatch ended on '%s'\n", end);
+    i = ACR_StrMatchA(argv[0], argv[1], &mp, 0);
+    printf("smatch returned  %d\n", i);
+    printf("smatch ended on '%s'\n", argv[0] + mp);
+
+    return 0;
+}
+
 /* The time value is used throughout the tests, so just make this a global.
  * Also, we need a single value that we can test for the positive tests, so
  * I chose the number below, it corresponds to:
@@ -544,6 +565,9 @@
         else if (!strcasecmp(run_test, "times")) {
             rv = test_times(argc, argv);
         }
+        else if (!strcasecmp(run_test, "pmatch")) {
+            rv = test_pmatch(argc, argv);
+        }
     }
 
 cleanup: