source: filterelement.c @ 7d4fbcd

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