From cc707c1e986b60f2c1c1932d0789038d465a7a59 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 18 Mar 2007 14:15:15 +0100 Subject: [PATCH] Lua improvements: * remove old lib-lua cruft. * make luapkg2c support bool type. * make luapkg2c support C bit-fields. * import beep{,_new}, and hcache_backend. Signed-off-by: Pierre Habouzit --- init.h | 12 ---------- lib-lua/Makefile.am | 4 ++-- lib-lua/lib-lua_priv.h | 38 -------------------------------- lib-lua/lua-token.sh | 3 +++ lib-lua/luapkg2c.pl | 50 ++++++++++++++++++++++++++++-------------- lib-lua/madmutt.cpkg | 23 +++++++++++++++++-- lib-lua/runtime.c | 3 +-- lib-ui/curs_main.c | 4 ++-- lib-ui/curses.h | 2 +- mutt.h | 2 -- 10 files changed, 64 insertions(+), 77 deletions(-) delete mode 100644 lib-lua/lib-lua_priv.h diff --git a/init.h b/init.h index af3445f..a5e6ca3 100644 --- a/init.h +++ b/init.h @@ -319,18 +319,6 @@ struct option_t MuttVars[] = { ** unset, you must first use the ``tag-prefix'' function (default: "\fT;\fP") to ** make the next function apply to all tagged messages. */ - {"beep", DT_BOOL, R_NONE, OPTBEEP, "yes" }, - /* - ** .pp - ** When this variable is \fIset\fP, Madmutt will beep when an error occurs. - */ - {"beep_new", DT_BOOL, R_NONE, OPTBEEPNEW, "no" }, - /* - ** .pp - ** When this variable is \fIset\fP, Madmutt will beep whenever it prints a message - ** notifying you of new mail. This is independent of the setting of the - ** ``$$beep'' variable. - */ {"bounce", DT_QUAD, R_NONE, OPT_BOUNCE, "ask-yes" }, /* ** .pp diff --git a/lib-lua/Makefile.am b/lib-lua/Makefile.am index b28c98d..8f149f5 100644 --- a/lib-lua/Makefile.am +++ b/lib-lua/Makefile.am @@ -8,11 +8,11 @@ noinst_LIBRARIES = liblua.a liblua_a_DEPENDENCIES = madmutt.h liblua_a_SOURCES = madmutt.cpkg \ - lib-lua.h lib-lua_priv.h \ + lib-lua.h \ runtime.c \ $(BUILT_SOURCES) -noinst_HEADERS = lib-lua.h lib-lua_priv.h +noinst_HEADERS = lib-lua.h lua-token.c lua-token.h: lua-token.sh sh $< $@ || (rm -f $@; exit 1) diff --git a/lib-lua/lib-lua_priv.h b/lib-lua/lib-lua_priv.h deleted file mode 100644 index 93dd397..0000000 --- a/lib-lua/lib-lua_priv.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * Copyright © 2007 Pierre Habouzit - */ - -#ifndef MUTT_LIB_LUA_LIB_LUA_PRIV_H -#define MUTT_LIB_LUA_LIB_LUA_PRIV_H - -#include "lib-lua.h" - -#include -#include -#include - -typedef struct reg_entry { - int type; - union { - int i; - char *s; - }; -} reg_entry; - - -#endif diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index 5c61d66..3f45eb5 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -110,10 +110,13 @@ chmod -w $1 exit 0 ############ Put tokens here ############ +## beep +## beep_new ## bindir ## docdir ## dotlock ## editor +## hcache_backend ## quit ## sendmail ## shell diff --git a/lib-lua/luapkg2c.pl b/lib-lua/luapkg2c.pl index 2d152cb..72d84c7 100755 --- a/lib-lua/luapkg2c.pl +++ b/lib-lua/luapkg2c.pl @@ -86,10 +86,10 @@ sub parse_type($$) { if (/^\s*\.(push|kind|ctype|check)\s*=\s*(.*?)\s*;\s*$/) { $t{$1} = $2; if ($1 eq "kind") { - if ($2 =~ /^'([si])'$/) { + if ($2 =~ /^'([bis])'$/) { $t{kind} = $1; } else { - fatal($src, "error: .kind should be 'i' or 's' got $2)"); + fatal($src, "error: .kind should be [ibs] got $2)"); } } } elsif (!/^\s*$/) { @@ -101,15 +101,22 @@ sub parse_type($$) { fatal($src, "incomplete type $type: missing .$i") unless defined $t{$i}; } unless (defined $t{check}) { - if ($t{kind} eq 's') { - $t{check} = 'luaL_checkstring($L, $$)'; + if ($t{kind} eq 'b') { + $t{check} = '(luaL_checkint($L, $$) == 0)'; } if ($t{kind} eq 'i') { - $t{check} = 'luaL_checkint($l, $$)'; + $t{check} = 'luaL_checkint($L, $$)'; + } + + if ($t{kind} eq 's') { + $t{check} = 'luaL_checkstring($L, $$)'; } } + $t{ctypefmt} .= ' %s' unless (($t{ctypefmt} = $t{ctype}) =~ s/:/ \%s :/); + $t{ctype} =~ s/:.*//; + return $types{$type} = \%t; } @@ -212,6 +219,16 @@ sub dump_fun($$) { $call =~ s/\$\$/$t{type}->{push}/; } + if ($t{type}->{kind} eq 'b') { + put_line($f, 0); + print " lua_pushboolean(L, $call);\n"; + } + + if ($t{type}->{kind} eq 'i') { + put_line($f, 0); + print " lua_pushint(L, $call);\n"; + } + if ($t{type}->{kind} eq 's') { if ($t{const}) { put_line($f, 0); @@ -226,11 +243,6 @@ sub dump_fun($$) { } } - if ($t{type}->{kind} eq 'i') { - put_line($f, 0); - print " lua_pushint(L, $call);\n"; - } - printf " return %d;\n", ($f->{type} ne "void"); print "}\n"; } @@ -253,6 +265,7 @@ sub dump_struct_full($) { put_line($p, 0); print " $p->{init},\n"; } else { + print " 0,\n" if ($t{type}->{kind} eq 'b'); print " 0,\n" if ($t{type}->{kind} eq 'i'); print " NULL,\n" if ($t{type}->{kind} eq 's'); } @@ -273,8 +286,9 @@ EOF next if $t{const}; put_line($p, 0); - print " m_strreplace(&$var, $p->{init});\n" if ($t{type}->{kind} eq 's'); + print " $var = $p->{init};\n" if ($t{type}->{kind} eq 'b'); print " $var = $p->{init};\n" if ($t{type}->{kind} eq 'i'); + print " m_strreplace(&$var, $p->{init});\n" if ($t{type}->{kind} eq 's'); } print "};\n"; }; @@ -286,7 +300,7 @@ sub dump_struct_short($) { foreach (@{$pkg->{props}}) { my $p = $pkg->{members}{$_}; my %t = find_type($p, $p->{type}); - print " $t{type}->{ctype} $p->{name};\n"; + printf " $t{type}->{ctypefmt};\n", $p->{name}; } put_line($pkg, 0); print <{name}; $tok =~ tr/a-z/A-Z/; - if ($t{type}->{kind} eq 's') { - $call = "lua_pushstring(L, $call)"; + if ($t{type}->{kind} eq 'b') { + $call = "lua_pushboolean(L, $call)"; } if ($t{type}->{kind} eq 'i') { $call = "lua_pushinteger(L, $call)"; } + if ($t{type}->{kind} eq 's') { + $call = "lua_pushstring(L, $call)"; + } + if (defined $t{type}->{push}) { $call =~ s/\$\$/$t{type}->{push}/; } @@ -376,8 +394,9 @@ EOF put_line($p, 0); print " case LTK_$tok: \n"; - print " m_strreplace(&$var, $check)" if ($t{type}->{kind} eq 's'); + print " $var = $check" if ($t{type}->{kind} eq 'b'); print " $var = $check" if ($t{type}->{kind} eq 'i'); + print " m_strreplace(&$var, $check)" if ($t{type}->{kind} eq 's'); print ";\n return 1;\n"; } @@ -469,7 +488,6 @@ sub do_c($) { print; } } - print "/* vi"."m:set ft=c: */\n"; stream_close(\%src); } diff --git a/lib-lua/madmutt.cpkg b/lib-lua/madmutt.cpkg index f11fc65..9d1ffd7 100644 --- a/lib-lua/madmutt.cpkg +++ b/lib-lua/madmutt.cpkg @@ -45,6 +45,11 @@ static const char *luaM_path_post(const char *val) return path; } +@type bool = { + .kind = 'b'; + .ctype = unsigned : 1; +}; + @type string_t = { .kind = 's'; .ctype = const char *; @@ -59,22 +64,36 @@ static const char *luaM_path_post(const char *val) @type quadopt_t = { .kind = 'i'; .check = luaM_checkquadopt($L, $$); - .ctype = quadopt_t; + .ctype = unsigned : 2; }; +#if defined(HAVE_QDBM) +# define HCACHE_BACKEND "qdbm" +#elif defined(HAVE_GDBM) +# define HCACHE_BACKEND "gdbm" +#elif defined(HAVE_DB4) +# define HCACHE_BACKEND "db4" +#else +# define HCACHE_BACKEND "unknown" +#endif + @package madmutt { const string_t version = VERSION; const string_t sysconfdir = SYSCONFDIR; const string_t bindir = BINDIR; const string_t docdir = PKGDOCDIR; + const string_t hcache_backend = HCACHE_BACKEND; path_t dotlock = BINDIR "/mutt_dotlock"; path_t editor = getenv("VISUAL") ?: getenv("EDITOR") ?: "vi"; path_t sendmail = SENDMAIL " -eom -oi"; path_t shell = madmutt_init_shell(); - quadopt_t quit = M_YES; + quadopt_t quit = M_YES; + bool beep = 1; + bool beep_new = 0; const string_t pwd(void) = madmutt_pwd(); } ml_core; +/* vim:set ft=c: */ diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index e4482f2..34de3bb 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -18,11 +18,10 @@ */ #include -#include "lib-lua_priv.h" +#include static lua_State *L; - void luaM_initialize(void) { static const luaL_Reg lualibs[] = { diff --git a/lib-ui/curs_main.c b/lib-ui/curs_main.c index 246f240..600932a 100644 --- a/lib-ui/curs_main.c +++ b/lib-ui/curs_main.c @@ -479,7 +479,7 @@ int mutt_index_menu (void) sidebar_draw (); mutt_message (_("New mail in this mailbox.")); - if (option (OPTBEEPNEW)) + if (ml_core.beep_new) beep (); } else if (check == M_FLAGS) @@ -506,7 +506,7 @@ int mutt_index_menu (void) menu->redraw |= REDRAW_SIDEBAR; } if (do_buffy_notify) { - if (buffy_notify () && option (OPTBEEPNEW)) + if (buffy_notify () && ml_core.beep_new) beep (); } else diff --git a/lib-ui/curses.h b/lib-ui/curses.h index 4304363..c86b651 100644 --- a/lib-ui/curses.h +++ b/lib-ui/curses.h @@ -62,7 +62,7 @@ #define CLEARLINE_WIN(x) move(x,(option(OPTMBOXPANE)?SidebarWidth:0)), clrtoeol() #define CLEARLINE(x) move(x,0), clrtoeol() #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x) -#define BEEP() do { if (option (OPTBEEP)) beep(); } while (0) +#define BEEP() do { if (ml_core.beep) beep(); } while (0) #if ! (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET)) #define curs_set(x) diff --git a/mutt.h b/mutt.h index 4758623..d30984f 100644 --- a/mutt.h +++ b/mutt.h @@ -225,8 +225,6 @@ enum { OPTATTACHSPLIT, OPTAUTOEDIT, OPTAUTOTAG, - OPTBEEP, - OPTBEEPNEW, OPTBOUNCEDELIVERED, OPTBRAILLEFRIENDLY, OPTCHECKNEW, -- 2.20.1