source: filterelement.c @ faf71b5

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since faf71b5 was e187445, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
reformatted filter, filterelement and regex to new code style
  • Property mode set to 100644
File size: 3.9 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
15
16void owl_filterelement_create_null(owl_filterelement *fe)
17{
18  fe->type=OWL_FILTERELEMENT_NULL;
19  fe->field=NULL;
20}
21
22void owl_filterelement_create_openbrace(owl_filterelement *fe)
23{
24  fe->type=OWL_FILTERELEMENT_OPENBRACE;
25  fe->field=NULL;
26}
27
28void owl_filterelement_create_closebrace(owl_filterelement *fe)
29{
30  fe->type=OWL_FILTERELEMENT_CLOSEBRACE;
31  fe->field=NULL;
32}
33
34void owl_filterelement_create_and(owl_filterelement *fe)
35{
36  fe->type=OWL_FILTERELEMENT_AND;
37  fe->field=NULL;
38}
39
40void owl_filterelement_create_or(owl_filterelement *fe)
41{
42  fe->type=OWL_FILTERELEMENT_OR;
43  fe->field=NULL;
44}
45
46void owl_filterelement_create_not(owl_filterelement *fe)
47{
48  fe->type=OWL_FILTERELEMENT_NOT;
49  fe->field=NULL;
50}
51
52void owl_filterelement_create_true(owl_filterelement *fe)
53{
54  fe->type=OWL_FILTERELEMENT_TRUE;
55  fe->field=NULL;
56}
57
58void owl_filterelement_create_false(owl_filterelement *fe)
59{
60  fe->type=OWL_FILTERELEMENT_FALSE;
61  fe->field=NULL;
62}
63
64void owl_filterelement_create_re(owl_filterelement *fe, char *field, char *re)
65{
66  fe->type=OWL_FILTERELEMENT_RE;
67  fe->field=owl_strdup(field);
68  owl_regex_create(&(fe->re), re);
69}
70
71void owl_filterelement_free(owl_filterelement *fe)
72{
73  if (fe->field) owl_free(fe->field);
74}
75
76int owl_filterelement_is_null(owl_filterelement *fe)
77{
78  if (fe->type==OWL_FILTERELEMENT_NULL) return(1);
79  return(0);
80}
81
82int owl_filterelement_is_openbrace(owl_filterelement *fe)
83{
84  if (fe->type==OWL_FILTERELEMENT_OPENBRACE) return(1);
85  return(0);
86}
87
88int owl_filterelement_is_closebrace(owl_filterelement *fe)
89{
90  if (fe->type==OWL_FILTERELEMENT_CLOSEBRACE) return(1);
91  return(0);
92}
93
94int owl_filterelement_is_and(owl_filterelement *fe)
95{
96  if (fe->type==OWL_FILTERELEMENT_AND) return(1);
97  return(0);
98}
99
100int owl_filterelement_is_or(owl_filterelement *fe)
101{
102  if (fe->type==OWL_FILTERELEMENT_OR) return(1);
103  return(0);
104}
105
106int owl_filterelement_is_not(owl_filterelement *fe)
107{
108  if (fe->type==OWL_FILTERELEMENT_NOT) return(1);
109  return(0);
110}
111
112int owl_filterelement_is_true(owl_filterelement *fe)
113{
114  if (fe->type==OWL_FILTERELEMENT_TRUE) return(1);
115  return(0);
116}
117
118int owl_filterelement_is_false(owl_filterelement *fe)
119{
120  if (fe->type==OWL_FILTERELEMENT_FALSE) return(1);
121  return(0);
122}
123
124int owl_filterelement_is_re(owl_filterelement *fe)
125{
126  if (fe->type==OWL_FILTERELEMENT_RE) return(1);
127  return(0);
128}
129
130owl_regex *owl_filterelement_get_re(owl_filterelement *fe)
131{
132  return(&(fe->re));
133}
134
135char *owl_filterelement_get_field(owl_filterelement *fe)
136{
137  return(fe->field);
138}
139
140int owl_filterelement_is_value(owl_filterelement *fe)
141{
142  if ( (fe->type==OWL_FILTERELEMENT_TRUE) ||
143       (fe->type==OWL_FILTERELEMENT_FALSE) ||
144       (fe->type==OWL_FILTERELEMENT_RE) ) {
145    return(1);
146  }
147  return(0);
148}
149
150
151char *owl_filterelement_to_string(owl_filterelement *fe)
152{
153  /* return must be freed by caller */
154 
155  if (owl_filterelement_is_openbrace(fe)) {
156    return(owl_strdup("( "));
157  } else if (owl_filterelement_is_closebrace(fe)) {
158    return(owl_strdup(") "));
159  } else if (owl_filterelement_is_and(fe)) {
160    return(owl_strdup("and "));
161  } else if (owl_filterelement_is_or(fe)) {
162    return(owl_strdup("or "));
163  } else if (owl_filterelement_is_not(fe)) {
164    return(owl_strdup("not "));
165  } else if (owl_filterelement_is_true(fe)) {
166    return(owl_strdup("true "));
167  } else if (owl_filterelement_is_false(fe)) {
168    return(owl_strdup("false "));
169  } else if (owl_filterelement_is_re(fe)) {
170    char *buff;
171    buff=owl_malloc(LINE);
172    sprintf(buff, "%s %s ", fe->field, owl_regex_get_string(&(fe->re)));
173    return(buff);
174  }
175  return(owl_strdup(""));
176}
Note: See TracBrowser for help on using the repository browser.