source: filterelement.c @ 039213e

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 039213e was 1aee7d9, checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
* Added RCS Id strings to all files. * 'show keymaps' shows details of all keymaps after summary list.
  • 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  fe->type=OWL_FILTERELEMENT_NULL;
18  fe->field=NULL;
19}
20
21void owl_filterelement_create_openbrace(owl_filterelement *fe) {
22  fe->type=OWL_FILTERELEMENT_OPENBRACE;
23  fe->field=NULL;
24}
25
26void owl_filterelement_create_closebrace(owl_filterelement *fe) {
27  fe->type=OWL_FILTERELEMENT_CLOSEBRACE;
28  fe->field=NULL;
29}
30
31void owl_filterelement_create_and(owl_filterelement *fe) {
32  fe->type=OWL_FILTERELEMENT_AND;
33  fe->field=NULL;
34}
35
36void owl_filterelement_create_or(owl_filterelement *fe) {
37  fe->type=OWL_FILTERELEMENT_OR;
38  fe->field=NULL;
39}
40
41void owl_filterelement_create_not(owl_filterelement *fe) {
42  fe->type=OWL_FILTERELEMENT_NOT;
43  fe->field=NULL;
44}
45
46void owl_filterelement_create_true(owl_filterelement *fe) {
47  fe->type=OWL_FILTERELEMENT_TRUE;
48  fe->field=NULL;
49}
50
51void owl_filterelement_create_false(owl_filterelement *fe) {
52  fe->type=OWL_FILTERELEMENT_FALSE;
53  fe->field=NULL;
54}
55
56void owl_filterelement_create_re(owl_filterelement *fe, char *field, char *re) {
57  fe->type=OWL_FILTERELEMENT_RE;
58  fe->field=owl_strdup(field);
59  owl_regex_create(&(fe->re), re);
60}
61
62void owl_filterelement_free(owl_filterelement *fe) {
63  if (fe->field) owl_free(fe->field);
64}
65
66int owl_filterelement_is_null(owl_filterelement *fe) {
67  if (fe->type==OWL_FILTERELEMENT_NULL) return(1);
68  return(0);
69}
70
71int owl_filterelement_is_openbrace(owl_filterelement *fe) {
72  if (fe->type==OWL_FILTERELEMENT_OPENBRACE) return(1);
73  return(0);
74}
75
76int owl_filterelement_is_closebrace(owl_filterelement *fe) {
77  if (fe->type==OWL_FILTERELEMENT_CLOSEBRACE) return(1);
78  return(0);
79}
80
81int owl_filterelement_is_and(owl_filterelement *fe) {
82  if (fe->type==OWL_FILTERELEMENT_AND) return(1);
83  return(0);
84}
85
86int owl_filterelement_is_or(owl_filterelement *fe) {
87  if (fe->type==OWL_FILTERELEMENT_OR) return(1);
88  return(0);
89}
90
91int owl_filterelement_is_not(owl_filterelement *fe) {
92  if (fe->type==OWL_FILTERELEMENT_NOT) return(1);
93  return(0);
94}
95
96int owl_filterelement_is_true(owl_filterelement *fe) {
97  if (fe->type==OWL_FILTERELEMENT_TRUE) return(1);
98  return(0);
99}
100
101int owl_filterelement_is_false(owl_filterelement *fe) {
102  if (fe->type==OWL_FILTERELEMENT_FALSE) return(1);
103  return(0);
104}
105
106int owl_filterelement_is_re(owl_filterelement *fe) {
107  if (fe->type==OWL_FILTERELEMENT_RE) return(1);
108  return(0);
109}
110
111owl_regex *owl_filterelement_get_re(owl_filterelement *fe) {
112  return(&(fe->re));
113}
114
115char *owl_filterelement_get_field(owl_filterelement *fe) {
116  return(fe->field);
117}
118
119int owl_filterelement_is_value(owl_filterelement *fe) {
120  if ( (fe->type==OWL_FILTERELEMENT_TRUE) ||
121       (fe->type==OWL_FILTERELEMENT_FALSE) ||
122       (fe->type==OWL_FILTERELEMENT_RE) ) {
123    return(1);
124  }
125  return(0);
126}
127
128
129char *owl_filterelement_to_string(owl_filterelement *fe) {
130  /* return must be freed by caller */
131 
132  if (owl_filterelement_is_openbrace(fe)) {
133    return(owl_strdup("( "));
134  } else if (owl_filterelement_is_closebrace(fe)) {
135    return(owl_strdup(") "));
136  } else if (owl_filterelement_is_and(fe)) {
137    return(owl_strdup("and "));
138  } else if (owl_filterelement_is_or(fe)) {
139    return(owl_strdup("or "));
140  } else if (owl_filterelement_is_not(fe)) {
141    return(owl_strdup("not "));
142  } else if (owl_filterelement_is_true(fe)) {
143    return(owl_strdup("true "));
144  } else if (owl_filterelement_is_false(fe)) {
145    return(owl_strdup("false "));
146  } else if (owl_filterelement_is_re(fe)) {
147    char *buff;
148    buff=owl_malloc(LINE);
149    sprintf(buff, "%s %s ", fe->field, owl_regex_get_string(&(fe->re)));
150    return(buff);
151  }
152  return(owl_strdup(""));
153}
Note: See TracBrowser for help on using the repository browser.