Changeset 0504f63 for filterelement.c


Ignore:
Timestamp:
Aug 10, 2008, 5:38:44 PM (16 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.10, 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.