[65377] trunk/base/src/cregistry
raimue at macports.org
raimue at macports.org
Thu Mar 25 14:50:25 PDT 2010
Revision: 65377
http://trac.macports.org/changeset/65377
Author: raimue at macports.org
Date: 2010-03-25 14:50:25 -0700 (Thu, 25 Mar 2010)
Log Message:
-----------
cregistry: Move sql_version to it's own file
Modified Paths:
--------------
trunk/base/src/cregistry/Makefile
trunk/base/src/cregistry/sql.c
Added Paths:
-----------
trunk/base/src/cregistry/vercomp.c
trunk/base/src/cregistry/vercomp.h
Modified: trunk/base/src/cregistry/Makefile
===================================================================
--- trunk/base/src/cregistry/Makefile 2010-03-25 21:38:23 UTC (rev 65376)
+++ trunk/base/src/cregistry/Makefile 2010-03-25 21:50:25 UTC (rev 65377)
@@ -1,6 +1,6 @@
# $Id$
-OBJS = registry.o entry.o sql.o
+OBJS = registry.o entry.o sql.o vercomp.o
STLIB_NAME = cregistry.a
RANLIB = ranlib
Modified: trunk/base/src/cregistry/sql.c
===================================================================
--- trunk/base/src/cregistry/sql.c 2010-03-25 21:38:23 UTC (rev 65376)
+++ trunk/base/src/cregistry/sql.c 2010-03-25 21:50:25 UTC (rev 65377)
@@ -32,12 +32,11 @@
#include <tcl.h>
#include <sqlite3.h>
-#include <string.h>
#include <time.h>
-#include <ctype.h>
#include <cregistry/registry.h>
#include <cregistry/sql.h>
+#include <cregistry/vercomp.h>
/*
* TODO: maybe this could be made into something that could be separately loaded
@@ -120,148 +119,6 @@
}
/**
- * RPM version comparison. Shamelessly copied from Pextlib, with some changes to
- * use string lengths instead of strlen by default. That's necessary to make it
- * work with sqlite3 collations. It should be shared with Pextlib, rather than
- * just copied though.
- *
- * @param [in] versionA first version string, i.e. "1.4.1"
- * @param [in] lengthA length of first version string, or -1 to use strlen
- * @param [in] versionB second version string, i.e. "1.4.2"
- * @param [in] lengthA length of second version string, or -1 to use strlen
- * @return -1 if A < B; 0 if A = B; 1 if A > B
- */
-static int rpm_vercomp (const char *versionA, int lengthA, const char *versionB,
- int lengthB) {
- const char *endA, *endB;
- const char *ptrA, *ptrB;
- const char *eptrA, *eptrB;
-
- if (lengthA < 0)
- lengthA = strlen(versionA);
- if (lengthB < 0)
- lengthB = strlen(versionB);
-
- /* if versions equal, return zero */
- if(lengthA == lengthB && !strncmp(versionA, versionB, lengthA))
- return 0;
-
- ptrA = versionA;
- ptrB = versionB;
- endA = versionA + lengthA;
- endB = versionB + lengthB;
- while (ptrA != endA && ptrB != endB) {
- /* skip all non-alphanumeric characters */
- while (ptrA != endB && !isalnum(*ptrA))
- ptrA++;
- while (ptrB != endB && !isalnum(*ptrB))
- ptrB++;
-
- eptrA = ptrA;
- eptrB = ptrB;
-
- /* Somewhat arbitrary rules as per RPM's implementation.
- * This code could be more clever, but we're aiming
- * for clarity instead. */
-
- /* If versionB's segment is not a digit segment, but
- * versionA's segment IS a digit segment, return 1.
- * (Added for redhat compatibility. See redhat bugzilla
- * #50977 for details) */
- if (!isdigit(*ptrB)) {
- if (isdigit(*ptrA))
- return 1;
- }
-
- /* Otherwise, if the segments are of different types,
- * return -1 */
-
- if ((isdigit(*ptrA) && isalpha(*ptrB)) || (isalpha(*ptrA) && isdigit(*ptrB)))
- return -1;
-
- /* Find the first segment composed of entirely alphabetical
- * or numeric members */
- if (isalpha(*ptrA)) {
- while (eptrA != endA && isalpha(*eptrA))
- eptrA++;
-
- while (eptrB != endB && isalpha(*eptrB))
- eptrB++;
- } else {
- int countA = 0, countB = 0;
- while (eptrA != endA && isdigit(*eptrA)) {
- countA++;
- eptrA++;
- }
- while (eptrB != endB && isdigit(*eptrB)) {
- countB++;
- eptrB++;
- }
-
- /* skip leading '0' characters */
- while (ptrA != eptrA && *ptrA == '0') {
- ptrA++;
- countA--;
- }
- while (ptrB != eptrB && *ptrB == '0') {
- ptrB++;
- countB--;
- }
-
- /* If A is longer than B, return 1 */
- if (countA > countB)
- return 1;
-
- /* If B is longer than A, return -1 */
- if (countB > countA)
- return -1;
- }
- /* Compare strings lexicographically */
- while (ptrA != eptrA && ptrB != eptrB && *ptrA == *ptrB) {
- ptrA++;
- ptrB++;
- }
- if (ptrA != eptrA && ptrB != eptrB)
- return *ptrA - *ptrB;
-
- ptrA = eptrA;
- ptrB = eptrB;
- }
-
- /* If both pointers are null, all alphanumeric
- * characters were identical and only seperating
- * characters differed. According to RPM, these
- * version strings are equal */
- if (ptrA == endA && ptrB == endB)
- return 0;
-
- /* If A has unchecked characters, return 1
- * Otherwise, if B has remaining unchecked characters,
- * return -1 */
- if (ptrA != endA)
- return 1;
- else
- return -1;
-}
-
-/**
- * VERSION collation for sqlite3. This function collates text according to
- * pextlib's rpm-vercomp function. This allows direct comparison and sorting of
- * version columns, such as port.version and port.revision.
- *
- * @param [in] userdata unused
- * @param [in] alen length of first string
- * @param [in] a first string
- * @param [in] blen length of second string
- * @param [in] b second string
- * @return -1 if a < b; 0 if a = b; 1 if a > b
- */
-static int sql_version(void* userdata UNUSED, int alen, const void* a, int blen,
- const void* b) {
- return rpm_vercomp((const char*)a, alen, (const char*)b, blen);
-}
-
-/**
* Creates tables in the registry. This function is called upon an uninitialized
* database to create the tables needed to record state between invocations of
* `port`.
Added: trunk/base/src/cregistry/vercomp.c
===================================================================
--- trunk/base/src/cregistry/vercomp.c (rev 0)
+++ trunk/base/src/cregistry/vercomp.c 2010-03-25 21:50:25 UTC (rev 65377)
@@ -0,0 +1,182 @@
+/*
+ * vercomp.c
+ * $Id$
+ *
+ * Copyright (c) 2010 The MacPorts Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright owner nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "vercomp.h"
+
+#include <string.h>
+#include <ctype.h>
+
+/**
+ * RPM version comparison. Shamelessly copied from Pextlib, with some changes to
+ * use string lengths instead of strlen by default. That's necessary to make it
+ * work with sqlite3 collations. It should be shared with Pextlib, rather than
+ * just copied though.
+ *
+ * @param [in] versionA first version string, i.e. "1.4.1"
+ * @param [in] lengthA length of first version string, or -1 to use strlen
+ * @param [in] versionB second version string, i.e. "1.4.2"
+ * @param [in] lengthA length of second version string, or -1 to use strlen
+ * @return -1 if A < B; 0 if A = B; 1 if A > B
+ */
+static int rpm_vercomp (const char *versionA, int lengthA, const char *versionB,
+ int lengthB) {
+ const char *endA, *endB;
+ const char *ptrA, *ptrB;
+ const char *eptrA, *eptrB;
+
+ if (lengthA < 0)
+ lengthA = strlen(versionA);
+ if (lengthB < 0)
+ lengthB = strlen(versionB);
+
+ /* if versions equal, return zero */
+ if(lengthA == lengthB && !strncmp(versionA, versionB, lengthA))
+ return 0;
+
+ ptrA = versionA;
+ ptrB = versionB;
+ endA = versionA + lengthA;
+ endB = versionB + lengthB;
+ while (ptrA != endA && ptrB != endB) {
+ /* skip all non-alphanumeric characters */
+ while (ptrA != endB && !isalnum(*ptrA))
+ ptrA++;
+ while (ptrB != endB && !isalnum(*ptrB))
+ ptrB++;
+
+ eptrA = ptrA;
+ eptrB = ptrB;
+
+ /* Somewhat arbitrary rules as per RPM's implementation.
+ * This code could be more clever, but we're aiming
+ * for clarity instead. */
+
+ /* If versionB's segment is not a digit segment, but
+ * versionA's segment IS a digit segment, return 1.
+ * (Added for redhat compatibility. See redhat bugzilla
+ * #50977 for details) */
+ if (!isdigit(*ptrB)) {
+ if (isdigit(*ptrA))
+ return 1;
+ }
+
+ /* Otherwise, if the segments are of different types,
+ * return -1 */
+
+ if ((isdigit(*ptrA) && isalpha(*ptrB)) || (isalpha(*ptrA) && isdigit(*ptrB)))
+ return -1;
+
+ /* Find the first segment composed of entirely alphabetical
+ * or numeric members */
+ if (isalpha(*ptrA)) {
+ while (eptrA != endA && isalpha(*eptrA))
+ eptrA++;
+
+ while (eptrB != endB && isalpha(*eptrB))
+ eptrB++;
+ } else {
+ int countA = 0, countB = 0;
+ while (eptrA != endA && isdigit(*eptrA)) {
+ countA++;
+ eptrA++;
+ }
+ while (eptrB != endB && isdigit(*eptrB)) {
+ countB++;
+ eptrB++;
+ }
+
+ /* skip leading '0' characters */
+ while (ptrA != eptrA && *ptrA == '0') {
+ ptrA++;
+ countA--;
+ }
+ while (ptrB != eptrB && *ptrB == '0') {
+ ptrB++;
+ countB--;
+ }
+
+ /* If A is longer than B, return 1 */
+ if (countA > countB)
+ return 1;
+
+ /* If B is longer than A, return -1 */
+ if (countB > countA)
+ return -1;
+ }
+ /* Compare strings lexicographically */
+ while (ptrA != eptrA && ptrB != eptrB && *ptrA == *ptrB) {
+ ptrA++;
+ ptrB++;
+ }
+ if (ptrA != eptrA && ptrB != eptrB)
+ return *ptrA - *ptrB;
+
+ ptrA = eptrA;
+ ptrB = eptrB;
+ }
+
+ /* If both pointers are null, all alphanumeric
+ * characters were identical and only seperating
+ * characters differed. According to RPM, these
+ * version strings are equal */
+ if (ptrA == endA && ptrB == endB)
+ return 0;
+
+ /* If A has unchecked characters, return 1
+ * Otherwise, if B has remaining unchecked characters,
+ * return -1 */
+ if (ptrA != endA)
+ return 1;
+ else
+ return -1;
+}
+
+/**
+ * VERSION collation for sqlite3. This function collates text according to
+ * pextlib's rpm-vercomp function. This allows direct comparison and sorting of
+ * version columns, such as port.version and port.revision.
+ *
+ * @param [in] userdata unused
+ * @param [in] alen length of first string
+ * @param [in] a first string
+ * @param [in] blen length of second string
+ * @param [in] b second string
+ * @return -1 if a < b; 0 if a = b; 1 if a > b
+ */
+int sql_version(void* userdata UNUSED, int alen, const void* a, int blen,
+ const void* b) {
+ return rpm_vercomp((const char*)a, alen, (const char*)b, blen);
+}
Property changes on: trunk/base/src/cregistry/vercomp.c
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/base/src/cregistry/vercomp.h
===================================================================
--- trunk/base/src/cregistry/vercomp.h (rev 0)
+++ trunk/base/src/cregistry/vercomp.h 2010-03-25 21:50:25 UTC (rev 65377)
@@ -0,0 +1,38 @@
+/*
+ * vercomp.h
+ * $Id$
+ *
+ * Copyright (c) 2010 The MacPorts Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright owner nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _VERCOMP_H
+#define _VERCOMP_H
+
+int sql_version(void* userdata UNUSED, int alen, const void* a, int blen,
+ const void* b);
+
+#endif /* _VERCOMP_H */
Property changes on: trunk/base/src/cregistry/vercomp.h
___________________________________________________________________
Added: svn:eol-style
+ native
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100325/d065cda0/attachment.html>
More information about the macports-changes
mailing list