Changeset 0504f63


Ignore:
Timestamp:
Aug 10, 2008, 5:38:44 PM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e9bb404
Parents:
d81f8d0
Message:
Rewrite owl_filter_print to use GString.

barnowl will no longer segfault on `show filter' with filters over
5000 characters or so.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • filter.c

    r601733d r0504f63  
    212212
    213213
    214 void owl_filter_print(owl_filter *f, char *out)
    215 {
    216   strcpy(out, owl_filter_get_name(f));
    217   strcat(out, ": ");
     214char* owl_filter_print(owl_filter *f)
     215{
     216  GString *out = g_string_new(owl_filter_get_name(f));
     217
     218  g_string_append(out, ": ");
    218219
    219220  if (f->fgcolor!=OWL_COLOR_DEFAULT) {
    220     strcat(out, "-c ");
     221    g_string_append(out, "-c ");
    221222    if (f->fgcolor < 8) {
    222       strcat(out, owl_util_color_to_string(f->fgcolor));
     223      g_string_append(out, owl_util_color_to_string(f->fgcolor));
    223224    }
    224225    else {
    225       char* c = owl_sprintf("%i",f->fgcolor);
    226       strcat(out, c);
    227       owl_free(c);
    228     }
    229     strcat(out, " ");
     226      g_string_append_printf(out, "%i",f->fgcolor);
     227    }
     228    g_string_append(out, " ");
    230229  }
    231230  if (f->bgcolor!=OWL_COLOR_DEFAULT) {
    232     strcat(out, "-b ");
     231    g_string_append(out, "-b ");
    233232    if (f->bgcolor < 8) {
    234       strcat(out, owl_util_color_to_string(f->bgcolor));
     233      g_string_append(out, owl_util_color_to_string(f->bgcolor));
    235234    }
    236235    else {
    237       char* c = owl_sprintf("%i",f->bgcolor);
    238       strcat(out, c);
    239       owl_free(c);
    240     }
    241     strcat(out, " ");
    242   }
    243   if(!f->root) return;
    244   owl_filterelement_print(f->root, out);
    245   strcat(out, "\n");
     236      g_string_append_printf(out, "%i",f->fgcolor);
     237    }
     238    g_string_append(out, " ");
     239  }
     240  if(f->root) {
     241    owl_filterelement_print(f->root, out);
     242    g_string_append(out, "\n");
     243  }
     244
     245  return g_string_free(out, 0);
    246246}
    247247
     
    249249int owl_filter_equiv(owl_filter *a, owl_filter *b)
    250250{
    251   char buff[LINE], buff2[LINE];
    252 
    253   owl_filter_print(a, buff);
    254   owl_filter_print(b, buff2);
    255 
    256   if (!strcmp(buff, buff2)) return(1);
    257   return(0);
     251  char *buffa, *buffb;
     252  int ret;
     253
     254  buffa = owl_filter_print(a);
     255  buffb = owl_filter_print(b);
     256
     257  ret = !strcmp(buffa, buffb);
     258
     259  owl_free(buffa);
     260  owl_free(buffb);
     261
     262  return ret;
    258263}
    259264
  • filterelement.c

    r81655f8 r0504f63  
    126126/* Print methods */
    127127
    128 static void owl_filterelement_print_true(owl_filterelement *fe, char *buf)
    129 {
    130   strcat(buf, "true");
    131 }
    132 
    133 static void owl_filterelement_print_false(owl_filterelement *fe, char *buf)
    134 {
    135   strcat(buf, "false");
    136 }
    137 
    138 static void owl_filterelement_print_re(owl_filterelement *fe, char *buf)
     128static void owl_filterelement_print_true(owl_filterelement *fe, GString *buf)
     129{
     130  g_string_append(buf, "true");
     131}
     132
     133static void owl_filterelement_print_false(owl_filterelement *fe, GString *buf)
     134{
     135  g_string_append(buf, "false");
     136}
     137
     138static void owl_filterelement_print_re(owl_filterelement *fe, GString *buf)
    139139{
    140140  char *re, *q;
    141   strcat(buf, fe->field);
    142   strcat(buf, " ");
     141  g_string_append(buf, fe->field);
     142  g_string_append(buf, " ");
    143143
    144144  re = owl_regex_get_string(&(fe->re));
    145145  q = owl_getquoting(re);
    146   strcat(buf, q);
    147   strcat(buf, re);
    148   strcat(buf, q);
    149 }
    150 
    151 static void owl_filterelement_print_filter(owl_filterelement *fe, char *buf)
    152 {
    153   strcat(buf, "filter ");
    154   strcat(buf, fe->field);
    155 }
    156 
    157 static void owl_filterelement_print_perl(owl_filterelement *fe, char *buf)
    158 {
    159   strcat(buf, "perl ");
    160   strcat(buf, fe->field);
    161 }
    162 
    163 static void owl_filterelement_print_group(owl_filterelement *fe, char *buf)
    164 {
    165   strcat(buf, "( ");
     146  g_string_append(buf, q);
     147  g_string_append(buf, re);
     148  g_string_append(buf, q);
     149}
     150
     151static void owl_filterelement_print_filter(owl_filterelement *fe, GString *buf)
     152{
     153  g_string_append(buf, "filter ");
     154  g_string_append(buf, fe->field);
     155}
     156
     157static void owl_filterelement_print_perl(owl_filterelement *fe, GString *buf)
     158{
     159  g_string_append(buf, "perl ");
     160  g_string_append(buf, fe->field);
     161}
     162
     163static void owl_filterelement_print_group(owl_filterelement *fe, GString *buf)
     164{
     165  g_string_append(buf, "( ");
    166166  owl_filterelement_print(fe->left, buf) ;
    167   strcat(buf, " )");
    168 }
    169 
    170 static void owl_filterelement_print_or(owl_filterelement *fe, char *buf)
     167  g_string_append(buf, " )");
     168}
     169
     170static void owl_filterelement_print_or(owl_filterelement *fe, GString *buf)
    171171{
    172172  owl_filterelement_print(fe->left, buf);
    173   strcat(buf, " or ");
     173  g_string_append(buf, " or ");
    174174  owl_filterelement_print(fe->right, buf);
    175175}
    176176
    177 static void owl_filterelement_print_and(owl_filterelement *fe, char *buf)
     177static void owl_filterelement_print_and(owl_filterelement *fe, GString *buf)
    178178{
    179179  owl_filterelement_print(fe->left, buf);
    180   strcat(buf, " and ");
     180  g_string_append(buf, " and ");
    181181  owl_filterelement_print(fe->right, buf);
    182182}
    183183
    184 static void owl_filterelement_print_not(owl_filterelement *fe, char *buf)
    185 {
    186   strcat(buf, " not ");
     184static void owl_filterelement_print_not(owl_filterelement *fe, GString *buf)
     185{
     186  g_string_append(buf, " not ");
    187187  owl_filterelement_print(fe->left, buf);
    188188}
     
    321321}
    322322
    323 void owl_filterelement_print(owl_filterelement *fe, char *buf)
     323void owl_filterelement_print(owl_filterelement *fe, GString *buf)
    324324{
    325325  if(!fe || !fe->print_elt) return;
  • functions.c

    rd81f8d0 r0504f63  
    25152515{
    25162516  owl_filter *f;
    2517   char buff[5000];
     2517  char *buff;
    25182518
    25192519  f=owl_global_get_filter(&g, name);
     
    25222522    return;
    25232523  }
    2524   owl_filter_print(f, buff);
     2524  buff = owl_filter_print(f);
    25252525  owl_function_popless_text(buff);
     2526  owl_free(buff);
    25262527}
    25272528
     
    25312532  owl_list *fl;
    25322533  char buff[5000];
     2534  char *tmp;
    25332535  owl_fmtext fm;
    25342536  int i, j;
     
    25442546    snprintf(buff, sizeof(buff), "[% 2d] ", i+1);
    25452547    owl_fmtext_append_normal(&fm, buff);
    2546     owl_filter_print(f, buff);
     2548    tmp = owl_filter_print(f);
     2549    owl_fmtext_append_normal(&fm, tmp);
     2550    owl_free(tmp);
    25472551    owl_fmtext_append_normal(&fm, buff);
    25482552  }
  • owl.h

    r731dd1e r0504f63  
    406406  int (*match_message)(struct _owl_filterelement *fe, owl_message *m);
    407407  /* Append a string representation of the filterelement onto buf*/
    408   void (*print_elt)(struct _owl_filterelement *fe, char * buf);
     408  void (*print_elt)(struct _owl_filterelement *fe, GString *buf);
    409409  /* Operands for and,or,not*/
    410410  struct _owl_filterelement *left, *right;
Note: See TracChangeset for help on using the changeset viewer.