Changeset 23fddad for filter.c


Ignore:
Timestamp:
Oct 23, 2009, 11:01:30 PM (12 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Branches:
master, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
8590774
Parents:
52761cc
git-author:
Karl Ramm <kcr@1ts.org> (09/30/09 10:12:27)
git-committer:
Karl Ramm <kcr@1ts.org> (10/23/09 23:01:30)
Message:
refactor & rename filter creation & storage management

filter_init_fromstring -> filter_new_fromstring
filter_init -> filter_new
filter_free -> filter_delete

Every time owl_filter_init and owl_filter_init_fromstring were called,
there was a call to malloc right above them;  Conversely, after every
owl_filter_free there needed to be a call to owl_free (and sometimes
there wasn't).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • filter.c

    r8bce750 r23fddad  
    22#include "owl.h"
    33
    4 int owl_filter_init_fromstring(owl_filter *f, const char *name, const char *string)
    5 {
     4owl_filter *owl_filter_new_fromstring(const char *name, const char *string)
     5{
     6  owl_filter *f;
    67  char **argv;
    7   int argc, out;
    8 
    9   argv=owl_parseline(string, &argc);
    10   out=owl_filter_init(f, name, argc, strs(argv));
     8  int argc;
     9
     10  argv = owl_parseline(string, &argc);
     11  f = owl_filter_new(name, argc, strs(argv));
    1112  owl_parsefree(argv, argc);
    12   return(out);
    13 }
    14 
    15 int owl_filter_init(owl_filter *f, const char *name, int argc, const char *const *argv)
    16 {
     13
     14  return f;
     15}
     16
     17owl_filter *owl_filter_new(const char *name, int argc, const char *const *argv)
     18{
     19  owl_filter *f;
     20
     21  f = owl_malloc(sizeof(owl_filter));
     22
    1723  f->name=owl_strdup(name);
    1824  f->fgcolor=OWL_COLOR_DEFAULT;
     
    4046  }
    4147
    42   if(!(f->root = owl_filter_parse_expression(argc, argv, NULL)))
    43     return(-1);
     48  if (!(f->root = owl_filter_parse_expression(argc, argv, NULL))) {
     49    owl_filter_delete(f);
     50    return NULL;
     51  }
    4452
    4553  /* Now check for recursion. */
    4654  if (owl_filter_is_toodeep(f)) {
    4755    owl_function_error("Filter loop!");
    48     owl_filter_free(f);
    49     return(-1);
    50   }
    51 
    52   return(0);
     56    owl_filter_delete(f);
     57    return NULL;
     58  }
     59
     60  return f;
    5361}
    5462
     
    255263}
    256264
    257 void owl_filter_free(owl_filter *f)
    258 {
    259   if(f->root) {
     265void owl_filter_delete(owl_filter *f)
     266{
     267  if (f == NULL)
     268    return;
     269  if (f->root) {
    260270    owl_filterelement_free(f->root);
    261271    owl_free(f->root);
    262272  }
    263   if (f->name) owl_free(f->name);
    264 }
     273  if (f->name)
     274    owl_free(f->name);
     275  owl_free(f);
     276}
Note: See TracChangeset for help on using the changeset viewer.