while (stream_getline($src)) {
last if (/^\s*\}\s*;\s*/);
- if (/^\s*\.(push|kind|ctype|check)\s*=\s*(.*?)\s*;\s*$/) {
+ if (/^\s*\.(push|kind|ctype|dtor|ctor|check)\s*=\s*(.*?)\s*;\s*$/) {
$t{$1} = $2;
if ($1 eq "kind") {
if ($2 =~ /^'([bis])'$/) {
}
}
- for my $i ('kind', 'ctype') {
- fatal($src, "incomplete type $type: missing .$i") unless defined $t{$i};
+ for ('kind', 'ctype') {
+ fatal($src, "incomplete type $type: missing .$_") unless defined $t{$_};
+ }
+ if ($t{kind} eq 's') {
+ for ('dtor', 'ctor') {
+ fatal($src, "incomplete type $type: missing .$_") unless defined $t{$_};
+ }
}
unless (defined $t{check}) {
if ($t{kind} eq 'b') {
next if $t{const};
put_line($p, 0);
- print " $var = $p->{init};\n" if ($t{type}->{kind} eq 'b');
- print " $var = $p->{init};\n" if ($t{type}->{kind} eq 'i');
- print " m_strreplace(&$var, $p->{init});\n" if ($t{type}->{kind} eq 's');
+ if ($t{type}->{dtor}) {
+ my $dtor = $t{type}->{dtor};
+ $dtor =~ s/\$\$/\&$var/;
+ print " $dtor;\n";
+ }
+ print " $var = $p->{init};\n"
}
print "};\n";
};
foreach (@{$pkg->{props}}) {
my $p = $pkg->{members}{$_};
my %t = find_type($p, $p->{type});
- printf " $t{type}->{ctypefmt};\n", $p->{name};
+ if ($t{const}) {
+ printf " const $t{type}->{ctypefmt};\n", $p->{name};
+ } else {
+ printf " $t{type}->{ctypefmt};\n", $p->{name};
+ }
}
put_line($pkg, 0);
print <<EOF;
put_line($p, 0);
print " case LTK_$tok: \n";
- print " $var = $check" if ($t{type}->{kind} eq 'b');
- print " $var = $check" if ($t{type}->{kind} eq 'i');
- print " m_strreplace(&$var, $check)" if ($t{type}->{kind} eq 's');
-
- print ";\n return 1;\n";
+ if ($t{type}->{dtor}) {
+ my $dtor = $t{type}->{dtor};
+ $dtor =~ s/\$\$/\&$var/;
+ print " $dtor;\n";
+ }
+ if ($t{type}->{ctor}) {
+ my $ctor = $t{type}->{ctor};
+ $ctor =~ s/\$\$/$check/;
+ $check = $ctor;
+ }
+ print " $var = $check;\n";
+ print " return 1;\n";
}
print <<EOF;
#include "../mutt.h"
-static const char *madmutt_init_shell(void)
+static char *madmutt_init_shell(void)
{
struct passwd *pw = getpwuid(getuid());
- return pw ? pw->pw_shell : (getenv("SHELL") ?: "/bin/sh");
+ return m_strdup(pw ? pw->pw_shell : (getenv("SHELL") ?: "/bin/sh"));
}
-static const char *madmutt_init_username(void)
+static char *madmutt_init_username(void)
{
struct passwd *pw = getpwuid(getuid());
- return pw ? pw->pw_name : (getenv("USER") ?: "john_doe");
+ return m_strdup(pw ? pw->pw_name : (getenv("USER") ?: "john_doe"));
}
-static const char *madmutt_init_homedir(void)
+static char *madmutt_init_homedir(void)
{
struct passwd *pw = getpwuid(getuid());
- return pw ? pw->pw_dir : (getenv("HOME") ?: "/");
+ return m_strdup(pw ? pw->pw_dir : (getenv("HOME") ?: "/"));
}
static const char *madmutt_pwd(void)
};
@type string_t = {
- .kind = 's';
- .ctype = const char *;
+ .kind = 's';
+ .ctype = char *;
+ .dtor = p_delete($$);
+ .ctor = m_strdup($$);
};
@type path_t = {
.push = luaM_path_post($$);
.kind = 's';
.ctype = char *;
+ .dtor = p_delete($$);
+ .ctor = m_strdup($$);
};
@type quadopt_t = {
const string_t docdir = PKGDOCDIR;
const string_t hcache_backend = HCACHE_BACKEND;
- path_t dotlock = BINDIR "/mutt_dotlock";
- path_t editor = getenv("VISUAL") ?: getenv("EDITOR") ?: "vi";
+ 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 = getenv("TMPDIR") ?: "/tmp";
+ path_t tmpdir = m_strdup(getenv("TMPDIR") ?: "/tmp");
quadopt_t quit = M_YES;
bool beep = 1;
} MCore;
@package MTransport {
- path_t sendmail = SENDMAIL " -eom -oi";
+ path_t sendmail = m_strdup(SENDMAIL " -eom -oi");
string_t dsn_notify = NULL;
string_t dsn_return = NULL;