From 1410cfc03a04ccce7aac48a62f9d465ab341cef1 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 18 Mar 2007 22:53:59 +0100 Subject: [PATCH] make Alias be a module as well. update luapkg2c to deal with "static" modules. Signed-off-by: Pierre Habouzit --- Makefile.am | 4 ++- alias.c => alias.cpkg | 35 +++++++++++++++++++-- alias.h | 4 +++ init.h | 14 --------- lib-lua/lua-token.sh | 1 + lib-lua/luapkg2c.pl | 71 ++++++++++++++++++++++++++++++++++++++++--- lib-lua/runtime.c | 3 ++ 7 files changed, 111 insertions(+), 21 deletions(-) rename alias.c => alias.cpkg (96%) diff --git a/Makefile.am b/Makefile.am index cc992ac..f09fc6c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,8 @@ AUTOMAKE_OPTIONS = foreign EXTRA_PROGRAMS = madmutt_dotlock pgpringng pgpewrapng makedoc +.cpkg.c: ; ./lib-lua/luapkg2c.pl -c $< > $@ + if BUILD_NNTP NNTP_SUBDIR = nntp endif @@ -17,7 +19,7 @@ DISTCLEANFILES = $(BUILT_SOURCES) bin_PROGRAMS = madmutt madmutt_dotlock pgpringng pgpewrapng smime_keysng madmutt_SOURCES = $(BUILT_SOURCES) \ - alias.c attach.c base64.c browser.c buffy.c charset.c commands.c \ + alias.cpkg attach.c base64.c browser.c buffy.c charset.c commands.c \ compose.c copy.c editmsg.c init.c keymap.c lib.c \ flags.c from.c handler.c headers.c help.c hook.c \ main.c muttlib.c mutt_idna.c pager.c pattern.c postpone.c recvattach.c recvcmd.c \ diff --git a/alias.c b/alias.cpkg similarity index 96% rename from alias.c rename to alias.cpkg index 03482c6..424adda 100644 --- a/alias.c +++ b/alias.cpkg @@ -37,7 +37,36 @@ #include "mutt_idna.h" #include "sort.h" -char *AliasFmt; +@type bool = { + .kind = 'b'; + .ctype = unsigned : 1; +}; + +@type string_t = { + .kind = 's'; + .ctype = char *; + .dtor = p_delete($$); + .ctor = m_strdup($$); +}; + +@type path_t = { + .push = luaM_path_post($$); + .kind = 's'; + .ctype = char *; + .dtor = p_delete($$); + .ctor = m_strdup($$); +}; + +@type quadopt_t = { + .kind = 'i'; + .check = luaM_checkquadopt($L, $$); + .ctype = unsigned : 2; +}; + +static @package MAlias { + path_t alias_format = m_strdup("%4n %2f %t %-10a %r"); +} MAlias; + char *AliasFile; alias_t *Aliases; rx_t GecosMask; @@ -516,7 +545,7 @@ alias_format_str(char *dest, ssize_t destlen, char op, const char *src, static void alias_entry(char *s, ssize_t slen, MUTTMENU *m, int num) { - m_strformat(s, slen, COLS - SW, AliasFmt, alias_format_str, + m_strformat(s, slen, COLS - SW, MAlias.alias_format, alias_format_str, ((alias_t **)m->data)[num], option(OPTARROWCURSOR) ? M_FORMAT_ARROWCURSOR : 0); } @@ -671,3 +700,5 @@ new_aliases: mutt_menuDestroy (&menu); p_delete(&AliasTable); } + +/* vim:set ft=c: */ diff --git a/alias.h b/alias.h index 1819da7..74eab42 100644 --- a/alias.h +++ b/alias.h @@ -28,8 +28,12 @@ #define _MUTT_ALIAS_H #include +#include + #include +int luaopen_MAlias(lua_State *L); + typedef struct alias_t { struct alias_t *next; char *name; diff --git a/init.h b/init.h index 1f706e6..abc629b 100644 --- a/init.h +++ b/init.h @@ -147,20 +147,6 @@ struct option_t MuttVars[] = { ** \fBNote:\fP Madmutt will not automatically source this file; you must ** explicitly use the ``$source'' command for it to be executed. */ - {"alias_format", DT_STR, R_NONE, UL &AliasFmt, "%4n %2f %t %-10a %r"}, - /* - ** .pp - ** Specifies the format of the data displayed for the ``alias'' menu. The - ** following \fTprintf(3)\fP-style sequences are available: - ** .pp - ** .dl - ** .dt %a .dd alias name - ** .dt %f .dd flags - currently, a "d" for an alias marked for deletion - ** .dt %n .dd index number - ** .dt %r .dd address which alias expands to - ** .dt %t .dd character which indicates if the alias is tagged for inclusion - ** .de - */ {"allow_8bit", DT_BOOL, R_NONE, OPTALLOW8BIT, "yes" }, /* ** .pp diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index e2f5ed3..a3ba223 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -127,3 +127,4 @@ exit 0 ## tmpdir ## username ## version +## alias_format diff --git a/lib-lua/luapkg2c.pl b/lib-lua/luapkg2c.pl index ac46db6..b7d1ba3 100755 --- a/lib-lua/luapkg2c.pl +++ b/lib-lua/luapkg2c.pl @@ -323,14 +323,74 @@ extern struct luaM_$pkg->{name}_t $pkg->{cname}; EOF } +sub dump_struct_static($) { + my ($pkg) = @_; + + print "static struct {\n"; + foreach (@{$pkg->{props}}) { + my $p = $pkg->{members}{$_}; + my %t = find_type($p, $p->{type}); + if ($t{const}) { + printf " const $t{type}->{ctypefmt};\n", $p->{name}; + } else { + printf " $t{type}->{ctypefmt};\n", $p->{name}; + } + } + put_line($pkg, 0); + print "} $pkg->{cname} = {\n"; + + foreach (@{$pkg->{props}}) { + my $p = $pkg->{members}{$_}; + my %t = find_type($p, $p->{type}); + + if ($t{const}) { + 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'); + } + } + + print <{cname}_init(void) +{ +EOF + + foreach (@{$pkg->{props}}) { + my $p = $pkg->{members}{$_}; + my %t = find_type($p, $p->{type}); + my $var = $pkg->{cname}.".".$p->{name}; + + next if $t{const}; + + put_line($p, 0); + if ($t{type}->{dtor}) { + my $dtor = $t{type}->{dtor}; + $dtor =~ s/\$L/L/; + $dtor =~ s/\$\$/\&$var/; + print " $dtor;\n"; + } + print " $var = $p->{init};\n" + } + print "};\n"; +}; + #}}} #{{{ dump package -sub dump_package_full($) { - my $pkg = shift; +sub dump_package_full($$) { + my ($pkg, $static) = @_; - dump_struct_full($pkg); + if ($static) { + dump_struct_static($pkg); + } else { + dump_struct_full($pkg); + } map { print "\n"; dump_fun($pkg->{name}, $pkg->{members}{$_}); } @{$pkg->{meths}}; print < #include +#include + static lua_State *L; void luaM_initialize(void) @@ -35,6 +37,7 @@ void luaM_initialize(void) {LUA_DBLIBNAME, luaopen_debug}, {"MCore", luaopen_MCore}, {"MTransport", luaopen_MTransport}, + {"MAlias", luaopen_MAlias}, }; int i; -- 2.20.1