]> mj.ucw.cz Git - umpf.git/blob - umpf.h
926c4768b55efbf3a9f6920e383977e5d5f7d00c
[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 temp_varcode_start;
172 char** var_tab; 
173 char** const_tab;
174 int cur_const_n;
175 int cur_const_s;
176
177 void init(void);
178 void compile(struct tree* t, struct list* where);
179 int find_var(char* name, struct list* hash);
180 int store_const(char* c);
181 struct list* new_var_hash(void);
182 int get_bucket_number(char* name);
183 void print_code(void);
184
185 /* int.c */
186 struct hlist {
187         struct node car;
188         char* name;
189         char* value;
190         int have_var;
191 };
192
193 struct email {
194         struct list* headers;
195         char* body;
196         int body_len;
197 };
198
199 void save_current_headers(struct list* hash);
200 void print_vars(struct list* hash);
201 void interp(struct list* ins, struct list* hash);
202
203 /* ham.c */
204 char* default_mailbox;
205
206 struct list* current_headers;
207 struct email* current_body;
208 struct list* make_hlist(void);
209 void print_headers(struct list* l);
210 struct email* get_body(void);
211
212 /* lock.c */
213 void save_gids(void);
214 void close_mailbox(int fd, char* path, int is_default_mailbox);
215 int open_mailbox(char* path, int is_default_mailbox);
216 char* cat(char* l, char* r);
217
218