make lua packages interfaces be *.li.
authorPierre Habouzit <madcoder@debian.org>
Sun, 18 Mar 2007 23:06:53 +0000 (00:06 +0100)
committerPierre Habouzit <madcoder@debian.org>
Sun, 18 Mar 2007 23:06:53 +0000 (00:06 +0100)
make our lua packages support regexps, needed some bindings enhancements.

fixes fixes fixes

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
15 files changed:
.gitignore [new file with mode: 0644]
Makefile.am
alias.cpkg
alias.h
init.c
init.h
lib-lua/.gitignore
lib-lua/Makefile.am
lib-lua/lib-lua.h
lib-lua/lua-token.sh
lib-lua/luapkg2c.pl
lib-lua/madmutt.cpkg
lib-lua/runtime.c
lib-sys/unix.c
lib-sys/unix.h

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..e0984dc
--- /dev/null
@@ -0,0 +1 @@
+alias.c
index f09fc6c..65c1bee 100644 (file)
@@ -4,7 +4,9 @@
 AUTOMAKE_OPTIONS = foreign
 EXTRA_PROGRAMS = madmutt_dotlock pgpringng pgpewrapng makedoc
 
 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
 
 if BUILD_NNTP
 NNTP_SUBDIR = nntp
@@ -39,7 +41,7 @@ madmutt_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ \
                $(top_builddir)/lib-lib/liblib.a \
                $(MUTTLIBS) $(INTLLIBS) $(LIBICONV)
 
                $(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 \
                       $(top_builddir)/lib-lua/lua-token.h \
                       @MUTT_LIB_OBJECTS@ @LIBOBJS@ \
                       $(top_builddir)/lib-lib/liblib.a \
index 424adda..a87f5f0 100644 (file)
 };
 
 @type path_t = {
 };
 
 @type path_t = {
-    .push  = luaM_path_post($$);
     .kind  = 's';
     .ctype = char *;
     .dtor  = p_delete($$);
     .kind  = 's';
     .ctype = char *;
     .dtor  = p_delete($$);
-    .ctor  = m_strdup($$);
+    .ctor  = luaM_pathnew($$);
 };
 
 @type quadopt_t = {
 };
 
 @type quadopt_t = {
 };
 
 static @package MAlias {
 };
 
 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;
 
 } MAlias;
 
-char    *AliasFile;
 alias_t *Aliases;
 alias_t *Aliases;
-rx_t     GecosMask;
 
 #define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x
 
 
 #define RSORT(x) (SortAlias & SORT_REVERSE) ? -x : x
 
@@ -311,7 +309,7 @@ void mutt_create_alias(ENVELOPE *cur, address_t *iadr)
 
     alias_list_push(&Aliases, new);
 
 
     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 (mutt_get_field(_("Save to file: "), buf, sizeof(buf), M_FILE)) {
         return;
     }
@@ -374,7 +372,7 @@ static address_t *mutt_expand_aliases_r(address_t *a, string_list_t **expn)
 
                 if (pw) {
                     char namebuf[STRING];
 
                 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);
                 }
             }
                     m_strreplace(&pop->personal, namebuf);
                 }
             }
diff --git a/alias.h b/alias.h
index 74eab42..29231bf 100644 (file)
--- a/alias.h
+++ b/alias.h
@@ -43,10 +43,7 @@ typedef struct alias_t {
     short num;
 } alias_t;
 
     short num;
 } alias_t;
 
-extern char    *AliasFmt;
-extern char    *AliasFile;
 extern alias_t *Aliases;
 extern alias_t *Aliases;
-extern rx_t     GecosMask;
 
 DO_INIT(alias_t, alias);
 static inline void alias_wipe(alias_t *a) {
 
 DO_INIT(alias_t, alias);
 static inline void alias_wipe(alias_t *a) {
diff --git a/init.c b/init.c
index 96fcf0b..1e9eaad 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2209,12 +2209,12 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
   snprintf (AttachmentMarker, sizeof(AttachmentMarker),
             "\033]9;%ld\a", (long) time (NULL));
 
   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];
   /* 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);
     Realname = m_strdup(rnbuf);
-    endpwent ();
   }
 
   /* And about the host... */
   }
 
   /* And about the host... */
