From fa6278b4d768c5f039d94963631d2deac5cf0a55 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Thu, 12 Nov 1998 21:23:33 +0000 Subject: [PATCH] Introduce a state_printf() function. --- handler.c | 49 ++++++++++++++----------------------------------- lib.c | 12 ++++++++++++ mutt.h | 1 + 3 files changed, 27 insertions(+), 35 deletions(-) diff --git a/handler.c b/handler.c index 23a1de5df..a115c69d4 100644 --- a/handler.c +++ b/handler.c @@ -1047,7 +1047,6 @@ int mutt_can_decode (BODY *a) void multipart_handler (BODY *a, STATE *s) { BODY *b, *p; - char buffer[STRING]; char length[5]; struct stat st; int count; @@ -1069,8 +1068,7 @@ void multipart_handler (BODY *a, STATE *s) { if (s->flags & M_DISPLAY) { - snprintf (buffer, sizeof (buffer), _("[-- Attachment #%d"), count); - state_puts (buffer, s); + state_printf (s, _("[-- Attachment #%d"), count); if (p->description || p->filename || p->form_name) { state_puts (": ", s); @@ -1080,11 +1078,9 @@ void multipart_handler (BODY *a, STATE *s) state_puts (" --]\n", s); mutt_pretty_size (length, sizeof (length), p->length); - - snprintf (buffer, sizeof (buffer), - _("[-- Type: %s/%s, Encoding: %s, Size: %s --]\n"), - TYPE (p), p->subtype, ENCODING (p->encoding), length); - state_puts (buffer, s); + + state_printf (s, _("[-- Type: %s/%s, Encoding: %s, Size: %s --]\n"), + TYPE (p), p->subtype, ENCODING (p->encoding), length); if (!option (OPTWEED)) { fseek (s->fpin, p->hdr_offset, 0); @@ -1096,16 +1092,11 @@ void multipart_handler (BODY *a, STATE *s) else { if (p->description && mutt_can_decode (p)) - { - state_puts ("Content-Description: ", s); - state_puts (p->description, s); - state_putc ('\n', s); - } + state_printf (s, "Content-Description: %s\n", p->description); + if (p->form_name) - { - state_puts (p->form_name, s); - state_puts (": \n", s); - } + state_printf(s, "%s: \n", p->form_name); + } mutt_body_handler (p, s); state_putc ('\n', s); @@ -1147,10 +1138,7 @@ void autoview_handler (BODY *a, STATE *s) if (s->flags & M_DISPLAY) { - char mesg[STRING]; - - snprintf (mesg, sizeof (buffer), _("[-- Autoview using %s --]\n"), command); - state_puts (mesg, s); + state_printf (s, _("[-- Autoview using %s --]\n"), command); mutt_message(_("Invoking autoview command: %s"),command); } @@ -1188,13 +1176,8 @@ void autoview_handler (BODY *a, STATE *s) if (fgets (buffer, sizeof(buffer), fperr)) { if (s->flags & M_DISPLAY) - { - char mesg[STRING]; + state_printf (s, _("[-- Autoview stderr of %s --]\n"), command); - snprintf (mesg, sizeof (buffer), _("[-- Autoview stderr of %s --]\n"), - command); - state_puts (mesg, s); - } state_puts (s->prefix, s); state_puts (buffer, s); while (fgets (buffer, sizeof(buffer), fperr) != NULL) @@ -1211,13 +1194,9 @@ void autoview_handler (BODY *a, STATE *s) if (fgets (buffer, sizeof(buffer), fperr)) { if (s->flags & M_DISPLAY) - { - char mesg[STRING]; - - snprintf (mesg, sizeof (buffer), _("[-- Autoview stderr of %s --]\n"), - command); - state_puts (mesg, s); - } + state_printf (s, _("[-- Autoview stderr of %s --]\n"), + command); + state_puts (buffer, s); mutt_copy_stream (fperr, s->fpout); } @@ -1491,7 +1470,7 @@ void mutt_body_handler (BODY *b, STATE *s) } else if (s->flags & M_DISPLAY) { - fprintf (s->fpout, _("[-- %s/%s is unsupported "), TYPE (b), b->subtype); + state_printf (s, _("[-- %s/%s is unsupported "), TYPE (b), b->subtype); if (!option (OPTVIEWATTACH)) { if (km_expand_key (type, sizeof(type), diff --git a/lib.c b/lib.c index da97222c9..f5f01ea69 100644 --- a/lib.c +++ b/lib.c @@ -1224,6 +1224,18 @@ void state_prefix_putc(char c, STATE *s) state_set_prefix(s); } +int state_printf(STATE *s, const char *fmt, ...) +{ + int rv; + va_list ap; + + va_start (ap, fmt); + rv = vfprintf(s->fpout, fmt, ap); + va_end(ap); + + return rv; +} + /* NULL-pointer aware string comparison functions */ int mutt_strcmp(const char *a, const char *b) diff --git a/mutt.h b/mutt.h index 7147468f1..49c4787b9 100644 --- a/mutt.h +++ b/mutt.h @@ -671,6 +671,7 @@ typedef struct #define state_putc(x,y) fputc(x,(y)->fpout) void state_prefix_putc(char, STATE *); +int state_printf(STATE *, const char *, ...); #include "protos.h" #include "globals.h" -- 2.40.0