Changeset 40458b9 for filterelement.c


Ignore:
Timestamp:
Dec 24, 2003, 7:35:21 PM (17 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
5c1393d
Parents:
dad943e
Message:
Filters of filters now work
File:
1 edited

Legend:

Unmodified
Added
Removed
  • filterelement.c

    re187445 r40458b9  
    1212#define OWL_FILTERELEMENT_NOT         7
    1313#define OWL_FILTERELEMENT_RE          8
    14 
     14#define OWL_FILTERELEMENT_FILTER      9
    1515
    1616void owl_filterelement_create_null(owl_filterelement *fe)
     
    1818  fe->type=OWL_FILTERELEMENT_NULL;
    1919  fe->field=NULL;
     20  fe->filtername=NULL;
    2021}
    2122
    2223void owl_filterelement_create_openbrace(owl_filterelement *fe)
    2324{
     25  owl_filterelement_create_null(fe);
    2426  fe->type=OWL_FILTERELEMENT_OPENBRACE;
    25   fe->field=NULL;
    2627}
    2728
    2829void owl_filterelement_create_closebrace(owl_filterelement *fe)
    2930{
     31  owl_filterelement_create_null(fe);
    3032  fe->type=OWL_FILTERELEMENT_CLOSEBRACE;
    31   fe->field=NULL;
    3233}
    3334
    3435void owl_filterelement_create_and(owl_filterelement *fe)
    3536{
     37  owl_filterelement_create_null(fe);
    3638  fe->type=OWL_FILTERELEMENT_AND;
    37   fe->field=NULL;
    3839}
    3940
    4041void owl_filterelement_create_or(owl_filterelement *fe)
    4142{
     43  owl_filterelement_create_null(fe);
    4244  fe->type=OWL_FILTERELEMENT_OR;
    43   fe->field=NULL;
    4445}
    4546
    4647void owl_filterelement_create_not(owl_filterelement *fe)
    4748{
     49  owl_filterelement_create_null(fe);
    4850  fe->type=OWL_FILTERELEMENT_NOT;
    49   fe->field=NULL;
    5051}
    5152
    5253void owl_filterelement_create_true(owl_filterelement *fe)
    5354{
     55  owl_filterelement_create_null(fe);
    5456  fe->type=OWL_FILTERELEMENT_TRUE;
    55   fe->field=NULL;
    5657}
    5758
    5859void owl_filterelement_create_false(owl_filterelement *fe)
    5960{
     61  owl_filterelement_create_null(fe);
    6062  fe->type=OWL_FILTERELEMENT_FALSE;
    61   fe->field=NULL;
    6263}
    6364
    6465void owl_filterelement_create_re(owl_filterelement *fe, char *field, char *re)
    6566{
     67  owl_filterelement_create_null(fe);
    6668  fe->type=OWL_FILTERELEMENT_RE;
    6769  fe->field=owl_strdup(field);
     
    6971}
    7072
     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
    7180void owl_filterelement_free(owl_filterelement *fe)
    7281{
    7382  if (fe->field) owl_free(fe->field);
     83  if (fe->filtername) owl_free(fe->filtername);
    7484}
    7585
     
    133143}
    134144
     145int owl_filterelement_is_filter(owl_filterelement *fe)
     146{
     147  if (fe->type==OWL_FILTERELEMENT_FILTER) return(1);
     148  return(0);
     149}
     150
    135151char *owl_filterelement_get_field(owl_filterelement *fe)
    136152{
    137   return(fe->field);
     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");
    138161}
    139162
     
    142165  if ( (fe->type==OWL_FILTERELEMENT_TRUE) ||
    143166       (fe->type==OWL_FILTERELEMENT_FALSE) ||
    144        (fe->type==OWL_FILTERELEMENT_RE) ) {
     167       (fe->type==OWL_FILTERELEMENT_RE) ||
     168       (fe->type==OWL_FILTERELEMENT_FILTER)) {
    145169    return(1);
    146170  }
     
    148172}
    149173
    150 
     174/* caller must free the return */
    151175char *owl_filterelement_to_string(owl_filterelement *fe)
    152176{
    153   /* return must be freed by caller */
    154  
    155177  if (owl_filterelement_is_openbrace(fe)) {
    156178    return(owl_strdup("( "));
     
    168190    return(owl_strdup("false "));
    169191  } 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);
     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));
    174195  }
    175   return(owl_strdup(""));
     196
     197  return(owl_strdup("?"));
    176198}
Note: See TracChangeset for help on using the changeset viewer.