Changeset 84ea53cceca0c0915283fccbb9e6fece4cbcc25f

Show
Ignore:
Timestamp:
10/23/09 22:50:42 (5 weeks ago)
Author:
Karl Ramm <kcr@1ts.org>
git-author:
Karl Ramm <kcr@1ts.org> / 2009-09-30T10:01:22Z-0400
Parents:
73faa26a4aa955d75df73bf1beb16726be045f26
Children:
52761cc7346cb35d2d70160f25573df691427ef2
git-committer:
Karl Ramm <kcr@1ts.org> / 2009-10-23T22:50:42Z-0400
Message:
data-driven owl_setup_default_filter

Factor out a bunch of calls to the same three subroutines into an array,
a loop, and one set of calls.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • owl.c

    r26255f0 r84ea53c  
    149149} 
    150150 
    151 void owl_setup_default_filters(void) { 
     151static void owl_setup_default_filters(void) 
     152{ 
    152153  owl_filter *f; 
     154  int i; 
     155  static const struct { 
     156    const char *name; 
     157    const char *desc; 
     158  } filters[] = { 
     159    { "personal", 
     160      "isprivate ^true$ and ( not type ^zephyr$ or ( class ^message  ) )" }, 
     161    { "trash", 
     162      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" }, 
     163    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" }, 
     164    { "ping", "opcode ^ping$" }, 
     165    { "auto", "opcode ^auto$" }, 
     166    { "login", "not login ^none$" }, 
     167    { "reply-lockout", "class ^noc or class ^mail$" }, 
     168    { "out", "direction ^out$" }, 
     169    { "aim", "type ^aim$" }, 
     170    { "zephyr", "type ^zephyr$" }, 
     171    { "none", "false" }, 
     172    { "all", "true" }, 
     173    { NULL, NULL } 
     174  }; 
    153175 
    154176  owl_function_debugmsg("startup: creating default filters"); 
    155   f=owl_malloc(sizeof(owl_filter)); 
    156   owl_filter_init_fromstring(f, "personal", "isprivate ^true$ and ( not type ^zephyr$" 
    157                              " or ( class ^message  ) )"); 
    158   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    159  
    160   f=owl_malloc(sizeof(owl_filter)); 
    161   owl_filter_init_fromstring(f, "wordwrap", "not ( type ^admin$ or type ^zephyr$ ) "); 
    162   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    163  
    164   f=owl_malloc(sizeof(owl_filter)); 
    165   owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )"); 
    166   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    167  
    168   f=owl_malloc(sizeof(owl_filter)); 
    169   owl_filter_init_fromstring(f, "ping", "opcode ^ping$"); 
    170   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    171  
    172   f=owl_malloc(sizeof(owl_filter)); 
    173   owl_filter_init_fromstring(f, "auto", "opcode ^auto$"); 
    174   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    175  
    176   f=owl_malloc(sizeof(owl_filter)); 
    177   owl_filter_init_fromstring(f, "login", "not login ^none$"); 
    178   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    179  
    180   f=owl_malloc(sizeof(owl_filter)); 
    181   owl_filter_init_fromstring(f, "reply-lockout", "class ^noc or class ^mail$"); 
    182   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    183  
    184   f=owl_malloc(sizeof(owl_filter)); 
    185   owl_filter_init_fromstring(f, "out", "direction ^out$"); 
    186   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    187  
    188   f=owl_malloc(sizeof(owl_filter)); 
    189   owl_filter_init_fromstring(f, "aim", "type ^aim$"); 
    190   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    191  
    192   f=owl_malloc(sizeof(owl_filter)); 
    193   owl_filter_init_fromstring(f, "zephyr", "type ^zephyr$"); 
    194   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    195  
    196   f=owl_malloc(sizeof(owl_filter)); 
    197   owl_filter_init_fromstring(f, "none", "false"); 
    198   owl_list_append_element(owl_global_get_filterlist(&g), f); 
    199  
    200   f=owl_malloc(sizeof(owl_filter)); 
    201   owl_filter_init_fromstring(f, "all", "true"); 
    202   owl_list_append_element(owl_global_get_filterlist(&g), f); 
     177 
     178  for (i = 0; filters[i].name != NULL; i++) { 
     179    f = owl_malloc(sizeof(owl_filter)); 
     180    owl_filter_init_fromstring(f, filters[i].name, filters[i].desc); 
     181    owl_list_append_element(owl_global_get_filterlist(&g), f); 
     182  } 
    203183} 
    204184