@@ -2299,7 +2299,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
     From = rfc822_parse_adrlist (NULL, p);
 
   charset_initialize();
     From = rfc822_parse_adrlist (NULL, p);
 
   charset_initialize();
-  luaM_initialize();
 
   /* Set standard defaults */
   hash_map (ConfigOptions, mutt_set_default, 0);
 
   /* Set standard defaults */
   hash_map (ConfigOptions, mutt_set_default, 0);
@@ -2330,8 +2329,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands)
     mutt_expand_path (buffer, sizeof(buffer));
     Muttrc = m_strdup(buffer);
   }
     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".  */
 
   /* Process the global rc file if it exists and the user hasn't explicity
      requested not to via "-n".  */
diff --git a/init.h b/init.h
index abc629b..136876f 100644 (file)
--- a/init.h
+++ b/init.h
@@ -138,15 +138,6 @@ struct option_t MuttVars[] = {
    ** check only happens after the \fIfirst\fP edit of the file).  When set
    ** to \fIno\fP, composition will never be aborted.
    */
    ** 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
   {"allow_8bit", DT_BOOL, R_NONE, OPTALLOW8BIT, "yes" },
   /*
    ** .pp
@@ -750,21 +741,6 @@ struct option_t MuttVars[] = {
    ** .pp
    ** Defaults to the contents of the environment variable \fT$$$EMAIL\fP.
    */
    ** .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"},
   /*
 #ifdef USE_NNTP
   {"nntp_group_index_format", DT_STR, R_BOTH, UL &GroupFormat, "%4C %M%N %5s  %-45.45f %d"},
   /*
index 2fc4ed7..5165eec 100644 (file)
@@ -1,2 +1,3 @@
 lua-token.[hc]
 lua-token.[hc]
-madmutt.[hc]
+madmutt.c
+madmutt.li
index 8f149f5..a12888b 100644 (file)
@@ -1,12 +1,12 @@
 BUILT_SOURCES    = lua-token.h lua-token.c
 DISTCLEANFILES   = $(BUILT_SOURCES)
 
 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
 
 
 noinst_LIBRARIES = liblua.a
 
-liblua_a_DEPENDENCIES = madmutt.h
+liblua_a_DEPENDENCIES = madmutt.li
 liblua_a_SOURCES = madmutt.cpkg \
                   lib-lua.h \
                   runtime.c \
 liblua_a_SOURCES = madmutt.cpkg \
                   lib-lua.h \
                   runtime.c \
index 5afb91f..862b6b5 100644 (file)
@@ -47,7 +47,10 @@ int luaM_wrap(void (*errfun)(const char *fmt, ...)
               int status);
 
 quadopt_t luaM_checkquadopt(lua_State *L, int narg);
               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
 
 #endif
index a3ba223..8c5540c 100644 (file)
@@ -110,6 +110,8 @@ chmod -w $1
 exit 0
 
 ############ Put tokens here ############
 exit 0
 
 ############ Put tokens here ############
+## alias_file
+## alias_format
 ## beep
 ## beep_new
 ## bindir
 ## beep
 ## beep_new
 ## bindir
@@ -118,6 +120,7 @@ exit 0
 ## dsn_notify
 ## dsn_return
 ## editor
 ## dsn_notify
 ## dsn_return
 ## editor
+## gecos_mask
 ## hcache_backend
 ## homedir
 ## quit
 ## hcache_backend
 ## homedir
 ## quit
@@ -127,4 +130,3 @@ exit 0
 ## tmpdir
 ## username
 ## version
 ## tmpdir
 ## username
 ## version
-## alias_format
index b7d1ba3..f1bab32 100755 (executable)
@@ -83,7 +83,7 @@ sub parse_type($$) {
 
     while (stream_getline($src)) {
         last if (/^\s*\}\s*;\s*/);
 
     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])'$/) {
             $t{$1} = $2;
             if ($1 eq "kind") {
                 if ($2 =~ /^'([bis])'$/) {
@@ -220,9 +220,7 @@ sub dump_fun($$) {
         }
     }
 
         }
     }
 
