void
set_cur_mail_length_var(int len, struct list* hash)
{
- char* buf;
struct variable* pv;
+ char buf[INT_TO_STRING_LEN];
pv = get_var_struct(INT_VAR_MAIL_LEN, VAR_INTERN, hash);
if (! pv) /* user is not interested */
return;
- buf = xmalloc(INT_TO_STRING_LEN);
sprintf(buf,"%d", len);
set_var(pv->varcode, buf);
- free_string(buf);
}
static void
set_exit_code_var(int code, struct list* hash)
{
- char* buf;
struct variable* pv;
+ char buf[INT_TO_STRING_LEN];
pv = get_var_struct(INT_VAR_LAST_EXIT, VAR_INTERN, hash);
if (! pv) /* user is not interested */
return;
- buf = xmalloc(INT_TO_STRING_LEN);
sprintf(buf,"%d", code);
set_var(pv->varcode, buf);
- free_string(buf);
}
static void
return xstrdup(var_tab[var].value);
}
+static char*
+get_var_nc(int var)
+{
+ if (var < 0)
+ return const_tab[-var];
+ return var_tab[var].value;
+}
+
static int
regex_cmp(char* s, char* r)
{
int i;
char* ret;
int len = strlen(value);
- int newlines[len / 78 + 5];
+ int newlines[len / 40 + 5];
int newl = 0;
int curr_ws = -1;
int pos = 0;
if(i != newlines[newl_done])
ret[pos++] = value[i];
else {
- newl++;
+ newl_done++;
ret[pos++] = '\n';
- ret[pos++] = ' ';
+ ret[pos++] = '\t';
}
}
return ret;
if (!pv)
continue;
u = unfold(p->value);
- value = get_var(pv->varcode);
+ value = get_var_nc(pv->varcode);
if (strcmp(u, value)){
set_modif_flag(pv->varcode, 0);
free_string(p->value);
strlen(p->name) + 2);
}
free_string(u);
- free_string(value);
}
// find new headers
static void
do_string_ternary_op(struct code* p)
{
- char* l = get_var(p->u.tpop.l);
- char* r = get_var(p->u.tpop.r);
+ char* l = get_var_nc(p->u.tpop.l);
+ char* r = get_var_nc(p->u.tpop.r);
char* result;
switch(p->opcode) {
default:
break;
};
-
+ free_string(result);
set_var(p->u.tpop.res, result);
}
static void
do_num_ternary_op(struct code* p)
{
- int l, r, res;
+ int l = 0, r = 0, res;
char* result = xmalloc(INT_TO_STRING_LEN);
- sscanf(get_var(p->u.tpop.l),"%d", &l);
- sscanf(get_var(p->u.tpop.r),"%d", &r);
+ sscanf(get_var_nc(p->u.tpop.l),"%d", &l);
+ sscanf(get_var_nc(p->u.tpop.r),"%d", &r);
switch(p->opcode) {
case OPC_GT:
}
sprintf(result, "%d", res);
+ free_string(result);
set_var(p->u.tpop.res, result);
}
static int
eval_cond(int var)
{
- char* val = get_var(var);
+ char* val = get_var_nc(var);
int v;
if (! val)
dup(pd[0]);
close(pd[0]);
//FIXME From?
- res = execl("/usr/lib/sendmail", "sendmail", where, NULL);
+ execl("/usr/lib/sendmail", "sendmail", where, NULL);
+ exit(1);
}
close(pd[0]);
write_email_to_fd(pd[1], &em);
close(pd_out[1]);
close(pd_in[1]);
close(pd_out[0]);
- res = execl("/bin/sh", "sh", "-c", program, NULL);
+ execl("/bin/sh", "sh", "-c", program, NULL);
+ exit(1);
}
close(pd_in[0]);
close(pd_out[1]);
break;
write(fd, buf, r);
}
- if (pfd[0].revents & POLLHUP)
+ if (pfd[0].revents & POLLHUP) {
+ if (e)
+ free_string(e);
break;
+ }
if (nfds < 2)
continue;
while ((struct node*) p != &ins->head) {
switch (p->opcode) {
case OPC_SET:
- result = get_var(p->u.set.r);
+ result = get_var_nc(p->u.set.r);
set_var(p->u.set.l, result);
- free_string(result);
break;
case OPC_JUMP:
p = p->u.jump.target;
break;
case OPC_NOT:
result = xmalloc(INT_TO_STRING_LEN);
- sscanf(get_var(p->u.dpop.par),"%d", &v);
+ sscanf(get_var_nc(p->u.dpop.par),"%d", &v);
sprintf(result, "%d", !v);
set_var(p->u.dpop.res, result);
free_string(result);
do_string_ternary_op(p);
break;
case OPC_PIPE:
- do_pipe(get_var(p->u.arrow.what), hash);
+ do_pipe(get_var_nc(p->u.arrow.what), hash);
break;
case OPC_FILTER:
- do_filter(get_var(p->u.arrow.what), hash);
+ do_filter(get_var_nc(p->u.arrow.what), hash);
break;
case OPC_MAIL:
- send_mail(get_var(p->u.arrow.what),
+ send_mail(get_var_nc(p->u.arrow.what),
p->u.arrow.copy, hash);
break;
case OPC_DELIVER:
- deliver(get_var(p->u.arrow.what),
+ deliver(get_var_nc(p->u.arrow.what),
p->u.arrow.copy, hash);
break;
case OPC_DISCARD:
for (i=0; i<HASHSIZE; i++){
LIST_FOREACH(p, hash + i)
- printf("%s=%s\n",p->name, get_var(p->varcode));
+ printf("%s=%s\n",p->name, get_var_nc(p->varcode));
}
}