From: Anicka Bernathova Date: Tue, 21 Jul 2009 13:54:37 +0000 (+0200) Subject: save internal vars X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;ds=sidebyside;h=e663cce47dfc6b079842056d046d21fcce179bdc;p=umpf.git save internal vars --- diff --git a/int.c b/int.c index 59c1f93..af67fe0 100644 --- 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 c3ef9a7..b8c2cd9 100644 --- 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 35f65ef..ef9651c 100644 --- 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;