From 782435b0bc1f24e98019863c956e994fea0b0940 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 23 Oct 2019 19:20:38 +0100 Subject: [PATCH] tidy source - move once-used symbol - move statics to the top - kill blank lines - correct grammar in log - reduce scope of variable - add doxygen comments --- conn/ssl_gnutls.c | 25 +++++++----- copy.c | 4 +- enter.c | 1 - hdrline.c | 30 +++++++------- keymap.c | 92 +++++++++++++++++++++--------------------- mbox/mbox.c | 2 +- mutt/charset.c | 58 +++++++++++++------------- mutt/string.c | 10 ++--- mutt_lua.c | 6 +-- muttlib.c | 8 ++-- muttlib.h | 2 - ncrypt/pgpkey.c | 18 ++++----- nntp/nntp.c | 1 - notmuch/mutt_notmuch.c | 1 - pattern.c | 14 +++---- pop/pop_lib.c | 4 -- postpone.c | 2 - recvcmd.c | 2 +- remailer.c | 12 +++--- send.c | 6 +++ sendlib.c | 88 ++++++++++++++++++++-------------------- 21 files changed, 192 insertions(+), 194 deletions(-) diff --git a/conn/ssl_gnutls.c b/conn/ssl_gnutls.c index 31ccba782..98e12bf5a 100644 --- a/conn/ssl_gnutls.c +++ b/conn/ssl_gnutls.c @@ -67,6 +67,19 @@ const int dialog_row_len = 128; static int tls_socket_close(struct Connection *conn); +#ifndef HAVE_GNUTLS_PRIORITY_SET_DIRECT +/* This array needs to be large enough to hold all the possible values support + * by NeoMutt. The initialized values are just placeholders--the array gets + * overwrriten in tls_negotiate() depending on the $ssl_use_* options. + * + * Note: gnutls_protocol_set_priority() was removed in GnuTLS version + * 3.4 (2015-04). TLS 1.3 support wasn't added until version 3.6.5. + * Therefore, no attempt is made to support $ssl_use_tlsv1_3 in this code. + */ +static int protocol_priority[] = { GNUTLS_TLS1_2, GNUTLS_TLS1_1, GNUTLS_TLS1, + GNUTLS_SSL3, 0 }; +#endif + /** * struct TlsSockData - TLS socket data */ @@ -952,18 +965,8 @@ cleanup: mutt_buffer_pool_release(&priority); return rv; } -#else -/* This array needs to be large enough to hold all the possible values support - * by NeoMutt. The initialized values are just placeholders--the array gets - * overwrriten in tls_negotiate() depending on the $ssl_use_* options. - * - * Note: gnutls_protocol_set_priority() was removed in GnuTLS version - * 3.4 (2015-04). TLS 1.3 support wasn't added until version 3.6.5. - * Therefore, no attempt is made to support $ssl_use_tlsv1_3 in this code. - */ -static int protocol_priority[] = { GNUTLS_TLS1_2, GNUTLS_TLS1_1, GNUTLS_TLS1, - GNUTLS_SSL3, 0 }; +#else /** * tls_set_priority - Set the priority of various protocols * @param data TLS socket data diff --git a/copy.c b/copy.c index ccb25e8ac..6e6dc0c83 100644 --- a/copy.c +++ b/copy.c @@ -122,7 +122,6 @@ int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, } else if ((chflags & CH_NOQFROM) && mutt_str_startswith(buf, ">From ", CASE_IGNORE)) continue; - else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n'))) break; /* end of header */ @@ -173,7 +172,7 @@ int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, } } - mutt_debug(LL_DEBUG1, "WEED is %s\n", (chflags & CH_WEED) ? "Set" : "Not"); + mutt_debug(LL_DEBUG1, "WEED is %sset\n", (chflags & CH_WEED) ? "" : "not "); headers = mutt_mem_calloc(hdr_count, sizeof(char *)); @@ -617,7 +616,6 @@ int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e, { if (cmflags & MUTT_CM_PREFIX) chflags |= CH_PREFIX; - else if (e->attach_del && (chflags & CH_UPDATE_LEN)) { int new_lines; diff --git a/enter.c b/enter.c index 0c86de0e8..702ee3cc4 100644 --- a/enter.c +++ b/enter.c @@ -692,7 +692,6 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, replace_part(state, 0, buf); } - #endif else goto self_insert; diff --git a/hdrline.c b/hdrline.c index 815033af3..d8bdb77d0 100644 --- a/hdrline.c +++ b/hdrline.c @@ -93,6 +93,21 @@ enum CryptChars FLAG_CHAR_CRYPT_NO_CRYPTO, ///< Character denoting a message has no cryptography information }; +/** + * enum FieldType - Header types + * + * Strings for printing headers + */ +enum FieldType +{ + DISP_TO, ///< To: string + DISP_CC, ///< Cc: string + DISP_BCC, ///< Bcc: string + DISP_FROM, ///< From: string + DISP_PLAIN, ///< Empty string + DISP_MAX, +}; + /** * mutt_is_mail_list - Is this the email address of a mailing list? * @param addr Address to test @@ -230,21 +245,6 @@ static size_t add_index_color(char *buf, size_t buflen, MuttFormatFlags flags, c return 2; } -/** - * enum FieldType - Header types - * - * Strings for printing headers - */ -enum FieldType -{ - DISP_TO, ///< To: string - DISP_CC, ///< Cc: string - DISP_BCC, ///< Bcc: string - DISP_FROM, ///< From: string - DISP_PLAIN, ///< Empty string - DISP_MAX, -}; - /** * get_nth_wchar - Extract one char from a multi-byte table * @param table Multi-byte table diff --git a/keymap.c b/keymap.c index a6b64515a..c2257667a 100644 --- a/keymap.c +++ b/keymap.c @@ -148,6 +148,53 @@ int LastKey; /**< contains the last key the user pressed */ struct Keymap *Keymaps[MENU_MAX]; +#ifdef NCURSES_VERSION +/** + * struct Extkey - Map key names from NeoMutt's style to Curses style + */ +struct Extkey +{ + const char *name; + const char *sym; +}; + +static const struct Extkey ExtKeys[] = { + { "", "kUP5" }, + { "", "kUP" }, + { "", "kUP3" }, + + { "", "kDN" }, + { "", "kDN3" }, + { "", "kDN5" }, + + { "", "kRIT5" }, + { "", "kRIT" }, + { "", "kRIT3" }, + + { "", "kLFT" }, + { "", "kLFT3" }, + { "", "kLFT5" }, + + { "", "kHOM" }, + { "", "kHOM3" }, + { "", "kHOM5" }, + + { "", "kEND" }, + { "", "kEND3" }, + { "", "kEND5" }, + + { "", "kNXT" }, + { "", "kNXT3" }, + { "", "kNXT5" }, + + { "", "kPRV" }, + { "", "kPRV3" }, + { "", "kPRV5" }, + + { 0, 0 }, +}; +#endif + /** * alloc_keys - Allocate space for a sequence of keys * @param len Number of keys @@ -818,51 +865,6 @@ struct Keymap *km_find_func(enum MenuType menu, int func) } #ifdef NCURSES_VERSION -/** - * struct Extkey - Map key names from NeoMutt's style to Curses style - */ -struct Extkey -{ - const char *name; - const char *sym; -}; - -static const struct Extkey ExtKeys[] = { - { "", "kUP5" }, - { "", "kUP" }, - { "", "kUP3" }, - - { "", "kDN" }, - { "", "kDN3" }, - { "", "kDN5" }, - - { "", "kRIT5" }, - { "", "kRIT" }, - { "", "kRIT3" }, - - { "", "kLFT" }, - { "", "kLFT3" }, - { "", "kLFT5" }, - - { "", "kHOM" }, - { "", "kHOM3" }, - { "", "kHOM5" }, - - { "", "kEND" }, - { "", "kEND3" }, - { "", "kEND5" }, - - { "", "kNXT" }, - { "", "kNXT3" }, - { "", "kNXT5" }, - - { "", "kPRV" }, - { "", "kPRV3" }, - { "", "kPRV5" }, - - { 0, 0 }, -}; - /** * find_ext_name - Find the curses name for a key * @param key Key name diff --git a/mbox/mbox.c b/mbox/mbox.c index 69d5e3372..57f989f09 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -915,7 +915,7 @@ static FILE *mbox_open_readwrite(struct Mailbox *m) } /** - * mbox_open_readwrite - Open an mbox read-only + * mbox_open_readonly - Open an mbox read-only * @param m Mailbox * @retval ptr FILE handle * diff --git a/mutt/charset.c b/mutt/charset.c index 900aea320..69fbd988a 100644 --- a/mutt/charset.c +++ b/mutt/charset.c @@ -79,35 +79,6 @@ TAILQ_HEAD(LookupList, Lookup); static struct LookupList Lookups = TAILQ_HEAD_INITIALIZER(Lookups); -/** - * lookup_new - Create a new Lookup - * @retval ptr New Lookup - */ -struct Lookup *lookup_new(void) -{ - return mutt_mem_calloc(1, sizeof(struct Lookup)); -} - -/** - * lookup_free - Free a Lookup - * @param ptr Lookup to free - */ -void lookup_free(struct Lookup **ptr) -{ - if (!ptr || !*ptr) - return; - - struct Lookup *l = *ptr; - FREE(&l->replacement); - FREE(&l->regex.pattern); - if (l->regex.regex) - regfree(l->regex.regex); - FREE(&l->regex.regex); - FREE(&l->regex); - - FREE(ptr); -} - // clang-format off /** * PreferredMimeNames - Lookup table of preferred charsets @@ -263,6 +234,35 @@ const struct MimeNames PreferredMimeNames[] = }; // clang-format on +/** + * lookup_new - Create a new Lookup + * @retval ptr New Lookup + */ +struct Lookup *lookup_new(void) +{ + return mutt_mem_calloc(1, sizeof(struct Lookup)); +} + +/** + * lookup_free - Free a Lookup + * @param ptr Lookup to free + */ +void lookup_free(struct Lookup **ptr) +{ + if (!ptr || !*ptr) + return; + + struct Lookup *l = *ptr; + FREE(&l->replacement); + FREE(&l->regex.pattern); + if (l->regex.regex) + regfree(l->regex.regex); + FREE(&l->regex.regex); + FREE(&l->regex); + + FREE(ptr); +} + /** * lookup_charset - Look for a preferred character set name * @param type Type, e.g. #MUTT_LOOKUP_CHARSET diff --git a/mutt/string.c b/mutt/string.c index 4a582d7c3..afbb91fc9 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -46,6 +46,11 @@ #include #endif +/** + * char_cmp - Pointer to a function taking two characters and returning bool + */ +typedef bool (*char_cmp)(char, char); + /** * struct SysExits - Lookup table of error messages */ @@ -142,11 +147,6 @@ static inline bool char_cmp_lower(char a, char b) return tolower((unsigned char) a) == tolower((unsigned char) b); } -/** - * char_cmp - Pointer to a function taking two characters and returning bool - */ -typedef bool (*char_cmp)(char, char); - /** * get_char_cmp - Retrieve the correct function to compare characters according to a case sensitivity setting * @param cs Case sensitivity setting diff --git a/mutt_lua.c b/mutt_lua.c index eef3b6db0..2f3326e88 100644 --- a/mutt_lua.c +++ b/mutt_lua.c @@ -351,6 +351,8 @@ static void lua_expose_command(void *p, const struct Command *cmd) (void) luaL_dostring(l, buf); } +lua_State *LuaState = NULL; + static const luaL_Reg luaMuttDecl[] = { { "set", lua_mutt_set }, { "get", lua_mutt_get }, { "call", lua_mutt_call }, { "enter", lua_mutt_enter }, @@ -423,10 +425,6 @@ static bool lua_init(lua_State **l) return true; } -/* Public API --------------------------------------------------------------- */ - -lua_State *LuaState = NULL; - /** * mutt_lua_parse - Parse the 'lua' command - Implements ::command_t */ diff --git a/muttlib.c b/muttlib.c index 12fa9dc56..cf28d04d7 100644 --- a/muttlib.c +++ b/muttlib.c @@ -71,6 +71,10 @@ /* These Config Variables are only used in muttlib.c */ struct Regex *C_GecosMask; ///< Config: Regex for parsing GECOS field of /etc/passwd +static FILE *fp_random; + +static const unsigned char base32[] = "abcdefghijklmnopqrstuvwxyz234567"; + static const char *xdg_env_vars[] = { [XDG_CONFIG_HOME] = "XDG_CONFIG_HOME", [XDG_CONFIG_DIRS] = "XDG_CONFIG_DIRS", @@ -458,8 +462,6 @@ bool mutt_is_text_part(struct Body *b) return false; } -static FILE *fp_random; - /** * mutt_randbuf - Fill a buffer with randomness * @param buf Buffer for result @@ -505,8 +507,6 @@ int mutt_randbuf(void *buf, size_t buflen) return 0; } -static const unsigned char base32[] = "abcdefghijklmnopqrstuvwxyz234567"; - /** * mutt_rand_base32 - Fill a buffer with a base32-encoded random string * @param buf Buffer for result diff --git a/muttlib.h b/muttlib.h index 9628421dd..2b02b0b43 100644 --- a/muttlib.h +++ b/muttlib.h @@ -40,8 +40,6 @@ struct stat; /* These Config Variables are only used in muttlib.c */ extern struct Regex *C_GecosMask; -#define MUTT_RANDTAG_LEN 16 - void mutt_adv_mktemp(struct Buffer *buf); void mutt_buffer_mktemp_full(struct Buffer *buf, const char *prefix, const char *suffix, const char *src, int line); void mutt_buffer_encode_path(struct Buffer *buf, const char *src); diff --git a/ncrypt/pgpkey.c b/ncrypt/pgpkey.c index 9a39ad6b6..70e8b2102 100644 --- a/ncrypt/pgpkey.c +++ b/ncrypt/pgpkey.c @@ -79,6 +79,15 @@ struct PgpCache struct PgpCache *next; }; +/** + * struct PgpEntry - An entry in a PGP key menu + */ +struct PgpEntry +{ + size_t num; + struct PgpUid *uid; +}; + static struct PgpCache *id_defaults = NULL; static const char trust_flags[] = "?- +"; @@ -156,15 +165,6 @@ static struct PgpKeyInfo *pgp_principal_key(struct PgpKeyInfo *key) return key; } -/** - * struct PgpEntry - An entry in a PGP key menu - */ -struct PgpEntry -{ - size_t num; - struct PgpUid *uid; -}; - /** * pgp_entry_fmt - Format an entry on the PGP key selection menu - Implements ::format_t * diff --git a/nntp/nntp.c b/nntp/nntp.c index 0ced10413..299e8263b 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -629,7 +629,6 @@ static int nntp_auth(struct NntpAccountData *adata) if (*buf == '5') continue; } - else { #ifdef USE_SASL diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 3e55dac12..f23d3e98d 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -511,7 +511,6 @@ static char *get_query_string(struct NmMboxData *mdata, bool window) } else if (strcmp(item->name, "type") == 0) mdata->query_type = string_to_query_type(item->value); - else if (strcmp(item->name, "query") == 0) mdata->db_query = mutt_str_strdup(item->value); } diff --git a/pattern.c b/pattern.c index 6fcfccb4a..d9527f7a2 100644 --- a/pattern.c +++ b/pattern.c @@ -199,6 +199,13 @@ static struct PatternList *SearchPattern = NULL; /**< current search pattern */ static char LastSearch[256] = { 0 }; /**< last pattern searched for */ static char LastSearchExpn[1024] = { 0 }; /**< expanded version of LastSearch */ +/** + * typedef addr_predicate_t - Test an Address for some condition + * @param a Address to test + * @retval bool True if Address matches the test + */ +typedef bool (*addr_predicate_t)(const struct Address *a); + /** * eat_regex - Parse a regex - Implements ::pattern_eat_t */ @@ -1725,13 +1732,6 @@ static bool match_reference(struct Pattern *pat, struct ListHead *refs) return false; } -/** - * typedef addr_predicate_t - Test an Address for some condition - * @param a Address to test - * @retval bool True if Address matches the test - */ -typedef bool (*addr_predicate_t)(const struct Address *a); - /** * mutt_is_predicate_recipient - Test an Envelopes Addresses using a predicate function * @param all_addr If true, ALL Addresses must match diff --git a/pop/pop_lib.c b/pop/pop_lib.c index 6ac6baaea..e20708c9d 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -132,16 +132,12 @@ static int fetch_capa(const char *line, void *data) const char *c = mutt_str_skip_email_wsp(line + 4); mutt_buffer_strcpy(&adata->auth_list, c); } - else if (mutt_str_startswith(line, "STLS", CASE_IGNORE)) adata->cmd_stls = true; - else if (mutt_str_startswith(line, "USER", CASE_IGNORE)) adata->cmd_user = 1; - else if (mutt_str_startswith(line, "UIDL", CASE_IGNORE)) adata->cmd_uidl = 1; - else if (mutt_str_startswith(line, "TOP", CASE_IGNORE)) adata->cmd_top = 1; diff --git a/postpone.c b/postpone.c index 1661c1323..6d54c9874 100644 --- a/postpone.c +++ b/postpone.c @@ -409,7 +409,6 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr, hdr->security = mutt_parse_crypt_hdr(strchr(np->data, ':') + 1, true, APPLICATION_SMIME); hdr->security |= APPLICATION_SMIME; } - #ifdef MIXMASTER else if (mutt_str_startswith(np->data, "X-Mutt-Mix:", CASE_MATCH)) { @@ -423,7 +422,6 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr, } } #endif - else { // skip header removal diff --git a/recvcmd.c b/recvcmd.c index 00c655479..381febe3c 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -910,7 +910,6 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx, struct Email *e_parent = NULL; FILE *fp_parent = NULL; struct Email *e_tmp = NULL; - struct State st; FILE *fp_tmp = NULL; struct Buffer *tmpbody = NULL; @@ -987,6 +986,7 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx, { mutt_make_attribution(Context->mailbox, e_parent, fp_tmp); + struct State st; memset(&st, 0, sizeof(struct State)); st.fp_out = fp_tmp; diff --git a/remailer.c b/remailer.c index f31a027c5..5cd5799e5 100644 --- a/remailer.c +++ b/remailer.c @@ -72,6 +72,12 @@ struct Coord short c; /**< column */ }; +static const struct Mapping RemailerHelp[] = { + { N_("Append"), OP_MIX_APPEND }, { N_("Insert"), OP_MIX_INSERT }, + { N_("Delete"), OP_MIX_DELETE }, { N_("Abort"), OP_EXIT }, + { N_("OK"), OP_MIX_USE }, { NULL, 0 }, +}; + /** * mix_get_caps - Get Mixmaster Capabilities * @param capstr Capability string to parse @@ -552,12 +558,6 @@ static int mix_chain_add(struct MixChain *chain, const char *s, struct Remailer return 0; } -static const struct Mapping RemailerHelp[] = { - { N_("Append"), OP_MIX_APPEND }, { N_("Insert"), OP_MIX_INSERT }, - { N_("Delete"), OP_MIX_DELETE }, { N_("Abort"), OP_EXIT }, - { N_("OK"), OP_MIX_USE }, { NULL, 0 }, -}; - /** * mix_make_chain - Create a Mixmaster chain * @param win Window diff --git a/send.c b/send.c index 55cf05f42..b2abd6de3 100644 --- a/send.c +++ b/send.c @@ -704,6 +704,12 @@ static int include_reply(struct Mailbox *m, struct Email *e, FILE *fp_out) return 0; } +/** + * choose_default_to - Pick the best 'to:' value + * @param from From Address + * @param env Envelope + * @retval ptr Addresses to use + */ static const struct AddressList *choose_default_to(const struct Address *from, const struct Envelope *env) { diff --git a/sendlib.c b/sendlib.c index 56b55d2c8..b13d3691a 100644 --- a/sendlib.c +++ b/sendlib.c @@ -97,6 +97,51 @@ bool C_UseEnvelopeFrom; ///< Config: Set the envelope sender of the message bool C_UserAgent; ///< Config: Add a 'User-Agent' head to outgoing mail short C_WrapHeaders; ///< Config: Width to wrap headers in outgoing messages +#define MUTT_RANDTAG_LEN 16 + +/** + * struct B64Context - Cursor for the Base64 conversion + */ +struct B64Context +{ + char buffer[3]; + short size; + short linelen; +}; + +/** + * struct ContentState - Info about the body of an email + */ +struct ContentState +{ + bool from; + int whitespace; + bool dot; + int linelen; + bool was_cr; +}; + +/** + * The next array/enum pair is used to to keep track of user headers that + * override pre-defined headers NeoMutt would emit. Keep the array sorted and + * in sync with the enum. + */ +static const char *const userhdrs_override_headers[] = { + "content-type:", + "user-agent:", +}; + +enum UserHdrsOverrideIdx +{ + USERHDRS_OVERRIDE_CONTENT_TYPE, + USERHDRS_OVERRIDE_USER_AGENT, +}; + +struct UserHdrsOverride +{ + bool is_overridden[mutt_array_size(userhdrs_override_headers)]; +}; + /** * encode_quoted - Encode text as quoted printable * @param fc Cursor for converting a file's encoding @@ -231,16 +276,6 @@ static void encode_quoted(struct FgetConv *fc, FILE *fp_out, bool istext) } } -/** - * struct B64Context - Cursor for the Base64 conversion - */ -struct B64Context -{ - char buffer[3]; - short size; - short linelen; -}; - /** * b64_init - Set up the base64 conversion * @param bctx Cursor for the base64 conversion @@ -610,18 +645,6 @@ void mutt_generate_boundary(struct ParameterList *pl) mutt_param_set(pl, "boundary", rs); } -/** - * struct ContentState - Info about the body of an email - */ -struct ContentState -{ - bool from; - int whitespace; - bool dot; - int linelen; - bool was_cr; -}; - /** * update_content_info - Cache some info about an email * @param info Info about an Attachment @@ -2209,27 +2232,6 @@ out: return rc; } -/** - * The next array/enum pair is used to to keep track of user headers that - * override pre-defined headers NeoMutt would emit. Keep the array sorted and - * in sync with the enum. - */ -static const char *const userhdrs_override_headers[] = { - "content-type:", - "user-agent:", -}; - -enum UserHdrsOverrideIdx -{ - USERHDRS_OVERRIDE_CONTENT_TYPE, - USERHDRS_OVERRIDE_USER_AGENT, -}; - -struct UserHdrsOverride -{ - bool is_overridden[mutt_array_size(userhdrs_override_headers)]; -}; - /** * userhdrs_override_cmp - Compare a user-defined header with an element of the userhdrs_override_headers list * @param a Pointer to the string containing the user-defined header -- 2.40.0