return (QuadOptions[n] >> b) & 0x3;
}
+int query_quadoption2(int opt, const char *prompt)
+{
+ int v = mlua_reggetq(opt);
+
+ switch (v) {
+ case M_YES:
+ case M_NO:
+ return (v);
+
+ default:
+ v = mutt_yesorno(prompt, (v == M_ASKYES));
+ CLEARLINE (LINES - 1);
+ return (v);
+ }
+}
+
int query_quadoption (int opt, const char *prompt)
{
int v = quadoption (opt);
** with the query string the user types. See ``$query'' for more
** information.
*/
- {"quit", DT_QUAD, R_NONE, OPT_QUIT, "yes" },
- /*
- ** .pp
- ** This variable controls whether ``quit'' and ``exit'' actually quit
- ** from Madmutt. If it set to \fIyes\fP, they do quit, if it is set to \fIno\fP, they
- ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are
- ** prompted for confirmation when you try to quit.
- */
{"quote_empty", DT_BOOL, R_NONE, OPTQUOTEEMPTY, "yes" },
/*
** .pp
#include "lua-token.h"
+/* possible arguments to set_quadoption() */
+typedef enum quadopt_t {
+ M_NO,
+ M_YES,
+ M_ASKNO,
+ M_ASKYES
+} quadopt_t;
+
void mlua_initialize(void);
void mlua_shutdown(void);
int mlua_wrap(void (*errfun)(const char *fmt, ...), int status);
const char *mlua_reggets(enum lua_token tk);
+quadopt_t mlua_reggetq(enum lua_token tk);
+
void mlua_regsets(enum lua_token tk, const char *s);
+void mlua_regsetq(enum lua_token tk, quadopt_t q);
#endif
############ Put tokens here ############
## dotlock
## editor
+## quit
## sendmail
## shell
## tmpdir
return 1;
}
+static quadopt_t quadopt_parse(const char *s)
+{
+ if (!m_strcasecmp("yes", s))
+ return M_YES;
+ if (!m_strcasecmp("no", s))
+ return M_NO;
+ if (!m_strcasecmp("ask-yes", s))
+ return M_ASKYES;
+ if (!m_strcasecmp("ask-no", s))
+ return M_ASKNO;
+ return -1;
+}
+
static int madmutt_assign(lua_State *L)
{
const char *idx = luaL_checkstring(L, 2);
switch ((tk = lua_which_token(idx, -1))) {
char buf[STRING];
+ int i;
default:
- luaL_error(L, "read-only or inexistant property '%s'", idx, tk);
- return 0;
+ return luaL_error(L, "read-only or inexistant property '%s'", idx, tk);
case LTK_DOTLOCK:
case LTK_SENDMAIL:
case LTK_SHELL:
+ case LTK_EDITOR:
_mutt_expand_path(buf, sizeof(buf), val, 0);
val = buf;
/* FALLTHROUGH */
- case LTK_EDITOR:
mlua_regsets(tk, val);
return 0;
+
+ case LTK_QUIT:
+ i = quadopt_parse(val);
+ if (i < 0)
+ return luaL_error(L, "invalid quad option value: '%s'", val);
+ mlua_regsetq(tk, i);
+ return 0;
}
}
static void madmutt_init_editor(char *buf, ssize_t len)
{
m_strcpy(buf, len, getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
- fprintf("%s\n", buf);
}
static void madmutt_init_shell(char *buf, ssize_t len)
** Command to use when spawning a subshell. By default, the user's login
** shell from \fT/etc/passwd\fP is used.
*/
+ {"quit", NULL, "yes" }
+ /*
+ ** .pp
+ ** This variable controls whether ``quit'' and ``exit'' actually quit
+ ** from Madmutt. If it set to \fIyes\fP, they do quit, if it is set to \fIno\fP, they
+ ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are
+ ** prompted for confirmation when you try to quit.
+ */
};
/* }}} */
return registry[tk].s;
}
+quadopt_t mlua_reggetq(int tk)
+{
+ if (registry[tk].type != REG_QUAD)
+ return -1;
+ return registry[tk].i;
+}
+
void mlua_regsets(int tk, const char *s)
{
reg_entry_wipe(registry + tk);
registry[tk].type = REG_STR;
registry[tk].s = m_strdup(s);
}
+
+void mlua_regsetq(int tk, quadopt_t q)
+{
+ reg_entry_wipe(registry + tk);
+ registry[tk].type = REG_QUAD;
+ registry[tk].i = q;
+}
break;
}
- if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
+ if (query_quadoption2(LTK_QUIT, _("Quit Madmutt?")) == M_YES) {
int check;
oldcount = Context ? Context->msgcount : 0;
}
if ((menu->menu == MENU_MAIN)
- && (query_quadoption (OPT_QUIT,
+ && (query_quadoption2(LTK_QUIT,
_("Exit Madmutt without saving?")) == M_YES))
{
if (Context) {
#include <lib-lib/lib-lib.h>
#include <lib-mime/mime.h>
+#include <lib-lua/lib-lua.h>
#define MUTT_VERSION (VERSION)
M_SAVE_OVERWRITE
};
-/* possible arguments to set_quadoption() */
-enum {
- M_NO,
- M_YES,
- M_ASKNO,
- M_ASKYES
-};
-
/* quad-option vars */
enum {
OPT_ABORT,
OPT_POPRECONNECT,
OPT_POSTPONE,
OPT_PRINT,
- OPT_QUIT,
OPT_REPLYTO,
OPT_RECALL,
#if defined(USE_SSL) || defined(USE_GNUTLS)
void set_quadoption (int, int);
int query_quadoption (int, const char *);
+int query_quadoption2(int, const char *);
int quadoption (int);
int mutt_option_value (const char* val, char* dst, ssize_t dstlen);