From 4eaac5c4a87b84ea9ec0668b4e088ac27e2d1106 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 28 Oct 2006 03:20:13 +0200 Subject: [PATCH] more constness. simplifications. --- commands.c | 8 ++--- crypt.c | 2 +- edit.c | 2 +- handler.c | 12 +++---- hash.c | 2 +- hash.h | 2 +- hdrline.c | 2 +- help.c | 2 +- history.c | 4 +-- history.h | 4 +-- init.c | 89 +++++++++++++++++++++++++--------------------------- keymap.c | 6 ++-- mutt_crypt.h | 2 +- mutt_sasl.c | 4 +-- pgpkey.c | 2 +- remailer.c | 2 +- rfc2047.c | 4 +-- sendlib.c | 16 +++------- smime.c | 2 +- xterm.c | 4 +-- xterm.h | 4 +-- 21 files changed, 82 insertions(+), 93 deletions(-) diff --git a/commands.c b/commands.c index b71c77d..95a7d1d 100644 --- a/commands.c +++ b/commands.c @@ -350,8 +350,8 @@ static void pipe_msg (HEADER * h, FILE * fp, int decode, int print) /* the following code is shared between printing and piping */ -static int _mutt_pipe_message (HEADER * h, char *cmd, - int decode, int print, int split, char *sep) +static int _mutt_pipe_message(HEADER * h, char *cmd, int decode, int print, + int split, const char *sep) { int i, rc = 0; @@ -595,11 +595,11 @@ void mutt_enter_command (void) void mutt_display_address (ENVELOPE * env) { - char *pfx = NULL; + const char *pfx = NULL; char buf[SHORT_STRING]; ADDRESS *adr = NULL; - adr = mutt_get_address (env, &pfx); + adr = mutt_get_address(env, &pfx); if (!adr) return; diff --git a/crypt.c b/crypt.c index eac7a85..54d60fe 100644 --- a/crypt.c +++ b/crypt.c @@ -51,7 +51,7 @@ /* print the current time to avoid spoofing of the signature output */ -void crypt_current_time (STATE * s, char *app_name) +void crypt_current_time (STATE * s, const char *app_name) { time_t t; char p[STRING], tmp[STRING]; diff --git a/edit.c b/edit.c index 966d1be..ff581b0 100644 --- a/edit.c +++ b/edit.c @@ -35,7 +35,7 @@ * SLcurses_waddnstr() can't take a "const char *", so this is only * declared "static" (sigh) */ -static char *EditorHelp = N_("\ +static const char *EditorHelp = N_("\ ~~ insert a line begining with a single ~\n\ ~b users add users to the Bcc: field\n\ ~c users add users to the Cc: field\n\ diff --git a/handler.c b/handler.c index adce68c..7da0547 100644 --- a/handler.c +++ b/handler.c @@ -585,16 +585,16 @@ static void enriched_putc (int c, struct enriched_state *stte) static void enriched_puts (const char *s, struct enriched_state *stte) { - char *c; + const char *p; if (stte->buff_len < stte->buff_used + str_len (s)) { stte->buff_len += LONG_STRING; mem_realloc (&stte->buffer, stte->buff_len + 1); } - c = s; - while (*c) { - stte->buffer[stte->buff_used++] = *c; - c++; + + p = s; + while (*p) { + stte->buffer[stte->buff_used++] = *p++; } } @@ -1288,7 +1288,7 @@ void mutt_decode_attachment (BODY * b, STATE * s) if (istext) { if (s->flags & M_CHARCONV) { - char *charset = mutt_get_parameter ("charset", b->parameter); + const char *charset = mutt_get_parameter ("charset", b->parameter); if (!option (OPTSTRICTMIME) && !charset) charset = mutt_get_first_charset (AssumedCharset); diff --git a/hash.c b/hash.c index 0e2192b..72225be 100644 --- a/hash.c +++ b/hash.c @@ -77,7 +77,7 @@ HASH *hash_resize (HASH * ptr, int nelem) * data data to associate with `key' * allow_dup if nonzero, duplicate keys are allowed in the table */ -int hash_insert (HASH * table, const char *key, const void *data, int allow_dup) +int hash_insert (HASH * table, const char *key, void *data, int allow_dup) { struct hash_elem *ptr; int h; diff --git a/hash.h b/hash.h index 3c072c1..1a4f985 100644 --- a/hash.h +++ b/hash.h @@ -27,7 +27,7 @@ typedef struct { HASH *hash_create (int nelem); int hash_string (const unsigned char *s, int n); -int hash_insert (HASH * table, const char *key, const void *data, int allow_dup); +int hash_insert (HASH * table, const char *key, void *data, int allow_dup); HASH *hash_resize (HASH * table, int nelem); void *hash_find_hash (const HASH * table, int hash, const char *key); void hash_delete_hash (HASH * table, int hash, const char *key, diff --git a/hdrline.c b/hdrline.c index bd83a43..716a5df 100644 --- a/hdrline.c +++ b/hdrline.c @@ -48,7 +48,7 @@ int mutt_is_subscribed_list (ADDRESS * addr) * return 1. Otherwise, simply return 0. */ static int -check_for_mailing_list (ADDRESS * adr, char *pfx, char *buf, int buflen) +check_for_mailing_list (ADDRESS * adr, const char *pfx, char *buf, int buflen) { for (; adr; adr = adr->next) { if (mutt_is_subscribed_list (adr)) { diff --git a/help.c b/help.c index b9b896a..0545777 100644 --- a/help.c +++ b/help.c @@ -281,7 +281,7 @@ 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; diff --git a/history.c b/history.c index d61d0ce..66559c0 100644 --- a/history.c +++ b/history.c @@ -79,7 +79,7 @@ void mutt_history_add (history_class_t hclass, const char *s) h->cur = h->last; /* reset to the last entry */ } -char *mutt_history_next (history_class_t hclass) +const char *mutt_history_next (history_class_t hclass) { int next; struct history *h = &History[hclass]; @@ -94,7 +94,7 @@ char *mutt_history_next (history_class_t hclass) return (h->hist[h->cur] ? h->hist[h->cur] : ""); } -char *mutt_history_prev (history_class_t hclass) +const char *mutt_history_prev (history_class_t hclass) { int prev; struct history *h = &History[hclass]; diff --git a/history.h b/history.h index aa4038e..c053b96 100644 --- a/history.h +++ b/history.h @@ -26,7 +26,7 @@ typedef enum history_class history_class_t; void mutt_init_history (void); void mutt_history_add (history_class_t, const char *); -char *mutt_history_next (history_class_t); -char *mutt_history_prev (history_class_t); +const char *mutt_history_next (history_class_t); +const char *mutt_history_prev (history_class_t); #endif diff --git a/init.c b/init.c index e8c3b0a..6ac482f 100644 --- a/init.c +++ b/init.c @@ -206,7 +206,7 @@ static int bool_from_string (struct option_t* dst, const char* val, static void num_to_string (char* dst, size_t dstlen, struct option_t* option) { /* XXX puke */ - const char* fmt = (str_cmp (option->option, "umask") == 0) ? + const char* fmt = (str_cmp (option->option, "umask") == 0) ? "%s=%04o" : "%s=%d"; snprintf (dst, dstlen, fmt, option->option, *((short*) option->data)); @@ -277,8 +277,8 @@ static void sys_to_string (char* dst, size_t dstlen, * if name starts with $folder, just strip it to keep hierarchy * $folder=imap://host, path=imap://host/inbox/b -> inbox/b */ - if (Maildirlength > 0 && str_ncmp (CurrentFolder, Maildir, - Maildirlength) == 0 && + if (Maildirlength > 0 && str_ncmp (CurrentFolder, Maildir, + Maildirlength) == 0 && str_len (CurrentFolder) > Maildirlength) { val = CurrentFolder + Maildirlength; if (Maildir[strlen(Maildir)-1]!='/') @@ -379,15 +379,14 @@ static int quad_from_string (struct option_t* dst, const char* val, static void sort_to_string (char* dst, size_t dstlen, struct option_t* option) { const struct mapping_t *map = get_sortmap (option); - char* p = NULL; + const char *p = NULL; if (!map) { snprintf (dst, sizeof (dst), "%s=unknown", option->option); return; } - p = mutt_getnamebyvalue (*((short *) option->data) & SORT_MASK, - map); + p = mutt_getnamebyvalue(*((short *)option->data) & SORT_MASK, map); snprintf (dst, dstlen, "%s=%s%s%s", option->option, (*((short *) option->data) & SORT_REVERSE) ? @@ -1103,9 +1102,9 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, LIST **ldata, if (!buf->data || *buf->data == '\0') continue; - + a = mem_malloc(sizeof(ATTACH_MATCH)); - + /* some cheap hacks that I expect to remove */ if (!str_casecmp(buf->data, "any")) a->major = str_dup("*/.*"); @@ -1113,7 +1112,7 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, LIST **ldata, a->major = str_dup("cheap_hack/this_should_never_match"); else a->major = str_dup(buf->data); - + if ((p = strchr(a->major, '/'))) { *p = '\0'; ++p; @@ -1128,10 +1127,10 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, LIST **ldata, tmpminor[0] = '^'; tmpminor[len+1] = '$'; tmpminor[len+2] = '\0'; - + a->major_int = mutt_check_mime_type(a->major); regcomp(&a->minor_rx, tmpminor, REG_ICASE|REG_EXTENDED); - + mem_free (&tmpminor); debug_print (5, ("parse_attach_list: added %s/%s [%d]\n", @@ -1162,14 +1161,14 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *er do { mutt_extract_token (buf, s, 0); - + if (!str_casecmp(buf->data, "any")) tmp = str_dup("*/.*"); else if (!str_casecmp(buf->data, "none")) tmp = str_dup("cheap_hack/this_should_never_match"); else tmp = str_dup(buf->data); - + if ((minor = strchr(tmp, '/'))) { *minor = '\0'; ++minor; @@ -1177,7 +1176,7 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *er minor = "unknown"; } major = mutt_check_mime_type(tmp); - + /* We must do our own walk here because remove_from_list() will only * remove the LIST->data, not anything pointed to by the LIST->data. */ lastp = NULL; @@ -1190,26 +1189,26 @@ static int parse_unattach_list (BUFFER *buf, BUFFER *s, LIST **ldata, BUFFER *er a->major, a->minor, a->major_int)); regfree(&a->minor_rx); mem_free(&a->major); - + /* Relink backward */ if (lastp) lastp->next = lp->next; else *ldata = lp->next; - + newlp = lp->next; mem_free(&lp->data); /* same as a */ mem_free(&lp); lp = newlp; continue; } - + lastp = lp; lp = lp->next; } } while (MoreArgs (s)); - + mem_free (&tmp); _attachments_clean(); return 0; @@ -1222,23 +1221,23 @@ static int print_attach_list (LIST *lp, char op, const char *name) { ((ATTACH_MATCH *)lp->data)->minor); lp = lp->next; } - + return 0; } static int parse_attachments (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) { char op, *category; LIST **listp; - + mutt_extract_token(buf, s, 0); if (!buf->data || *buf->data == '\0') { strfcpy(err->data, _("attachments: no disposition"), err->dsize); return -1; } - + category = buf->data; op = *category++; - + if (op == '?') { mutt_endwin (NULL); fflush (stdout); @@ -1272,20 +1271,20 @@ static int parse_attachments (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER strfcpy(err->data, _("attachments: invalid disposition"), err->dsize); return -1; } - + return parse_attach_list(buf, s, listp, err); } static int parse_unattachments (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) { char op, *p; LIST **listp; - + mutt_extract_token(buf, s, 0); if (!buf->data || *buf->data == '\0') { strfcpy(err->data, _("unattachments: no disposition"), err->dsize); return -1; } - + p = buf->data; op = *p++; if (op != '+' && op != '-') { @@ -1308,7 +1307,7 @@ static int parse_unattachments (BUFFER *buf, BUFFER *s, unsigned long data, BUFF strfcpy(err->data, _("unattachments: invalid disposition"), err->dsize); return -1; } - + return parse_unattach_list(buf, s, listp, err); } @@ -1853,7 +1852,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, mutt_extract_token (tmp, s, M_TOKEN_EQUAL); /* resolve synonyms */ - if ((option = hash_find (ConfigOptions, tmp->data)) != NULL && + if ((option = hash_find (ConfigOptions, tmp->data)) != NULL && DTYPE (option->type == DT_SYN)) { struct option_t* newopt = hash_find (ConfigOptions, (char*) option->data); syn_add (newopt, option); @@ -2205,13 +2204,13 @@ finish: #define NUMVARS (sizeof (MuttVars)/sizeof (MuttVars[0])) #define NUMCOMMANDS (sizeof (Commands)/sizeof (Commands[0])) -/* initial string that starts completion. No telling how much crap +/* initial string that starts completion. No telling how much crap * the user has typed so far. Allocate LONG_STRING just to be sure! */ char User_typed[LONG_STRING] = { 0 }; int Num_matched = 0; /* Number of matches for completion */ char Completed[STRING] = { 0 }; /* completed string (command or variable) */ -char *Matches[MAX (NUMVARS, NUMCOMMANDS) + 1]; /* all the matches + User_typed */ +const char *Matches[MAX (NUMVARS, NUMCOMMANDS) + 1]; /* all the matches + User_typed */ /* helper function for completion. Changes the dest buffer if necessary/possible to aid completion. @@ -2429,7 +2428,7 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos) snprintf (tmp, sizeof (tmp), "%d", (*((short *) option->data))); else if (DTYPE (option->type) == DT_SORT) { const struct mapping_t *map; - char *p; + const char *p; switch (option->type & DT_SUBTYPE_MASK) { case DT_SORT_ALIAS: @@ -2448,15 +2447,11 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos) map = SortMethods; break; } - p = - mutt_getnamebyvalue (*((short *) option->data) & SORT_MASK, - map); - snprintf (tmp, sizeof (tmp), "%s%s%s", - (*((short *) option->data) & SORT_REVERSE) ? - "reverse-" : "", - (*((short *) option->data) & SORT_LAST) ? "last-" : - "", p); - } + p = mutt_getnamebyvalue(*((short *) option->data) & SORT_MASK, map); + snprintf(tmp, sizeof (tmp), "%s%s%s", + (*((short *)option->data) & SORT_REVERSE) ? "reverse-" : "", + (*((short *)option->data) & SORT_LAST) ? "last-" : "", p); + } else if (DTYPE (option->type) == DT_MAGIC) { const char *p; switch (DefaultMagic) { @@ -2582,7 +2577,7 @@ void mutt_init (int skip_sys_rc, LIST * commands) err.data = error; err.dsize = sizeof (error); - /* use 3*sizeof(muttvars) instead of 2*sizeof() + /* use 3*sizeof(muttvars) instead of 2*sizeof() * to have some room for $user_ vars */ ConfigOptions = hash_create (sizeof (MuttVars) * 3); for (i = 0; MuttVars[i].option; i++) { @@ -2594,7 +2589,7 @@ void mutt_init (int skip_sys_rc, LIST * commands) DT_SYS, 0), 0); } - /* + /* * XXX - use something even more difficult to predict? */ snprintf (AttachmentMarker, sizeof (AttachmentMarker), @@ -2667,9 +2662,9 @@ void mutt_init (int skip_sys_rc, LIST * commands) if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r"))) { buffer[0] = '\0'; fgets (buffer, sizeof (buffer), f); - p = (char*)&buffer; + p = buffer; SKIPWS (p); - q = p; + q = (char*)p; while (*q && !isspace(*q)) q++; *q = '\0'; @@ -2762,13 +2757,13 @@ void mutt_init (int skip_sys_rc, LIST * commands) /* - * + * * BIG FAT WARNING - * + * * When changing the code which looks for a configuration file, * please also change the corresponding code in muttbug.sh.in. - * - * + * + * */ diff --git a/keymap.c b/keymap.c index 2219c68..6a7f5c1 100644 --- a/keymap.c +++ b/keymap.c @@ -137,7 +137,7 @@ static int parse_keycode (const char *s) return -1; } -static int parsekeys (char *str, keycode_t * d, int max) +static int parsekeys (const char *str, keycode_t * d, int max) { int n, len = max; char buff[SHORT_STRING]; @@ -259,7 +259,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 const char *get_func (struct binding_t *bindings, int op) { int i; @@ -457,7 +457,7 @@ static void create_bindings (struct binding_t *map, int menu) char *km_keyname (int c) { static char buf[10]; - char *p; + const char *p; if ((p = mutt_getnamebyvalue (c, KeyNames))) return p; diff --git a/mutt_crypt.h b/mutt_crypt.h index 3d39aab..8d64d35 100644 --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -121,7 +121,7 @@ void convert_to_7bit (BODY *); /*-- crypt.c --*/ /* Print the current time. */ -void crypt_current_time (STATE * s, char *app_name); +void crypt_current_time (STATE * s, const char *app_name); /* Check out the type of encryption used and set the cached status values if there are any. */ diff --git a/mutt_sasl.c b/mutt_sasl.c index 94783ae..6b6f0ea 100644 --- a/mutt_sasl.c +++ b/mutt_sasl.c @@ -362,12 +362,12 @@ void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn) sasldata->saslconn = saslconn; /* get ssf so we know whether we have to (en|de)code read/write */ - sasl_getprop (saslconn, SASL_SSF, (const void **) &sasldata->ssf); + sasl_getprop (saslconn, SASL_SSF, (const void **)(void *)&sasldata->ssf); debug_print (3, ("SASL protection strength: %u\n", *sasldata->ssf)); /* Add SASL SSF to transport SSF */ conn->ssf += *sasldata->ssf; sasl_getprop (saslconn, SASL_MAXOUTBUF, - (const void **) &sasldata->pbufsize); + (const void **)(void *)&sasldata->pbufsize); debug_print (3, ("SASL protection buffer size: %u\n", *sasldata->pbufsize)); /* clear input buffer */ diff --git a/pgpkey.c b/pgpkey.c index 640f080..3804817 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -581,7 +581,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, ADDRESS * p, const char *s) if (option (OPTPGPCHECKTRUST) && (!pgp_id_is_valid (KeyTable[menu->current]) || !pgp_id_is_strong (KeyTable[menu->current]))) { - char *s = ""; + const char *s = ""; char buff[LONG_STRING]; if (KeyTable[menu->current]->flags & KEYFLAG_CANTUSE) diff --git a/remailer.c b/remailer.c index 8f934b4..79d0c12 100644 --- a/remailer.c +++ b/remailer.c @@ -484,7 +484,7 @@ void mix_make_chain (LIST ** chainp, int *redraw) int op; int i, j; - char *t; + const char *t; if (!(type2_list = mix_type2_list (&ttll))) { mutt_error _("Can't get mixmaster's type2.list!"); diff --git a/rfc2047.c b/rfc2047.c index a81a849..e173254 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -357,7 +357,7 @@ static int rfc2047_encode (const char *d, size_t dlen, int col, encoder_t encoder; char *tocode1 = 0; const char *tocode; - char *icode = "UTF-8"; + const char *icode = "UTF-8"; /* Try to convert to UTF-8. */ if (convert_string (d, dlen, fromcode, icode, &u, &ulen)) { @@ -520,7 +520,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col) { char *e; size_t elen; - char *charsets; + const char *charsets; if (!Charset || !*pd) return; diff --git a/sendlib.c b/sendlib.c index d55cd55..7c8ab2b 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1612,19 +1612,13 @@ int mutt_write_rfc822_header (FILE * fp, ENVELOPE * env, BODY * attach, } if (mode == 0 && !privacy && option (OPTXMAILER) && !has_agent) { - struct utsname un; - char *os; + const char *os; if (OperatingSystem != NULL) { os = OperatingSystem; - } - else { - if (uname (&un) == -1) { - os = "UNIX"; - } - else { - os = un.sysname; - } + } else { + struct utsname un; + os = (uname(&un) == -1) ? "UNIX" : un.sysname; } /* Add a vanity header */ fprintf (fp, "User-Agent: %s (%s)\n", mutt_make_version (0), os); @@ -1964,7 +1958,7 @@ static char **add_args (char **args, size_t * argslen, size_t * argsmax, return (args); } -static char **add_option(char **args, size_t * argslen, size_t * argsmax, +static char **add_option(const char **args, size_t * argslen, size_t * argsmax, const char *s) { if (*argslen == *argsmax) { diff --git a/smime.c b/smime.c index 803e717..cba7100 100644 --- a/smime.c +++ b/smime.c @@ -303,7 +303,7 @@ static void smime_entry (char *s, size_t l, MUTTMENU * menu, int num) { smime_id *Table = (smime_id *) menu->data; smime_id this = Table[num]; - char *truststate; + const char *truststate; switch (this.trust) { case 't': diff --git a/xterm.c b/xterm.c index 1b2d852..5ce9a81 100644 --- a/xterm.c +++ b/xterm.c @@ -7,14 +7,14 @@ #include "xterm.h" #include "lib/str.h" -void mutt_xterm_set_title (char *title) { +void mutt_xterm_set_title (const char *title) { fputs ("\033]2;", stdout); fputs (NONULL (title), stdout); fputs ("\007", stdout); fflush (stdout); } -void mutt_xterm_set_icon (char *name) { +void mutt_xterm_set_icon (const char *name) { fputs ("\033]1;", stdout); fputs (NONULL (name), stdout); fputs ("\007", stdout); diff --git a/xterm.h b/xterm.h index 62a8d7f..0e8f970 100644 --- a/xterm.h +++ b/xterm.h @@ -7,9 +7,9 @@ #define MUTT_XTERM_H /* sets the current xterm's title */ -void mutt_xterm_set_title (char *title); +void mutt_xterm_set_title(const char *title); /* sets the current xterm's icon */ -void mutt_xterm_set_icon (char *name); +void mutt_xterm_set_icon(const char *name); #endif /* !MUTT_XTERM_H */ -- 2.20.1