From d4489be467e7229e17fb17a0489bf711d6ce66d6 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 5 Sep 2018 16:57:30 +0200 Subject: common: New function status_printf. * common/asshelp2.c (set_assuan_context_func): New. (status_printf): New. * po/Makevars (XGETTEXT_OPTIONS): Add status_printf -- This is a first patch to unify the status printing functions. Signed-off-by: Werner Koch --- common/asshelp2.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'common/asshelp2.c') diff --git a/common/asshelp2.c b/common/asshelp2.c index 0a7c4549d..32e60dfb0 100644 --- a/common/asshelp2.c +++ b/common/asshelp2.c @@ -36,6 +36,24 @@ #include "util.h" #include "asshelp.h" +#include "status.h" + + +/* A variable with a function to be used to return the current assuan + * context for a CTRL variable. This needs to be set using the + * set_assuan_ctx_func function. */ +static assuan_context_t (*the_assuan_ctx_func)(ctrl_t ctrl); + + +/* Set FUNC to be used as a mapping fucntion from CTRL to an assuan + * context. Pass NULL for FUNC to disable the use of the assuan + * context in this module. */ +void +set_assuan_context_func (assuan_context_t (*func)(ctrl_t ctrl)) +{ + the_assuan_ctx_func = func; +} + /* Helper function to print an assuan status line using a printf format string. */ @@ -134,3 +152,22 @@ print_assuan_status_strings (assuan_context_t ctx, const char *keyword, ...) va_end (arg_ptr); return err; } + + +/* This function is similar to print_assuan_status but takes a CTRL + * arg instead of an assuan context as first argument. */ +gpg_error_t +status_printf (ctrl_t ctrl, int no, const char *format, ...) +{ + gpg_error_t err; + va_list arg_ptr; + assuan_context_t ctx; + + if (!ctrl || !the_assuan_ctx_func || !(ctx = the_assuan_ctx_func (ctrl))) + return 0; + + va_start (arg_ptr, format); + err = vprint_assuan_status (ctx, get_status_string (no), format, arg_ptr); + va_end (arg_ptr); + return err; +} -- cgit v1.2.3