From 6f1bd3d49f9bb02c57e2c7a1ba8e5507edb28ad5 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 11 Mar 2007 22:22:23 +0100 Subject: [PATCH] rationalize settings into a central registry. Signed-off-by: Pierre Habouzit --- commands.c | 2 +- lib-lua/lib-lua.h | 7 ++- lib-lua/lib-lua_priv.h | 30 +++++++++++- lib-lua/lua-token.sh | 11 ++++- lib-lua/madmutt.c | 108 ++++++++++++++++++++++++++--------------- lib-lua/runtime.c | 23 +++++---- lib-mx/mx.c | 7 +-- sendlib.c | 2 +- 8 files changed, 126 insertions(+), 64 deletions(-) diff --git a/commands.c b/commands.c index 8d31af6..a7cc074 100644 --- a/commands.c +++ b/commands.c @@ -520,7 +520,7 @@ void mutt_shell_escape (void) buf[0] = 0; if (mutt_get_field (_("Shell command: "), buf, sizeof (buf), M_CMD) == 0) { if (!buf[0]) - mlua_value(buf, sizeof(buf), "madmutt", "shell"); + m_strcpy(buf, sizeof(buf), mlua_reggets(LTK_SHELL)); if (buf[0]) { CLEARLINE (LINES - 1); mutt_endwin (NULL); diff --git a/lib-lua/lib-lua.h b/lib-lua/lib-lua.h index 75b58fa..47e9daa 100644 --- a/lib-lua/lib-lua.h +++ b/lib-lua/lib-lua.h @@ -24,12 +24,15 @@ # include "../config.h" #endif +#include "lua-token.h" + void mlua_initialize(void); 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); + +const char *mlua_reggets(enum lua_token tk); +void mlua_regsets(enum lua_token tk, const char *s); #endif diff --git a/lib-lua/lib-lua_priv.h b/lib-lua/lib-lua_priv.h index ff68378..5f69d81 100644 --- a/lib-lua/lib-lua_priv.h +++ b/lib-lua/lib-lua_priv.h @@ -21,14 +21,40 @@ #define MUTT_LIB_LUA_LIB_LUA_PRIV_H #include "lib-lua.h" -#include "lua-token.h" #include #include #include -#define LUA_MADMUTT "madmutt" +typedef enum reg_type { + REG_NIL, + REG_INT, + REG_BOOL, + REG_QUAD, + REG_STR, +} reg_type; +typedef struct reg_entry { + int type; + union { + int i; + void *p; + char *s; + }; +} reg_entry; + +static inline void reg_entry_wipe(reg_entry *e) { + switch (e->type) { + case REG_STR: + p_delete(&e->s); + break; + default: + break; + } + e->type = REG_NIL; +} + +#define LUA_MADMUTT "madmutt" int luaopen_madmutt(lua_State *L); #endif diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index 7c83e5d..654ff54 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -38,8 +38,9 @@ do_h() { #define MUTT_LIB_LUA_LUA_TOKEN_H enum lua_token { - LTK_UNKNOWN, + LTK_UNKNOWN = -1, `tr 'a-z-/' 'A-Z__' | sed -e 's/.*/ LTK_&,/'` + LTK_count, }; __attribute__((pure)) @@ -48,6 +49,12 @@ enum lua_token lua_which_token(const char *s, ssize_t len); EOF } +do_tokens() { + while read tok; do + echo "$tok, LTK_`echo $tok | tr 'a-z-' 'A-Z_'`" + done +} + do_c() { cat <