mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
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 <wk@gnupg.org>
This commit is contained in:
parent
23738c9530
commit
d4489be467
3 changed files with 44 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue