9d1ffd7f4299372949a468d96909918b6d955e31
[apps/madmutt.git] / lib-lua / madmutt.cpkg
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2007 Pierre Habouzit
18  */
19
20 #include <lib-lib/lib-lib.h>
21 #include <lib-lua/lib-lua.h>
22
23 #include <sys/types.h>
24 #include <pwd.h>
25
26 #include "../mutt.h"
27
28 static const char *madmutt_init_shell(void)
29 {
30     struct passwd *pw = getpwuid(getuid());
31     return pw ? pw->pw_shell : (getenv("SHELL") ?: "/bin/sh");
32 }
33
34 static const char *madmutt_pwd(void)
35 {
36     char path[_POSIX_PATH_MAX];
37     getcwd(path, sizeof(path));
38     return path;
39 }
40
41 static const char *luaM_path_post(const char *val)
42 {
43     char path[PATH_MAX];
44     _mutt_expand_path(path, sizeof(path), val, 0);
45     return path;
46 }
47
48 @type bool = {
49     .kind = 'b';
50     .ctype = unsigned : 1;
51 };
52
53 @type string_t = {
54     .kind = 's';
55     .ctype = const char *;
56 };
57
58 @type path_t = {
59     .push  = luaM_path_post($$);
60     .kind  = 's';
61     .ctype = char *;
62 };
63
64 @type quadopt_t = {
65     .kind  = 'i';
66     .check = luaM_checkquadopt($L, $$);
67     .ctype = unsigned : 2;
68 };
69
70 #if defined(HAVE_QDBM)
71 #  define HCACHE_BACKEND "qdbm"
72 #elif defined(HAVE_GDBM)
73 #  define HCACHE_BACKEND "gdbm"
74 #elif defined(HAVE_DB4)
75 #  define HCACHE_BACKEND "db4"
76 #else
77 #  define HCACHE_BACKEND "unknown"
78 #endif
79
80 @package madmutt {
81     const string_t version    = VERSION;
82     const string_t sysconfdir = SYSCONFDIR;
83     const string_t bindir     = BINDIR;
84     const string_t docdir     = PKGDOCDIR;
85     const string_t hcache_backend = HCACHE_BACKEND;
86
87     path_t dotlock  = BINDIR "/mutt_dotlock";
88     path_t editor   = getenv("VISUAL") ?: getenv("EDITOR") ?: "vi";
89     path_t sendmail = SENDMAIL " -eom -oi";
90     path_t shell    = madmutt_init_shell();
91
92     quadopt_t quit     = M_YES;
93     bool      beep     = 1;
94     bool      beep_new = 0;
95
96     const string_t pwd(void) = madmutt_pwd();
97 } ml_core;
98
99 /* vim:set ft=c: */