Introduce struct xbps_handle and use it for xbps_init().

This structure sets up function callbacks for fetching files and
unpacking binary packages, as well as setting the debug boolean.

This way the affected functions (xbps_fetch_file() and
xbps_unpack_binary_pkg()) do not need to accept the fn cb pointers
and data as arguments.

Bump XBPS_RELVER.
This commit is contained in:
Juan RP
2011-02-21 13:38:44 +01:00
parent 0bd533f8a9
commit 22ae7aa2e8
11 changed files with 212 additions and 204 deletions

View File

@ -149,10 +149,46 @@ cleanup(int signum)
exit(signum);
}
static void
unpack_progress_cb_verbose(void *data)
{
struct xbps_unpack_progress_data *xpd = data;
if (xpd->entry == NULL || xpd->entry_is_metadata)
return;
else if (xpd->entry_size <= 0)
return;
fprintf(stderr, "Extracted %sfile `%s' (%" PRIi64 " bytes)\n",
xpd->entry_is_conf ? "configuration " : "", xpd->entry,
xpd->entry_size);
}
static void
unpack_progress_cb_percentage(void *data)
{
struct xbps_unpack_progress_data *xpd = data;
double percent = 0;
if (xpd->entry_is_metadata)
return;
percent =
(double)((xpd->entry_extract_count * 100.0) / xpd->entry_total_count);
if (percent > 100.0 ||
xpd->entry_extract_count >= xpd->entry_total_count)
percent = 100.0;
printf("\033[s(%3.2f%%)\033[u", percent);
}
int
main(int argc, char **argv)
{
prop_dictionary_t dict;
struct xbps_handle xh;
struct xbps_unpack_progress_data xupd;
struct xbps_fetch_progress_data xfpd;
struct list_pkgver_cb lpc;
struct sigaction sa;
int i , c, flags, rv;
@ -225,7 +261,16 @@ main(int argc, char **argv)
/*
* Initialize stuff for libxbps.
*/
xbps_init(with_debug);
memset(&xh, 0, sizeof(xh));
xh.with_debug = with_debug;
xh.xbps_fetch_cb = fetch_file_progress_cb;
xh.xfpd = &xfpd;
if (flags & XBPS_FLAG_VERBOSE)
xh.xbps_unpack_cb = unpack_progress_cb_verbose;
else
xh.xbps_unpack_cb = unpack_progress_cb_percentage;
xh.xupd = &xupd;
xbps_init(&xh);
if ((dict = xbps_regpkgdb_dictionary_get()) == NULL) {
if (errno && errno != ENOENT) {