various cleanups.
[apps/madmutt.git] / lib-lua / madmutt.c
index dfcf084..cc6cb8f 100644 (file)
@@ -60,6 +60,7 @@ static int madmutt_assign(lua_State *L)
 {
     const char *idx = luaL_checkstring(L, 2);
     const char *val = luaL_checkstring(L, 3);
+    char buf[STRING];
 
     switch (lua_which_token(idx, -1)) {
       default:
@@ -68,6 +69,8 @@ static int madmutt_assign(lua_State *L)
 
       case LTK_SENDMAIL:
       case LTK_SHELL:
+        _mutt_expand_path(buf, sizeof(buf), val, 0);
+        val = buf;
         break;
     }
 
@@ -164,18 +167,21 @@ static const struct {
 #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 },
     /*
@@ -200,8 +206,10 @@ int luaopen_madmutt(lua_State *L)
     }
 
     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");