Make xbps_fetch_file accept a callback to update its progress.

This also makes xbps_unpack_binary_pkg follow this convention by avoiding
static variables.

--HG--
branch : progress_callback
rename : bin/xbps-repo/util.c => bin/xbps-bin/util.c
This commit is contained in:
Juan RP
2011-01-22 12:40:19 +01:00
parent 8c2ccea435
commit 984eae1578
22 changed files with 354 additions and 365 deletions

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2010 Juan Romero Pardines.
* Copyright (c) 2011 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -50,18 +50,13 @@ xbps_end(void)
xbps_fetch_unset_cache_connection();
}
void
xbps_dbg_printf(const char *fmt, ...)
static void
common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
{
va_list ap;
if (msg != NULL)
fprintf(f, "%s", msg);
if (!with_debug)
return;
va_start(ap, fmt);
fprintf(stderr, "[DEBUG] ");
vfprintf(stderr, fmt, ap);
va_end(ap);
vfprintf(f, fmt, ap);
}
void
@ -73,7 +68,20 @@ xbps_dbg_printf_append(const char *fmt, ...)
return;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
common_printf(stderr, NULL, fmt, ap);
va_end(ap);
}
void
xbps_dbg_printf(const char *fmt, ...)
{
va_list ap;
if (!with_debug)
return;
va_start(ap, fmt);
common_printf(stderr, "[DEBUG] ", fmt, ap);
va_end(ap);
}
@ -83,7 +91,30 @@ xbps_error_printf(const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "ERROR: ");
vfprintf(stderr, fmt, ap);
common_printf(stderr, "ERROR: ", fmt, ap);
va_end(ap);
}
void
xbps_warn_printf(const char *fmt, ...)
{
int flags = xbps_get_flags();
va_list ap;
if ((flags & XBPS_FLAG_VERBOSE) == 0)
return;
va_start(ap, fmt);
common_printf(stderr, "WARNING: ", fmt, ap);
va_end(ap);
}
void
xbps_printf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
common_printf(stdout, NULL, fmt, ap);
va_end(ap);
}