From: Pierre Habouzit Date: Sun, 11 Mar 2007 22:41:43 +0000 (+0100) Subject: move OPT_QUIT into the lua registry X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=0dd5b492f18e549ef95b0ac6765329473e426633;p=apps%2Fmadmutt.git move OPT_QUIT into the lua registry Signed-off-by: Pierre Habouzit --- diff --git a/init.c b/init.c index 163ad04..f99452a 100644 --- a/init.c +++ b/init.c @@ -494,6 +494,22 @@ int quadoption (int opt) 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); diff --git a/init.h b/init.h index e9c0f85..68edc32 100644 --- a/init.h +++ b/init.h @@ -2718,14 +2718,6 @@ struct option_t MuttVars[] = { ** 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 diff --git a/lib-lua/lib-lua.h b/lib-lua/lib-lua.h index 47e9daa..efad96c 100644 --- a/lib-lua/lib-lua.h +++ b/lib-lua/lib-lua.h @@ -26,6 +26,14 @@ #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); @@ -33,6 +41,9 @@ int mlua_dofile(const char *filename); 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 diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index 4a73f32..8dc5a83 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -106,6 +106,7 @@ exit 0 ############ Put tokens here ############ ## dotlock ## editor +## quit ## sendmail ## shell ## tmpdir diff --git a/lib-lua/madmutt.c b/lib-lua/madmutt.c index 3bd3428..29907f3 100644 --- a/lib-lua/madmutt.c +++ b/lib-lua/madmutt.c @@ -58,6 +58,19 @@ static int madmutt_folder_name(lua_State *L) 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); @@ -66,21 +79,28 @@ static int madmutt_assign(lua_State *L) 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; } } @@ -203,7 +223,6 @@ static const struct { 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) @@ -249,6 +268,14 @@ static const struct { ** 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. + */ }; /* }}} */ diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index 552587c..7a351ee 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -74,9 +74,23 @@ const char *mlua_reggets(int tk) 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; +} diff --git a/lib-ui/curs_main.c b/lib-ui/curs_main.c index 71af8bd..c716dc5 100644 --- a/lib-ui/curs_main.c +++ b/lib-ui/curs_main.c @@ -974,7 +974,7 @@ int mutt_index_menu (void) 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; @@ -1302,7 +1302,7 @@ int mutt_index_menu (void) } if ((menu->menu == MENU_MAIN) - && (query_quadoption (OPT_QUIT, + && (query_quadoption2(LTK_QUIT, _("Exit Madmutt without saving?")) == M_YES)) { if (Context) { diff --git a/mutt.h b/mutt.h index 34dff23..4b53da4 100644 --- a/mutt.h +++ b/mutt.h @@ -13,6 +13,7 @@ #include #include +#include #define MUTT_VERSION (VERSION) @@ -153,14 +154,6 @@ enum { M_SAVE_OVERWRITE }; -/* possible arguments to set_quadoption() */ -enum { - M_NO, - M_YES, - M_ASKNO, - M_ASKYES -}; - /* quad-option vars */ enum { OPT_ABORT, @@ -180,7 +173,6 @@ enum { OPT_POPRECONNECT, OPT_POSTPONE, OPT_PRINT, - OPT_QUIT, OPT_REPLYTO, OPT_RECALL, #if defined(USE_SSL) || defined(USE_GNUTLS) diff --git a/protos.h b/protos.h index 16121c3..068cc4a 100644 --- a/protos.h +++ b/protos.h @@ -16,6 +16,7 @@ void mutt_mktemp (char *) __attribute__((deprecated)); 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);