From: Pierre Habouzit Date: Sun, 11 Mar 2007 17:06:11 +0000 (+0100) Subject: Deal with $shell from lua from now on. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=0840ecb90bb99da0d6b0c028ace977dd1932e6e1 Deal with $shell from lua from now on. (also remove other cruft) Signed-off-by: Pierre Habouzit --- diff --git a/commands.c b/commands.c index 3493587..8d31af6 100644 --- a/commands.c +++ b/commands.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -518,8 +519,8 @@ void mutt_shell_escape (void) buf[0] = 0; if (mutt_get_field (_("Shell command: "), buf, sizeof (buf), M_CMD) == 0) { - if (!buf[0] && Shell) - m_strcpy(buf, sizeof(buf), Shell); + if (!buf[0]) + mlua_value(buf, sizeof(buf), "madmutt", "shell"); if (buf[0]) { CLEARLINE (LINES - 1); mutt_endwin (NULL); diff --git a/globals.h b/globals.h index 3e4e9f8..aed2d80 100644 --- a/globals.h +++ b/globals.h @@ -119,7 +119,6 @@ WHERE char *QueryCmd; WHERE char *Realname; WHERE char *SendCharset; WHERE char *Sendmail; -WHERE char *Shell; WHERE char *SidebarDelim; WHERE char *SidebarNumberFormat; WHERE char *SidebarBoundary; diff --git a/init.c b/init.c index 0d8b52b..a40576b 100644 --- a/init.c +++ b/init.c @@ -1570,11 +1570,6 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, set_option (OPTRESORTINIT); set_option (OPTREDRAWTREE); return (0); - } - else if (!FuncTable[DTYPE (option->type)].opt_fromstr) { - snprintf (err->data, err->dsize, _("$%s is read-only"), option->option); - r = -1; - break; } else { CHECK_PAGER; mutt_restore_default (NULL, option, 1); @@ -1629,12 +1624,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, { if (unset) { CHECK_PAGER; - if (!FuncTable[DTYPE (option->type)].opt_fromstr) { - snprintf (err->data, err->dsize, _("$%s is read-only"), - option->option); - r = -1; - break; - } else if (DTYPE (option->type) == DT_ADDR) + if (DTYPE (option->type) == DT_ADDR) address_list_wipe((address_t **) option->data); else p_delete((void **)(void *)&option->data); @@ -1648,20 +1638,12 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, break; } - /* the $madmutt_ variables are read-only */ - if (!FuncTable[DTYPE (option->type)].opt_fromstr) { - snprintf (err->data, err->dsize, _("$%s is read-only"), - option->option); + CHECK_PAGER; + s->dptr++; + mutt_extract_token (tmp, s, 0); + if (!FuncTable[DTYPE (option->type)].opt_fromstr + (option, tmp->data, err->data, err->dsize)) r = -1; - break; - } else { - CHECK_PAGER; - s->dptr++; - mutt_extract_token (tmp, s, 0); - if (!FuncTable[DTYPE (option->type)].opt_fromstr - (option, tmp->data, err->data, err->dsize)) - r = -1; - } } else if (DTYPE (option->type) == DT_QUAD) { @@ -2239,7 +2221,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) mutt_gecos_name(rnbuf, sizeof(rnbuf), pw, GecosMask.rx); Realname = m_strdup(rnbuf); - Shell = m_strdup(pw->pw_shell); endpwent (); } else { @@ -2255,7 +2236,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) fputs (_("unable to determine username"), stderr); exit (1); } - Shell = m_strdup((p = getenv ("SHELL")) ? p : "/bin/sh"); } /* And about the host... */ diff --git a/init.h b/init.h index 0de8ae3..66603eb 100644 --- a/init.h +++ b/init.h @@ -2980,12 +2980,6 @@ struct option_t MuttVars[] = { ** process will be put in a temporary file. If there is some error, you ** will be informed as to where to find the output. */ - {"shell", DT_PATH, R_NONE, UL &Shell, "" }, - /* - ** .pp - ** Command to use when spawning a subshell. By default, the user's login - ** shell from \fT/etc/passwd\fP is used. - */ #ifdef USE_NNTP {"nntp_save_unsubscribed", DT_BOOL, R_NONE, OPTSAVEUNSUB, "no" }, /* diff --git a/lib-lua/lib-lua.h b/lib-lua/lib-lua.h index 8983322..75b58fa 100644 --- a/lib-lua/lib-lua.h +++ b/lib-lua/lib-lua.h @@ -29,5 +29,7 @@ void mlua_shutdown(void); int mlua_dofile(const char *filename); int mlua_wrap(void (*errfun)(const char *fmt, ...), int status); +ssize_t mlua_value(char *buf, ssize_t len, + const char *table, const char *key); #endif diff --git a/lib-lua/madmutt.c b/lib-lua/madmutt.c index 31ee28a..dfcf084 100644 --- a/lib-lua/madmutt.c +++ b/lib-lua/madmutt.c @@ -18,6 +18,10 @@ */ #include + +#include +#include + #include "lib-lua_priv.h" #include "../mutt.h" @@ -144,13 +148,13 @@ static const struct { */ #ifdef USE_HCACHE #if defined(HAVE_QDBM) - {"hcache_backend", "qdbm" }, + { "hcache_backend", "qdbm" }, #elif defined(HAVE_GDBM) - {"hcache_backend", "gdbm" }, + { "hcache_backend", "gdbm" }, #elif defined(HAVE_DB4) - {"hcache_backend", "db4" }, + { "hcache_backend", "db4" }, #else - {"hcache_backend", "unknown" }, + { "hcache_backend", "unknown" }, #endif /* ** .pp @@ -160,6 +164,27 @@ static const struct { #endif }; +static const char *madmutt_init_shell(void) +{ + struct passwd *pw = getpwuid(getuid()); + + if (pw) + return pw->pw_shell; + return getenv("SHELL") ?: "/bin/sh"; +} + +static const struct { + const char *k; + const char *(*f)(void); +} madmutt_module_vars2[] = { + { "shell", madmutt_init_shell }, + /* + ** .pp + ** Command to use when spawning a subshell. By default, the user's login + ** shell from \fT/etc/passwd\fP is used. + */ +}; + int luaopen_madmutt(lua_State *L) { int i; @@ -174,6 +199,11 @@ int luaopen_madmutt(lua_State *L) lua_setfield(L, -2, madmutt_module_vars[i].key); } + 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); + } + lua_pushstring(L, "__index"); lua_pushvalue(L, -2); lua_settable(L, -3); diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index 8788ed5..a442401 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -66,3 +66,18 @@ int mlua_wrap(void (*errfun)(const char *fmt, ...), int status) return status; } +ssize_t mlua_value(char *buf, ssize_t len, + const char *table, const char *key) +{ + ssize_t res; + + lua_getglobal(L, table); + lua_pushstring(L, key); + lua_gettable(L, -2); + res = m_strcpy(buf, len, lua_tostring(L, -1)); + lua_remove(L, -1); + lua_remove(L, -1); + + return res; +} +