]> mj.ucw.cz Git - umpf.git/commitdiff
save internal vars
authorAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 13:54:37 +0000 (15:54 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Tue, 21 Jul 2009 13:54:37 +0000 (15:54 +0200)
int.c
umpf.c
umpf.h

diff --git a/int.c b/int.c
index 59c1f93a396f011ff339c067773de3775199082a..af67fe0f694e1aafed984e1405271d91de8d0e12 100644 (file)
--- a/int.c
+++ b/int.c
@@ -63,6 +63,52 @@ set_var(int var, char* value)
        var_tab[var] = xstrdup(value);
 }
 
+void
+set_cur_mail_length_var(int len, struct list* hash)
+{
+       char* buf;
+       struct variable* pv;
+
+       pv = get_var_struct(INT_VAR_MAIL_LEN, VAR_INTERN, hash);
+
+       if (! pv) /* user is not interested */
+               return;
+
+       buf = xmalloc(INT_TO_STRING_LEN);
+       sscanf(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;
+
+       pv = get_var_struct(INT_VAR_LAST_EXIT, VAR_INTERN, hash);
+
+       if (! pv) /* user is not interested */
+               return;
+
+       buf = xmalloc(INT_TO_STRING_LEN);
+       sscanf(buf,"%d", &code);
+       set_var(pv->varcode, buf);
+       free_string(buf);
+}
+
+static void
+set_last_pipe_var(char* buf, struct list* hash)
+{
+       struct variable* pv;
+
+       pv = get_var_struct(INT_VAR_LAST_EXIT, VAR_INTERN, hash);
+
+       if (! pv) /* user is not interested */
+               return;
+       set_var(pv->varcode, buf);
+}
+
 static char*
 get_var(int var)
 {
@@ -567,8 +613,8 @@ do_filter(char* program, struct list* hash)
        destroy_body(current_body);
        current_headers = make_hlist(f->fd);
        current_body = get_body(f->fd); 
-//     set_cur_mail_length_var(current_email_len);
-//     set_exit_code_var(f->exit);
+       set_cur_mail_length_var(curr_email_len, hash);
+       set_exit_code_var(f->exit, hash);
 
        unlink(f->name);
        free(f);
@@ -596,7 +642,8 @@ do_pipe(char* program, struct list* hash)
        buf = xmalloc(pos);
        
        read(f->fd, buf, pos);
-       //set_last_pipe_var(buf);
+       set_exit_code_var(f->exit, hash);
+       set_last_pipe_var(buf, hash);
        free(buf);
        
        unlink(f->name);
diff --git a/umpf.c b/umpf.c
index c3ef9a7044a53d7291ee6c524a325eb114aef312..b8c2cd9effe94c6a194ef68dc2451d29e6ece128 100644 (file)
--- a/umpf.c
+++ b/umpf.c
@@ -52,6 +52,7 @@ main(int argc, char** argv)
 //     print_headers(current_headers);
        current_body = get_body(0);
        save_current_headers(var_hash);
+       set_cur_mail_length_var(curr_email_len, var_hash);
 
        interp(&input_code, var_hash);
 
diff --git a/umpf.h b/umpf.h
index 35f65ef7c352a39dbdfb9de0ea1636e02d267465..ef9651c50e64fbb5f4f88ccd4e732ca846c36aea 100644 (file)
--- a/umpf.h
+++ b/umpf.h
@@ -1,5 +1,10 @@
 #include "lists.h"
 
+/* definitions of internal variables */
+#define INT_VAR_MAIL_LEN "MAIL_LEN"
+#define INT_VAR_LAST_EXIT "LAST_EXIT_CODE"
+#define INT_VAR_PIPE_RES "LAST_OUTPUT"
+
 /* cond.h */
 int yylex (void);
 void yyerror (char const *);
@@ -214,6 +219,7 @@ void print_vars(struct list* hash);
 void interp(struct list* ins, struct list* hash);
 void free_string(char* c);
 void __attribute__ ((noreturn)) bye(int code, char* msg, ...);
+void set_cur_mail_length_var(int len, struct list* hash);
 
 /* ham.c */
 char* default_mailbox;