Просмотр исходного кода

libdpkg: Fold vercmp module into version module

Guillem Jover лет назад: 14
Родитель
Сommit
6d4c03ebe9
7 измененных файлов с 119 добавлено и 146 удалено
  1. 0 1
      lib/dpkg/Makefile.am
  2. 0 8
      lib/dpkg/dpkg-db.h
  3. 0 135
      lib/dpkg/vercmp.c
  4. 112 0
      lib/dpkg/version.c
  5. 5 0
      lib/dpkg/version.h
  6. 1 1
      po/POTFILES.in
  7. 1 1
      scripts/Dpkg/Version.pm

+ 0 - 1
lib/dpkg/Makefile.am

@@ -74,7 +74,6 @@ libdpkg_a_SOURCES = \
 	trigdeferred.l \
 	utils.c \
 	varbuf.c \
-	vercmp.c \
 	version.c
 
 pkginclude_HEADERS = \

+ 0 - 8
lib/dpkg/dpkg-db.h

@@ -372,14 +372,6 @@ void varbufrecord(struct varbuf *, const struct pkginfo *,
                   const struct pkgbin *);
 void varbufdependency(struct varbuf *vb, struct dependency *dep);
 
-/*** from vercmp.c ***/
-
-bool dpkg_version_relate(const struct dpkg_version *a,
-                         enum dpkg_relation rel,
-                         const struct dpkg_version *b);
-int dpkg_version_compare(const struct dpkg_version *a,
-                         const struct dpkg_version *b);
-
 /*** from depcon.c ***/
 
 bool versionsatisfied(struct pkgbin *it, struct deppossi *against);

+ 0 - 135
lib/dpkg/vercmp.c

@@ -1,135 +0,0 @@
-/*
- * libdpkg - Debian packaging suite library routines
- * vercmp.c - comparison of version numbers
- *
- * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
- *
- * This is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-#include <compat.h>
-
-#include <ctype.h>
-
-#include <dpkg/dpkg.h>
-#include <dpkg/dpkg-db.h>
-
-/**
- * Give a weight to the character to order in the version comparison.
- *
- * @param c An ASCII character.
- */
-static int
-order(int c)
-{
-  if (cisdigit(c))
-    return 0;
-  else if (cisalpha(c))
-    return c;
-  else if (c == '~')
-    return -1;
-  else if (c)
-    return c + 256;
-  else
-    return 0;
-}
-
-static int
-verrevcmp(const char *a, const char *b)
-{
-  if (a == NULL)
-    a = "";
-  if (b == NULL)
-    b = "";
-
-  while (*a || *b) {
-    int first_diff= 0;
-
-    while ((*a && !cisdigit(*a)) || (*b && !cisdigit(*b))) {
-      int ac = order(*a);
-      int bc = order(*b);
-
-      if (ac != bc)
-        return ac - bc;
-
-      a++;
-      b++;
-    }
-    while (*a == '0')
-      a++;
-    while (*b == '0')
-      b++;
-    while (cisdigit(*a) && cisdigit(*b)) {
-      if (!first_diff)
-        first_diff = *a - *b;
-      a++;
-      b++;
-    }
-
-    if (cisdigit(*a))
-      return 1;
-    if (cisdigit(*b))
-      return -1;
-    if (first_diff) return first_diff;
-  }
-  return 0;
-}
-
-int
-dpkg_version_compare(const struct dpkg_version *a,
-                     const struct dpkg_version *b)
-{
-  int r;
-
-  if (a->epoch > b->epoch)
-    return 1;
-  if (a->epoch < b->epoch)
-    return -1;
-
-  r = verrevcmp(a->version, b->version);
-  if (r)
-    return r;
-
-  return verrevcmp(a->revision, b->revision);
-}
-
-bool
-dpkg_version_relate(const struct dpkg_version *a,
-                    enum dpkg_relation rel,
-                    const struct dpkg_version *b)
-{
-  int r;
-
-  if (rel == dpkg_relation_none)
-    return true;
-
-  r = dpkg_version_compare(a, b);
-
-  switch (rel) {
-  case dpkg_relation_eq:
-    return r == 0;
-  case dpkg_relation_lt:
-    return r < 0;
-  case dpkg_relation_le:
-    return r <= 0;
-  case dpkg_relation_gt:
-    return r > 0;
-  case dpkg_relation_ge:
-    return r >= 0;
-  default:
-    internerr("unknown dpkg_relation %d", rel);
-  }
-  return false;
-}

