mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-02 12:01:32 +01: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
@ -82,8 +82,14 @@ gpg_error_t get_assuan_server_version (assuan_context_t ctx,
|
||||
|
||||
/*-- asshelp2.c --*/
|
||||
|
||||
void set_assuan_context_func (assuan_context_t (*func)(ctrl_t ctrl));
|
||||
|
||||
/* Helper function to print an assuan status line using a printf
|
||||
format string. */
|
||||
|
||||
gpg_error_t status_printf (ctrl_t ctrl, int no, const char *format,
|
||||
...) GPGRT_ATTR_PRINTF(3,4);
|
||||
|
||||
gpg_error_t print_assuan_status (assuan_context_t ctx,
|
||||
const char *keyword,
|
||||
const char *format,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ XGETTEXT_OPTIONS = \
|
||||
--flag=xasprintf:1:c-format \
|
||||
--flag=xtryasprintf:1:c-format \
|
||||
--flag=log_debug_with_string:2:c-format \
|
||||
--flag=status_printf:3:c-format \
|
||||
--flag=print_assuan_status:3:c-format \
|
||||
--flag=vprint_assuan_status:3:c-format \
|
||||
--flag=agent_print_status:3:c-format \
|
||||
|
Loading…
x
Reference in New Issue
Block a user