diff options
Diffstat (limited to 'tools/wks-util.c')
-rw-r--r-- | tools/wks-util.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tools/wks-util.c b/tools/wks-util.c index f4f44f6b2..e6f6b7acd 100644 --- a/tools/wks-util.c +++ b/tools/wks-util.c @@ -23,6 +23,7 @@ #include <string.h> #include "util.h" +#include "status.h" #include "ccparray.h" #include "exectool.h" #include "mbox-util.h" @@ -30,6 +31,65 @@ #include "send-mail.h" #include "gpg-wks.h" +/* The stream to output the status information. Output is disabled if + this is NULL. */ +static estream_t statusfp; + + + +/* Set the status FD. */ +void +wks_set_status_fd (int fd) +{ + static int last_fd = -1; + + if (fd != -1 && last_fd == fd) + return; + + if (statusfp && statusfp != es_stdout && statusfp != es_stderr) + es_fclose (statusfp); + statusfp = NULL; + if (fd == -1) + return; + + if (fd == 1) + statusfp = es_stdout; + else if (fd == 2) + statusfp = es_stderr; + else + statusfp = es_fdopen (fd, "w"); + if (!statusfp) + { + log_fatal ("can't open fd %d for status output: %s\n", + fd, gpg_strerror (gpg_error_from_syserror ())); + } + last_fd = fd; +} + + +/* Write a status line with code NO followed by the outout of the + * printf style FORMAT. The caller needs to make sure that LFs and + * CRs are not printed. */ +void +wks_write_status (int no, const char *format, ...) +{ + va_list arg_ptr; + + if (!statusfp) + return; /* Not enabled. */ + + es_fputs ("[GNUPG:] ", statusfp); + es_fputs (get_status_string (no), statusfp); + if (format) + { + es_putc (' ', statusfp); + va_start (arg_ptr, format); + es_vfprintf (statusfp, format, arg_ptr); + va_end (arg_ptr); + } + es_putc ('\n', statusfp); +} + /* Helper for wks_list_key. */ |