drop old code.
[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 char *madmutt_init_shell(void)
29 {
30     struct passwd *pw = getpwuid(getuid());
31     return m_strdup(pw ? pw->pw_shell : (getenv("SHELL") ?: "/bin/sh"));
32 }
33
34 static char *madmutt_init_username(void)
35 {
36     struct passwd *pw = getpwuid(getuid());
37     return m_strdup(pw ? pw->pw_name : (getenv("USER") ?: "john_doe"));
38 }
39
40 static char *madmutt_init_homedir(void)
41 {
42     struct passwd *pw = getpwuid(getuid());
43     return m_strdup(pw ? pw->pw_dir : (getenv("HOME") ?: "/"));
44 }
45
46 static const char *madmutt_pwd(void)
47 {
48     char path[_POSIX_PATH_MAX];
49     getcwd(path, sizeof(path));
50     return path;
51 }
52
53 @type bool = {
54     .kind = 'b';
55     .ctype = unsigned : 1;
56 };
57
58 @type string_t = {
59     .kind  = 's';
60     .ctype = char *;
61     .dtor  = p_delete($$);
62     .ctor  = m_strdup($$);
63 };
64
65 @type path_t = {
66     .kind  = 's';
67     .ctype = char *;
68     .dtor  = p_delete($$);
69     .ctor  = luaM_pathnew($$);
70 };
71
72 @type quadopt_t = {
73     .kind  = 'i';
74     .check = luaM_checkquadopt($L, $$);
75     .ctype = unsigned : 2;
76 };
77
78 @type rx_t = {
79     .kind  = 's';
80     .ctype = rx_t *;
81     .check = luaM_checkrx($L, $$);
82     .push  = ($$)->pattern;
83     .ctor  = luaM_rxnew($$);
84     .dtor  = rx_delete($$);
85 };
86
87 #if defined(HAVE_QDBM)
88 #  define HCACHE_BACKEND "qdbm"
89 #elif defined(HAVE_GDBM)
90 #  define HCACHE_BACKEND "gdbm"
91 #elif defined(HAVE_DB4)
92 #  define HCACHE_BACKEND "db4"
93 #else
94 #  define HCACHE_BACKEND "unknown"
95 #endif
96
97 @package MCore {
98     const string_t version    = VERSION;
99     const string_t sysconfdir = SYSCONFDIR;
100     const string_t bindir     = BINDIR;
101     const string_t docdir     = PKGDOCDIR;
102     const string_t hcache_backend = HCACHE_BACKEND;
103
104     path_t dotlock     = m_strdup(BINDIR "/mutt_dotlock");
105     path_t editor      = m_strdup(getenv("VISUAL") ?: getenv("EDITOR") ?: "vi");
106     path_t shell       = madmutt_init_shell();
107     path_t username    = madmutt_init_username();
108     path_t homedir     = madmutt_init_homedir();
109     path_t tmpdir      = m_strdup(getenv("TMPDIR") ?: "/tmp");
110     rx_t   gecos_mask  = luaM_rxnew("^[^,]*");
111
112     quadopt_t quit     = M_YES;
113     bool      beep     = 1;
114     bool      beep_new = 0;
115
116     const string_t pwd(void) = madmutt_pwd();
117 } MCore;
118
119 @package MTransport {
120     path_t   sendmail = m_strdup(SENDMAIL " -eom -oi");
121
122     string_t dsn_notify = NULL /* TODO: check it's NULL, hdrs or full */;
123     string_t dsn_return = NULL /* TODO: check it's never, delay, failure, success with ',' */;
124 } MTransport;
125
126 /* vim:set ft=c: */