-    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);
 
     if ($t{type}->{kind} eq 'b') {
         put_line($f, 0);
@@ -411,7 +409,10 @@ EOF
     foreach (@{$pkg->{props}}) {
         my $p = $pkg->{members}{$_};
         my %t = find_type($p, $p->{type});
     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/;
 
         my $tok = $p->{name};
         $tok =~ tr/a-z/A-Z/;
@@ -428,10 +429,6 @@ EOF
             $call = "lua_pushstring(L, $call)";
         }
 
             $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";
         put_line($p, 0);
         print  "      case LTK_$tok:\n";
         printf "        $call;\n";
index 270e198..5e48a45 100644 (file)
@@ -50,13 +50,6 @@ static const char *madmutt_pwd(void)
     return path;
 }
 
     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 bool = {
     .kind = 'b';
     .ctype = unsigned : 1;
@@ -70,11 +63,10 @@ static const char *luaM_path_post(const char *val)
 };
 
 @type path_t = {
 };
 
 @type path_t = {
-    .push  = luaM_path_post($$);
     .kind  = 's';
     .ctype = char *;
     .dtor  = p_delete($$);
     .kind  = 's';
     .ctype = char *;
     .dtor  = p_delete($$);
-    .ctor  = m_strdup($$);
+    .ctor  = luaM_pathnew($$);
 };
 
 @type quadopt_t = {
 };
 
 @type quadopt_t = {
@@ -83,6 +75,15 @@ static const char *luaM_path_post(const char *val)
     .ctype = unsigned : 2;
 };
 
     .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)
 #if defined(HAVE_QDBM)
 #  define HCACHE_BACKEND "qdbm"
 #elif defined(HAVE_GDBM)
@@ -100,12 +101,13 @@ static const char *luaM_path_post(const char *val)
     const string_t docdir     = PKGDOCDIR;
     const string_t hcache_backend = HCACHE_BACKEND;
 
     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;
 
     quadopt_t quit     = M_YES;
     bool      beep     = 1;
index f570b55..ac724af 100644 (file)
@@ -20,7 +20,8 @@
 #include <lib-lib/lib-lib.h>
 #include <lib-lua/lib-lua.h>
 
 #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;
 
 
 static lua_State *L;
 
@@ -83,3 +84,32 @@ quadopt_t luaM_checkquadopt(lua_State *Ls, int narg)
     return i;
 }
 
     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));
+}
+
index 38389b2..9054435 100644 (file)
@@ -20,7 +20,7 @@
  * otherwise assume that the GECOS field is a comma-separated list.
  * Replace "&" by a capitalized version of the user's login name.
  */
  * 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;
 {
     const char *p, *end;
     ssize_t len;
@@ -31,10 +31,10 @@ ssize_t mutt_gecos_name(char *dst, ssize_t n, struct passwd *pw, regex_t *rx)
     if (!pw->pw_gecos)
         return 0;
 
     if (!pw->pw_gecos)
         return 0;
 
-    if (rx) {
+    if (rx->rx) {
         regmatch_t pat_match[1];
 
         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;
         }
 
             return 0;
         }
 
index bfc16c0..eda9d8b 100644 (file)
@@ -23,7 +23,7 @@
 #include <lib-lib/lib-lib.h>
 #include <pwd.h>
 
 #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() */
 int getdnsdomainname(char *, ssize_t);
 
 /* flags for _mutt_system() */