+ 112 - 0
lib/dpkg/version.c

@@ -21,6 +21,8 @@
 #include <config.h>
 #include <compat.h>
 
+#include <dpkg/dpkg.h> /* cis* */
+#include <dpkg/ehandle.h>
 #include <dpkg/version.h>
 
 void
@@ -38,3 +40,113 @@ dpkg_version_is_informative(const struct dpkg_version *version)
 	        (version->version && *version->version) ||
 	        (version->revision && *version->revision));
 }
+
+/**
+ * Give a weight to the character to order in the version comparison.
+ *
+ * @param c An ASCII character.
+ */
+static int
+order(int c)
+{
+	if (cisdigit(c))
+		return 0;
+	else if (cisalpha(c))
+		return c;
+	else if (c == '~')
+		return -1;
+	else if (c)
+		return c + 256;
+	else
+		return 0;
+}
+
+static int
+verrevcmp(const char *a, const char *b)
+{
+	if (a == NULL)
+		a = "";
+	if (b == NULL)
+		b = "";
+
+	while (*a || *b) {
+		int first_diff = 0;
+
+		while ((*a && !cisdigit(*a)) || (*b && !cisdigit(*b))) {
+			int ac = order(*a);
+			int bc = order(*b);
+
+			if (ac != bc)
+				return ac - bc;
+
+			a++;
+			b++;
+		}
+		while (*a == '0')
+			a++;
+		while (*b == '0')
+			b++;
+		while (cisdigit(*a) && cisdigit(*b)) {
+			if (!first_diff)
+				first_diff = *a - *b;
+			a++;
+			b++;
+		}
+
+		if (cisdigit(*a))
+			return 1;
+		if (cisdigit(*b))
+			return -1;
+		if (first_diff)
+			return first_diff;
+	}
+
+	return 0;
+}
+
+int
+dpkg_version_compare(const struct dpkg_version *a,
+                     const struct dpkg_version *b)
+{
+	int r;
+
+	if (a->epoch > b->epoch)
+		return 1;
+	if (a->epoch < b->epoch)
+		return -1;
+
+	r = verrevcmp(a->version, b->version);
+	if (r)
+		return r;
+
+	return verrevcmp(a->revision, b->revision);
+}
+
+bool
+dpkg_version_relate(const struct dpkg_version *a,
+                    enum dpkg_relation rel,
+                    const struct dpkg_version *b)
+{
+	int r;
+
+	if (rel == dpkg_relation_none)
+		return true;
+
+	r = dpkg_version_compare(a, b);
+
+	switch (rel) {
+	case dpkg_relation_eq:
+		return r == 0;
+	case dpkg_relation_lt:
+		return r < 0;
+	case dpkg_relation_le:
+		return r <= 0;
+	case dpkg_relation_gt:
+		return r > 0;
+	case dpkg_relation_ge:
+		return r >= 0;
+	default:
+		internerr("unknown dpkg_relation %d", rel);
+	}
+	return false;
+}

+ 5 - 0
lib/dpkg/version.h

@@ -50,6 +50,11 @@ enum dpkg_relation {
 
 void dpkg_version_blank(struct dpkg_version *version);
 bool dpkg_version_is_informative(const struct dpkg_version *version);
+int dpkg_version_compare(const struct dpkg_version *a,
+                         const struct dpkg_version *b);
+bool dpkg_version_relate(const struct dpkg_version *a,
+                         enum dpkg_relation rel,
+                         const struct dpkg_version *b);
 
 /** @} */
 

+ 1 - 1
po/POTFILES.in

@@ -40,7 +40,7 @@ lib/dpkg/triglib.c
 lib/dpkg/trigname.c
 lib/dpkg/utils.c
 lib/dpkg/varbuf.c
-lib/dpkg/vercmp.c
+lib/dpkg/version.c
 
 src/archives.c
 src/cleanup.c

+ 1 - 1
scripts/Dpkg/Version.pm

@@ -397,7 +397,7 @@ sub version_check($) {
 
 Don Armstrong <don@donarmstrong.com>, Colin Watson
 <cjwatson@debian.org> and Raphaël Hertzog <hertzog@debian.org>, based on
-the implementation in C<dpkg/lib/vercmp.c> by Ian Jackson and others.
+the implementation in C<dpkg/lib/version.c> by Ian Jackson and others.
 
 =cut