PoC support for lua.
[apps/madmutt.git] / init.c
diff --git a/init.c b/init.c
index 8f6070c..eb92e17 100644 (file)
--- a/init.c
+++ b/init.c
 #include <lib-lib/lib-lib.h>
 #include <sys/utsname.h>
 
+#include <lib-lua/lib-lua.h>
 #include <lib-sys/unix.h>
 #include <lib-sys/mutt_ssl.h>
-
 #include <lib-ui/curses.h>
 #include <lib-ui/history.h>
 #include <lib-mx/mx.h>
+#include <lib-crypt/crypt.h>
 
 #include "mutt.h"
 #include "keymap.h"
 #include "charset.h"
 #include "thread.h"
-#include <lib-crypt/crypt.h>
 #include "mutt_idna.h"
 
 #if defined (USE_LIBESMTP) && (defined (USE_SSL) || defined (USE_GNUTLS))
@@ -2304,9 +2304,6 @@ static int mutt_execute_commands (string_list_t * p)
   return 0;
 }
 
-#include "parse.h"
-#include "rcparser.h"
-
 void mutt_init (int skip_sys_rc, string_list_t * commands)
 {
   struct passwd *pw;
@@ -2465,6 +2462,7 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
     From = rfc822_parse_adrlist (NULL, p);
 
   charset_initialize();
+  mlua_initialize();
 
   /* Set standard defaults */
   hash_map (ConfigOptions, mutt_set_default, 0);
@@ -2519,36 +2517,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
     }
   }
 
-#if 0
-  {
-    void *parser = rcparseAlloc(malloc);
-    struct rcstate state;
-    segment s1 = {" ", 1};
-    segment s2 = {"toto", 4 };
-    segment s3 = {"titi", 4 };
-    segment s4 = {"\"", 1 };
-
-    mutt_endwin(NULL);
-
-    p_clear(&state, 1);
-
-    rcparseTrace(stderr, "> ");
-    rcparse(parser, RCTK_ALTERNATIVE_ORDER, s1, &state);
-    rcparse(parser, RCTK_SPACE, s1, &state);
-    rcparse(parser, RCTK_ATOM, s2, &state);
-    rcparse(parser, RCTK_SPACE, s1, &state);
-    rcparse(parser, RCTK_DQUOTE, s4, &state);
-    rcparse(parser, RCTK_ATOM, s3, &state);
-    rcparse(parser, RCTK_SPACE, s1, &state);
-    rcparse(parser, RCTK_ATOM, s3, &state);
-    rcparse(parser, RCTK_DQUOTE, s4, &state);
-    rcparse(parser, RCTK_NL, s1, &state);
-    rcparse(parser, 0, s1, &state);
-
-    exit(0);
-  }
-#endif
-
   /* Read the user's initialization file.  */
   if (access (Muttrc, F_OK) != -1) {
     if (!option (OPTNOCURSES))
@@ -2566,6 +2534,15 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
     exit (1);
   }
 
+  /* LUA {{{ */
+  snprintf(buffer, sizeof(buffer), "%s/.madmutt.lua", NONULL(Homedir));
+  if (access(buffer, F_OK) < 0)
+      snprintf(buffer, sizeof(buffer), "%s/.madmutt/cfg.lua", NONULL(Homedir));
+  if (!access(buffer, F_OK)) {
+      need_pause = mlua_wrap(mutt_error, mlua_dofile(buffer));
+  }
+  /* }}} */
+
   if (mutt_execute_commands (commands) != 0)
     need_pause = 1;