From: Anicka Bernathova Date: Tue, 21 Jul 2009 13:10:49 +0000 (+0200) Subject: little cleanup before bigger events ;) X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=9b2589b98aaebf080ef327cbc572846937fe53c7;p=umpf.git little cleanup before bigger events ;) --- diff --git a/code.c b/code.c index 59742fc..2200d23 100644 --- a/code.c +++ b/code.c @@ -32,6 +32,22 @@ get_bucket_number(char* name) return n; } +/* return var struct or NULL if not found */ +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; +} + int find_var(char* name, struct list* hash) { diff --git a/int.c b/int.c index b0cd396..5c9c33a 100644 --- a/int.c +++ b/int.c @@ -71,22 +71,6 @@ get_var(int var) 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) { @@ -586,6 +570,35 @@ do_filter(char* program, struct list* hash) // 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: @@ -647,6 +660,7 @@ interp(struct list* ins, struct list* hash) 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); diff --git a/umpf.h b/umpf.h index 7c3bd80..e379c84 100644 --- a/umpf.h +++ b/umpf.h @@ -180,6 +180,7 @@ char* empty; void init(void); void compile(struct tree* t, struct list* where); int find_var(char* name, struct list* hash); +struct variable* get_var_struct(char* name, struct list* hash); int store_const(char* c); struct list* new_var_hash(void); int get_bucket_number(char* name);