]> mj.ucw.cz Git - umpf.git/blob - umpf.h
attempt to cope with big emails
[umpf.git] / umpf.h
1 #include "lists.h"
2
3 /* cond.h */
4 int yylex (void);
5 void yyerror (char const *);
6
7 enum keyword {
8         K_DISCARD,
9         K_COPY,
10         K_MAIL,
11         K_PIPE,
12         K_EMPTY
13 };
14
15 struct tree {
16         enum {
17                 ST_IF,
18                 ST_COND,
19                 ST_BLOCK,
20                 ST_ASS,
21                 ST_LEAF,
22                 ST_EMPTY,
23                 ST_ARROW,
24                 ST_OP
25         } st;   /* subtree type */
26         union {
27                 struct {
28                         struct tree* c; /* condition */
29                         struct tree* i; /* if */
30                         struct tree* e; /* else */
31                 } tif;
32
33                 struct {
34                         enum {
35                                 OP_REL,
36                                 OP_BOOL,
37                                 JUST_BOOL /* value only in left, no op */       
38                         } type;
39                         int op;
40                         struct tree* left;
41                         struct tree* right;
42                 } cond; /* binary operator */
43
44                 struct {
45                         struct tree* head;
46                         struct tree* tail;
47                 } block;
48
49                 struct {
50                         struct tree* left;
51                         struct tree* right;
52                 } ass;
53
54                 struct {
55                         enum {
56                                 L_VAR,
57                                 L_CONST,
58                         } type;
59                         char* value;
60                         int n;
61                 } leaf;
62
63                 struct {
64                         enum keyword left;
65                         enum keyword right;
66                         struct tree* s;
67                 } arrow;
68
69                 struct {
70                         int op;
71                         struct tree* left;
72                         struct tree* right;
73                 } op;
74
75         } pt;
76 };
77
78 struct tree* input_tree;
79
80 /* lex.c */
81 #define CC(a,b) ((a<<8)|b)
82 void* xmalloc(size_t size);
83 void* xrealloc(void* buf, size_t size);
84 char* xstrdup(char* s);
85 void __attribute__ ((noreturn)) die(char* msg, ...);
86 void read_conf(char* filename);
87 int line;
88 FILE* conf;
89
90 /* code.c */
91 #define BUFSIZE 4096 
92 #define HASHSIZE 103
93 #define MAGIC 19
94
95 struct code {
96         struct node car;
97         enum {
98                 OPC_SET,
99                 OPC_JUMP,
100                 OPC_JUMP_IF,
101                 OPC_JUMP_UNLESS,
102                 OPC_DELIVER,
103                 OPC_CALL_EXT,
104                 OPC_NOP,
105                 OPC_CAT,
106                 OPC_GT,
107                 OPC_LT,
108                 OPC_LE,
109                 OPC_GE,
110                 OPC_EQ,
111                 OPC_NEQ,
112                 OPC_RE,
113                 OPC_NRE,
114                 OPC_AND,
115                 OPC_OR,
116                 OPC_XOR,
117                 OPC_NOT,
118                 OPC_PLUS,
119                 OPC_MINUS,
120                 OPC_MUL,
121                 OPC_DIV,
122                 OPC_PIPE,
123                 OPC_MAIL,
124                 OPC_DISCARD
125         } opcode;
126
127         union {
128                 struct {
129                         struct code* target;
130                 } jump;
131                 struct {
132                         struct code* target;
133                         int cond;
134                 } jump_if;
135                 struct {
136                         struct code* target;
137                         int cond;
138                 } jump_unless;
139                 struct {
140                         int l;
141                         int r;
142                 } set;
143                 struct {
144                         int l;
145                         int r;
146                         int res; /* result */
147                 } tpop;
148                 struct {
149                         int par;
150                         int res; /* result */
151                 } dpop;
152                 struct {
153                         int copy;
154                         int what;
155                 } arrow;
156                 struct {
157                 } nop;
158         } u;
159 };
160
161 struct variable {
162         struct node car;
163         char* name;
164         int varcode;
165         int modified;
166 };
167
168 struct list input_code;
169 struct list* var_hash;
170 int current_varcode;
171 int max_varcode;
172 int temp_varcode_start;
173 char** var_tab; 
174 char** const_tab;
175 int cur_const_n;
176 int cur_const_s;
177
178 void init(void);
179 void compile(struct tree* t, struct list* where);
180 int find_var(char* name, struct list* hash);
181 int store_const(char* c);
182 struct list* new_var_hash(void);
183 int get_bucket_number(char* name);
184 void print_code(void);
185
186 /* int.c */
187 struct hlist {
188         struct node car;
189         char* name;
190         char* value;
191         int have_var;
192 };
193
194 struct email {
195         struct list* headers;
196         char* body;
197         char* tmpfile;
198         int fd;
199         int body_len;
200 };
201
202 void save_current_headers(struct list* hash);
203 void print_vars(struct list* hash);
204 void interp(struct list* ins, struct list* hash);
205
206 /* ham.c */
207 char* default_mailbox;
208
209 struct list* current_headers;
210 struct email* current_body;
211 struct list* make_hlist(void);
212 void print_headers(struct list* l);
213 struct email* get_body(void);
214 int deliver_local_email(char* folder, struct email* email);
215
216 /* lock.c */
217 void save_gids(void);
218 void close_mailbox(int fd, char* path, int is_default_mailbox);
219 int open_mailbox(char* path, int is_default_mailbox);
220 char* cat(char* l, char* r);
221
222