This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=23cfdbf1054a3c9fdef741cdc5f6769b3fd57413 commit 23cfdbf1054a3c9fdef741cdc5f6769b3fd57413 Author: Guillem Jover <[email protected]> AuthorDate: Sat Nov 17 05:27:49 2018 +0100 libdpkg: Add new warning printer setter function This will make it possible for library users to specify alternative warning printers. Prompted-by: Julian Andres Klode <[email protected]> --- debian/changelog | 2 ++ lib/dpkg/libdpkg.map | 2 ++ lib/dpkg/report.c | 22 +++++++++++++++++++--- lib/dpkg/report.h | 5 +++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 04d98a183..e4c4d2cbe 100644 --- a/debian/changelog +++ b/debian/changelog @@ -115,6 +115,8 @@ dpkg (1.19.3) UNRELEASED; urgency=medium - libdpkg: Rename ret variable to next. - libdpkg: Cleanup fsys module symbol names. - libdpkg: Rename pkg_db symbols to pkg_hash. + - libdpkg: Add new warning printer setter function. + Prompted by Julian Andres Klode <[email protected]>. * Build system: - get-version: Use a format string with printf. - run-script: Use $() instead of deprecated ``. diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index fe4e299ee..359418992 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -55,6 +55,8 @@ LIBDPKG_PRIVATE { do_internerr; dpkg_set_report_piped_mode; dpkg_set_report_buffer; + dpkg_warning_printer; + dpkg_set_warning_printer; warning_get_count; warningv; warning; diff --git a/lib/dpkg/report.c b/lib/dpkg/report.c index 58df60006..f7763b362 100644 --- a/lib/dpkg/report.c +++ b/lib/dpkg/report.c @@ -51,6 +51,24 @@ dpkg_set_report_buffer(FILE *fp) setvbuf(fp, NULL, piped_mode, 0); } +void +dpkg_warning_printer(const char *msg, void *data) +{ + fprintf(stderr, "%s%s:%s %s%s:%s %s\n", + color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), + color_get(COLOR_WARN), _("warning"), color_reset(), msg); +} + +static dpkg_warning_printer_func *warning_printer_func = dpkg_warning_printer; +static void *warning_printer_data; + +void +dpkg_set_warning_printer(dpkg_warning_printer_func *printer, void *data) +{ + warning_printer_func = printer; + warning_printer_data = data; +} + static int warn_count = 0; int @@ -67,9 +85,7 @@ warningv(const char *fmt, va_list args) warn_count++; m_vasprintf(&buf, fmt, args); - fprintf(stderr, "%s%s:%s %s%s:%s %s\n", - color_get(COLOR_PROG), dpkg_get_progname(), color_reset(), - color_get(COLOR_WARN), _("warning"), color_reset(), buf); + warning_printer_func(buf, warning_printer_data); free(buf); } diff --git a/lib/dpkg/report.h b/lib/dpkg/report.h index 4cadc7fe3..862a8429a 100644 --- a/lib/dpkg/report.h +++ b/lib/dpkg/report.h @@ -38,6 +38,11 @@ DPKG_BEGIN_DECLS void dpkg_set_report_piped_mode(int mode); void dpkg_set_report_buffer(FILE *fp); +typedef void dpkg_warning_printer_func(const char *msg, void *data); + +void dpkg_warning_printer(const char *msg, void *data); +void dpkg_set_warning_printer(dpkg_warning_printer_func *printer, void *data); + int warning_get_count(void); void warningv(const char *fmt, va_list args) DPKG_ATTR_VPRINTF(1); void warning(const char *fmt, ...) DPKG_ATTR_PRINTF(1); -- Dpkg.Org's dpkg

