]> mj.ucw.cz Git - umpf.git/commitdiff
little cleanup before bigger events ;)
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 13:10:49 +0000 (15:10 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 13:10:49 +0000 (15:10 +0200)
code.c
int.c
umpf.h

diff --git a/code.c b/code.c
index 59742fc9a8292c7241ca4241dafacacbdde840b6..2200d234dc8229f46172e576699f5499d56fb7d0 100644 (file)
--- 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 b0cd3967412c153e43c6ec1153b01b48fc0d83be..5c9c33a71c78d5102042629ccec6e95655e0bf3c 100644 (file)
--- 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 7c3bd8030df1bccd919207bc0a0f1d0ac1a06516..e379c8400a0a1120f910c35e7abc044b4ccf3008 100644 (file)
--- 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);