static void rx_to_string (char* dst, ssize_t dstlen, struct option_t* option);
static void magic_to_string (char* dst, ssize_t dstlen, struct option_t* option);
static void addr_to_string (char* dst, ssize_t dstlen, struct option_t* option);
-static void sys_to_string (char* dst, ssize_t dstlen, struct option_t* option);
/* protos for config type handles: convert to value from string */
static int bool_from_string (struct option_t* dst, const char* val,
* but must define it as DT_ is used for indexing */
{ DT_SYN, NULL, NULL },
{ DT_ADDR, addr_to_string, addr_from_string },
- { DT_SYS, sys_to_string, NULL },
};
static void bool_to_string (char* dst, ssize_t dstlen,
NONULL (*((char**) option->data)));
}
-static void sys_to_string (char* dst, ssize_t dstlen,
- struct option_t* option) {
- char *val = NULL, *t = NULL;
- int clean = 0;
-
- /* get some $madmutt_ values dynamically */
- if (m_strcmp("madmutt_pwd", option->option) == 0) {
- val = p_new(char, _POSIX_PATH_MAX);
- val = getcwd (val, _POSIX_PATH_MAX-1);
- clean = 1;
- } else if (m_strcmp("madmutt_folder_path", option->option) == 0 &&
- CurrentFolder && *CurrentFolder) {
- val = CurrentFolder;
- } else if (m_strcmp("madmutt_folder_name", option->option) == 0 &&
- CurrentFolder && *CurrentFolder) {
-
- ssize_t Maildirlength = m_strlen(Maildir);
-
- /*
- * if name starts with $folder, just strip it to keep hierarchy
- * $folder=imap://host, path=imap://host/inbox/b -> inbox/b
- */
- if (Maildirlength > 0 && m_strncmp(CurrentFolder, Maildir,
- Maildirlength) == 0 &&
- m_strlen(CurrentFolder) > Maildirlength) {
- val = CurrentFolder + Maildirlength;
- if (Maildir[Maildirlength]!='/')
- val += 1;
- /* if not $folder, just use everything after last / */
- } else if ((t = strrchr (CurrentFolder, '/')) != NULL)
- val = t+1;
- /* default: use as-is */
- else
- val = (char *) CurrentFolder;
-
- } else
- val = (char *) option->init;
-
- snprintf (dst, dstlen, "%s=\"%s\"", option->option, NONULL (val));
- if (clean)
- p_delete(&val);
-}
-
static int path_from_string (struct option_t* dst, const char* val,
char* errbuf __attribute__ ((unused)), ssize_t errlen __attribute__ ((unused))) {
char path[_POSIX_PATH_MAX];
DTYPE (option->type) == DT_MAGIC ||
DTYPE (option->type) == DT_NUM ||
DTYPE (option->type) == DT_SORT ||
- DTYPE (option->type) == DT_RX ||
- DTYPE (option->type) == DT_SYS) {
-
+ DTYPE (option->type) == DT_RX)
+ {
/* XXX maybe we need to get unset into handlers? */
if (DTYPE (option->type) == DT_STR ||
DTYPE (option->type) == DT_PATH ||
- DTYPE (option->type) == DT_ADDR ||
- DTYPE (option->type) == DT_SYS) {
+ DTYPE (option->type) == DT_ADDR)
+ {
if (unset) {
CHECK_PAGER;
if (!FuncTable[DTYPE (option->type)].opt_fromstr) {
ConfigOptions = hash_create (sizeof(MuttVars) * 2);
for (i = 0; MuttVars[i].option; i++) {
- if (DTYPE (MuttVars[i].type) != DT_SYS)
- hash_insert (ConfigOptions, MuttVars[i].option, &MuttVars[i], 0);
- else
- hash_insert (ConfigOptions, MuttVars[i].option,
- add_option (MuttVars[i].option, MuttVars[i].init,
- DT_SYS, 0), 0);
+ hash_insert (ConfigOptions, MuttVars[i].option, &MuttVars[i], 0);
}
/*
#define DT_MAGIC 8 /* mailbox type */
#define DT_SYN 9 /* synonym for another variable */
#define DT_ADDR 10 /* e-mail address */
-#define DT_SYS 11 /* pre-defined via $madmutt_ */
#define DTYPE(x) ((x) & DT_MASK)
** This specifies the folder into which read mail in your ``$$spoolfile''
** folder will be appended.
*/
- {"madmutt_folder_path", DT_SYS, R_NONE, 0, "" },
- /*
- ** .pp
- ** \fIThis is a read-only system property and, at runtime,
- ** specifies the full path or URI of the folder currently
- ** open (if any).\fP
- */
- {"madmutt_folder_name", DT_SYS, R_NONE, 0, "" },
- /*
- ** .pp
- ** \fIThis is a read-only system property and, at runtime,
- ** specifies the actual name of the folder as far as it could
- ** be detected.\fP
- ** .pp
- ** For detection, $$$folder is first taken into account
- ** and simply stripped to form the result when a match is found. For
- ** example, with $$$folder being \fTimap://host\fP and the folder is
- ** \fTimap://host/INBOX/foo\fP, $$$madmutt_folder_name will be just
- ** \fTINBOX/foo\fP.)
- ** .pp
- ** Second, if the initial portion of a name is not $$$folder,
- ** the result will be everything after the last ``/''.
- ** .pp
- ** Third and last, the result will be just the name if neither
- ** $$$folder nor a ``/'' were found in the name.
- */
- {"madmutt_pwd", DT_SYS, R_NONE, 0, "" },
- /*
- ** .pp
- ** \fIThis is a read-only system property and, at runtime,
- ** specifies the current working directory of the madmutt
- ** binary.\fP
- */
{"operating_system", DT_STR, R_NONE, UL &OperatingSystem, "" },
/*
** .pp
/* comparisons */
/****************************************************************************/
+/** \brief Tells whether s begins with p.
+ *
+ * \param[in] s the input string
+ * \param[in] p the prefix
+ * \param[out] pp position in s
+ *
+ * \return 1 if a match is found, 0 otherwise.
+ */
+static inline int m_strstart(const char *s, const char *p, const char **pp)
+{
+ if (!s)
+ return 0;
+
+ while (*p) {
+ if (*s++ != *p++)
+ return 0;
+ }
+ if (pp)
+ *pp = s;
+ return 1;
+}
+
/** \brief \c NULL resistant strcmp.
* \param[in] a the first string.
* \param[in] b the second string.
noinst_LIBRARIES = liblua.a
-liblua_a_SOURCES = lib-lua.h \
- runtime.c
+liblua_a_SOURCES = lib-lua.h lib-lua_priv.h \
+ runtime.c madmutt.c
-noinst_HEADERS = lib-lua.h
+noinst_HEADERS = lib-lua.h lib-lua_priv.h
DEFS=-DPKGDATADIR=\"$(pkgdatadir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \
-DBINDIR=\"$(bindir)\" -DMUTTLOCALEDIR=\"$(datadir)/locale\" \
--- /dev/null
+/*
+ * 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 <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+#define LUA_MADMUTT "madmutt"
+
+int luaopen_madmutt(lua_State *L);
+
+#endif
--- /dev/null
+/*
+ * 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
+ */
+
+#include <lib-lib/lib-lib.h>
+#include "lib-lua_priv.h"
+
+#include "../mutt.h"
+
+static int madmutt_pwd(lua_State *L)
+{
+ char path[_POSIX_PATH_MAX];
+ getcwd(path, sizeof(path));
+ lua_pushstring(L, path);
+ return 1;
+}
+
+static int madmutt_folder_path(lua_State *L)
+{
+ lua_pushstring(L, CurrentFolder ?: "");
+ return 1;
+}
+
+static int madmutt_folder_name(lua_State *L)
+{
+ const char *p;
+
+ if (!m_strisempty(Maildir)
+ && m_strstart(CurrentFolder, Maildir, &p) && *p) {
+ while (*p == '/')
+ p++;
+ lua_pushstring(L, p);
+ } else {
+ p = strchr(CurrentFolder ?: "", '/');
+ lua_pushstring(L, p ? p + 1 : (CurrentFolder ?: ""));
+ }
+ return 1;
+}
+
+static const struct luaL_Reg madmutt_module_funcs[] = {
+ {"pwd", madmutt_pwd},
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and, at runtime,
+ ** specifies the current working directory of the madmutt
+ ** binary.\fP
+ */
+ {"folder_path", madmutt_folder_path},
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and, at runtime,
+ ** specifies the full path or URI of the folder currently
+ ** open (if any).\fP
+ */
+ {"folder_name", madmutt_folder_name},
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and, at runtime,
+ ** specifies the actual name of the folder as far as it could
+ ** be detected.\fP
+ ** .pp
+ ** For detection, $$$folder is first taken into account
+ ** and simply stripped to form the result when a match is found. For
+ ** example, with $$$folder being \fTimap://host\fP and the folder is
+ ** \fTimap://host/INBOX/foo\fP, $$$madmutt_folder_name will be just
+ ** \fTINBOX/foo\fP.)
+ ** .pp
+ ** Second, if the initial portion of a name is not $$$folder,
+ ** the result will be everything after the last ``/''.
+ ** .pp
+ ** Third and last, the result will be just the name if neither
+ ** $$$folder nor a ``/'' were found in the name.
+ */
+ {NULL, NULL}
+};
+
+static const struct {
+ const char *key;
+ const char *value;
+} madmutt_module_vars[] = {
+ { "version", VERSION },
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and specifies madmutt's
+ ** version string.\fP
+ */
+ { "sysconfdir", SYSCONFDIR },
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and specifies madmutt's
+ ** subversion revision string.\fP
+ */
+ { "bindir", BINDIR },
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and specifies the
+ ** directory containing the madmutt binary.\fP
+ */
+ { "docdir", PKGDOCDIR },
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and specifies the
+ ** directory containing the madmutt documentation.\fP
+ */
+#ifdef USE_HCACHE
+#if defined(HAVE_QDBM)
+ {"hcache_backend", "qdbm" },
+#elif defined(HAVE_GDBM)
+ {"hcache_backend", "gdbm" },
+#elif defined(HAVE_DB4)
+ {"hcache_backend", "db4" },
+#else
+ {"hcache_backend", "unknown" },
+#endif
+ /*
+ ** .pp
+ ** \fIThis is a read-only system property and specifies the
+ ** header chaching's database backend.\fP
+ */
+#endif
+};
+
+int luaopen_madmutt(lua_State *L)
+{
+ int i;
+ luaL_register(L, LUA_MADMUTT, madmutt_module_funcs);
+
+ for (i = 0; i < countof(madmutt_module_vars); i++) {
+ lua_pushstring(L, madmutt_module_vars[i].value);
+ lua_setfield(L, -2, madmutt_module_vars[i].key);
+ }
+ return 1;
+}
*/
#include <lib-lib/lib-lib.h>
-
-#include <lua.h>
-#include <lualib.h>
-#include <lauxlib.h>
-
-#include "lib-lua.h"
+#include "lib-lua_priv.h"
static lua_State *L;
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
-};
-
-static const struct luaL_Reg madmutt_module_funcs[] = {
- {NULL, NULL}
-};
-
-static const struct {
- const char *key;
- const char *value;
-} madmutt_module_vars[] = {
- { "version", VERSION },
- /*
- ** .pp
- ** \fIThis is a read-only system property and specifies madmutt's
- ** version string.\fP
- */
- { "sysconfdir", SYSCONFDIR },
- /*
- ** .pp
- ** \fIThis is a read-only system property and specifies madmutt's
- ** subversion revision string.\fP
- */
- { "bindir", BINDIR },
- /*
- ** .pp
- ** \fIThis is a read-only system property and specifies the
- ** directory containing the madmutt binary.\fP
- */
- { "docdir", PKGDOCDIR },
- /*
- ** .pp
- ** \fIThis is a read-only system property and specifies the
- ** directory containing the madmutt documentation.\fP
- */
-#ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
- {"hcache_backend", "qdbm" },
-#elif defined(HAVE_GDBM)
- {"hcache_backend", "gdbm" },
-#elif defined(HAVE_DB4)
- {"hcache_backend", "db4" },
-#else
- {"hcache_backend", "unknown" },
-#endif
- /*
- ** .pp
- ** \fIThis is a read-only system property and specifies the
- ** header chaching's database backend.\fP
- */
-#endif
+ {LUA_MADMUTT, luaopen_madmutt},
};
void mlua_initialize(void)
lua_pushstring(L, lualibs[i].name);
lua_call(L, 1, 0);
}
- luaL_register(L, "madmutt", madmutt_module_funcs);
-
- for (i = 0; i < countof(madmutt_module_vars); i++) {
- lua_pushstring(L, madmutt_module_vars[i].value);
- lua_setfield(L, -2, madmutt_module_vars[i].key);
- }
}
void mlua_shutdown(void)