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