tree.h
3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* tree.h -- abstract syntax tree
* Larry Greenfield
* $Id$
*/
/***********************************************************
Copyright 1999 by Carnegie Mellon University
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Carnegie Mellon
University not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
#ifndef TREE_H
#define TREE_H
#include "comparator.h"
/* abstract syntax tree for sieve */
typedef struct Stringlist stringlist_t;
typedef struct Patternlist patternlist_t;
typedef struct Commandlist commandlist_t;
typedef struct Test test_t;
typedef struct Testlist testlist_t;
typedef struct Tag tag_t;
typedef struct Taglist taglist_t;
struct Stringlist {
char *s;
stringlist_t *next;
};
struct Patternlist {
void *p;
patternlist_t *next;
};
struct Tag {
int type;
char *arg;
};
struct Taglist {
tag_t *t;
taglist_t *next;
};
struct Test {
int type;
union {
testlist_t *tl; /* anyof, allof */
stringlist_t *sl; /* exists */
struct { /* it's a header test */
int comptag;
comparator_t *comp;
stringlist_t *sl;
patternlist_t *pl;
} h;
struct { /* it's an address or envelope test */
int comptag;
comparator_t *comp;
stringlist_t *sl;
patternlist_t *pl;
int addrpart;
} ae;
test_t *t; /* not */
struct { /* size */
int t; /* tag */
int n; /* param */
} sz;
} u;
};
struct Testlist {
test_t *t;
testlist_t *next;
};
struct Commandlist {
int type;
union {
char *str;
stringlist_t *sl; /* the parameters */
struct { /* it's an if statement */
test_t *t;
commandlist_t *do_then;
commandlist_t *do_else;
} i;
struct { /* it's a vacation action */
char *subject;
int days;
stringlist_t *addresses;
char *message;
int mime;
} v;
struct { /* it's a notify action */
char *priority;
char *message;
stringlist_t *headers_list;
} n;
} u;
struct Commandlist *next;
};
stringlist_t *new_sl(char *s, stringlist_t *n);
tag_t *new_tag(int type, char *s);
taglist_t *new_taglist(tag_t *t, taglist_t *n);
test_t *new_test(int type);
testlist_t *new_testlist(test_t *t, testlist_t *n);
commandlist_t *new_command(int type);
commandlist_t *new_if(test_t *t, commandlist_t *y, commandlist_t *n);
void free_sl(stringlist_t *sl);
void free_test(test_t *t);
void free_tree(commandlist_t *cl);
#endif