source: filterelement.c @ dd0edbf

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