The following commit has been merged in the master branch:
commit a44743e16e53c3ec812d48e0579344f447cf72dd
Author: Guillem Jover <guil...@debian.org>
Date:   Mon Mar 26 05:10:57 2012 +0200

    libdpkg: New deb format version module

diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index f2bccb0..a9182a9 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -33,6 +33,7 @@ libdpkg_a_SOURCES = \
        compress.c \
        dbdir.c \
        dbmodify.c \
+       deb-version.c \
        debug.c \
        depcon.c \
        dir.c \
@@ -83,6 +84,7 @@ pkginclude_HEADERS = \
        buffer.h \
        command.h \
        compress.h \
+       deb-version.h \
        debug.h \
        dir.h \
        dpkg.h \
diff --git a/lib/dpkg/deb-version.c b/lib/dpkg/deb-version.c
new file mode 100644
index 0000000..a5ef415
--- /dev/null
+++ b/lib/dpkg/deb-version.c
@@ -0,0 +1,58 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * deb-version.c - deb format version handling routines
+ *
+ * Copyright © 2012 Guillem Jover <guil...@debian.org>
+ *
+ * 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 <string.h>
+#include <stdlib.h>
+
+#include <dpkg/i18n.h>
+#include <dpkg/dpkg.h>
+#include <dpkg/deb-version.h>
+
+const char *
+deb_version_parse(struct deb_version *version, const char *str)
+{
+       const char *str_minor, *end;
+       int major = 0;
+       int minor = 0;
+
+       for (end = str; *end && cisdigit(*end); end++)
+               major = major * 10  + *end - '0';
+
+       if (end == str)
+               return _("format version with empty major component");
+       if (*end != '.')
+               return _("format version has no dot");
+
+       for (end = str_minor = end + 1; *end && cisdigit(*end); end++)
+               minor = minor * 10 + *end - '0';
+
+       if (end == str_minor)
+               return _("format version with empty minor component");
+       if (*end != '\n' && *end != '\0')
+               return _("format version followed by junk");
+
+       version->major = major;
+       version->minor = minor;
+
+       return NULL;
+}
diff --git a/lib/dpkg/progname.h b/lib/dpkg/deb-version.h
similarity index 69%
copy from lib/dpkg/progname.h
copy to lib/dpkg/deb-version.h
index 52ed3da..b791c06 100644
--- a/lib/dpkg/progname.h
+++ b/lib/dpkg/deb-version.h
@@ -1,8 +1,8 @@
 /*
  * libdpkg - Debian packaging suite library routines
- * progname.h - program name handling functions
+ * deb-version.h - deb format version handling routines
  *
- * Copyright © 2011 Guillem Jover <guil...@debian.org>
+ * Copyright © 2012 Guillem Jover <guil...@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -18,24 +18,20 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef LIBDPKG_PROGNAME_H
-#define LIBDPKG_PROGNAME_H
+#ifndef LIBDPKG_DEB_VERSION_H
+#define LIBDPKG_DEB_VERSION_H
 
 #include <dpkg/macros.h>
 
 DPKG_BEGIN_DECLS
 
-/**
- * @defgroup progname Program name handling
- * @ingroup dpkg-public
- * @{
- */
-
-void dpkg_set_progname(const char *name);
-const char *dpkg_get_progname(void);
+struct deb_version {
+       int major;
+       int minor;
+};
 
-/** @} */
+const char *deb_version_parse(struct deb_version *version, const char *str);
 
 DPKG_END_DECLS
 
-#endif
+#endif /* LIBDPKG_DEB_VERSION_H */
diff --git a/lib/dpkg/test/.gitignore b/lib/dpkg/test/.gitignore
index 8f56d8c..7e78979 100644
--- a/lib/dpkg/test/.gitignore
+++ b/lib/dpkg/test/.gitignore
@@ -2,6 +2,7 @@ t-ar
 t-arch
 t-buffer
 t-command
+t-deb-version
 t-macros
 t-mod-db
 t-path
diff --git a/lib/dpkg/test/Makefile.am b/lib/dpkg/test/Makefile.am
index dea5bcc..54fbd15 100644
--- a/lib/dpkg/test/Makefile.am
+++ b/lib/dpkg/test/Makefile.am
@@ -23,6 +23,7 @@ check_PROGRAMS = \
        t-command \
        t-varbuf \
        t-ar \
+       t-deb-version \
        t-arch \
        t-version \
        t-pkginfo \
diff --git a/lib/dpkg/test/t-deb-version.c b/lib/dpkg/test/t-deb-version.c
new file mode 100644
index 0000000..ea42db8
--- /dev/null
+++ b/lib/dpkg/test/t-deb-version.c
@@ -0,0 +1,69 @@
+/*
+ * libdpkg - Debian packaging suite library routines
+ * t-deb-version.c - test deb version handling
+ *
+ * Copyright © 2012 Guillem Jover <guil...@debian.org>
+ *
+ * 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 <dpkg/test.h>
+#include <dpkg/deb-version.h>
+
+static void
+test_deb_version_parse(void)
+{
+       struct deb_version v;
+
+       /* Test valid versions. */
+       test_pass(deb_version_parse(&v, "0.0") == NULL);
+       test_pass(v.major == 0 && v.minor == 0);
+
+       test_pass(deb_version_parse(&v, "1.1") == NULL);
+       test_pass(v.major == 1 && v.minor == 1);
+
+       test_pass(deb_version_parse(&v, "1.001") == NULL);
+       test_pass(v.major == 1 && v.minor == 1);
+
+       test_pass(deb_version_parse(&v, "1.0010") == NULL);
+       test_pass(v.major == 1 && v.minor == 10);
+
+       test_pass(deb_version_parse(&v, "0.939000") == NULL);
+       test_pass(v.major == 0 && v.minor == 939000);
+
+       test_pass(deb_version_parse(&v, "1.1\n") == NULL);
+       test_pass(v.major == 1 && v.minor == 1);
+
+       /* Test invalid versions. */
+       test_fail(deb_version_parse(&v, "0") == NULL);
+       test_fail(deb_version_parse(&v, "a") == NULL);
+       test_fail(deb_version_parse(&v, "a.b") == NULL);
+       test_fail(deb_version_parse(&v, "a~b") == NULL);
+       test_fail(deb_version_parse(&v, " 1.1") == NULL);
+       test_fail(deb_version_parse(&v, "2 .2") == NULL);
+       test_fail(deb_version_parse(&v, "3. 3") == NULL);
+       test_fail(deb_version_parse(&v, "4.4 ") == NULL);
+       test_fail(deb_version_parse(&v, " 5.5 ") == NULL);
+
+       /* FIXME: Complete. */
+}
+
+static void
+test(void)
+{
+       test_deb_version_parse();
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 689851d..dc0235b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,6 +8,7 @@ lib/dpkg/cleanup.c
 lib/dpkg/command.c
 lib/dpkg/compress.c
 lib/dpkg/dbmodify.c
+lib/dpkg/deb-version.c
 lib/dpkg/dir.c
 lib/dpkg/dump.c
 lib/dpkg/ehandle.c

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to