From: Richard Russon Date: Wed, 23 Oct 2019 23:59:10 +0000 (+0100) Subject: unify state functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=af708f4fa94b41446fb9ccd6f7c44f77fa1c240d;p=neomutt unify state functions --- diff --git a/enriched.c b/enriched.c index abd715ba8..5c3a27cbd 100644 --- a/enriched.c +++ b/enriched.c @@ -168,7 +168,7 @@ static void enriched_wrap(struct EnrichedState *stte) x = extra / 2; while (x) { - state_putc(' ', stte->s); + state_putc(stte->s, ' '); x--; } } @@ -177,22 +177,22 @@ static void enriched_wrap(struct EnrichedState *stte) x = extra - 1; while (x) { - state_putc(' ', stte->s); + state_putc(stte->s, ' '); x--; } } } - state_putws((const wchar_t *) stte->line, stte->s); + state_putws(stte->s, (const wchar_t *) stte->line); } - state_putc('\n', stte->s); + state_putc(stte->s, '\n'); stte->line[0] = (wchar_t) '\0'; stte->line_len = 0; stte->line_used = 0; stte->indent_len = 0; if (stte->s->prefix) { - state_puts(stte->s->prefix, stte->s); + state_puts(stte->s, stte->s->prefix); stte->indent_len += mutt_str_strlen(stte->s->prefix); } @@ -203,12 +203,12 @@ static void enriched_wrap(struct EnrichedState *stte) { if (stte->s->prefix) { - state_puts(stte->s->prefix, stte->s); + state_puts(stte->s, stte->s->prefix); stte->indent_len += mutt_str_strlen(stte->s->prefix); } else { - state_puts("> ", stte->s); + state_puts(stte->s, "> "); stte->indent_len += mutt_str_strlen("> "); } x--; @@ -222,7 +222,7 @@ static void enriched_wrap(struct EnrichedState *stte) stte->indent_len += x; while (x) { - state_putc(' ', stte->s); + state_putc(stte->s, ' '); x--; } } @@ -489,7 +489,7 @@ int text_enriched_handler(struct Body *a, struct State *s) if (s->prefix) { - state_puts(s->prefix, s); + state_puts(s, s->prefix); stte.indent_len += mutt_str_strlen(s->prefix); } @@ -584,7 +584,7 @@ int text_enriched_handler(struct Body *a, struct State *s) } } - state_putc('\n', s); /* add a final newline */ + state_putc(s, '\n'); /* add a final newline */ FREE(&(stte.buffer)); FREE(&(stte.line)); diff --git a/handler.c b/handler.c index bfd0aaf8a..7f03eb382 100644 --- a/handler.c +++ b/handler.c @@ -134,14 +134,14 @@ static void convert_to_state(iconv_t cd, char *bufi, size_t *l, struct State *s) obl = sizeof(bufo); iconv(cd, NULL, NULL, &ob, &obl); if (ob != bufo) - state_prefix_put(bufo, ob - bufo, s); + state_prefix_put(s, bufo, ob - bufo); } return; } if (cd == (iconv_t)(-1)) { - state_prefix_put(bufi, *l, s); + state_prefix_put(s, bufi, *l); *l = 0; return; } @@ -155,7 +155,7 @@ static void convert_to_state(iconv_t cd, char *bufi, size_t *l, struct State *s) mutt_ch_iconv(cd, &ib, &ibl, &ob, &obl, 0, "?", NULL); if (ob == bufo) break; - state_prefix_put(bufo, ob - bufo, s); + state_prefix_put(s, bufo, ob - bufo); } memmove(bufi, ib, ibl); *l = ibl; @@ -603,8 +603,8 @@ static int autoview_handler(struct Body *a, struct State *s) { while (fgets(buf, sizeof(buf), fp_out)) { - state_puts(s->prefix, s); - state_puts(buf, s); + state_puts(s, s->prefix); + state_puts(s, buf); } /* check for data on stderr */ if (fgets(buf, sizeof(buf), fp_err)) @@ -615,12 +615,12 @@ static int autoview_handler(struct Body *a, struct State *s) state_printf(s, _("[-- Autoview stderr of %s --]\n"), mutt_b2s(cmd)); } - state_puts(s->prefix, s); - state_puts(buf, s); + state_puts(s, s->prefix); + state_puts(s, buf); while (fgets(buf, sizeof(buf), fp_err)) { - state_puts(s->prefix, s); - state_puts(buf, s); + state_puts(s, s->prefix); + state_puts(s, buf); } } } @@ -636,7 +636,7 @@ static int autoview_handler(struct Body *a, struct State *s) state_printf(s, _("[-- Autoview stderr of %s --]\n"), mutt_b2s(cmd)); } - state_puts(buf, s); + state_puts(s, buf); mutt_file_copy_stream(fp_err, s->fp_out); } } @@ -686,9 +686,9 @@ static int text_plain_handler(struct Body *b, struct State *s) buf[--len] = '\0'; } if (s->prefix) - state_puts(s->prefix, s); - state_puts(buf, s); - state_putc('\n', s); + state_puts(s, s->prefix); + state_puts(s, buf); + state_putc(s, '\n'); } FREE(&buf); @@ -733,8 +733,8 @@ static int message_handler(struct Body *a, struct State *s) mutt_copy_hdr(s->fp_in, s->fp_out, off_start, b->parts->offset, chflags, s->prefix, 0); if (s->prefix) - state_puts(s->prefix, s); - state_putc('\n', s); + state_puts(s, s->prefix); + state_putc(s, '\n'); rc = mutt_body_handler(b->parts, s); } @@ -762,9 +762,8 @@ static int external_body_handler(struct Body *b, struct State *s) if (s->flags & MUTT_DISPLAY) { state_mark_attach(s); - state_puts(_("[-- Error: message/external-body has no access-type " - "parameter --]\n"), - s); + state_puts(s, _("[-- Error: message/external-body has no access-type " + "parameter --]\n")); return 0; } else @@ -861,7 +860,7 @@ static int external_body_handler(struct Body *b, struct State *s) snprintf(strbuf, sizeof(strbuf), str, TYPE(b->parts), b->parts->subtype, pretty_size, expiration); - state_attach_puts(strbuf, s); + state_attach_puts(s, strbuf); if (b->parts->filename) { state_mark_attach(s); @@ -885,7 +884,7 @@ static int external_body_handler(struct Body *b, struct State *s) The "%s/%s" is a MIME type, e.g. "text/plain". */ snprintf(strbuf, sizeof(strbuf), _("[-- This %s/%s attachment is not included, --]\n[-- and the indicated external source has --]\n[-- expired. --]\n"), TYPE(b->parts), b->parts->subtype); - state_attach_puts(strbuf, s); + state_attach_puts(s, strbuf); CopyHeaderFlags chflags = CH_DECODE | CH_DISPLAY; if (C_Weed) @@ -906,7 +905,7 @@ static int external_body_handler(struct Body *b, struct State *s) "LOCAL-FILE", "MAIL-SERVER". */ snprintf(strbuf, sizeof(strbuf), _("[-- This %s/%s attachment is not included, --]\n[-- and the indicated access-type %s is unsupported --]\n"), TYPE(b->parts), b->parts->subtype, access_type); - state_attach_puts(strbuf, s); + state_attach_puts(s, strbuf); CopyHeaderFlags chflags = CH_DECODE | CH_DISPLAY; if (C_Weed) @@ -1077,7 +1076,7 @@ static int alternative_handler(struct Body *a, struct State *s) { count += 1; if (count == 1) - state_putc('\n', s); + state_putc(s, '\n'); print_part_line(s, b, count); } @@ -1089,9 +1088,8 @@ static int alternative_handler(struct Body *a, struct State *s) { /* didn't find anything that we could display! */ state_mark_attach(s); - state_puts(_("[-- Error: Could not display any parts of " - "Multipart/Alternative --]\n"), - s); + state_puts(s, _("[-- Error: Could not display any parts of " + "Multipart/Alternative --]\n")); rc = -1; } @@ -1244,11 +1242,11 @@ static int multipart_handler(struct Body *a, struct State *s) mutt_file_copy_bytes(s->fp_in, s->fp_out, p->offset - p->hdr_offset); } else - state_putc('\n', s); + state_putc(s, '\n'); } rc = mutt_body_handler(p, s); - state_putc('\n', s); + state_putc(s, '\n'); if (rc != 0) { diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index b99f97f70..cf412853e 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -96,7 +96,7 @@ void crypt_current_time(struct State *s, const char *app_name) *p = '\0'; snprintf(tmp, sizeof(tmp), _("[-- %s output follows%s --]\n"), NONULL(app_name), p); - state_attach_puts(tmp, s); + state_attach_puts(s, tmp); } /** @@ -1111,7 +1111,7 @@ int mutt_protected_headers_handler(struct Body *a, struct State *s) mutt_write_one_header(s->fp_out, "Subject", a->mime_headers->subject, s->prefix, wraplen, display ? CH_DISPLAY : CH_NO_FLAGS); - state_puts("\n", s); + state_puts(s, "\n"); } } @@ -1179,10 +1179,8 @@ int mutt_signed_handler(struct Body *a, struct State *s) } if (inconsistent) { - state_attach_puts(_("[-- Error: " - "Missing or bad-format multipart/signed signature" - " --]\n\n"), - s); + state_attach_puts(s, _("[-- Error: Missing or bad-format multipart/signed " + "signature --]\n\n")); return mutt_body_handler(a, s); } @@ -1236,20 +1234,21 @@ int mutt_signed_handler(struct Body *a, struct State *s) b->badsig = !goodsig; /* Now display the signed body */ - state_attach_puts(_("[-- The following data is signed --]\n\n"), s); + state_attach_puts(s, _("[-- The following data is signed --]\n\n")); mutt_protected_headers_handler(a, s); FREE(&signatures); } else - state_attach_puts(_("[-- Warning: Can't find any signatures. --]\n\n"), s); + state_attach_puts(s, + _("[-- Warning: Can't find any signatures. --]\n\n")); } rc = mutt_body_handler(a, s); if ((s->flags & MUTT_DISPLAY) && (sigcnt != 0)) - state_attach_puts(_("\n[-- End of signed data --]\n"), s); + state_attach_puts(s, _("\n[-- End of signed data --]\n")); return rc; } diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 0337be22b..7346ec8af 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -1391,7 +1391,7 @@ static void print_time(time_t t, struct State *s) { char p[256]; mutt_date_localtime_format(p, sizeof(p), nl_langinfo(D_T_FMT), t); - state_puts(p, s); + state_puts(s, p); } /** @@ -1638,7 +1638,7 @@ static int show_sig_summary(unsigned long sum, gpgme_ctx_t ctx, gpgme_key_t key, if ((sum & GPGME_SIGSUM_KEY_REVOKED)) { - state_puts(_("Warning: One of the keys has been revoked\n"), s); + state_puts(s, _("Warning: One of the keys has been revoked\n")); severe = true; } @@ -1647,17 +1647,14 @@ static int show_sig_summary(unsigned long sum, gpgme_ctx_t ctx, gpgme_key_t key, time_t at = key->subkeys->expires ? key->subkeys->expires : 0; if (at) { - state_puts(_("Warning: The key used to create the " - "signature expired at: "), - s); + state_puts( + s, _("Warning: The key used to create the signature expired at: ")); print_time(at, s); - state_puts("\n", s); + state_puts(s, "\n"); } else { - state_puts(_("Warning: At least one certification key " - "has expired\n"), - s); + state_puts(s, _("Warning: At least one certification key has expired\n")); } } @@ -1671,32 +1668,30 @@ static int show_sig_summary(unsigned long sum, gpgme_ctx_t ctx, gpgme_key_t key, for (sig2 = result->signatures, i = 0; sig2 && (i < idx); sig2 = sig2->next, i++) ; - state_puts(_("Warning: The signature expired at: "), s); + state_puts(s, _("Warning: The signature expired at: ")); print_time(sig2 ? sig2->exp_timestamp : 0, s); - state_puts("\n", s); + state_puts(s, "\n"); } if ((sum & GPGME_SIGSUM_KEY_MISSING)) { - state_puts(_("Can't verify due to a missing " - "key or certificate\n"), - s); + state_puts(s, _("Can't verify due to a missing key or certificate\n")); } if ((sum & GPGME_SIGSUM_CRL_MISSING)) { - state_puts(_("The CRL is not available\n"), s); + state_puts(s, _("The CRL is not available\n")); severe = true; } if ((sum & GPGME_SIGSUM_CRL_TOO_OLD)) { - state_puts(_("Available CRL is too old\n"), s); + state_puts(s, _("Available CRL is too old\n")); severe = true; } if ((sum & GPGME_SIGSUM_BAD_POLICY)) - state_puts(_("A policy requirement was not met\n"), s); + state_puts(s, _("A policy requirement was not met\n")); if ((sum & GPGME_SIGSUM_SYS_ERROR)) { @@ -1705,7 +1700,7 @@ static int show_sig_summary(unsigned long sum, gpgme_ctx_t ctx, gpgme_key_t key, gpgme_signature_t sig2 = NULL; unsigned int i; - state_puts(_("A system error occurred"), s); + state_puts(s, _("A system error occurred")); /* Try to figure out some more detailed system error information. */ result = gpgme_op_verify_result(ctx); @@ -1719,34 +1714,32 @@ static int show_sig_summary(unsigned long sum, gpgme_ctx_t ctx, gpgme_key_t key, if (t0 || t1) { - state_puts(": ", s); + state_puts(s, ": "); if (t0) - state_puts(t0, s); + state_puts(s, t0); if (t1 && !(t0 && (strcmp(t0, t1) == 0))) { if (t0) - state_puts(",", s); - state_puts(t1, s); + state_puts(s, ","); + state_puts(s, t1); } } - state_puts("\n", s); + state_puts(s, "\n"); } if (C_CryptUsePka) { if ((sig->pka_trust == 1) && sig->pka_address) { - state_puts(_("WARNING: PKA entry does not match " - "signer's address: "), - s); - state_puts(sig->pka_address, s); - state_puts("\n", s); + state_puts(s, _("WARNING: PKA entry does not match signer's address: ")); + state_puts(s, sig->pka_address); + state_puts(s, "\n"); } else if ((sig->pka_trust == 2) && sig->pka_address) { - state_puts(_("PKA verified signer's address is: "), s); - state_puts(sig->pka_address, s); - state_puts("\n", s); + state_puts(s, _("PKA verified signer's address is: ")); + state_puts(s, sig->pka_address); + state_puts(s, "\n"); } } @@ -1803,7 +1796,7 @@ static void show_fingerprint(gpgme_key_t key, struct State *state) *p++ = *s; *p++ = '\n'; *p = '\0'; - state_puts(buf, state); + state_puts(state, buf); FREE(&buf); } @@ -1846,7 +1839,7 @@ static void show_one_sig_validity(gpgme_ctx_t ctx, int idx, struct State *s) break; } if (txt) - state_puts(txt, s); + state_puts(s, txt); } /** @@ -1861,8 +1854,8 @@ static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, { int msgwid; - state_puts(msg, s); - state_puts(" ", s); + state_puts(s, msg); + state_puts(s, " "); /* key is NULL when not present in the user's keyring */ if (key) { @@ -1877,11 +1870,11 @@ static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, if (msgwid < 0) msgwid = 0; for (int i = 0; i < msgwid; i++) - state_puts(" ", s); - state_puts(_("aka: "), s); + state_puts(s, " "); + state_puts(s, _("aka: ")); } - state_puts(uids->uid, s); - state_puts("\n", s); + state_puts(s, uids->uid); + state_puts(s, "\n"); aka = true; } @@ -1890,16 +1883,16 @@ static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, { if (sig->fpr) { - state_puts(_("KeyID "), s); - state_puts(sig->fpr, s); + state_puts(s, _("KeyID ")); + state_puts(s, sig->fpr); } else { /* L10N: You will see this message in place of "KeyID " if the S/MIME key has no ID. This is quite an error. */ - state_puts(_("no signature fingerprint available"), s); + state_puts(s, _("no signature fingerprint available")); } - state_puts("\n", s); + state_puts(s, "\n"); } /* timestamp is 0 when verification failed. @@ -1910,10 +1903,10 @@ static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, if (msgwid < 0) msgwid = 0; for (int i = 0; i < msgwid; i++) - state_puts(" ", s); - state_puts(_("created: "), s); + state_puts(s, " "); + state_puts(s, _("created: ")); print_time(sig->timestamp, s); - state_puts("\n", s); + state_puts(s, "\n"); } } @@ -1987,7 +1980,7 @@ static int show_one_sig_status(gpgme_ctx_t ctx, int idx, struct State *s) char buf[1024]; snprintf(buf, sizeof(buf), _("Error getting key information for KeyID %s: %s\n"), fpr, gpgme_strerror(err)); - state_puts(buf, s); + state_puts(s, buf); anybad = true; } else if ((sum & GPGME_SIGSUM_GREEN)) @@ -2021,9 +2014,9 @@ static int show_one_sig_status(gpgme_ctx_t ctx, int idx, struct State *s) { /* L10N: This is trying to match the width of the "Problem signature from:" translation just above. */ - state_puts(_(" expires: "), s); + state_puts(s, _(" expires: ")); print_time(sig->exp_timestamp, s); - state_puts("\n", s); + state_puts(s, "\n"); } show_sig_summary(sum, ctx, key, idx, s, sig); anywarn = true; @@ -2068,7 +2061,7 @@ static int verify_one(struct Body *sigbdy, struct State *s, const char *tempfile /* Note: We don't need a current time output because GPGME avoids * such an attack by separating the meta information from the data. */ - state_attach_puts(_("[-- Begin signature information --]\n"), s); + state_attach_puts(s, _("[-- Begin signature information --]\n")); err = gpgme_op_verify(ctx, signature, message, NULL); gpgme_data_release(message); @@ -2081,7 +2074,7 @@ static int verify_one(struct Body *sigbdy, struct State *s, const char *tempfile snprintf(buf, sizeof(buf) - 1, _("Error: verification failed: %s\n"), gpgme_strerror(err)); - state_puts(buf, s); + state_puts(s, buf); } else { /* Verification succeeded, see what the result is. */ @@ -2131,7 +2124,7 @@ static int verify_one(struct Body *sigbdy, struct State *s, const char *tempfile char buf[128]; snprintf(buf, sizeof(buf), _("*** Begin Notation (signature by: %s) ***\n"), sig->fpr); - state_puts(buf, s); + state_puts(s, buf); for (notation = sig->notations; notation; notation = notation->next) { if (is_pka_notation(notation)) @@ -2139,17 +2132,17 @@ static int verify_one(struct Body *sigbdy, struct State *s, const char *tempfile if (notation->name) { - state_puts(notation->name, s); - state_puts("=", s); + state_puts(s, notation->name); + state_puts(s, "="); } if (notation->value) { - state_puts(notation->value, s); + state_puts(s, notation->value); if (!(*notation->value && (notation->value[strlen(notation->value) - 1] == '\n'))) - state_puts("\n", s); + state_puts(s, "\n"); } } - state_puts(_("*** End Notation ***\n"), s); + state_puts(s, _("*** End Notation ***\n")); } } } @@ -2157,7 +2150,7 @@ static int verify_one(struct Body *sigbdy, struct State *s, const char *tempfile gpgme_release(ctx); - state_attach_puts(_("[-- End signature information --]\n\n"), s); + state_attach_puts(s, _("[-- End signature information --]\n\n")); mutt_debug(LL_DEBUG1, "returning %d\n", badsig); return badsig ? 1 : anywarn ? 2 : 0; @@ -2273,7 +2266,7 @@ restart: snprintf(buf, sizeof(buf) - 1, _("[-- Error: decryption failed: %s --]\n\n"), gpgme_strerror(err)); - state_attach_puts(buf, s); + state_attach_puts(s, buf); } goto cleanup; } @@ -2298,9 +2291,7 @@ restart: if ((s->flags & MUTT_DISPLAY)) { - state_attach_puts(_("[-- Begin signature " - "information --]\n"), - s); + state_attach_puts(s, _("[-- Begin signature information --]\n")); } for (idx = 0; (res = show_one_sig_status(ctx, idx, s)) != -1; idx++) { @@ -2314,9 +2305,7 @@ restart: if ((s->flags & MUTT_DISPLAY)) { - state_attach_puts(_("[-- End signature " - "information --]\n\n"), - s); + state_attach_puts(s, _("[-- End signature information --]\n\n")); } } gpgme_release(ctx); @@ -2938,7 +2927,7 @@ static void copy_clearsigned(gpgme_data_t data, struct State *s, char *charset) if (!complete) { if (!armor_header) - state_puts(buf, s); + state_puts(s, buf); continue; } @@ -2953,12 +2942,12 @@ static void copy_clearsigned(gpgme_data_t data, struct State *s, char *charset) } if (s->prefix) - state_puts(s->prefix, s); + state_puts(s, s->prefix); if ((buf[0] == '-') && (buf[1] == ' ')) - state_puts(buf + 2, s); + state_puts(s, buf + 2); else - state_puts(buf, s); + state_puts(s, buf); } mutt_ch_fgetconv_close(&fc); @@ -3026,8 +3015,8 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) { /* XXX we may wish to recode here */ if (s->prefix) - state_puts(s->prefix, s); - state_puts(buf, s); + state_puts(s, s->prefix); + state_puts(s, buf); continue; } @@ -3068,7 +3057,7 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) snprintf(errbuf, sizeof(errbuf) - 1, _("Error: decryption/verification failed: %s\n"), gpgme_strerror(err)); - state_puts(errbuf, s); + state_puts(s, errbuf); } else { /* Decryption/Verification succeeded */ @@ -3089,9 +3078,7 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) int res, idx; bool anybad = false; - state_attach_puts(_("[-- Begin signature " - "information --]\n"), - s); + state_attach_puts(s, _("[-- Begin signature information --]\n")); have_any_sigs = true; for (idx = 0; (res = show_one_sig_status(ctx, idx, s)) != -1; idx++) { @@ -3101,16 +3088,14 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) if (!anybad && idx) maybe_goodsig = true; - state_attach_puts(_("[-- End signature " - "information --]\n\n"), - s); + state_attach_puts(s, _("[-- End signature information --]\n\n")); } tmpfname = data_object_to_tempfile(plaintext, &fp_out); if (!tmpfname) { mutt_file_fclose(&fp_out); - state_puts(_("Error: copy data failed\n"), s); + state_puts(s, _("Error: copy data failed\n")); } else { @@ -3128,11 +3113,11 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) if (s->flags & MUTT_DISPLAY) { if (needpass) - state_attach_puts(_("[-- BEGIN PGP MESSAGE --]\n\n"), s); + state_attach_puts(s, _("[-- BEGIN PGP MESSAGE --]\n\n")); else if (pgp_keyblock) - state_attach_puts(_("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"), s); + state_attach_puts(s, _("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n")); else - state_attach_puts(_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), s); + state_attach_puts(s, _("[-- BEGIN PGP SIGNED MESSAGE --]\n\n")); } if (clearsign) @@ -3146,22 +3131,22 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) struct FgetConv *fc = mutt_ch_fgetconv_open(fp_out, "utf-8", C_Charset, 0); while ((c = mutt_ch_fgetconv(fc)) != EOF) { - state_putc(c, s); + state_putc(s, c); if ((c == '\n') && s->prefix) - state_puts(s->prefix, s); + state_puts(s, s->prefix); } mutt_ch_fgetconv_close(&fc); } if (s->flags & MUTT_DISPLAY) { - state_putc('\n', s); + state_putc(s, '\n'); if (needpass) - state_attach_puts(_("[-- END PGP MESSAGE --]\n"), s); + state_attach_puts(s, _("[-- END PGP MESSAGE --]\n")); else if (pgp_keyblock) - state_attach_puts(_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s); + state_attach_puts(s, _("[-- END PGP PUBLIC KEY BLOCK --]\n")); else - state_attach_puts(_("[-- END PGP SIGNED MESSAGE --]\n"), s); + state_attach_puts(s, _("[-- END PGP SIGNED MESSAGE --]\n")); } gpgme_data_release(armored_data); @@ -3172,8 +3157,8 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) /* A traditional PGP part may mix signed and unsigned content */ /* XXX we may wish to recode here */ if (s->prefix) - state_puts(s->prefix, s); - state_puts(buf, s); + state_puts(s, s->prefix); + state_puts(s, buf); } } @@ -3181,9 +3166,8 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) if (needpass == -1) { - state_attach_puts(_("[-- Error: could not find beginning" - " of PGP message --]\n\n"), - s); + state_attach_puts( + s, _("[-- Error: could not find beginning of PGP message --]\n\n")); return 1; } mutt_debug(LL_DEBUG2, "Leaving handler\n"); @@ -3210,9 +3194,8 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) mutt_perror(_("Can't create temporary file")); if (s->flags & MUTT_DISPLAY) { - state_attach_puts(_("[-- Error: could not create temporary file " - "--]\n"), - s); + state_attach_puts(s, + _("[-- Error: could not create temporary file --]\n")); } return -1; } @@ -3225,10 +3208,10 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) if (s->flags & MUTT_DISPLAY) { state_attach_puts( - is_signed ? _("[-- The following data is PGP/MIME signed and " - "encrypted --]\n\n") : - _("[-- The following data is PGP/MIME encrypted --]\n\n"), - s); + s, is_signed ? + _("[-- The following data is PGP/MIME signed and encrypted " + "--]\n\n") : + _("[-- The following data is PGP/MIME encrypted --]\n\n")); mutt_protected_headers_handler(tattach, s); } @@ -3265,11 +3248,11 @@ int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s) if (s->flags & MUTT_DISPLAY) { - state_puts("\n", s); + state_puts(s, "\n"); state_attach_puts( - is_signed ? _("[-- End of PGP/MIME signed and encrypted data --]\n") : - _("[-- End of PGP/MIME encrypted data --]\n"), - s); + s, is_signed ? + _("[-- End of PGP/MIME signed and encrypted data --]\n") : + _("[-- End of PGP/MIME encrypted data --]\n")); } mutt_body_free(&tattach); @@ -3309,9 +3292,8 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) mutt_perror(_("Can't create temporary file")); if (s->flags & MUTT_DISPLAY) { - state_attach_puts(_("[-- Error: could not create temporary file " - "--]\n"), - s); + state_attach_puts(s, + _("[-- Error: could not create temporary file --]\n")); } return -1; } @@ -3324,9 +3306,9 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) if (s->flags & MUTT_DISPLAY) { state_attach_puts( - is_signed ? _("[-- The following data is S/MIME signed --]\n\n") : - _("[-- The following data is S/MIME encrypted --]\n\n"), - s); + s, is_signed ? + _("[-- The following data is S/MIME signed --]\n\n") : + _("[-- The following data is S/MIME encrypted --]\n\n")); mutt_protected_headers_handler(tattach, s); } @@ -3371,10 +3353,10 @@ int smime_gpgme_application_handler(struct Body *a, struct State *s) if (s->flags & MUTT_DISPLAY) { - state_puts("\n", s); - state_attach_puts(is_signed ? _("[-- End of S/MIME signed data --]\n") : - _("[-- End of S/MIME encrypted data --]\n"), - s); + state_puts(s, "\n"); + state_attach_puts(s, is_signed ? + _("[-- End of S/MIME signed data --]\n") : + _("[-- End of S/MIME encrypted data --]\n")); } mutt_body_free(&tattach); diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index 99d698e3c..a6e43bcff 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -430,7 +430,7 @@ static void pgp_copy_clearsigned(FILE *fp_in, struct State *s, char *charset) if (!complete) { if (!armor_header) - state_puts(buf, s); + state_puts(s, buf); continue; } @@ -446,12 +446,12 @@ static void pgp_copy_clearsigned(FILE *fp_in, struct State *s, char *charset) } if (s->prefix) - state_puts(s->prefix, s); + state_puts(s, s->prefix); if ((buf[0] == '-') && (buf[1] == ' ')) - state_puts(buf + 2, s); + state_puts(s, buf + 2); else - state_puts(buf, s); + state_puts(s, buf); } mutt_ch_fgetconv_close(&fc); @@ -519,8 +519,8 @@ int pgp_class_application_handler(struct Body *m, struct State *s) { /* XXX we may wish to recode here */ if (s->prefix) - state_puts(s->prefix, s); - state_puts(buf, s); + state_puts(s, s->prefix); + state_puts(s, buf); continue; } @@ -594,7 +594,7 @@ int pgp_class_application_handler(struct Body *m, struct State *s) maybe_goodsig = false; fp_pgp_in = NULL; state_attach_puts( - _("[-- Error: unable to create PGP subprocess --]\n"), s); + s, _("[-- Error: unable to create PGP subprocess --]\n")); } else /* PGP started successfully */ { @@ -643,7 +643,7 @@ int pgp_class_application_handler(struct Body *m, struct State *s) if (checksig_rc == -1 || (wait_filter_rc != 0)) maybe_goodsig = false; - state_attach_puts(_("[-- End of PGP output --]\n\n"), s); + state_attach_puts(s, _("[-- End of PGP output --]\n\n")); } if (pgp_use_gpg_agent()) mutt_need_hard_redraw(); @@ -674,11 +674,11 @@ int pgp_class_application_handler(struct Body *m, struct State *s) if (s->flags & MUTT_DISPLAY) { if (needpass) - state_attach_puts(_("[-- BEGIN PGP MESSAGE --]\n\n"), s); + state_attach_puts(s, _("[-- BEGIN PGP MESSAGE --]\n\n")); else if (pgp_keyblock) - state_attach_puts(_("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"), s); + state_attach_puts(s, _("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n")); else - state_attach_puts(_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), s); + state_attach_puts(s, _("[-- BEGIN PGP SIGNED MESSAGE --]\n\n")); } if (clearsign) @@ -699,7 +699,7 @@ int pgp_class_application_handler(struct Body *m, struct State *s) state_set_prefix(s); fc = mutt_ch_fgetconv_open(fp_pgp_out, expected_charset, C_Charset, MUTT_ICONV_HOOK_FROM); while ((ch = mutt_ch_fgetconv(fc)) != EOF) - state_prefix_putc(ch, s); + state_prefix_putc(s, ch); mutt_ch_fgetconv_close(&fc); } @@ -712,10 +712,10 @@ int pgp_class_application_handler(struct Body *m, struct State *s) if (s->flags & MUTT_DISPLAY) { - state_putc('\n', s); + state_putc(s, '\n'); if (needpass) { - state_attach_puts(_("[-- END PGP MESSAGE --]\n"), s); + state_attach_puts(s, _("[-- END PGP MESSAGE --]\n")); if (could_not_decrypt || (decrypt_okay_rc <= -3)) mutt_error(_("Could not decrypt PGP message")); else if (decrypt_okay_rc < 0) @@ -729,9 +729,9 @@ int pgp_class_application_handler(struct Body *m, struct State *s) mutt_message(_("PGP message successfully decrypted")); } else if (pgp_keyblock) - state_attach_puts(_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s); + state_attach_puts(s, _("[-- END PGP PUBLIC KEY BLOCK --]\n")); else - state_attach_puts(_("[-- END PGP SIGNED MESSAGE --]\n"), s); + state_attach_puts(s, _("[-- END PGP SIGNED MESSAGE --]\n")); } } else @@ -739,8 +739,8 @@ int pgp_class_application_handler(struct Body *m, struct State *s) /* A traditional PGP part may mix signed and unsigned content */ /* XXX we may wish to recode here */ if (s->prefix) - state_puts(s->prefix, s); - state_puts(buf, s); + state_puts(s, s->prefix); + state_puts(s, buf); } } @@ -764,7 +764,7 @@ out: if (needpass == -1) { state_attach_puts( - _("[-- Error: could not find beginning of PGP message --]\n\n"), s); + s, _("[-- Error: could not find beginning of PGP message --]\n\n")); return -1; } @@ -925,7 +925,7 @@ int pgp_class_verify_one(struct Body *sigbdy, struct State *s, const char *tempf mutt_file_fclose(&fp_pgp_err); - state_attach_puts(_("[-- End of PGP output --]\n\n"), s); + state_attach_puts(s, _("[-- End of PGP output --]\n\n")); mutt_file_unlink(mutt_b2s(sigfile)); @@ -1042,7 +1042,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, if (s->flags & MUTT_DISPLAY) { state_attach_puts( - _("[-- Error: could not create a PGP subprocess --]\n\n"), s); + s, _("[-- Error: could not create a PGP subprocess --]\n\n")); } goto cleanup; } @@ -1085,7 +1085,7 @@ static struct Body *pgp_decrypt_part(struct Body *a, struct State *s, p->goodsig = true; else p->goodsig = false; - state_attach_puts(_("[-- End of PGP output --]\n\n"), s); + state_attach_puts(s, _("[-- End of PGP output --]\n\n")); } mutt_file_fclose(&fp_pgp_err); @@ -1216,7 +1216,8 @@ int pgp_class_encrypted_handler(struct Body *a, struct State *s) { mutt_perror(_("Can't create temporary file")); if (s->flags & MUTT_DISPLAY) - state_attach_puts(_("[-- Error: could not create temporary file --]\n"), s); + state_attach_puts(s, + _("[-- Error: could not create temporary file --]\n")); return -1; } @@ -1229,7 +1230,7 @@ int pgp_class_encrypted_handler(struct Body *a, struct State *s) if (s->flags & MUTT_DISPLAY) { state_attach_puts( - _("[-- The following data is PGP/MIME encrypted --]\n\n"), s); + s, _("[-- The following data is PGP/MIME encrypted --]\n\n")); mutt_protected_headers_handler(tattach, s); } @@ -1264,8 +1265,8 @@ int pgp_class_encrypted_handler(struct Body *a, struct State *s) if (s->flags & MUTT_DISPLAY) { - state_puts("\n", s); - state_attach_puts(_("[-- End of PGP/MIME encrypted data --]\n"), s); + state_puts(s, "\n"); + state_attach_puts(s, _("[-- End of PGP/MIME encrypted data --]\n")); } mutt_body_free(&tattach); diff --git a/ncrypt/smime.c b/ncrypt/smime.c index e34ecf897..1bf9fc727 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -1962,7 +1962,7 @@ int smime_class_verify_one(struct Body *sigbdy, struct State *s, const char *tem mutt_file_copy_stream(fp_smime_err, s->fp_out); mutt_file_fclose(&fp_smime_err); - state_attach_puts(_("[-- End of OpenSSL output --]\n\n"), s); + state_attach_puts(s, _("[-- End of OpenSSL output --]\n\n")); mutt_file_unlink(signedfile); @@ -2039,7 +2039,7 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *f if (s->flags & MUTT_DISPLAY) { state_attach_puts( - _("[-- Error: unable to create OpenSSL subprocess --]\n"), s); + s, _("[-- Error: unable to create OpenSSL subprocess --]\n")); } mutt_file_fclose(&fp_smime_err); return NULL; @@ -2054,7 +2054,7 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *f if (s->flags & MUTT_DISPLAY) { state_attach_puts( - _("[-- Error: unable to create OpenSSL subprocess --]\n"), s); + s, _("[-- Error: unable to create OpenSSL subprocess --]\n")); } mutt_file_fclose(&fp_smime_err); return NULL; @@ -2085,17 +2085,16 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *f crypt_current_time(s, "OpenSSL"); mutt_file_copy_stream(fp_smime_err, s->fp_out); - state_attach_puts(_("[-- End of OpenSSL output --]\n\n"), s); + state_attach_puts(s, _("[-- End of OpenSSL output --]\n\n")); } if (type & SEC_ENCRYPT) { - state_attach_puts(_("[-- The following data is S/MIME" - " encrypted --]\n"), - s); + state_attach_puts(s, + _("[-- The following data is S/MIME encrypted --]\n")); } else - state_attach_puts(_("[-- The following data is S/MIME signed --]\n"), s); + state_attach_puts(s, _("[-- The following data is S/MIME signed --]\n")); } fflush(fp_smime_out); @@ -2189,9 +2188,9 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *f if (s->flags & MUTT_DISPLAY) { if (type & SEC_ENCRYPT) - state_attach_puts(_("\n[-- End of S/MIME encrypted data. --]\n"), s); + state_attach_puts(s, _("\n[-- End of S/MIME encrypted data. --]\n")); else - state_attach_puts(_("\n[-- End of S/MIME signed data. --]\n"), s); + state_attach_puts(s, _("\n[-- End of S/MIME signed data. --]\n")); } if (type & SEC_SIGNOPAQUE) diff --git a/recvattach.c b/recvattach.c index 9301bfe6c..975fd980d 100644 --- a/recvattach.c +++ b/recvattach.c @@ -813,7 +813,7 @@ static void pipe_attachment(FILE *fp, struct Body *b, struct State *state) state->fp_in = fp; mutt_decode_attachment(b, state); if (C_AttachSep) - state_puts(C_AttachSep, state); + state_puts(state, C_AttachSep); } else { @@ -826,7 +826,7 @@ static void pipe_attachment(FILE *fp, struct Body *b, struct State *state) mutt_file_copy_stream(fp_in, state->fp_out); mutt_file_fclose(&fp_in); if (C_AttachSep) - state_puts(C_AttachSep, state); + state_puts(state, C_AttachSep); } } @@ -998,7 +998,7 @@ static void print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, mutt_file_copy_stream(fp_in, state->fp_out); mutt_file_fclose(&fp_in); if (C_AttachSep) - state_puts(C_AttachSep, state); + state_puts(state, C_AttachSep); } } mutt_file_unlink(mutt_b2s(newfile)); diff --git a/recvcmd.c b/recvcmd.c index 8fe30e13c..00c655479 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -562,7 +562,7 @@ static void attach_forward_bodies(FILE *fp, struct Email *e, struct AttachCtx *a { st.fp_in = fp; mutt_body_handler(cur, &st); - state_putc('\n', &st); + state_putc(&st, '\n'); } else { @@ -582,7 +582,7 @@ static void attach_forward_bodies(FILE *fp, struct Email *e, struct AttachCtx *a { st.fp_in = actx->idx[i]->fp; mutt_body_handler(actx->idx[i]->content, &st); - state_putc('\n', &st); + state_putc(&st, '\n'); } } } @@ -1013,7 +1013,7 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx, { st.fp_in = fp; mutt_body_handler(e_cur, &st); - state_putc('\n', &st); + state_putc(&st, '\n'); } else mutt_body_copy(fp, &e_tmp->content, e_cur); @@ -1026,7 +1026,7 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx, { st.fp_in = actx->idx[i]->fp; mutt_body_handler(actx->idx[i]->content, &st); - state_putc('\n', &st); + state_putc(&st, '\n'); } } } diff --git a/rfc3676.c b/rfc3676.c index 325dee14d..62700b4ce 100644 --- a/rfc3676.c +++ b/rfc3676.c @@ -146,18 +146,18 @@ static size_t print_indent(int ql, struct State *s, int add_suffix) ql++; else { - state_puts(s->prefix, s); + state_puts(s, s->prefix); wid = mutt_strwidth(s->prefix); } } for (int i = 0; i < ql; i++) { - state_putc('>', s); + state_putc(s, '>'); if (space_quotes(s)) - state_putc(' ', s); + state_putc(s, ' '); } if (add_suffix) - state_putc(' ', s); + state_putc(s, ' '); if (space_quotes(s)) ql *= 2; @@ -174,7 +174,7 @@ static void flush_par(struct State *s, struct FlowedState *fst) { if (fst->width > 0) { - state_putc('\n', s); + state_putc(s, '\n'); fst->width = 0; } fst->spaces = 0; @@ -233,7 +233,7 @@ static void print_flowed_line(char *line, struct State *s, int ql, /* flush current paragraph (if any) first */ flush_par(s, fst); print_indent(ql, s, 0); - state_putc('\n', s); + state_putc(s, '\n'); return; } @@ -272,8 +272,8 @@ static void print_flowed_line(char *line, struct State *s, int ql, /* only honor trailing spaces for format=flowed replies */ if (C_TextFlowed) for (; fst->spaces; fst->spaces--) - state_putc(' ', s); - state_putc('\n', s); + state_putc(s, ' '); + state_putc(s, '\n'); fst->width = 0; fst->spaces = 0; words = 0; @@ -283,8 +283,8 @@ static void print_flowed_line(char *line, struct State *s, int ql, fst->width = print_indent(ql, s, add_quote_suffix(s, ql)); fst->width += w + fst->spaces; for (; fst->spaces; fst->spaces--) - state_putc(' ', s); - state_puts(p, s); + state_putc(s, ' '); + state_puts(s, p); words++; } @@ -303,8 +303,8 @@ static void print_fixed_line(const char *line, struct State *s, int ql, struct F { print_indent(ql, s, add_quote_suffix(s, ql)); if (line && *line) - state_puts(line, s); - state_putc('\n', s); + state_puts(s, line); + state_putc(s, '\n'); fst->width = 0; fst->spaces = 0; diff --git a/state.c b/state.c index 5c92d8093..62789fb4e 100644 --- a/state.c +++ b/state.c @@ -45,7 +45,7 @@ void state_mark_attach(struct State *s) if ((s->flags & MUTT_DISPLAY) && (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0))) { - state_puts(AttachmentMarker, s); + state_puts(s, AttachmentMarker); } } @@ -58,25 +58,25 @@ void state_mark_protected_header(struct State *s) if ((s->flags & MUTT_DISPLAY) && (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0))) { - state_puts(ProtectedHeaderMarker, s); + state_puts(s, ProtectedHeaderMarker); } } /** * state_attach_puts - Write a string to the state - * @param t Text to write * @param s State to write to + * @param t Text to write */ -void state_attach_puts(const char *t, struct State *s) +void state_attach_puts(struct State *s, const char *t) { - if (!t || !s || !s->fp_out) + if (!s || !s->fp_out || !t) return; if (*t != '\n') state_mark_attach(s); while (*t) { - state_putc(*t, s); + state_putc(s, *t); if ((*t++ == '\n') && *t) if (*t != '\n') state_mark_attach(s); @@ -85,12 +85,12 @@ void state_attach_puts(const char *t, struct State *s) /** * state_putwc - Write a wide character to the state - * @param wc Wide character to write * @param s State to write to + * @param wc Wide character to write * @retval 0 Success * @retval -1 Error */ -static int state_putwc(wchar_t wc, struct State *s) +static int state_putwc(struct State *s, wchar_t wc) { char mb[MB_LEN_MAX] = { 0 }; int rc; @@ -105,18 +105,18 @@ static int state_putwc(wchar_t wc, struct State *s) /** * state_putws - Write a wide string to the state - * @param ws Wide string to write * @param s State to write to + * @param ws Wide string to write * @retval 0 Success * @retval -1 Error */ -int state_putws(const wchar_t *ws, struct State *s) +int state_putws(struct State *s, const wchar_t *ws) { const wchar_t *p = ws; while (p && (*p != L'\0')) { - if (state_putwc(*p, s) < 0) + if (state_putwc(s, *p) < 0) return -1; p++; } @@ -125,19 +125,19 @@ int state_putws(const wchar_t *ws, struct State *s) /** * state_prefix_putc - Write a prefixed character to the state - * @param c Character to write * @param s State to write to + * @param c Character to write */ -void state_prefix_putc(char c, struct State *s) +void state_prefix_putc(struct State *s, char c) { if (s->flags & MUTT_PENDINGPREFIX) { state_reset_prefix(s); if (s->prefix) - state_puts(s->prefix, s); + state_puts(s, s->prefix); } - state_putc(c, s); + state_putc(s, c); if (c == '\n') state_set_prefix(s); @@ -164,16 +164,16 @@ int state_printf(struct State *s, const char *fmt, ...) /** * state_prefix_put - Write a prefixed fixed-string to the State + * @param s State to write to * @param buf String to write * @param buflen Length of string - * @param s State to write to */ -void state_prefix_put(const char *buf, size_t buflen, struct State *s) +void state_prefix_put(struct State *s, const char *buf, size_t buflen) { if (s->prefix) { while (buflen--) - state_prefix_putc(*buf++, s); + state_prefix_putc(s, *buf++); } else fwrite(buf, buflen, 1, s->fp_out); diff --git a/state.h b/state.h index 998bcefa7..ca26007d6 100644 --- a/state.h +++ b/state.h @@ -52,15 +52,15 @@ struct State #define state_set_prefix(state) ((state)->flags |= MUTT_PENDINGPREFIX) #define state_reset_prefix(state) ((state)->flags &= ~MUTT_PENDINGPREFIX) -#define state_puts(str, state) fputs(str, (state)->fp_out) -#define state_putc(str, state) fputc(str, (state)->fp_out) +#define state_puts(STATE, STR) fputs(STR, (STATE)->fp_out) +#define state_putc(STATE, STR) fputc(STR, (STATE)->fp_out) -void state_mark_attach(struct State *s); -void state_mark_protected_header (struct State *s); -void state_attach_puts(const char *t, struct State *s); -void state_prefix_putc(char c, struct State *s); -int state_printf(struct State *s, const char *fmt, ...); -int state_putws(const wchar_t *ws, struct State *s); -void state_prefix_put(const char *buf, size_t buflen, struct State *s); +void state_attach_puts (struct State *s, const char *t); +void state_mark_attach (struct State *s); +void state_mark_protected_header(struct State *s); +void state_prefix_put (struct State *s, const char *buf, size_t buflen); +void state_prefix_putc (struct State *s, char c); +int state_printf (struct State *s, const char *fmt, ...); +int state_putws (struct State *s, const wchar_t *ws); #endif /* MUTT_STATE_H */