Date: Wed, 26 Jun 2013 23:28:59 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253567 - in soc2013/mattbw/backend: . actions Message-ID: <201306262328.r5QNSxi9074024@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Wed Jun 26 23:28:59 2013 New Revision: 253567 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253567 Log: cleanup and formatting Modified: soc2013/mattbw/backend/Makefile soc2013/mattbw/backend/actions/get-details.c soc2013/mattbw/backend/actions/get-files.c soc2013/mattbw/backend/actions/get-repo-list.c soc2013/mattbw/backend/iterate.h Modified: soc2013/mattbw/backend/Makefile ============================================================================== --- soc2013/mattbw/backend/Makefile Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/Makefile Wed Jun 26 23:28:59 2013 (r253567) @@ -22,5 +22,6 @@ CFLAGS+= `pkg-config --cflags ${PKGS}` CFLAGS+= -DPK_COMPILATION LDFLAGS+= `pkg-config --libs ${PKGS}` +CSTD?= c99 .include <bsd.lib.mk> Modified: soc2013/mattbw/backend/actions/get-details.c ============================================================================== --- soc2013/mattbw/backend/actions/get-details.c Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/actions/get-details.c Wed Jun 26 23:28:59 2013 (r253567) @@ -30,11 +30,9 @@ #include "get-details.h" /* get_details_thread prototype */ static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_LICENSES; -static void get_details_emit(struct pkg *pkg, const gchar *id, PkBackend *backend); -static gboolean -get_details_for(gchar *package_id, - PkBackend *backend, - struct pkgdb *db); + +static void emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend); +static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db); /* * The thread that performs a GetDetails operation. Should be invoked by the @@ -43,14 +41,24 @@ gboolean get_details_thread(PkBackend *backend) { - return iterate_ids(backend, get_details_for); + return iterate_ids(backend, get_for); +} + +/* + * Look up and emit package details for the given PackageID, if it can be + * found. + */ +static gboolean +get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) +{ + return db_query_with_id(id, backend, db, LOAD_FLAGS, emit_pkg); } /* * Emits the given package's details. To be used as an iterating function. */ static void -get_details_emit(struct pkg *pkg, const gchar *id, PkBackend *backend) +emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend) { const char *description; const char *origin; @@ -72,13 +80,3 @@ www, flatsize); } - -/* - * Look up and emit package details for the given PackageID, if it can be - * found. - */ -gboolean -get_details_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) -{ - return db_query_with_id(package_id, backend, db, LOAD_FLAGS, get_details_emit); -} Modified: soc2013/mattbw/backend/actions/get-files.c ============================================================================== --- soc2013/mattbw/backend/actions/get-files.c Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/actions/get-files.c Wed Jun 26 23:28:59 2013 (r253567) @@ -24,19 +24,17 @@ #include "../db.h" /* db_query_from_id */ #include "../groups.h" /* group_from_origin */ +#include "../hash_traverse.h" /* HASH_FOR */ #include "../iterate.h" /* Package iteration */ #include "../licenses.h" /* license_from_pkg */ -#include "get-files.h" /* get_files_thread prototype */ +#include "get-files.h" /* get_files_thread prototype */ static const int FILE_NAME_STEP = 10; static const int LOAD_FLAGS = PKG_LOAD_BASIC | PKG_LOAD_FILES; -static void get_files_emit(struct pkg *pkg, const gchar *id, PkBackend *backend); -static gboolean -get_files_for(gchar *package_id, - PkBackend *backend, - struct pkgdb *db); +static void emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend); +static gboolean get_for(const gchar *id, PkBackend *backend, struct pkgdb *db); /* * The thread that performs a GetDetails operation. Should be invoked by the @@ -45,43 +43,40 @@ gboolean get_files_thread(PkBackend *backend) { - return iterate_ids(backend, get_files_for); + return iterate_ids(backend, get_for); } /* * Emits the given package's files. To be used as an iterating function. */ static void -get_files_emit(struct pkg *pkg, const gchar *id, PkBackend *backend) +emit_pkg(struct pkg *pkg, const gchar *id, PkBackend *backend) { struct pkg_file *file; - int err; + int err; - gchar **filenames; - gchar *joined_filenames; - gint capacity; - gint i; - - i = 0; - file = NULL; - /* Start off with a small array to hold the file names, - * and expand it if needs be. + gchar **filenames; + gchar *joined_filenames; + gint capacity; + gint i; + + /* + * Start off with a small array to hold the file names, and expand it + * if needs be. */ capacity = FILE_NAME_STEP; - filenames = g_new(gchar *, capacity); - do { - err = pkg_files(pkg, &file); - if (err == EPKG_OK) { - /* Out of capacity (leaving a NULL)? Expand the array. */ - if (i >= (capacity - 1)) { - capacity += FILE_NAME_STEP; - filenames = g_renew(gchar *, filenames, capacity); - } - - filenames[i] = g_strdup(pkg_file_path(file)); - i++; + i = 0; + file = NULL; + filenames = g_new(gchar *, capacity); + for (HASH_FOR(err, pkg_files, pkg, &file)) { + /* Out of capacity (leaving a NULL)? Expand the array. */ + if (i >= (capacity - 1)) { + capacity += FILE_NAME_STEP; + filenames = g_renew(gchar *, filenames, capacity); } - } while (err == EPKG_OK); + filenames[i] = g_strdup(pkg_file_path(file)); + i++; + } filenames[i] = NULL; joined_filenames = g_strjoinv(";", filenames); @@ -96,7 +91,7 @@ * found. */ gboolean -get_files_for(gchar *package_id, PkBackend *backend, struct pkgdb *db) +get_for(const gchar *id, PkBackend *backend, struct pkgdb *db) { - return db_query_with_id(package_id, backend, db, LOAD_FLAGS, get_files_emit); + return db_query_with_id(id, backend, db, LOAD_FLAGS, emit_pkg); } Modified: soc2013/mattbw/backend/actions/get-repo-list.c ============================================================================== --- soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/actions/get-repo-list.c Wed Jun 26 23:28:59 2013 (r253567) @@ -23,6 +23,7 @@ #include "pkg.h" #include "../hash_traverse.h" /* HASH_FOR */ +#include "get-repo-list.h" /* Prototypes */ /* * The thread that performs a GetRepoList operation. Should be invoked by the Modified: soc2013/mattbw/backend/iterate.h ============================================================================== --- soc2013/mattbw/backend/iterate.h Wed Jun 26 22:58:59 2013 (r253566) +++ soc2013/mattbw/backend/iterate.h Wed Jun 26 23:28:59 2013 (r253567) @@ -26,9 +26,9 @@ #include "pkg.h" typedef void (*pkg_func_ptr) (struct pkg *pkg, - const char *id, - PkBackend *backend); -typedef gboolean (*ids_func_ptr) (gchar *id, PkBackend *backend, struct pkgdb *db); + const gchar *id, + PkBackend *backend); +typedef gboolean (*ids_func_ptr) (const gchar *id, PkBackend *backend, struct pkgdb *db); gboolean iterate_id_matches(struct pkgdb_it *iterator, @@ -39,6 +39,6 @@ const gchar *data, int fetch_flags, pkg_func_ptr iterate_f); -gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f); +gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f); #endif /* !_PKGNG_BACKEND_ITERATE_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306262328.r5QNSxi9074024>