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