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