Beispiel #1
0
/* Same as tty_printf but if FP is not NULL, behave like a regular
   fprintf. */
void
tty_fprintf (estream_t fp, const char *fmt, ... )
{
    va_list arg_ptr;

    if (fp)
    {
        va_start (arg_ptr, fmt) ;
        es_vfprintf (fp, fmt, arg_ptr );
        va_end (arg_ptr);
        return;
    }

    if (no_terminal)
        return;

    if (!initialized)
        init_ttyfp ();

    va_start (arg_ptr, fmt);
#ifdef USE_W32_CONSOLE
    {
        char *buf = NULL;
        int n;
        DWORD nwritten;

        n = vasprintf(&buf, fmt, arg_ptr);
        if (!buf)
            log_bug("vasprintf() failed\n");

        if (!WriteConsoleA( con.out, buf, n, &nwritten, NULL ))
            log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() );
        if (n != nwritten)
            log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten );
        last_prompt_len += n;
        xfree (buf);
    }
#else
    last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ;
    fflush(ttyfp);
#endif
    va_end(arg_ptr);
}
Beispiel #2
0
/* 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);
}