#include <lib-sys/exit.h>
#include <lib-sys/unix.h>
+#include <lib-lua/lib-lua.h>
#include <lib-ui/curses.h>
#include <lib-ui/enter.h>
#include <lib-ui/menu.h>
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);
WHERE char *Realname;
WHERE char *SendCharset;
WHERE char *Sendmail;
-WHERE char *Shell;
WHERE char *SidebarDelim;
WHERE char *SidebarNumberFormat;
WHERE char *SidebarBoundary;
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);
{
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);
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) {
mutt_gecos_name(rnbuf, sizeof(rnbuf), pw, GecosMask.rx);
Realname = m_strdup(rnbuf);
- Shell = m_strdup(pw->pw_shell);
endpwent ();
}
else {
fputs (_("unable to determine username"), stderr);
exit (1);
}
- Shell = m_strdup((p = getenv ("SHELL")) ? p : "/bin/sh");
}
/* And about the host... */
** 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" },
/*
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
*/
#include <lib-lib/lib-lib.h>
+
+#include <sys/types.h>
+#include <pwd.h>
+
#include "lib-lua_priv.h"
#include "../mutt.h"
*/
#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
#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;
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);
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;
+}
+