From b68199f8a07bb0cf5e897454ce98368bf2e50703 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Sat, 3 Dec 2011 11:13:10 -0800 Subject: [PATCH] Declare many structures const (closes #3552) Many structs used in mutt are actually constant but are defined without the 'const' keyword. This can slow initialization (slightly) in some environments due to extra copying and increases the amount of writable RAM required at run-time, which can be significant on non-MMU systems. Using const can also increase the opportunities for compiler optimization. The attached patch marks many such structures as const. On my test x86 build, this reduces the size of .data by over 50%. --- addrbook.c | 2 +- browser.c | 2 +- charset.c | 6 +++--- color.c | 6 +++--- compose.c | 4 ++-- crypt-gpgme.c | 4 ++-- curs_lib.c | 4 ++-- curs_main.c | 2 +- date.c | 4 ++-- enter.c | 2 +- functions.h | 26 +++++++++++++------------- globals.h | 12 ++++++------ handler.c | 6 +++--- help.c | 14 +++++++------- imap/auth.c | 4 ++-- imap/command.c | 2 +- imap/message.c | 2 +- imap/utf7.c | 4 ++-- imap/util.c | 3 ++- init.c | 17 +++++++++-------- init.h | 2 +- keymap.c | 24 ++++++++++++------------ keymap.h | 31 +++++++++++++++---------------- lib.c | 6 +++--- mapping.h | 6 +++--- mime.h | 6 +++--- mutt_ssl.c | 2 +- pager.c | 4 ++-- parse.c | 2 +- pattern.c | 6 +++--- pgpkey.c | 2 +- pgpmicalg.c | 2 +- pop_auth.c | 4 ++-- postpone.c | 2 +- protos.h | 2 +- query.c | 2 +- recvattach.c | 2 +- remailer.c | 2 +- rfc2047.c | 2 +- rfc822.c | 2 +- rfc822.h | 2 +- sendlib.c | 2 +- url.c | 2 +- 43 files changed, 122 insertions(+), 121 deletions(-) diff --git a/addrbook.c b/addrbook.c index 7d82cf578..8767a00fc 100644 --- a/addrbook.c +++ b/addrbook.c @@ -33,7 +33,7 @@ #define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x -static struct mapping_t AliasHelp[] = { +static const struct mapping_t AliasHelp[] = { { N_("Exit"), OP_EXIT }, { N_("Del"), OP_DELETE }, { N_("Undel"), OP_UNDELETE }, diff --git a/browser.c b/browser.c index 3cc249392..cda4900a3 100644 --- a/browser.c +++ b/browser.c @@ -42,7 +42,7 @@ #include #include -static struct mapping_t FolderHelp[] = { +static const struct mapping_t FolderHelp[] = { { N_("Exit"), OP_EXIT }, { N_("Chdir"), OP_CHANGE_DIRECTORY }, { N_("Mask"), OP_ENTER_MASK }, diff --git a/charset.c b/charset.c index fd011a495..9dd278ee5 100644 --- a/charset.c +++ b/charset.c @@ -50,10 +50,10 @@ * a preferred MIME name is given. */ -static struct +static const const struct { - char *key; - char *pref; + const char *key; + const char *pref; } PreferredMIMENames[] = { diff --git a/color.c b/color.c index b39957f0c..db8266d0b 100644 --- a/color.c +++ b/color.c @@ -55,7 +55,7 @@ typedef struct color_list static COLOR_LIST *ColorList = NULL; static int UserColors = 0; -static struct mapping_t Colors[] = +static const struct mapping_t Colors[] = { { "black", COLOR_BLACK }, { "blue", COLOR_BLUE }, @@ -73,7 +73,7 @@ static struct mapping_t Colors[] = #endif /* HAVE_COLOR */ -static struct mapping_t Fields[] = +static const struct mapping_t Fields[] = { { "hdrdefault", MT_COLOR_HDEFAULT }, { "quoted", MT_COLOR_QUOTED }, @@ -159,7 +159,7 @@ void ci_start_color (void) #ifdef USE_SLANG_CURSES static char *get_color_name (char *dest, size_t destlen, int val) { - static char * missing[3] = {"brown", "lightgray", "default"}; + static const char * const missing[3] = {"brown", "lightgray", "default"}; int i; switch (val) diff --git a/compose.c b/compose.c index 3b7cb1730..edda021da 100644 --- a/compose.c +++ b/compose.c @@ -74,7 +74,7 @@ enum #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */ #define W (COLS - HDR_XOFFSET) -static char *Prompts[] = +static const char * const Prompts[] = { "From: ", "To: ", @@ -85,7 +85,7 @@ static char *Prompts[] = "Fcc: " }; -static struct mapping_t ComposeHelp[] = { +static const struct mapping_t ComposeHelp[] = { { N_("Send"), OP_COMPOSE_SEND_MESSAGE }, { N_("Abort"), OP_EXIT }, { "To", OP_COMPOSE_EDIT_TO }, diff --git a/crypt-gpgme.c b/crypt-gpgme.c index b1da88bfc..3ef629db0 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -129,7 +129,7 @@ static char *current_sender = NULL; * General helper functions. */ -/* return true when S pints to a didgit or letter. */ +/* return true when s points to a digit or letter. */ static int digit_or_letter (const unsigned char *s) { @@ -2923,7 +2923,7 @@ print_dn_part (FILE *fp, struct dn_array_s *dn, const char *key) static void print_dn_parts (FILE *fp, struct dn_array_s *dn) { - const char *stdpart[] = { + static const char * const stdpart[] = { "CN", "OU", "O", "STREET", "L", "ST", "C", NULL }; int any=0, any2=0, i; diff --git a/curs_lib.c b/curs_lib.c index 7f88cc936..291149062 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -129,7 +129,7 @@ event_t mutt_getch (void) return (ch == ctrl ('G') ? err : ret); } -int _mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles) +int _mutt_get_field (const char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles) { int ret; int x, y; @@ -139,7 +139,7 @@ int _mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int comp do { CLEARLINE (LINES-1); - addstr (field); + addstr ((char *)field); /* cast to get around bad prototypes */ mutt_refresh (); getyx (stdscr, y, x); ret = _mutt_enter_string (buf, buflen, y, x, complete, multiple, files, numfiles, es); diff --git a/curs_main.c b/curs_main.c index dd2ac3986..302082b49 100644 --- a/curs_main.c +++ b/curs_main.c @@ -401,7 +401,7 @@ static void resort_index (MUTTMENU *menu) menu->redraw = REDRAW_INDEX | REDRAW_STATUS; } -static struct mapping_t IndexHelp[] = { +static const struct mapping_t IndexHelp[] = { { N_("Quit"), OP_QUIT }, { N_("Del"), OP_DELETE }, { N_("Undel"), OP_UNDELETE }, diff --git a/date.c b/date.c index a2f000486..0cd831228 100644 --- a/date.c +++ b/date.c @@ -69,7 +69,7 @@ time_t mutt_mktime (struct tm *t, int local) { time_t g; - static int AccumDaysPerMonth[12] = { + static const int AccumDaysPerMonth[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; @@ -118,7 +118,7 @@ static int isLeapYearFeb (struct tm *tm) void mutt_normalize_time (struct tm *tm) { - static char DaysPerMonth[12] = { + static const char DaysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int nLeap; diff --git a/enter.c b/enter.c index 9f8a45e60..ac083f5c6 100644 --- a/enter.c +++ b/enter.c @@ -191,7 +191,7 @@ static void replace_part (ENTER_STATE *state, size_t from, char *buf) */ static inline int is_shell_char(wchar_t ch) { - static wchar_t shell_chars[] = L"<>&()$?*;{}| "; /* ! not included because it can be part of a pathname in Mutt */ + static const wchar_t shell_chars[] = L"<>&()$?*;{}| "; /* ! not included because it can be part of a pathname in Mutt */ return wcschr(shell_chars, ch) != NULL; } diff --git a/functions.h b/functions.h index e8beacb4c..7a1c5a9f1 100644 --- a/functions.h +++ b/functions.h @@ -38,7 +38,7 @@ # include "doc/makedoc-defs.h" #endif -struct binding_t OpGeneric[] = { /* map: generic */ +const struct binding_t OpGeneric[] = { /* map: generic */ /* ** ** The generic menu is not a real menu, but specifies common functions @@ -82,7 +82,7 @@ struct binding_t OpGeneric[] = { /* map: generic */ { NULL, 0, NULL } }; -struct binding_t OpMain[] = { /* map: index */ +const struct binding_t OpMain[] = { /* map: index */ { "create-alias", OP_CREATE_ALIAS, "a" }, { "bounce-message", OP_BOUNCE_MESSAGE, "b" }, { "break-thread", OP_MAIN_BREAK_THREAD, "#" }, @@ -172,7 +172,7 @@ struct binding_t OpMain[] = { /* map: index */ { NULL, 0, NULL } }; -struct binding_t OpPager[] = { /* map: pager */ +const struct binding_t OpPager[] = { /* map: pager */ { "break-thread", OP_MAIN_BREAK_THREAD, "#" }, { "create-alias", OP_CREATE_ALIAS, "a" }, { "bounce-message", OP_BOUNCE_MESSAGE, "b" }, @@ -275,7 +275,7 @@ struct binding_t OpPager[] = { /* map: pager */ { NULL, 0, NULL } }; -struct binding_t OpAttach[] = { /* map: attachment */ +const struct binding_t OpAttach[] = { /* map: attachment */ { "bounce-message", OP_BOUNCE_MESSAGE, "b" }, { "display-toggle-weed", OP_DISPLAY_HEADERS, "h" }, { "edit-type", OP_EDIT_TYPE, "\005" }, @@ -301,7 +301,7 @@ struct binding_t OpAttach[] = { /* map: attachment */ { NULL, 0, NULL } }; -struct binding_t OpCompose[] = { /* map: compose */ +const struct binding_t OpCompose[] = { /* map: compose */ { "attach-file", OP_COMPOSE_ATTACH_FILE, "a" }, { "attach-message", OP_COMPOSE_ATTACH_MESSAGE, "A" }, { "edit-bcc", OP_COMPOSE_EDIT_BCC, "b" }, @@ -351,13 +351,13 @@ struct binding_t OpCompose[] = { /* map: compose */ { NULL, 0, NULL } }; -struct binding_t OpPost[] = { /* map: postpone */ +const struct binding_t OpPost[] = { /* map: postpone */ { "delete-entry", OP_DELETE, "d" }, { "undelete-entry", OP_UNDELETE, "u" }, { NULL, 0, NULL } }; -struct binding_t OpAlias[] = { /* map: alias */ +const struct binding_t OpAlias[] = { /* map: alias */ { "delete-entry", OP_DELETE, "d" }, { "undelete-entry", OP_UNDELETE, "u" }, { NULL, 0, NULL } @@ -365,7 +365,7 @@ struct binding_t OpAlias[] = { /* map: alias */ /* The file browser */ -struct binding_t OpBrowser[] = { /* map: browser */ +const struct binding_t OpBrowser[] = { /* map: browser */ { "change-dir", OP_CHANGE_DIRECTORY, "c" }, { "display-filename", OP_BROWSER_TELL, "@" }, { "enter-mask", OP_ENTER_MASK, "m" }, @@ -388,7 +388,7 @@ struct binding_t OpBrowser[] = { /* map: browser */ }; /* External Query Menu */ -struct binding_t OpQuery[] = { /* map: query */ +const struct binding_t OpQuery[] = { /* map: query */ { "create-alias", OP_CREATE_ALIAS, "a" }, { "mail", OP_MAIL, "m" }, { "query", OP_QUERY, "Q" }, @@ -396,7 +396,7 @@ struct binding_t OpQuery[] = { /* map: query */ { NULL, 0, NULL } }; -struct binding_t OpEditor[] = { /* map: editor */ +const struct binding_t OpEditor[] = { /* map: editor */ { "bol", OP_EDITOR_BOL, "\001" }, { "backward-char", OP_EDITOR_BACKWARD_CHAR, "\002" }, { "backward-word", OP_EDITOR_BACKWARD_WORD, "\033b"}, @@ -424,7 +424,7 @@ struct binding_t OpEditor[] = { /* map: editor */ -struct binding_t OpPgp[] = { /* map: pgp */ +const struct binding_t OpPgp[] = { /* map: pgp */ { "verify-key", OP_VERIFY_KEY, "c" }, { "view-name", OP_VIEW_ID, "%" }, { NULL, 0, NULL } @@ -434,7 +434,7 @@ struct binding_t OpPgp[] = { /* map: pgp */ /* When using the GPGME based backend we have some useful functions for the SMIME menu. */ -struct binding_t OpSmime[] = { /* map: smime */ +const struct binding_t OpSmime[] = { /* map: smime */ #ifdef CRYPT_BACKEND_GPGME { "verify-key", OP_VERIFY_KEY, "c" }, { "view-name", OP_VIEW_ID, "%" }, @@ -445,7 +445,7 @@ struct binding_t OpSmime[] = { /* map: smime */ #ifdef MIXMASTER -struct binding_t OpMix[] = { /* map: mixmaster */ +const struct binding_t OpMix[] = { /* map: mixmaster */ { "accept", OP_MIX_USE, M_ENTER_S }, { "append", OP_MIX_APPEND, "a" }, { "insert", OP_MIX_INSERT, "i" }, diff --git a/globals.h b/globals.h index 5aec53007..6fefe5b03 100644 --- a/globals.h +++ b/globals.h @@ -266,14 +266,14 @@ WHERE char *SmimeGetCertEmailCommand; #ifdef MAIN_C -const char *Weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; -const char *Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "ERR" }; +const char * const Weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; +const char * const Months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "ERR" }; -const char *BodyTypes[] = { "x-unknown", "audio", "application", "image", "message", "model", "multipart", "text", "video" }; -const char *BodyEncodings[] = { "x-unknown", "7bit", "8bit", "quoted-printable", "base64", "binary", "x-uuencoded" }; +const char * const BodyTypes[] = { "x-unknown", "audio", "application", "image", "message", "model", "multipart", "text", "video" }; +const char * const BodyEncodings[] = { "x-unknown", "7bit", "8bit", "quoted-printable", "base64", "binary", "x-uuencoded" }; #else -extern const char *Weekdays[]; -extern const char *Months[]; +extern const char * const Weekdays[]; +extern const char * const Months[]; #endif #ifdef MAIN_C diff --git a/handler.c b/handler.c index 39b7979bc..13c89ecc5 100644 --- a/handler.c +++ b/handler.c @@ -43,7 +43,7 @@ typedef int (*handler_t) (BODY *, STATE *); -int Index_hex[128] = { +const int Index_hex[128] = { -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, @@ -54,7 +54,7 @@ int Index_hex[128] = { -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1 }; -int Index_64[128] = { +const int Index_64[128] = { -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63, @@ -434,7 +434,7 @@ enum { RICH_PARAM=0, RICH_BOLD, RICH_UNDERLINE, RICH_ITALIC, RICH_NOFILL, RICH_INDENT, RICH_INDENT_RIGHT, RICH_EXCERPT, RICH_CENTER, RICH_FLUSHLEFT, RICH_FLUSHRIGHT, RICH_COLOR, RICH_LAST_TAG }; -static struct { +static const struct { const wchar_t *tag_name; int index; } EnrichedTags[] = { diff --git a/help.c b/help.c index 6d54059fd..c1d2d0c69 100644 --- a/help.c +++ b/help.c @@ -31,10 +31,10 @@ #include #include -static struct binding_t *help_lookupFunction (int op, int menu) +static const struct binding_t *help_lookupFunction (int op, int menu) { int i; - struct binding_t *map; + const struct binding_t *map; if (menu != MENU_PAGER) { @@ -66,7 +66,7 @@ void mutt_make_help (char *d, size_t dlen, char *txt, int menu, int op) } char * -mutt_compile_help (char *buf, size_t buflen, int menu, struct mapping_t *items) +mutt_compile_help (char *buf, size_t buflen, int menu, const struct mapping_t *items) { int i; size_t len; @@ -282,7 +282,7 @@ static void format_line (FILE *f, int ismacro, static void dump_menu (FILE *f, int menu) { struct keymap_t *map; - struct binding_t *b; + const struct binding_t *b; char buf[SHORT_STRING]; /* browse through the keymap table */ @@ -318,7 +318,7 @@ static int is_bound (struct keymap_t *map, int op) } static void dump_unbound (FILE *f, - struct binding_t *funcs, + const struct binding_t *funcs, struct keymap_t *map, struct keymap_t *aux) { @@ -336,9 +336,9 @@ void mutt_help (int menu) { char t[_POSIX_PATH_MAX]; char buf[SHORT_STRING]; - char *desc; + const char *desc; FILE *f; - struct binding_t *funcs; + const struct binding_t *funcs; mutt_mktemp (t, sizeof (t)); diff --git a/imap/auth.c b/imap/auth.c index 6ac292517..8a7f0789d 100644 --- a/imap/auth.c +++ b/imap/auth.c @@ -28,7 +28,7 @@ #include "imap_private.h" #include "auth.h" -static imap_auth_t imap_authenticators[] = { +static const imap_auth_t imap_authenticators[] = { #ifdef USE_SASL { imap_auth_sasl, NULL }, #else @@ -50,7 +50,7 @@ static imap_auth_t imap_authenticators[] = { * authentication method if specified, or any. */ int imap_authenticate (IMAP_DATA* idata) { - imap_auth_t* authenticator; + const imap_auth_t* authenticator; char* methods; char* method; char* delim; diff --git a/imap/command.c b/imap/command.c index 18e1a57c3..70e7d4814 100644 --- a/imap/command.c +++ b/imap/command.c @@ -53,7 +53,7 @@ static void cmd_parse_myrights (IMAP_DATA* idata, const char* s); static void cmd_parse_search (IMAP_DATA* idata, const char* s); static void cmd_parse_status (IMAP_DATA* idata, char* s); -static char *Capabilities[] = { +static const char * const Capabilities[] = { "IMAP4", "IMAP4rev1", "STATUS", diff --git a/imap/message.c b/imap/message.c index 3c7a38e89..d318b6935 100644 --- a/imap/message.c +++ b/imap/message.c @@ -71,7 +71,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) int rc, mfhrc, oldmsgcount; int fetchlast = 0; int maxuid = 0; - const char *want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL"; + static const char * const want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL"; progress_t progress; int retval = -1; diff --git a/imap/utf7.c b/imap/utf7.c index cf2ecb4ed..a433971c4 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -24,7 +24,7 @@ #include "charset.h" #include "imap_private.h" -static int Index_64[128] = { +static const int Index_64[128] = { -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, 63,-1,-1,-1, @@ -35,7 +35,7 @@ static int Index_64[128] = { 41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1 }; -static char B64Chars[64] = { +static const char B64Chars[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', diff --git a/imap/util.c b/imap/util.c index b38268e22..f7e0ef5aa 100644 --- a/imap/util.c +++ b/imap/util.c @@ -612,7 +612,8 @@ void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path) * surround string with quotes, escape " and \ with \ */ void imap_quote_string (char *dest, size_t dlen, const char *src) { - char quote[] = "\"\\", *pt; + static const char quote[] = "\"\\"; + char *pt; const char *s; pt = dest; diff --git a/init.c b/init.c index 7773a920a..efdba2dbb 100644 --- a/init.c +++ b/init.c @@ -1691,7 +1691,8 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) { int query, unset, inv, reset, r = 0; int idx = -1; - char *p, scratch[_POSIX_PATH_MAX]; + const char *p; + char scratch[_POSIX_PATH_MAX]; char* myvar; while (MoreArgs (s)) @@ -2113,7 +2114,7 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) { if (query) { - char *vals[] = { "no", "yes", "ask-no", "ask-yes" }; + static const char * const vals[] = { "no", "yes", "ask-no", "ask-yes" }; snprintf (err->data, err->dsize, "%s=%s", MuttVars[idx].option, vals [ quadoption (MuttVars[idx].data) ]); @@ -2481,7 +2482,7 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs) || !mutt_strncmp (buffer, "reset", 5) || !mutt_strncmp (buffer, "toggle", 6)) { /* complete variables */ - char *prefixes[] = { "no", "inv", "?", "&", 0 }; + static const char * const prefixes[] = { "no", "inv", "?", "&", 0 }; pt++; /* loop through all the possible prefixes (no, inv, ...) */ @@ -2533,7 +2534,7 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs) } else if (!mutt_strncmp (buffer, "exec", 4)) { - struct binding_t *menu = km_get_table (CurrentMenu); + const struct binding_t *menu = km_get_table (CurrentMenu); if (!menu && CurrentMenu != MENU_PAGER) menu = OpGeneric; @@ -2632,7 +2633,7 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos) static int var_to_string (int idx, char* val, size_t len) { char tmp[LONG_STRING]; - char *vals[] = { "no", "yes", "ask-no", "ask-yes" }; + static const char * const vals[] = { "no", "yes", "ask-no", "ask-yes" }; tmp[0] = '\0'; @@ -2663,7 +2664,7 @@ static int var_to_string (int idx, char* val, size_t len) else if (DTYPE (MuttVars[idx].type) == DT_SORT) { const struct mapping_t *map; - char *p; + const char *p; switch (MuttVars[idx].type & DT_SUBTYPE_MASK) { @@ -2789,7 +2790,7 @@ int mutt_dump_variables (void) return 0; } -char *mutt_getnamebyvalue (int val, const struct mapping_t *map) +const char *mutt_getnamebyvalue (int val, const struct mapping_t *map) { int i; @@ -3150,7 +3151,7 @@ void mutt_init (int skip_sys_rc, LIST *commands) int mutt_get_hook_type (const char *name) { - struct command_t *c; + const struct command_t *c; for (c = Commands ; c->name ; c++) if (c->func == mutt_parse_hook && ascii_strcasecmp (c->name, name) == 0) diff --git a/init.h b/init.h index 09dfbf28f..360886a1e 100644 --- a/init.h +++ b/init.h @@ -3488,7 +3488,7 @@ struct command_t unsigned long data; }; -struct command_t Commands[] = { +const struct command_t Commands[] = { { "alternates", parse_alternates, 0 }, { "unalternates", parse_unalternates, 0 }, #ifdef USE_SOCKET diff --git a/keymap.c b/keymap.c index d82310a7b..56ec05d3e 100644 --- a/keymap.c +++ b/keymap.c @@ -36,7 +36,7 @@ #include "functions.h" -struct mapping_t Menus[] = { +const struct mapping_t Menus[] = { { "alias", MENU_ALIAS }, { "attach", MENU_ATTACH }, { "browser", MENU_FOLDER }, @@ -298,7 +298,7 @@ void km_bindkey (char *s, int menu, int op) km_bind (s, menu, op, NULL, NULL); } -static int get_op (struct binding_t *bindings, const char *start, size_t len) +static int get_op (const struct binding_t *bindings, const char *start, size_t len) { int i; @@ -312,7 +312,7 @@ static int get_op (struct binding_t *bindings, const char *start, size_t len) return OP_NULL; } -static char *get_func (struct binding_t *bindings, int op) +static char *get_func (const struct binding_t *bindings, int op) { int i; @@ -366,7 +366,7 @@ static void push_string (char *s) * skip the '<' and the '>' when comparing */ for (i = 0; Menus[i].name; i++) { - struct binding_t *binding = km_get_table (Menus[i].value); + const struct binding_t *binding = km_get_table (Menus[i].value); if (binding) { op = get_op (binding, pp + 1, l - 2); @@ -465,7 +465,7 @@ int km_dokey (int menu) if (tmp.op) { char *func = NULL; - struct binding_t *bindings; + const struct binding_t *bindings; /* is this a valid op for this menu? */ if ((bindings = km_get_table (menu)) && @@ -540,7 +540,7 @@ int km_dokey (int menu) /* not reached */ } -static void create_bindings (struct binding_t *map, int menu) +static void create_bindings (const struct binding_t *map, int menu) { int i; @@ -549,10 +549,10 @@ static void create_bindings (struct binding_t *map, int menu) km_bindkey (map[i].seq, menu, map[i].op); } -char *km_keyname (int c) +static const char *km_keyname (int c) { static char buf[10]; - char *p; + const char *p; if ((p = mutt_getnamebyvalue (c, KeyNames))) return p; @@ -911,7 +911,7 @@ error: } static int -try_bind (char *key, int menu, char *func, struct binding_t *bindings) +try_bind (char *key, int menu, char *func, const struct binding_t *bindings) { int i; @@ -924,7 +924,7 @@ try_bind (char *key, int menu, char *func, struct binding_t *bindings) return (-1); } -struct binding_t *km_get_table (int menu) +const struct binding_t *km_get_table (int menu) { switch (menu) { @@ -971,7 +971,7 @@ struct binding_t *km_get_table (int menu) /* bind menu-name '' function-name */ int mutt_parse_bind (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) { - struct binding_t *bindings = NULL; + const struct binding_t *bindings = NULL; char *key; int menu[sizeof(Menus)/sizeof(struct mapping_t)-1], r = 0, nummenus, i; @@ -1072,7 +1072,7 @@ int mutt_parse_exec (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) { int ops[128]; int nops = 0; - struct binding_t *bindings = NULL; + const struct binding_t *bindings = NULL; char *function; if (!MoreArgs (s)) diff --git a/keymap.h b/keymap.h index 20212fd5b..e5c85dea9 100644 --- a/keymap.h +++ b/keymap.h @@ -45,7 +45,6 @@ struct keymap_t keycode_t *keys; /* key sequence */ }; -char *km_keyname (int); int km_expand_key (char *, size_t, struct keymap_t *); struct keymap_t *km_find_func (int, int); void km_init (void); @@ -89,7 +88,7 @@ extern struct keymap_t *Keymaps[]; /* dokey() records the last real key pressed */ extern int LastKey; -extern struct mapping_t Menus[]; +extern const struct mapping_t Menus[]; struct binding_t { @@ -98,25 +97,25 @@ struct binding_t char *seq; /* default key binding */ }; -struct binding_t *km_get_table (int menu); +const struct binding_t *km_get_table (int menu); -extern struct binding_t OpGeneric[]; -extern struct binding_t OpPost[]; -extern struct binding_t OpMain[]; -extern struct binding_t OpAttach[]; -extern struct binding_t OpPager[]; -extern struct binding_t OpCompose[]; -extern struct binding_t OpBrowser[]; -extern struct binding_t OpEditor[]; -extern struct binding_t OpQuery[]; -extern struct binding_t OpAlias[]; +extern const struct binding_t OpGeneric[]; +extern const struct binding_t OpPost[]; +extern const struct binding_t OpMain[]; +extern const struct binding_t OpAttach[]; +extern const struct binding_t OpPager[]; +extern const struct binding_t OpCompose[]; +extern const struct binding_t OpBrowser[]; +extern const struct binding_t OpEditor[]; +extern const struct binding_t OpQuery[]; +extern const struct binding_t OpAlias[]; -extern struct binding_t OpPgp[]; +extern const struct binding_t OpPgp[]; -extern struct binding_t OpSmime[]; +extern const struct binding_t OpSmime[]; #ifdef MIXMASTER -extern struct binding_t OpMix[]; +extern const struct binding_t OpMix[]; #endif #include "keymap_defs.h" diff --git a/lib.c b/lib.c index 17cc5160b..9662760d7 100644 --- a/lib.c +++ b/lib.c @@ -53,7 +53,7 @@ #include "lib.h" -static struct sysexits +static const struct sysexits { int v; const char *str; @@ -696,7 +696,7 @@ FILE *safe_fopen (const char *path, const char *mode) return (fopen (path, mode)); } -static char safe_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+@{}._-:%/"; +static const char safe_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+@{}._-:%/"; void mutt_sanitize_filename (char *f, short slash) { @@ -711,7 +711,7 @@ void mutt_sanitize_filename (char *f, short slash) /* these characters must be escaped in regular expressions */ -static char rx_special_chars[] = "^.[$()|*+?{\\"; +static const char rx_special_chars[] = "^.[$()|*+?{\\"; int mutt_rx_sanitize_string (char *dest, size_t destlen, const char *src) { diff --git a/mapping.h b/mapping.h index 6f400575a..760c33a8f 100644 --- a/mapping.h +++ b/mapping.h @@ -21,12 +21,12 @@ struct mapping_t { - char *name; + const char *name; int value; }; -char *mutt_getnamebyvalue (int, const struct mapping_t *); -char *mutt_compile_help (char *, size_t, int, struct mapping_t *); +const char *mutt_getnamebyvalue (int, const struct mapping_t *); +char *mutt_compile_help (char *, size_t, int, const struct mapping_t *); int mutt_getvaluebyname (const char *, const struct mapping_t *); diff --git a/mime.h b/mime.h index aec907221..e0239be86 100644 --- a/mime.h +++ b/mime.h @@ -55,9 +55,9 @@ enum /* MIME encoding/decoding global vars */ #ifndef _SENDLIB_C -extern int Index_hex[]; -extern int Index_64[]; -extern char B64Chars[]; +extern const int Index_hex[]; +extern const int Index_64[]; +extern const char B64Chars[]; #endif #define hexval(c) Index_hex[(unsigned int)(c)] diff --git a/mutt_ssl.c b/mutt_ssl.c index 616a0681b..d727cc692 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -911,7 +911,7 @@ static int ssl_check_certificate (CONNECTION *conn, sslsockdata *data) static int interactive_check_cert (X509 *cert, int idx, int len) { - char *part[] = + static const char * const part[] = {"/CN=", "/Email=", "/O=", "/OU=", "/L=", "/ST=", "/C="}; char helpstr[LONG_STRING]; char buf[STRING]; diff --git a/pager.c b/pager.c index e19174cd0..ade00c5f2 100644 --- a/pager.c +++ b/pager.c @@ -1526,13 +1526,13 @@ upNLines (int nlines, struct line_t *info, int cur, int hiding) return cur; } -static struct mapping_t PagerHelp[] = { +static const struct mapping_t PagerHelp[] = { { N_("Exit"), OP_EXIT }, { N_("PrevPg"), OP_PREV_PAGE }, { N_("NextPg"), OP_NEXT_PAGE }, { NULL, 0 } }; -static struct mapping_t PagerHelpExtra[] = { +static const struct mapping_t PagerHelpExtra[] = { { N_("View Attachm."), OP_VIEW_ATTACHMENTS }, { N_("Del"), OP_DELETE }, { N_("Reply"), OP_REPLY }, diff --git a/parse.c b/parse.c index cba966229..9f227a8c5 100644 --- a/parse.c +++ b/parse.c @@ -672,7 +672,7 @@ static const char *uncomment_timezone (char *buf, size_t buflen, const char *tz) return buf; } -static struct tz_t +static const struct tz_t { char tzname[5]; unsigned char zhours; diff --git a/pattern.c b/pattern.c index dbd73bda2..310d2eed8 100644 --- a/pattern.c +++ b/pattern.c @@ -47,7 +47,7 @@ static int eat_date (pattern_t *pat, BUFFER *, BUFFER *); static int eat_range (pattern_t *pat, BUFFER *, BUFFER *); static int patmatch (const pattern_t *pat, const char *buf); -static struct pattern_flags +static const struct pattern_flags { int tag; /* character used to represent this op */ int op; /* operation to perform */ @@ -712,7 +712,7 @@ static int patmatch (const pattern_t* pat, const char* buf) return regexec (pat->p.rx, buf, 0, NULL, 0); } -static struct pattern_flags *lookup_tag (char tag) +static const struct pattern_flags *lookup_tag (char tag) { int i; @@ -774,7 +774,7 @@ pattern_t *mutt_pattern_comp (/* const */ char *s, int flags, BUFFER *err) int alladdr = 0; int or = 0; int implicit = 1; /* used to detect logical AND operator */ - struct pattern_flags *entry; + const struct pattern_flags *entry; char *p; char *buf; BUFFER ps; diff --git a/pgpkey.c b/pgpkey.c index 04bca9f78..dad51b0ea 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -52,7 +52,7 @@ struct pgp_cache static struct pgp_cache *id_defaults = NULL; -static char trust_flags[] = "?- +"; +static const char trust_flags[] = "?- +"; static char *pgp_key_abilities (int flags) { diff --git a/pgpmicalg.c b/pgpmicalg.c index 37519825f..c1ec37f50 100644 --- a/pgpmicalg.c +++ b/pgpmicalg.c @@ -35,7 +35,7 @@ #include #include -static struct +static const struct { short id; const char *name; diff --git a/pop_auth.c b/pop_auth.c index b750533ab..62663438c 100644 --- a/pop_auth.c +++ b/pop_auth.c @@ -277,7 +277,7 @@ static pop_auth_res_t pop_auth_user (POP_DATA *pop_data, const char *method) return POP_A_FAILURE; } -static pop_auth_t pop_authenticators[] = { +static const pop_auth_t pop_authenticators[] = { #ifdef USE_SASL { pop_auth_sasl, NULL }, #endif @@ -296,7 +296,7 @@ static pop_auth_t pop_authenticators[] = { int pop_authenticate (POP_DATA* pop_data) { ACCOUNT *acct = &pop_data->conn->account; - pop_auth_t* authenticator; + const pop_auth_t* authenticator; char* methods; char* comma; char* method; diff --git a/postpone.c b/postpone.c index fa3ec64d3..4c518200e 100644 --- a/postpone.c +++ b/postpone.c @@ -37,7 +37,7 @@ #include #include -static struct mapping_t PostponeHelp[] = { +static const struct mapping_t PostponeHelp[] = { { N_("Exit"), OP_EXIT }, { N_("Del"), OP_DELETE }, { N_("Undel"), OP_UNDELETE }, diff --git a/protos.h b/protos.h index 140dfc351..95611ed10 100644 --- a/protos.h +++ b/protos.h @@ -300,7 +300,7 @@ int _mutt_enter_fname (const char *, char *, size_t, int *, int, int, char ***, int mutt_enter_string (char *buf, size_t buflen, int y, int x, int flags); int _mutt_enter_string (char *, size_t, int, int, int, int, char ***, int *, ENTER_STATE *); #define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL) -int _mutt_get_field (char *, char *, size_t, int, int, char ***, int *); +int _mutt_get_field (const char *, char *, size_t, int, int, char ***, int *); int mutt_get_hook_type (const char *); int mutt_get_field_unbuffered (char *, char *, size_t, int); #define mutt_get_password(A,B,C) mutt_get_field_unbuffered(A,B,C,M_PASS) diff --git a/query.c b/query.c index f2464b955..b3b8f08b6 100644 --- a/query.c +++ b/query.c @@ -44,7 +44,7 @@ typedef struct entry QUERY *data; } ENTRY; -static struct mapping_t QueryHelp[] = { +static const struct mapping_t QueryHelp[] = { { N_("Exit"), OP_EXIT }, { N_("Mail"), OP_MAIL }, { N_("New Query"), OP_QUERY }, diff --git a/recvattach.c b/recvattach.c index d9d87bcce..31dfcadd5 100644 --- a/recvattach.c +++ b/recvattach.c @@ -49,7 +49,7 @@ static const char *Mailbox_is_read_only = N_("Mailbox is read-only."); break; \ } -static struct mapping_t AttachHelp[] = { +static const struct mapping_t AttachHelp[] = { { N_("Exit"), OP_EXIT }, { N_("Save"), OP_SAVE }, { N_("Pipe"), OP_PIPE }, diff --git a/remailer.c b/remailer.c index 3354540fb..06eae3e06 100644 --- a/remailer.c +++ b/remailer.c @@ -480,7 +480,7 @@ static int mix_chain_add (MIXCHAIN *chain, const char *s, return 0; } -static struct mapping_t RemailerHelp[] = +static const struct mapping_t RemailerHelp[] = { { N_("Append"), OP_MIX_APPEND }, { N_("Insert"), OP_MIX_INSERT }, diff --git a/rfc2047.c b/rfc2047.c index 2927b6f5d..b5e8704d1 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -234,7 +234,7 @@ static size_t b_encoder (char *s, ICONV_CONST char *d, size_t dlen, static size_t q_encoder (char *s, ICONV_CONST char *d, size_t dlen, const char *tocode) { - char hex[] = "0123456789ABCDEF"; + static const char hex[] = "0123456789ABCDEF"; char *s0 = s; memcpy (s, "=?", 2), s += 2; diff --git a/rfc822.c b/rfc822.c index 22f9d9bd3..fd54a71aa 100644 --- a/rfc822.c +++ b/rfc822.c @@ -51,7 +51,7 @@ const char RFC822Specials[] = "@.,:;<>[]\\\"()"; int RFC822Error = 0; /* these must defined in the same order as the numerated errors given in rfc822.h */ -const char *RFC822Errors[] = { +const char * const RFC822Errors[] = { "out of memory", "mismatched parenthesis", "mismatched quotes", diff --git a/rfc822.h b/rfc822.h index 0c48f75a9..ba11801c4 100644 --- a/rfc822.h +++ b/rfc822.h @@ -61,7 +61,7 @@ int rfc822_valid_msgid (const char *msgid); int rfc822_remove_from_adrlist (ADDRESS **a, const char *mailbox); extern int RFC822Error; -extern const char *RFC822Errors[]; +extern const char * const RFC822Errors[]; #define rfc822_error(x) RFC822Errors[x] #define rfc822_new_address() safe_calloc(1,sizeof(ADDRESS)) diff --git a/sendlib.c b/sendlib.c index 1ee7fb2b1..249d6a1d1 100644 --- a/sendlib.c +++ b/sendlib.c @@ -65,7 +65,7 @@ extern char RFC822Specials[]; const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t"; -char B64Chars[64] = { +const char B64Chars[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', diff --git a/url.c b/url.c index 347047cd9..1b583b506 100644 --- a/url.c +++ b/url.c @@ -32,7 +32,7 @@ #include -static struct mapping_t UrlMap[] = +static const struct mapping_t UrlMap[] = { { "file", U_FILE }, { "imap", U_IMAP }, -- 2.40.0