From: Pierre Habouzit Date: Sun, 11 Mar 2007 18:07:03 +0000 (+0100) Subject: various cleanups. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=418e55040ec4a95698a8f1f128f3afbfd6aba48b;p=apps%2Fmadmutt.git various cleanups. Signed-off-by: Pierre Habouzit --- diff --git a/alias.c b/alias.c index 5eab9db..f1021ef 100644 --- a/alias.c +++ b/alias.c @@ -287,7 +287,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr) return; } - mutt_expand_path(buf, sizeof (buf)); + mutt_expand_path(buf, sizeof(buf)); rc = safe_fopen (buf, "a"); if (rc) { diff --git a/extlib.c b/extlib.c index ea984e6..2ce734c 100644 --- a/extlib.c +++ b/extlib.c @@ -18,7 +18,8 @@ #include #include "lib.h" -void (*mutt_error) (const char *, ...) = mutt_nocurses_error; +void (*mutt_error)(const char *, ...) + __attribute__((format(printf, 1, 2))) = mutt_nocurses_error; void mutt_exit (int code) { diff --git a/globals.h b/globals.h index aed2d80..fe17703 100644 --- a/globals.h +++ b/globals.h @@ -11,8 +11,8 @@ #include -WHERE void (*mutt_error) (const char *, ...); -WHERE void (*mutt_message) (const char *, ...); +WHERE void (*mutt_error) (const char *, ...) __attribute__((format(printf, 1, 2))) ; +WHERE void (*mutt_message) (const char *, ...) __attribute__((format(printf, 1, 2))) ; WHERE CONTEXT *Context; diff --git a/hook.c b/hook.c index 69ca2a0..b81b9c8 100644 --- a/hook.c +++ b/hook.c @@ -77,8 +77,7 @@ int mutt_parse_hook (BUFFER * buf __attribute__ ((unused)), BUFFER * s, } if (data & (M_FOLDERHOOK | M_MBOXHOOK)) { - m_strcpy(path, sizeof(path), pattern.data); - _mutt_expand_path (path, sizeof (path), 1); + _mutt_expand_path (path, sizeof (path), pattern.data, 1); p_delete(&pattern.data); p_clear(&pattern, 1); pattern.data = m_strdup(path); diff --git a/init.c b/init.c index a40576b..93daf2d 100644 --- a/init.c +++ b/init.c @@ -1305,17 +1305,6 @@ static void mutt_set_default(const char *name __attribute__ ((unused)), void* p, ptr->init = m_strdup(buf); } -static struct option_t* add_option (const char* name, const char* init, - short type, short dodup) { - struct option_t* option = p_new(struct option_t, 1); - - option->option = m_strdup(name); - option->type = type; - if (init) - option->init = dodup ? m_strdup(init) : (char*) init; - return (option); -} - static int init_expand (char** dst, struct option_t* src) { BUFFER token, in; ssize_t len = 0; diff --git a/lib-lua/madmutt.c b/lib-lua/madmutt.c index dfcf084..cc6cb8f 100644 --- a/lib-lua/madmutt.c +++ b/lib-lua/madmutt.c @@ -60,6 +60,7 @@ static int madmutt_assign(lua_State *L) { const char *idx = luaL_checkstring(L, 2); const char *val = luaL_checkstring(L, 3); + char buf[STRING]; switch (lua_which_token(idx, -1)) { default: @@ -68,6 +69,8 @@ static int madmutt_assign(lua_State *L) case LTK_SENDMAIL: case LTK_SHELL: + _mutt_expand_path(buf, sizeof(buf), val, 0); + val = buf; break; } @@ -164,18 +167,21 @@ static const struct { #endif }; -static const char *madmutt_init_shell(void) +static void madmutt_init_shell(char *buf, ssize_t len) { struct passwd *pw = getpwuid(getuid()); - if (pw) - return pw->pw_shell; - return getenv("SHELL") ?: "/bin/sh"; + if (pw) { + m_strcpy(buf, len, pw->pw_shell); + _mutt_expand_path(buf, len, pw->pw_shell, 0); + } else { + m_strcpy(buf, len, getenv("SHELL") ?: "/bin/sh"); + } } static const struct { - const char *k; - const char *(*f)(void); + const char *key; + void (*fun)(char *buf, ssize_t len); } madmutt_module_vars2[] = { { "shell", madmutt_init_shell }, /* @@ -200,8 +206,10 @@ int luaopen_madmutt(lua_State *L) } for (i = 0; i < countof(madmutt_module_vars2); i++) { - lua_pushstring(L, madmutt_module_vars2[i].f()); - lua_setfield(L, -2, madmutt_module_vars2[i].k); + char buf[STRING]; + (madmutt_module_vars2[i].fun)(buf, sizeof(buf)); + lua_pushstring(L, buf); + lua_setfield(L, -2, madmutt_module_vars2[i].key); } lua_pushstring(L, "__index"); diff --git a/lib-mime/rfc1524.c b/lib-mime/rfc1524.c index 5b6eb50..fdbf182 100644 --- a/lib-mime/rfc1524.c +++ b/lib-mime/rfc1524.c @@ -389,7 +389,7 @@ int rfc1524_mailcap_lookup (BODY * a, char *type, rfc1524_entry * entry, continue; path[x] = '\0'; - mutt_expand_path (path, sizeof (path)); + mutt_expand_path(path, sizeof(path)); found = rfc1524_mailcap_parse (a, path, type, entry, opt); } diff --git a/lib-ui/curses.h b/lib-ui/curses.h index 074a93c..4cedb6c 100644 --- a/lib-ui/curses.h +++ b/lib-ui/curses.h @@ -148,8 +148,10 @@ typedef struct { void mutt_progress_bar (progress_t* progress, long pos); void mutt_clear_error (void); void mutt_edit_file (const char *, const char *); -void mutt_curses_error (const char *, ...); -void mutt_curses_message (const char *, ...); +void mutt_curses_error (const char *, ...) + __attribute__((format(printf, 1, 2))); +void mutt_curses_message (const char *, ...) + __attribute__((format(printf, 1, 2))); void mutt_format_string (char *, ssize_t, int, int, int, char, const char *, ssize_t, int); void mutt_format_s (char *, ssize_t, const char *, const char *); diff --git a/lib.h b/lib.h index 11dcf66..247a1f3 100644 --- a/lib.h +++ b/lib.h @@ -12,6 +12,7 @@ # define _LIB_H void mutt_exit (int); -void mutt_nocurses_error (const char *, ...); +void mutt_nocurses_error(const char *, ...) + __attribute__((format(printf, 1, 2))); #endif diff --git a/muttlib.c b/muttlib.c index 1aadda3..d8b94aa 100644 --- a/muttlib.c +++ b/muttlib.c @@ -52,103 +52,97 @@ void mutt_mktemp(char *s) } } -ssize_t _mutt_expand_path(char *s, ssize_t slen, int rx) +ssize_t _mutt_expand_path(char *buf, ssize_t len, const char *s, int rx) { char p[_POSIX_PATH_MAX] = ""; char tmp[_POSIX_PATH_MAX]; const char *tail = ""; + const address_t *alias; - do { - const address_t *alias; - - switch (*s) { - case '~': - if (s[1] == '/' || s[1] == '\0') { - m_strcpy(p, sizeof(p), Homedir); - tail = s + 1; - } else { - struct passwd *pw; - tail = m_strchrnul(s + 1, '/'); + switch (*s) { + case '~': + if (s[1] == '/' || s[1] == '\0') { + m_strcpy(p, sizeof(p), Homedir); + tail = s + 1; + } else { + struct passwd *pw; + tail = m_strchrnul(s + 1, '/'); - m_strncpy(tmp, sizeof(tmp), s + 1, tail - s - 1); + m_strncpy(tmp, sizeof(tmp), s + 1, tail - s - 1); - if ((pw = getpwnam(tmp))) { - m_strcpy(p, sizeof(p), pw->pw_dir); - } else { - /* user not found! */ - tail = s; - } - } - break; - - case '=': - case '+': - /* if folder = imap[s]://host/: don't append slash */ - if (imap_is_magic(NONULL(Maildir), NULL) == M_IMAP - && Maildir[m_strlen(Maildir) - 1] == '/') { - m_strcpy(p, sizeof(p), Maildir); + if ((pw = getpwnam(tmp))) { + m_strcpy(p, sizeof(p), pw->pw_dir); } else { - snprintf(p, sizeof(p), "%s/", NONULL(Maildir)); + /* user not found! */ + tail = s; } + } + break; - tail = s + 1; - break; - - /* elm compatibility, @ expands alias to user name */ - - case '@': - if ((alias = alias_lookup(s + 1))) { - HEADER h; - header_init(&h); - h.env = envelope_new(); - h.env->from = h.env->to = (address_t *)alias; - mutt_default_save(p, sizeof (p), &h); - h.env->from = h.env->to = NULL; - header_wipe(&h); - - if (*p != '@') { - /* recurse iff the result do not starts with '@' */ - m_strcpy(s, slen, p); - continue; - } - } - break; + case '=': + case '+': + /* if folder = imap[s]://host/: don't append slash */ + if (imap_is_magic(NONULL(Maildir), NULL) == M_IMAP + && Maildir[m_strlen(Maildir) - 1] == '/') { + m_strcpy(p, sizeof(p), Maildir); + } else { + snprintf(p, sizeof(p), "%s/", NONULL(Maildir)); + } - case '>': - m_strcpy(p, sizeof(p), Inbox); - tail = s + 1; - break; + tail = s + 1; + break; - case '<': - m_strcpy(p, sizeof(p), Outbox); - tail = s + 1; - break; + /* elm compatibility, @ expands alias to user name */ - case '!': - if (s[1] == '!') { - m_strcpy(p, sizeof(p), LastFolder); - tail = s + 2; - } else { - m_strcpy(p, sizeof(p), Spoolfile); - tail = s + 1; - } - break; + case '@': + if ((alias = alias_lookup(s + 1))) { + HEADER h; + header_init(&h); + h.env = envelope_new(); + h.env->from = h.env->to = (address_t *)alias; + mutt_default_save(p, sizeof (p), &h); + h.env->from = h.env->to = NULL; + header_wipe(&h); - case '-': - m_strcpy(p, sizeof(p), NONULL(LastFolder)); - tail = s + 1; - break; + if (*p != '@') + return _mutt_expand_path(buf, len, p, rx); + } + break; - case '^': - m_strcpy(p, sizeof(p), NONULL(CurrentFolder)); - tail = s + 1; - break; + case '>': + m_strcpy(p, sizeof(p), Inbox); + tail = s + 1; + break; + + case '<': + m_strcpy(p, sizeof(p), Outbox); + tail = s + 1; + break; - default: - *p = '\0'; - tail = s; + case '!': + if (s[1] == '!') { + m_strcpy(p, sizeof(p), LastFolder); + tail = s + 2; + } else { + m_strcpy(p, sizeof(p), Spoolfile); + tail = s + 1; } - } while (0); + break; + + case '-': + m_strcpy(p, sizeof(p), NONULL(LastFolder)); + tail = s + 1; + break; + + case '^': + m_strcpy(p, sizeof(p), NONULL(CurrentFolder)); + tail = s + 1; + break; + + default: + *p = '\0'; + tail = s; + } if (rx) { char q[_POSIX_PATH_MAX]; @@ -158,7 +152,7 @@ ssize_t _mutt_expand_path(char *s, ssize_t slen, int rx) snprintf(tmp, sizeof(tmp), "%s%s", p, tail); } - return m_strcpy(s, slen, tmp); + return m_strcpy(buf, len, tmp); } /* collapse the pathname using ~ or = when possible */ diff --git a/protos.h b/protos.h index 6f9f5b1..6a2ab8c 100644 --- a/protos.h +++ b/protos.h @@ -36,8 +36,8 @@ int is_from (const char *, char *, ssize_t, time_t *); const char *mutt_charset_hook (const char *); const char *mutt_iconv_hook (const char *); -ssize_t _mutt_expand_path (char *, ssize_t, int); -#define mutt_expand_path(s, n) _mutt_expand_path((s), (n), 0) +ssize_t _mutt_expand_path(char *, ssize_t, const char *, int); +#define mutt_expand_path(s, n) _mutt_expand_path((s), (n), (s), 0) char *mutt_find_hook (int, const char *); char *mutt_get_body_charset (char *, ssize_t, BODY *); diff --git a/state.h b/state.h index 61b9c95..2832af8 100644 --- a/state.h +++ b/state.h @@ -39,7 +39,8 @@ typedef struct { void state_mark_attach (STATE *); void state_attach_puts (const char *, STATE *); void state_prefix_putc (char, STATE *); -int state_printf (STATE *, const char *, ...); +int state_printf (STATE *, const char *, ...) + __attribute__((format(printf, 2, 3))); void mutt_convert_to_state (iconv_t, char*, ssize_t*, STATE*);