Procházet zdrojové kódy

libdpkg: Move pkg_sorter code to a new pkg module

Guillem Jover před 17 roky
rodič
revize
30a6d6d131
7 změnil soubory, kde provedl 77 přidání a 16 odebrání
  1. 1 0
      lib/dpkg/Makefile.am
  2. 0 9
      lib/dpkg/pkg-array.c
  3. 1 2
      lib/dpkg/pkg-array.h
  4. 39 0
      lib/dpkg/pkg.c
  5. 35 0
      lib/dpkg/pkg.h
  6. 1 0
      po/POTFILES.in
  7. 0 5
      src/main.h

+ 1 - 0
lib/dpkg/Makefile.am

@@ -40,6 +40,7 @@ libdpkg_a_SOURCES = \
 	parsehelp.c \
 	parsedump.h \
 	path.c path.h \
+	pkg.c pkg.h \
 	pkg-array.c pkg-array.h \
 	pkg-list.c pkg-list.h \
 	progress.c progress.h \

+ 0 - 9
lib/dpkg/pkg-array.c

@@ -31,15 +31,6 @@
 #include <dpkg/dpkg-db.h>
 #include <dpkg/pkg-array.h>
 
-int
-pkg_sorter_by_name(const void *a, const void *b)
-{
-	const struct pkginfo *pa = *(const struct pkginfo **)a;
-	const struct pkginfo *pb = *(const struct pkginfo **)b;
-
-	return strcmp(pa->name, pb->name);
-}
-
 void
 pkg_array_init_from_db(struct pkg_array *a)
 {

+ 1 - 2
lib/dpkg/pkg-array.h

@@ -26,11 +26,10 @@
 #include <compat.h>
 
 #include <dpkg/dpkg-db.h>
+#include <dpkg/pkg.h>
 
 DPKG_BEGIN_DECLS
 
-typedef int pkg_sorter_func(const void *a, const void *b);
-
 struct pkg_array {
 	int n_pkgs;
 	struct pkginfo **pkgs;

+ 39 - 0
lib/dpkg/pkg.c

@@ -0,0 +1,39 @@
+/*
+ * dpkg - main program for package management
+ * pkg-array.c - primitives for pkg handling
+ *
+ * Copyright © 1995, 1996 Ian Jackson <ian@chiark.greenend.org.uk>
+ * Copyright © 2009 Guillem Jover <guillem@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,
+ * 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 dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+#include <compat.h>
+
+#include <string.h>
+
+#include <dpkg/dpkg-db.h>
+#include <dpkg/pkg.h>
+
+int
+pkg_sorter_by_name(const void *a, const void *b)
+{
+	const struct pkginfo *pa = *(const struct pkginfo **)a;
+	const struct pkginfo *pb = *(const struct pkginfo **)b;
+
+	return strcmp(pa->name, pb->name);
+}
+

+ 35 - 0
lib/dpkg/pkg.h

@@ -0,0 +1,35 @@
+/*
+ * dpkg - main program for package management
+ * pkg.h - primitives for pkg handling
+ *
+ * Copyright © 2009 Guillem Jover <guillem@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,
+ * 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 dpkg; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef DPKG_PKG_H
+#define DPKG_PKG_H
+
+#include <dpkg/macros.h>
+
+DPKG_BEGIN_DECLS
+
+typedef int pkg_sorter_func(const void *a, const void *b);
+
+int pkg_sorter_by_name(const void *a, const void *b);
+
+DPKG_END_DECLS
+
+#endif /* DPKG_PKG_H */

+ 1 - 0
po/POTFILES.in

@@ -18,6 +18,7 @@ lib/dpkg/nfmalloc.c
 lib/dpkg/parse.c
 lib/dpkg/parsehelp.c
 lib/dpkg/path.c
+lib/dpkg/pkg.c
 lib/dpkg/pkg-array.c
 lib/dpkg/pkg-list.c
 lib/dpkg/progress.c

+ 0 - 5
src/main.h

@@ -165,11 +165,6 @@ void printarch(const char *const *argv);
 void printinstarch(const char *const *argv);
 void cmpversions(const char *const *argv) DPKG_ATTR_NORET;
 
-/* Intended for use as a comparison function for qsort when
- * sorting an array of pointers to struct pkginfo:
- */
-int pkg_sorter_by_name(const void *a, const void *b);
-
 void limiteddescription(struct pkginfo *pkg,
                         int maxl, const char **pdesc_r, int *l_r);