source: filterelement.c @ 40458b9

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 40458b9 was 40458b9, checked in by James M. Kretchmar <kretch@mit.edu>, 15 years ago
Filters of filters now work
  • Property mode set to 100644
File size: 4.8 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5#define OWL_FILTERELEMENT_NULL        0
6#define OWL_FILTERELEMENT_TRUE        1
7#define OWL_FILTERELEMENT_FALSE       2
8#define OWL_FILTERELEMENT_OPENBRACE   3
9#define OWL_FILTERELEMENT_CLOSEBRACE  4
10#define OWL_FILTERELEMENT_AND         5
11#define OWL_FILTERELEMENT_OR          6
12#define OWL_FILTERELEMENT_NOT         7
13#define OWL_FILTERELEMENT_RE          8
14#define OWL_FILTERELEMENT_FILTER      9
15
16void owl_filterelement_create_null(owl_filterelement *fe)
17{
18  fe->type=OWL_FILTERELEMENT_NULL;
19  fe->field=NULL;
20  fe->filtername=NULL;
21}
22
23void owl_filterelement_create_openbrace(owl_filterelement *fe)
24{
25  owl_filterelement_create_null(fe);
26  fe->type=OWL_FILTERELEMENT_OPENBRACE;
27}
28
29void owl_filterelement_create_closebrace(owl_filterelement *fe)
30{
31  owl_filterelement_create_null(fe);
32  fe->type=OWL_FILTERELEMENT_CLOSEBRACE;
33}
34
35void owl_filterelement_create_and(owl_filterelement *fe)
36{
37  owl_filterelement_create_null(fe);
38  fe->type=OWL_FILTERELEMENT_AND;
39}
40
41void owl_filterelement_create_or(owl_filterelement *fe)
42{
43  owl_filterelement_create_null(fe);
44  fe->type=OWL_FILTERELEMENT_OR;
45}
46
47void owl_filterelement_create_not(owl_filterelement *fe)
48{
49  owl_filterelement_create_null(fe);
50  fe->type=OWL_FILTERELEMENT_NOT;
51}
52
53void owl_filterelement_create_true(owl_filterelement *fe)
54{
55  owl_filterelement_create_null(fe);
56  fe->type=OWL_FILTERELEMENT_TRUE;
57}
58
59void owl_filterelement_create_false(owl_filterelement *fe)
60{
61  owl_filterelement_create_null(fe);
62  fe->type=OWL_FILTERELEMENT_FALSE;
63}
64
65void owl_filterelement_create_re(owl_filterelement *fe, char *field, char *re)
66{
67  owl_filterelement_create_null(fe);
68  fe->type=OWL_FILTERELEMENT_RE;
69  fe->field=owl_strdup(field);
70  owl_regex_create(&(fe->re), re);
71}
72
73void owl_filterelement_create_filter(owl_filterelement *fe, char *name)
74{
75  owl_filterelement_create_null(fe);
76  fe->type=OWL_FILTERELEMENT_FILTER;
77  fe->filtername=owl_strdup(name);
78}
79
80void owl_filterelement_free(owl_filterelement *fe)
81{
82  if (fe->field) owl_free(fe->field);
83  if (fe->filtername) owl_free(fe->filtername);
84}
85
86int owl_filterelement_is_null(owl_filterelement *fe)
87{
88  if (fe->type==OWL_FILTERELEMENT_NULL) return(1);
89  return(0);
90}
91
92int owl_filterelement_is_openbrace(owl_filterelement *fe)
93{
94  if (fe->type==OWL_FILTERELEMENT_OPENBRACE) return(1);
95  return(0);
96}
97
98int owl_filterelement_is_closebrace(owl_filterelement *fe)
99{
100  if (fe->type==OWL_FILTERELEMENT_CLOSEBRACE) return(1);
101  return(0);
102}
103
104int owl_filterelement_is_and(owl_filterelement *fe)
105{
106  if (fe->type==OWL_FILTERELEMENT_AND) return(1);
107  return(0);
108}
109
110int owl_filterelement_is_or(owl_filterelement *fe)
111{
112  if (fe->type==OWL_FILTERELEMENT_OR) return(1);
113  return(0);
114}
115
116int owl_filterelement_is_not(owl_filterelement *fe)
117{
118  if (fe->type==OWL_FILTERELEMENT_NOT) return(1);
119  return(0);
120}
121
122int owl_filterelement_is_true(owl_filterelement *fe)
123{
124  if (fe->type==OWL_FILTERELEMENT_TRUE) return(1);
125  return(0);
126}
127
128int owl_filterelement_is_false(owl_filterelement *fe)
129{
130  if (fe->type==OWL_FILTERELEMENT_FALSE) return(1);
131  return(0);
132}
133
134int owl_filterelement_is_re(owl_filterelement *fe)
135{
136  if (fe->type==OWL_FILTERELEMENT_RE) return(1);
137  return(0);
138}
139
140owl_regex *owl_filterelement_get_re(owl_filterelement *fe)
141{
142  return(&(fe->re));
143}
144
145int owl_filterelement_is_filter(owl_filterelement *fe)
146{
147  if (fe->type==OWL_FILTERELEMENT_FILTER) return(1);
148  return(0);
149}
150
151char *owl_filterelement_get_field(owl_filterelement *fe)
152{
153  if (fe->field) return(fe->field);
154  return("unknown-field");
155}
156
157char *owl_filterelement_get_filtername(owl_filterelement *fe)
158{
159  if (fe->filtername) return(fe->filtername);
160  return("unknown-filter");
161}
162
163int owl_filterelement_is_value(owl_filterelement *fe)
164{
165  if ( (fe->type==OWL_FILTERELEMENT_TRUE) ||
166       (fe->type==OWL_FILTERELEMENT_FALSE) ||
167       (fe->type==OWL_FILTERELEMENT_RE) ||
168       (fe->type==OWL_FILTERELEMENT_FILTER)) {
169    return(1);
170  }
171  return(0);
172}
173
174/* caller must free the return */
175char *owl_filterelement_to_string(owl_filterelement *fe)
176{
177  if (owl_filterelement_is_openbrace(fe)) {
178    return(owl_strdup("( "));
179  } else if (owl_filterelement_is_closebrace(fe)) {
180    return(owl_strdup(") "));
181  } else if (owl_filterelement_is_and(fe)) {
182    return(owl_strdup("and "));
183  } else if (owl_filterelement_is_or(fe)) {
184    return(owl_strdup("or "));
185  } else if (owl_filterelement_is_not(fe)) {
186    return(owl_strdup("not "));
187  } else if (owl_filterelement_is_true(fe)) {
188    return(owl_strdup("true "));
189  } else if (owl_filterelement_is_false(fe)) {
190    return(owl_strdup("false "));
191  } else if (owl_filterelement_is_re(fe)) {
192    return(owl_sprintf("%s %s ", fe->field, owl_regex_get_string(&(fe->re))));
193  } else if (owl_filterelement_is_filter(fe)) {
194    return(owl_sprintf("filter %s ", fe->filtername));
195  }
196
197  return(owl_strdup("?"));
198}
Note: See TracBrowser for help on using the repository browser.