From: Pierre Habouzit Date: Mon, 26 Mar 2007 22:14:30 +0000 (+0200) Subject: update source to use our brand new source generator. Update automakes. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=2dc50decd320b310ef56c14041b6fa4fefd865ac;p=apps%2Fmadmutt.git update source to use our brand new source generator. Update automakes. Yes the current state of affairs is completely hacky, using unbearable hacks in tools/Makefile, I f***ing don't care, it works (for now). Signed-off-by: Pierre Habouzit --- diff --git a/Makefile.am b/Makefile.am index bd8aab9..4330ce2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,15 +4,11 @@ AUTOMAKE_OPTIONS = foreign EXTRA_PROGRAMS = madmutt_dotlock pgpringng pgpewrapng makedoc -.cpkg.c: ; ./lib-lua/luapkg2c.pl -c $< > $@ -.cpkg.li: ; ./lib-lua/luapkg2c.pl -h $< > $@ - - if BUILD_NNTP NNTP_SUBDIR = nntp endif -SUBDIRS = intl m4 po $(XXXXXXXXXXXX_doc) apidoc contrib \ +SUBDIRS = tools intl m4 po $(XXXXXXXXXXXX_doc) apidoc contrib \ lib-lua lib-mime lib-lib lib-mx lib-crypt lib-hash lib-sys lib-ui \ pop imap $(NNTP_SUBDIR) @@ -21,7 +17,7 @@ DISTCLEANFILES = $(BUILT_SOURCES) bin_PROGRAMS = madmutt madmutt_dotlock pgpringng pgpewrapng smime_keysng madmutt_SOURCES = $(BUILT_SOURCES) \ - alias.cpkg attach.c base64.c browser.c buffy.c charset.c commands.c \ + alias.c 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 \ @@ -41,8 +37,8 @@ madmutt_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \ $(top_builddir)/lib-lib/liblib.a \ $(MUTTLIBS) $(INTLLIBS) $(LIBICONV) -madmutt_DEPENDENCIES = $(top_builddir)/lib-lua/madmutt.li \ - $(top_builddir)/lib-lua/lua-token.h \ +madmutt_DEPENDENCIES = \ + \ @MUTT_LIB_OBJECTS@ @LIBOBJS@ \ $(top_builddir)/lib-lib/liblib.a \ $(top_builddir)/lib-mime/libmime.a \ @@ -152,7 +148,8 @@ stamp-doc-rc: $(srcdir)/init.h makedoc Madmuttrc.head $(srcdir)/init.h | ./makedoc -c | cat Madmuttrc.head - > Madmuttrc touch $@ --include cflags.mk +include $(top_builddir)/tools/cpkg2c.mk +-include $(top_buildir)/tools/cflags.mk wc: @sloccount $(wildcard *.h *.c) $(wildcard lib-*/) lib imap nntp pop | grep 'ansic[=:]' diff --git a/alias.cpkg b/alias.cpkg index 6e33e29..b6b1dbe 100644 --- a/alias.cpkg +++ b/alias.cpkg @@ -36,36 +36,12 @@ #include "alias.h" #include "mutt_idna.h" #include "sort.h" +@import "lib-lua/base.cpkg" -@type bool = { - .kind = 'b'; - .ctype = unsigned : 1; -}; - -@type string_t = { - .kind = 's'; - .ctype = char *; - .dtor = p_delete($$); - .ctor = m_strdup($$); -}; - -@type path_t = { - .kind = 's'; - .ctype = char *; - .dtor = p_delete($$); - .ctor = luaM_pathnew($$); -}; - -@type quadopt_t = { - .kind = 'i'; - .check = luaM_checkquadopt($L, $$); - .ctype = unsigned : 2; -}; - -static @package MAlias { +@static_package MAlias { string_t alias_format = m_strdup("%4n %2f %t %-10a %r"); path_t alias_file = m_strdup("~/.madmutt/aliases"); -} MAlias; +}; alias_t *Aliases; diff --git a/imap/Makefile.am b/imap/Makefile.am index 8396aac..fb51379 100644 --- a/imap/Makefile.am +++ b/imap/Makefile.am @@ -14,4 +14,4 @@ noinst_HEADERS = auth.h imap_private.h message.h libimap_a_SOURCES = auth.c auth_login.c browse.c command.c imap.c imap.h \ message.c utf7.c util.c $(AUTHENTICATORS) auth_gss.c --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/lib-crypt/Makefile.am b/lib-crypt/Makefile.am index 5dfc49b..2832f56 100644 --- a/lib-crypt/Makefile.am +++ b/lib-crypt/Makefile.am @@ -14,4 +14,4 @@ libcrypt_a_SOURCES = pgp.h pgplib.h pgppacket.h smime.h crypt.h crypt-mod.h \ noinst_HEADERS = pgp.h pgplib.h pgppacket.h smime.h crypt.h crypt-mod.h \ crypt-gpgme.h --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/lib-hash/Makefile.am b/lib-hash/Makefile.am index 7a55dee..7231e4f 100644 --- a/lib-hash/Makefile.am +++ b/lib-hash/Makefile.am @@ -5,3 +5,4 @@ libhash_a_SOURCES = md5.h sha1.h crypthash.h \ noinst_HEADERS = md5.h sha1.h +-include $(top_buildir)/tools/cflags.mk diff --git a/lib-lib/Makefile.am b/lib-lib/Makefile.am index c4bacb2..3346eeb 100644 --- a/lib-lib/Makefile.am +++ b/lib-lib/Makefile.am @@ -7,4 +7,4 @@ liblib_a_SOURCES = lib-lib.h mem.h \ noinst_HEADERS = lib-lib.h mem.h \ str.h utf8.h buffer.h hash.h array.h list.h file.h mapping.h date.h rx.h url.h --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/lib-lua/Makefile.am b/lib-lua/Makefile.am index a12888b..64b8e6c 100644 --- a/lib-lua/Makefile.am +++ b/lib-lua/Makefile.am @@ -1,13 +1,10 @@ BUILT_SOURCES = lua-token.h lua-token.c DISTCLEANFILES = $(BUILT_SOURCES) -.cpkg.c: ; ./luapkg2c.pl -c $< > $@ -.cpkg.li: ; ./luapkg2c.pl -h $< > $@ - noinst_LIBRARIES = liblua.a liblua_a_DEPENDENCIES = madmutt.li -liblua_a_SOURCES = madmutt.cpkg \ +liblua_a_SOURCES = madmutt.c \ lib-lua.h \ runtime.c \ $(BUILT_SOURCES) @@ -21,4 +18,5 @@ DEFS=-DPKGDATADIR=\"$(pkgdatadir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \ -DBINDIR=\"$(bindir)\" -DMUTTLOCALEDIR=\"$(datadir)/locale\" \ -DHAVE_CONFIG_H=1 -DPKGDOCDIR=\"$(docdir)\" --include ../cflags.mk +include $(top_builddir)/tools/cpkg2c.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/lib-lua/base.cpkg b/lib-lua/base.cpkg new file mode 100644 index 0000000..f9b7304 --- /dev/null +++ b/lib-lua/base.cpkg @@ -0,0 +1,33 @@ +@type bool { + .ctype = unsigned : 1; + .check = (luaL_checkinteger($L, $$) != 0); + .push = lua_pushboolean($L, $$); +}; + +@type quadopt_t { + .ctype = unsigned : 2; + .check = luaM_checkquadopt($L, $$); + .push = lua_pushinteger($L, $$); +}; + +@type string_t { + .ctype = char *; + .check = luaL_checkstring($L, $$); + .push = lua_pushstring($L, $$); + .ctor = m_strdup($$); + .dtor = p_delete($$); +}; + +@type path_t : string_t { + .ctor = luaM_pathnew($$); +}; + +@type rx_t { + .ctype = rx_t *; + .check = luaM_checkrx($L, $$); + .push = lua_pushstring($L, $$ ? ($$)->pattern : NULL); + .ctor = luaM_rxnew($$); + .dtor = rx_delete($$); +}; + +/* vim:set ft=c: */ diff --git a/lib-lua/luapkg2c.pl b/lib-lua/luapkg2c.pl deleted file mode 100755 index f1bab32..0000000 --- a/lib-lua/luapkg2c.pl +++ /dev/null @@ -1,606 +0,0 @@ -#!/usr/bin/perl -w -# 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 - -use strict; - -my %types; -my %pkgs; - -#{{{ stream functions - -sub stream_open($) { - my $name = shift; - open FILE, $name; - return (file => $name, line => 0, f => \*FILE); -} - -sub stream_close($) { - my $stream = shift; - close $stream->{f}; -} - -sub stream_getline($) { - my $stream = shift; - my $file = $stream->{f}; - while (<$file>) { - ${$stream}{line}++; - return $_; - } - return; -} - -#}}} - -#{{{ file:line functions - -sub fatal($$) { - my ($stream, $msg) = @_; - printf STDERR "%s:%d: %s\n", $stream->{file}, $stream->{line}, $msg; - exit 1; -} - -sub get_pos($$) { - my ($h,$k) = @_; - return $h->{$k}{file}.':'.$h->{$k}{line}; -} - -sub put_line($$) { - my ($src,$inc) = @_; - printf "#line %d \"%s\"\n", $src->{line} + $inc, $src->{file}; -} - -#}}} - -#{{{ parsers - -sub parse_type($$) { - my ($src, $type) = @_; - my %t = ( - name => $type, - file => $src->{file}, - line => $src->{line}, - ); - - if (defined $types{$type}) { - my $pos = get_pos(\%types, $type); - fatal($src, "already defined type: `$type' at $pos"); - } - - while (stream_getline($src)) { - last if (/^\s*\}\s*;\s*/); - if (/^\s*\.(kind|ctype|dtor|ctor|push|check)\s*=\s*(.*?)\s*;\s*$/) { - $t{$1} = $2; - if ($1 eq "kind") { - if ($2 =~ /^'([bis])'$/) { - $t{kind} = $1; - } else { - fatal($src, "error: .kind should be [ibs] got $2)"); - } - } - } elsif (!/^\s*$/) { - fatal($src, "syntax error: unknown type directive"); - } - } - - for ('kind', 'ctype') { - fatal($src, "incomplete type $type: missing .$_") unless defined $t{$_}; - } - if ($t{kind} eq 's') { - for ('dtor', 'ctor') { - fatal($src, "incomplete type $type: missing .$_") unless defined $t{$_}; - } - } - unless (defined $t{check}) { - if ($t{kind} eq 'b') { - $t{check} = '(luaL_checkint($L, $$) == 0)'; - } - - if ($t{kind} eq 'i') { - $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; -} - -sub parse_package($$) { - my ($src, $pkg) = @_; - my %p = ( - name => $pkg, - file => $src->{file}, - line => $src->{line}, - ); - - if (defined $pkgs{$pkg}) { - my $pos = get_pos(\%pkgs, $pkg); - fatal($src, "already defined package: `$pkg' at $pos"); - } - - while (stream_getline($src)) { - if (/^\s*\}\s*(\w+)\s*;\s*$/) { - $p{cname} = $1; - last; - } - - if (/^\s*(.*?)\s*=\s*(.*?)\s*;\s*$/) { - my ($lhs, $rhs) = ($1, $2); - my %m = ( file => $src->{file}, line => $src->{line} ); - - if ($lhs =~ /^((?:const\s+)?\w+?)\s*(\w+)$/) { - $m{type} = $1; - $m{name} = $2; - $m{init} = $rhs; - push @{$p{props}}, $2; - } elsif ($lhs =~ /^((?:const\s+)?\w+?)\s*(\w*)\((.*)\)$/) { - $m{type} = $1; - $m{name} = $2; - $m{proto} = $3; - $m{cfun} = $rhs; - push @{$p{meths}}, $2; - } else { - fatal($src, "syntax error"); - } - - if (defined $p{members}{$m{name}}) { - my $pos = get_pos($p{members}{$m{name}}, 0); - fatal($src, "already defined package member: `$m{name}' at $pos"); - } - - $p{members}{$m{name}} = \%m; - next; - } - - if (!/^\s*$/) { - fatal($src, "syntax error"); - } - } - - return $pkgs{$pkg} = \%p; -} - -sub find_type($$) { - my ($ref, $typ) = @_; - - if ($typ =~ /^const\s+(\w*)$/) { - fatal($ref, "undefined type `$1'") unless defined $types{$1}; - return (const => 1, type => $types{$1}); - } - - fatal($ref, "undefined type `$typ'") unless defined $types{$typ}; - return (const => 0, type => $types{$typ}); -} - -#}}} - -#{{{ dump_fun - -sub dump_fun($$) { - my ($pkg, $f) = @_; - my %t = find_type($f, $f->{type}); - my $call = $f->{cfun}; - $call =~ s/\$/var/; - - print "static int luaM_${pkg}_$f->{name}(lua_State *L) {\n"; - - if ($f->{proto} ne "void") { - my $i = 1; - for my $tmp (split /,/,$f->{proto}) { - s/^\s+//; - s/\s+$//; - - my %pt = find_type($f, $tmp); - my $check = $pt{type}->{check}; - $check =~ s/\$L/L/; - $check =~ s/\$\$/\%d/; - - put_line($pt{type}, 0); - printf " $pt{type}->{ctype} var$i = $check\n", $i++; - } - } - - die "UNIMPLEMENTED" if defined $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); - print " lua_pushstring(L, $call);\n"; - } else { - print " {\n"; - put_line($f, 0); - print " char *s = $call;\n"; - print " lua_pushstring(L, s);\n"; - print " p_delete(&s);\n"; - print " }\n"; - } - } - - printf " return %d;\n", ($f->{type} ne "void"); - print "}\n"; -} - -#}}} - -#{{{ dump_struct - -sub dump_struct_full($) { - my ($pkg) = @_; - - put_line($pkg, 0); - print "struct luaM_$pkg->{name}_t $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"; -}; - -sub dump_struct_short($) { - my ($pkg) = @_; - - print "struct luaM_$pkg->{name}_t {\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 <{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, $static) = @_; - - if ($static) { - dump_struct_static($pkg); - } else { - dump_struct_full($pkg); - } - map { print "\n"; dump_fun($pkg->{name}, $pkg->{members}{$_}); } @{$pkg->{meths}}; - print <{name}_methods[] = { -EOF - map { print " { \"$_\", luaM_$pkg->{name}_$_ },\n"; } @{$pkg->{meths}}; - print <{name}_index(lua_State *L) -{ - const char *idx = luaL_checkstring(L, 2); - - switch (mlua_which_token(idx, -1)) { -EOF - - foreach (@{$pkg->{props}}) { - my $p = $pkg->{members}{$_}; - my %t = find_type($p, $p->{type}); - my $call = $t{type}->{push} || '$$'; - - $call =~ s/\$L/L/; - $call =~ s/\$\$/$pkg->{cname}.$p->{name}/; - - my $tok = $p->{name}; - $tok =~ tr/a-z/A-Z/; - - 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)"; - } - - put_line($p, 0); - print " case LTK_$tok:\n"; - printf " $call;\n"; - print " return 1;\n"; - } - -print <{name}_newindex(lua_State *L) -{ - const char *idx = luaL_checkstring(L, 2); - - switch (mlua_which_token(idx, -1)) { -EOF - - foreach (@{$pkg->{props}}) { - my $p = $pkg->{members}{$_}; - my %t = find_type($p, $p->{type}); - - next if ($t{const}); - - my $tok = $p->{name}; - my $var = $pkg->{cname}.".".$p->{name}; - my $check = $t{type}->{check}; - $tok =~ tr/a-z/A-Z/; - $check =~ s/\$L/L/; - $check =~ s/\$\$/3/; - - put_line($p, 0); - print " case LTK_$tok: \n"; - if ($t{type}->{dtor}) { - my $dtor = $t{type}->{dtor}; - $dtor =~ s/\$L/L/; - $dtor =~ s/\$\$/\&$var/; - print " $dtor;\n"; - } - if ($t{type}->{ctor}) { - my $ctor = $t{type}->{ctor}; - $ctor =~ s/\$L/L/; - $ctor =~ s/\$\$/$check/; - $check = $ctor; - } - print " $var = $check;\n"; - print " return 1;\n"; - } - -print <{name}(lua_State *L) -{ - int mt, methods; - - $pkg->{cname}_init(); - - /* create methods table, add it the the table of globals */ - luaL_openlib(L, "$pkg->{name}", luaM_$pkg->{name}_methods, 0); - methods = lua_gettop(L); - - /* create metatable for $pkg->{name}, add it to the registry */ - luaL_newmetatable(L, "$pkg->{name}"); - mt = lua_gettop(L); - - lua_pushliteral(L, "__index"); - lua_pushvalue(L, mt); /* upvalue 1 */ - lua_pushvalue(L, methods); /* upvalue 2 */ - lua_pushcclosure(L, &luaM_$pkg->{name}_index, 2); - lua_rawset(L, mt); /* set mt.__index */ - - lua_pushliteral(L, "__newindex"); - lua_newtable(L); /* for new members */ - lua_pushcclosure(L, &luaM_$pkg->{name}_newindex, 1); - lua_rawset(L, mt); /* set mt.__newindex */ - - lua_pushliteral(L, "__metatable"); - lua_pushvalue(L, methods); /* dup methods table */ - lua_rawset(L, mt); /* hide metatable */ - - lua_setmetatable(L, methods); - - lua_pop(L, 1); /* drop mt */ - return 1; /* return methods */ -} - -EOF -} - -sub dump_package_short($) { - my $pkg = shift; - my $upp = $pkg->{name}; - $upp =~ tr/a-z/A-Z/; - - print <{name}(lua_State *L); - -#endif /* MUTT_LUA_${upp}_H */ -EOF -} - -#}}} - -sub do_c($) { - my %src = stream_open(shift); - my $resync = 1; - - while (stream_getline(\%src)) { - if (/^\s*\@type\s+([a-zA-Z]\w*)\s*=\s*{\s*$/) { - parse_type(\%src, $1); - $resync = 1; - } elsif (/^\s*static\s+\@package\s+([a-zA-Z]\w*)\s+{\s*$/) { - dump_package_full(parse_package(\%src, $1), 1); - $resync = 1; - } elsif (/^\s*\@package\s+([a-zA-Z]\w*)\s+{\s*$/) { - dump_package_full(parse_package(\%src, $1), 0); - $resync = 1; - } elsif (/^\s*(\@\w*)/) { - fatal(\%src, "syntax error: unknown directive `$1'"); - } else { - next if ($resync && /^\s+$/); - if ($resync) { - put_line(\%src, 0); - $resync = 0; - } - print; - } - } - - stream_close(\%src); -} - -sub do_h($) { - my %src = stream_open(shift); - my $resync = 1; - - while (stream_getline(\%src)) { - if (/^\s*\@type\s+([a-zA-Z]\w*)\s*=\s*{\s*$/) { - parse_type(\%src, $1); - } elsif (/^\s*\@package\s+([a-zA-Z]\w*)\s+{\s*$/) { - dump_package_short(parse_package(\%src, $1)); - } elsif (/^\s*(\@\w*)/) { - fatal(\%src, "syntax error: unknown directive `$1'"); - } - } - - stream_close(\%src); -} - -if ($#ARGV < 1 || ($ARGV[0] ne "-h" && $ARGV[0] ne "-c")) { - print < #include "../mutt.h" +@import "base.cpkg" static char *madmutt_init_shell(void) { @@ -43,55 +44,14 @@ static char *madmutt_init_homedir(void) return m_strdup(pw ? pw->pw_dir : (getenv("HOME") ?: "/")); } -static const char *madmutt_pwd(void) -{ - char path[_POSIX_PATH_MAX]; - getcwd(path, sizeof(path)); - return path; -} - -@type bool = { - .kind = 'b'; - .ctype = unsigned : 1; -}; - -@type string_t = { - .kind = 's'; - .ctype = char *; - .dtor = p_delete($$); - .ctor = m_strdup($$); -}; - -@type path_t = { - .kind = 's'; - .ctype = char *; - .dtor = p_delete($$); - .ctor = luaM_pathnew($$); -}; - -@type quadopt_t = { - .kind = 'i'; - .check = luaM_checkquadopt($L, $$); - .ctype = unsigned : 2; -}; - -@type rx_t = { - .kind = 's'; - .ctype = rx_t *; - .check = luaM_checkrx($L, $$); - .push = ($$)->pattern; - .ctor = luaM_rxnew($$); - .dtor = rx_delete($$); -}; - #if defined(HAVE_QDBM) -# define HCACHE_BACKEND "qdbm" +# define HCACHE_BACKEND "qdbm" #elif defined(HAVE_GDBM) -# define HCACHE_BACKEND "gdbm" +# define HCACHE_BACKEND "gdbm" #elif defined(HAVE_DB4) -# define HCACHE_BACKEND "db4" +# define HCACHE_BACKEND "db4" #else -# define HCACHE_BACKEND "unknown" +# define HCACHE_BACKEND NULL #endif @package MCore { @@ -113,14 +73,21 @@ static const char *madmutt_pwd(void) bool beep = 1; bool beep_new = 0; - const string_t pwd(void) = madmutt_pwd(); -} MCore; + const string_t pwd(void) { + char path[_POSIX_PATH_MAX]; + getcwd(path, sizeof(path)); + RETURN(path); + }; +}; @package MTransport { path_t sendmail = m_strdup(SENDMAIL " -eom -oi"); - string_t dsn_notify = NULL /* TODO: check it's NULL, hdrs or full */; - string_t dsn_return = NULL /* TODO: check it's never, delay, failure, success with ',' */; -} MTransport; + /* TODO: check it's NULL, hdrs or full */ + string_t dsn_notify = NULL; + + /* TODO: check it's never, delay, failure, success with ',' */ + string_t dsn_return = NULL; +}; /* vim:set ft=c: */ diff --git a/lib-mime/Makefile.am b/lib-mime/Makefile.am index 779ef44..24c8e0f 100644 --- a/lib-mime/Makefile.am +++ b/lib-mime/Makefile.am @@ -15,4 +15,4 @@ noinst_HEADERS = mime.h mime-types.h mime-token.c mime-token.h: mime-token.def mime-token.sh sh mime-token.sh $@ < $< --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/lib-mx/Makefile.am b/lib-mx/Makefile.am index 3261100..a9548c9 100644 --- a/lib-mx/Makefile.am +++ b/lib-mx/Makefile.am @@ -5,4 +5,4 @@ libmx_a_SOURCES = mx.h mh.h mbox.h compress.h hcache.h \ noinst_HEADERS = mx.h --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/lib-sys/Makefile.am b/lib-sys/Makefile.am index 20ce69f..102fb76 100644 --- a/lib-sys/Makefile.am +++ b/lib-sys/Makefile.am @@ -9,4 +9,4 @@ libsys_a_SOURCES = exit.h unix.h mutt_signal.h \ noinst_HEADERS = exit.h unix.h \ mutt_socket.h mutt_tunnel.c mutt_ssl.h --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/lib-ui/Makefile.am b/lib-ui/Makefile.am index 4461598..f372e2f 100644 --- a/lib-ui/Makefile.am +++ b/lib-ui/Makefile.am @@ -7,4 +7,4 @@ libui_a_SOURCES = curses.h enter.h menu.h history.h sidebar.h \ noinst_HEADERS = curses.h enter.h menu.h history.h sidebar.h --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/nntp/Makefile.am b/nntp/Makefile.am index ca6d65b..0907c36 100644 --- a/nntp/Makefile.am +++ b/nntp/Makefile.am @@ -11,4 +11,4 @@ noinst_HEADERS = nntp.h libnntp_a_SOURCES = nntp.h nntp.c newsrc.c --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/pop/Makefile.am b/pop/Makefile.am index 1467447..6fca1fb 100644 --- a/pop/Makefile.am +++ b/pop/Makefile.am @@ -11,4 +11,4 @@ noinst_HEADERS = pop.h libpop_a_SOURCES = pop.c pop_auth.c pop_lib.c pop.h --include ../cflags.mk +-include $(top_builddir)/tools/cflags.mk diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 0000000..0977d93 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1 @@ +cpkg2c diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..ec3e895 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,14 @@ +# automake sucks, badly +all: ../lib-mime/mime-token.h \ + ../lib-lua/lua-token.h \ + ../lib-lua/madmutt.li + +../%: ; $(MAKE) -C $(@D) $(@F) + +cpkg2c: cpkg2c.mll + ocamllex $< + $(if $(shell which ocamlopt),ocamlopt -o $@ str.cmxa,ocamlc -o $@ str.cma) $@.ml + @$(RM) cpkg2c.ml cpkg2c.c* cpkg2c.o + +clean: + $(RM) cpkg2c diff --git a/cflags.mk b/tools/cflags.mk similarity index 100% rename from cflags.mk rename to tools/cflags.mk diff --git a/tools/cpkg2c.mk b/tools/cpkg2c.mk new file mode 100644 index 0000000..66660fd --- /dev/null +++ b/tools/cpkg2c.mk @@ -0,0 +1,9 @@ +%.c: %.cpkg $(top_builddir)/tools/cpkg2c + $(top_builddir)/tools/cpkg2c -c $< > $@ || (rm -f $@; exit 1) + +%.li: %.cpkg $(top_builddir)/tools/cpkg2c + $(top_builddir)/tools/cpkg2c -h $< > $@ || (rm -f $@; exit 1) + +$(top_builddir)/tools/cpkg2c: + $(MAKE) -C $(@D) $(@F) +