X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=umpf.h;h=32cd804e174d93edaa74863b07d8705e8d48e881;hb=43367dfb74d85a732b8973140a7b87a888b11902;hp=c12492fc2418150d29b0f93c2a2792c60c4f401d;hpb=45c6350961f844802e4ed6bf636be14772b09d20;p=umpf.git diff --git a/umpf.h b/umpf.h index c12492f..32cd804 100644 --- a/umpf.h +++ b/umpf.h @@ -4,6 +4,15 @@ int yylex (void); void yyerror (char const *); +enum keyword { + K_DISCARD, + K_COPY, + K_MAIL, + K_PIPE, + K_EMPTY, + K_FILTER +}; + struct tree { enum { ST_IF, @@ -23,11 +32,12 @@ struct tree { } tif; struct { - int op; enum { OP_REL, - OP_BOOL + OP_BOOL, + JUST_BOOL /* value only in left, no op */ } type; + int op; struct tree* left; struct tree* right; } cond; /* binary operator */ @@ -48,11 +58,12 @@ struct tree { L_CONST, } type; char* value; + int n; } leaf; struct { - char* kw_left; - char* kw_right; + enum keyword left; + enum keyword right; struct tree* s; } arrow; @@ -71,41 +82,144 @@ struct tree* input_tree; #define CC(a,b) ((a<<8)|b) void* xmalloc(size_t size); void* xrealloc(void* buf, size_t size); -char* xstrdup(char* s); +char* xstrdup(const char* s); void __attribute__ ((noreturn)) die(char* msg, ...); void read_conf(char* filename); int line; FILE* conf; +/* code.c */ +#define BUFSIZE 4096 +#define HASHSIZE 103 +#define MAGIC 19 + +struct code { + struct node car; + enum { + OPC_SET, + OPC_JUMP, + OPC_JUMP_IF, + OPC_JUMP_UNLESS, + OPC_DELIVER, + OPC_NOP, + OPC_CAT, + OPC_GT, + OPC_LT, + OPC_LE, + OPC_GE, + OPC_EQ, + OPC_NEQ, + OPC_RE, + OPC_NRE, + OPC_AND, + OPC_OR, + OPC_XOR, + OPC_NOT, + OPC_PLUS, + OPC_MINUS, + OPC_MUL, + OPC_DIV, + OPC_PIPE, + OPC_MAIL, + OPC_FILTER, + OPC_DISCARD + } opcode; + + union { + struct { + struct code* target; + } jump; + struct { + struct code* target; + int cond; + } jump_if; + struct { + struct code* target; + int cond; + } jump_unless; + struct { + int l; + int r; + } set; + struct { + int l; + int r; + int res; /* result */ + } tpop; + struct { + int par; + int res; /* result */ + } dpop; + struct { + int copy; + int what; + } arrow; + struct { + } nop; + } u; +}; + +struct variable { + struct node car; + char* name; + int varcode; + int modified; +}; + +struct list input_code; +struct list* var_hash; +int current_varcode; +int max_varcode; +int temp_varcode_start; +char** var_tab; +char** const_tab; +int cur_const_n; +int cur_const_s; +char* empty; + +void init(void); +void compile(struct tree* t, struct list* where); +int find_var(char* name, struct list* hash); +int store_const(char* c); +struct list* new_var_hash(void); +int get_bucket_number(char* name); +void print_code(void); + /* int.c */ struct hlist { struct node car; char* name; char* value; + int have_var; }; struct email { struct list* headers; char* body; + char* tmpfile; + int fd; int body_len; }; -struct action { - char* l; - char* r; - char* s; - struct email e; -}; +void save_current_headers(struct list* hash); +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, ...); /* ham.c */ char* default_mailbox; +int chars_written; struct list* current_headers; struct email* current_body; struct list* make_hlist(void); void print_headers(struct list* l); -void do_action(struct action* a); struct email* get_body(void); +int deliver_local_email(char* folder, struct email* email); +int write_email_to_fd(int fd, struct email* email); +char* read_email(struct email* em); +void open_email(void); /* lock.c */ void save_gids(void); @@ -113,44 +227,4 @@ void close_mailbox(int fd, char* path, int is_default_mailbox); int open_mailbox(char* path, int is_default_mailbox); char* cat(char* l, char* r); -/* code.c */ -enum opcode { - SET, - JUMP, - JUMP_IF, - JUMP_UNLESS, - DELIVER, - CALL_EXT, - NOP -}; - -union op { - int i; - char* s; - struct code* c; -}; -struct code { - struct node car; - enum opcode opc; - union op op1; - union op op2; - union op op3; -}; - -struct variable { - struct node car; - char* name; - int varcode; -}; - -struct list input_code; -struct list* var_hash; -int current_varcode; -char** var_tab; -char** const_tab; -int cur_const_n, cur_const_s; - -void init(void); -void compile(struct tree* t); -void print_code(struct tree* t);