return xstrdup(var_tab[var]);
}
-/* return var struct or NULL if not found */
-static struct variable*
-get_var_struct(char* name, struct list* hash)
-{
- int n;
- struct variable *p;
-
- n = get_bucket_number(name);
- int nocase = isupper(*name);
- LIST_FOREACH(p, hash + n)
- if (!(nocase ? strcasecmp : strcmp)(p->name,name))
- return p;
-
- return NULL;
-}
-
static int
regex_cmp(char* s, char* r)
{
// set_cur_mail_length_var(current_email_len);
// set_exit_code_var(f->exit);
+ unlink(f->name);
+ free(f);
+end:
+ //FIXME: what to do with exit code when pipe failed?
+ destroy_email(em);
+}
+
+static void
+do_pipe(char* program, struct list* hash)
+{
+ struct email em = prepare_email(hash);
+ struct procstat* f;
+ int res = 0;
+ char* buf;
+ off_t pos;
+
+ f = pipe_to(program, &em);
+ if (!f) {
+ res++;
+ goto end;
+ }
+ pos = lseek(f->fd, 0, SEEK_END);
+ lseek(f->fd, 0, SEEK_SET);
+ buf = xmalloc(pos);
+
+ read(f->fd, buf, pos);
+ //set_last_pipe_var(buf);
+ free(buf);
+
unlink(f->name);
free(f);
end:
do_string_ternary_op(p);
break;
case OPC_PIPE:
+ do_pipe(get_var(p->u.arrow.what), hash);
break;
case OPC_FILTER:
do_filter(get_var(p->u.arrow.what), hash);