return;
}
- mutt_expand_path(buf, sizeof (buf));
+ mutt_expand_path(buf, sizeof(buf));
rc = safe_fopen (buf, "a");
if (rc) {
#include <lib-lib/lib-lib.h>
#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)
{
#include <lib-lib/lib-lib.h>
-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;
}
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);
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;
{
const char *idx = luaL_checkstring(L, 2);
const char *val = luaL_checkstring(L, 3);
+ char buf[STRING];
switch (lua_which_token(idx, -1)) {
default:
case LTK_SENDMAIL:
case LTK_SHELL:
+ _mutt_expand_path(buf, sizeof(buf), val, 0);
+ val = buf;
break;
}
#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 },
/*
}
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");
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);
}
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 *);
# 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
}
}
-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];
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 */
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 *);
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*);