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