make our lua packages support regexps, needed some bindings enhancements.
fixes fixes fixes
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
AUTOMAKE_OPTIONS = foreign
EXTRA_PROGRAMS = madmutt_dotlock pgpringng pgpewrapng makedoc
-.cpkg.c: ; ./lib-lua/luapkg2c.pl -c $< > $@
+.cpkg.c: ; ./lib-lua/luapkg2c.pl -c $< > $@
+.cpkg.li: ; ./lib-lua/luapkg2c.pl -h $< > $@
+
if BUILD_NNTP
NNTP_SUBDIR = nntp
$(top_builddir)/lib-lib/liblib.a \
$(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
-madmutt_DEPENDENCIES = $(top_builddir)/lib-lua/madmutt.h \
+madmutt_DEPENDENCIES = $(top_builddir)/lib-lua/madmutt.li \
$(top_builddir)/lib-lua/lua-token.h \
@MUTT_LIB_OBJECTS@ @LIBOBJS@ \
$(top_builddir)/lib-lib/liblib.a \
};
@type path_t = {
- .push = luaM_path_post($$);
.kind = 's';
.ctype = char *;
.dtor = p_delete($$);
- .ctor = m_strdup($$);
+ .ctor = luaM_pathnew($$);
};
@type quadopt_t = {
};
static @package MAlias {
- path_t alias_format = m_strdup("%4n %2f %t %-10a %r");
+ string_t alias_format = m_strdup("%4n %2f %t %-10a %r");
+ path_t alias_file = m_strdup("~/.madmutt/aliases");
} MAlias;
-char *AliasFile;
alias_t *Aliases;
-rx_t GecosMask;
#define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x
alias_list_push(&Aliases, new);
- m_strcpy(buf, sizeof(buf), NONULL(AliasFile));
+ m_strcpy(buf, sizeof(buf), NONULL(MAlias.alias_file));
if (mutt_get_field(_("Save to file: "), buf, sizeof(buf), M_FILE)) {
return;
}
if (pw) {
char namebuf[STRING];
- mutt_gecos_name(namebuf, sizeof(namebuf), pw, GecosMask.rx);
+ mutt_gecos_name(namebuf, sizeof(namebuf), pw, MCore.gecos_mask.rx);
m_strreplace(&pop->personal, namebuf);
}
}
short num;
} alias_t;
-extern char *AliasFmt;
-extern char *AliasFile;
extern alias_t *Aliases;
-extern rx_t GecosMask;
DO_INIT(alias_t, alias);
static inline void alias_wipe(alias_t *a) {
snprintf (AttachmentMarker, sizeof(AttachmentMarker),
"\033]9;%ld\a", (long) time (NULL));
+ luaM_initialize();
/* Get some information about the user */
if ((pw = getpwuid (getuid ()))) {
char rnbuf[STRING];
- mutt_gecos_name(rnbuf, sizeof(rnbuf), pw, GecosMask.rx);
+ mutt_gecos_name(rnbuf, sizeof(rnbuf), pw, MCore.gecos_mask);
Realname = m_strdup(rnbuf);
- endpwent ();
}
/* And about the host... */
From = rfc822_parse_adrlist (NULL, p);
charset_initialize();
- luaM_initialize();
/* Set standard defaults */
hash_map (ConfigOptions, mutt_set_default, 0);
mutt_expand_path (buffer, sizeof(buffer));
Muttrc = m_strdup(buffer);
}
- p_delete(&AliasFile);
- AliasFile = m_strdup(NONULL (Muttrc));
/* Process the global rc file if it exists and the user hasn't explicity
requested not to via "-n". */
** check only happens after the \fIfirst\fP edit of the file). When set
** to \fIno\fP, composition will never be aborted.
*/
- {"alias_file", DT_PATH, R_NONE, UL &AliasFile, "~/.madmuttrc"},
- /*
- ** .pp
- ** The default file in which to save aliases created by the
- ** ``$create-alias'' function.
- ** .pp
- ** \fBNote:\fP Madmutt will not automatically source this file; you must
- ** explicitly use the ``$source'' command for it to be executed.
- */
{"allow_8bit", DT_BOOL, R_NONE, OPTALLOW8BIT, "yes" },
/*
** .pp
** .pp
** Defaults to the contents of the environment variable \fT$$$EMAIL\fP.
*/
- {"gecos_mask", DT_RX, R_NONE, UL &GecosMask, "^[^,]*"},
- /*
- ** .pp
- ** A regular expression used by Madmutt to parse the GECOS field of a password
- ** entry when expanding the alias. By default the regular expression is set
- ** to ``\fT^[^,]*\fP'' which will return the string up to the first ``\fT,\fP'' encountered.
- ** If the GECOS field contains a string like "lastname, firstname" then you
- ** should do: \fTset gecos_mask=".*"\fP.
- ** .pp
- ** This can be useful if you see the following behavior: you address a e-mail
- ** to user ID stevef whose full name is Steve Franklin. If Madmutt expands
- ** stevef to ``Franklin'' stevef@foo.bar then you should set the gecos_mask to
- ** a regular expression that will match the whole name so Madmutt will expand
- ** ``Franklin'' to ``Franklin, Steve''.
- */
#ifdef USE_NNTP
{"nntp_group_index_format", DT_STR, R_BOTH, UL &GroupFormat, "%4C %M%N %5s %-45.45f %d"},
/*
lua-token.[hc]
-madmutt.[hc]
+madmutt.c
+madmutt.li
BUILT_SOURCES = lua-token.h lua-token.c
DISTCLEANFILES = $(BUILT_SOURCES)
-.cpkg.c: ; ./luapkg2c.pl -c $< > $@
-.cpkg.h: ; ./luapkg2c.pl -h $< > $@
+.cpkg.c: ; ./luapkg2c.pl -c $< > $@
+.cpkg.li: ; ./luapkg2c.pl -h $< > $@
noinst_LIBRARIES = liblua.a
-liblua_a_DEPENDENCIES = madmutt.h
+liblua_a_DEPENDENCIES = madmutt.li
liblua_a_SOURCES = madmutt.cpkg \
lib-lua.h \
runtime.c \
int status);
quadopt_t luaM_checkquadopt(lua_State *L, int narg);
+const char *luaM_checkrx(lua_State *Ls, int narg);
+char *luaM_pathnew(const char *val);
+rx_t *luaM_rxnew(const char* val);
-#include "madmutt.h"
+#include "madmutt.li"
#endif
exit 0
############ Put tokens here ############
+## alias_file
+## alias_format
## beep
## beep_new
## bindir
## dsn_notify
## dsn_return
## editor
+## gecos_mask
## hcache_backend
## homedir
## quit
## tmpdir
## username
## version
-## alias_format
while (stream_getline($src)) {
last if (/^\s*\}\s*;\s*/);
- if (/^\s*\.(push|kind|ctype|dtor|ctor|check)\s*=\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])'$/) {
}
}
- if (defined $t{type}->{push}) {
- $call =~ s/\$\$/$t{type}->{push}/;
- }
+ die "UNIMPLEMENTED" if defined $t{type}->{push};
if ($t{type}->{kind} eq 'b') {
put_line($f, 0);
foreach (@{$pkg->{props}}) {
my $p = $pkg->{members}{$_};
my %t = find_type($p, $p->{type});
- my $call = $pkg->{cname}.".".$p->{name};
+ 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/;
$call = "lua_pushstring(L, $call)";
}
- if (defined $t{type}->{push}) {
- $call =~ s/\$\$/$t{type}->{push}/;
- }
-
put_line($p, 0);
print " case LTK_$tok:\n";
printf " $call;\n";
return path;
}
-static const char *luaM_path_post(const char *val)
-{
- char path[PATH_MAX];
- _mutt_expand_path(path, sizeof(path), val, 0);
- return path;
-}
-
@type bool = {
.kind = 'b';
.ctype = unsigned : 1;
};
@type path_t = {
- .push = luaM_path_post($$);
.kind = 's';
.ctype = char *;
.dtor = p_delete($$);
- .ctor = m_strdup($$);
+ .ctor = luaM_pathnew($$);
};
@type quadopt_t = {
.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"
#elif defined(HAVE_GDBM)
const string_t docdir = PKGDOCDIR;
const string_t hcache_backend = HCACHE_BACKEND;
- path_t dotlock = m_strdup(BINDIR "/mutt_dotlock");
- path_t editor = m_strdup(getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
- path_t shell = madmutt_init_shell();
- path_t username = madmutt_init_username();
- path_t homedir = madmutt_init_homedir();
- path_t tmpdir = m_strdup(getenv("TMPDIR") ?: "/tmp");
+ path_t dotlock = m_strdup(BINDIR "/mutt_dotlock");
+ path_t editor = m_strdup(getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
+ path_t shell = madmutt_init_shell();
+ path_t username = madmutt_init_username();
+ path_t homedir = madmutt_init_homedir();
+ path_t tmpdir = m_strdup(getenv("TMPDIR") ?: "/tmp");
+ rx_t gecos_mask = luaM_rxnew("^[^,]*");
quadopt_t quit = M_YES;
bool beep = 1;
#include <lib-lib/lib-lib.h>
#include <lib-lua/lib-lua.h>
-#include <alias.h>
+#include "../alias.h"
+#include "../mutt.h"
static lua_State *L;
return i;
}
+const char *luaM_checkrx(lua_State *Ls, int narg)
+{
+ const char *s = luaL_checkstring(Ls, narg);
+ char buf[STRING];
+
+ if (rx_validate(s, buf, ssizeof(buf))) {
+ s = lua_pushfstring(Ls, "invalid regexp: `%s'", buf);
+ luaL_argerror(Ls, narg, s);
+ return NULL;
+ }
+
+ return s;
+}
+
+char *luaM_pathnew(const char *val)
+{
+ char path[PATH_MAX];
+ _mutt_expand_path(path, sizeof(path), val, 0);
+ return m_strdup(path);
+}
+
+rx_t *luaM_rxnew(const char *val)
+{
+ if (m_strisempty(val))
+ val = ".";
+
+ return rx_compile(val, mutt_which_case(val));
+}
+
* otherwise assume that the GECOS field is a comma-separated list.
* Replace "&" by a capitalized version of the user's login name.
*/
-ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, regex_t *rx)
+ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx)
{
const char *p, *end;
ssize_t len;
if (!pw->pw_gecos)
return 0;
- if (rx) {
+ if (rx->rx) {
regmatch_t pat_match[1];
- if (regexec(rx, pw->pw_gecos, 1, pat_match, 0)) {
+ if (regexec(rx->rx, pw->pw_gecos, 1, pat_match, 0)) {
return 0;
}
#include <lib-lib/lib-lib.h>
#include <pwd.h>
-ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, regex_t *rx);
+ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, rx_t *rx);
int getdnsdomainname(char *, ssize_t);
/* flags for _mutt_system() */