* src/filtering.c
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 12 Jan 2003 14:07:40 +0000 (14:07 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Sun, 12 Jan 2003 14:07:40 +0000 (14:07 +0000)
* src/matcher_parser_parse.y
prepare change_score filtering action
* src/matcher.[ch]
give up const-correctness on functions that call non-const-correct functions;
several casts to gpointer in g_free();
add change_score;

ChangeLog.claws
configure.in
src/filtering.c
src/matcher.c
src/matcher.h
src/matcher_parser_parse.y

index 6c11697c6c5c9816c9146e314b762253cfe2446e..d03194afe634f4f16603037cbebef1ba8097e7de 100644 (file)
@@ -1,3 +1,13 @@
+2002-01-12 [alfons]    0.8.8claws85
+
+       * src/filtering.c
+       * src/matcher_parser_parse.y
+               prepare change_score filtering action
+       * src/matcher.[ch]
+               give up const-correctness on functions that call non-const-correct functions;
+               several casts to gpointer in g_free();
+               add change_score;
+               
 2003-01-12 [christoph] 0.8.8claws84
 
        * src/compose.c
index 4d668d57d7919c19a8c156b104fa3077d9236b00..278a6a4a65b2302c5a4602e00f7d0a6f5dfbbe3b 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=8
 MICRO_VERSION=8
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws84
+EXTRA_VERSION=claws85
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index b879b9027834dcee975dd240b51630b237ea09ce..7cbb0d4f1a8ced680f8256846b3382914ff3a5f8 100644 (file)
@@ -57,6 +57,11 @@ FilteringAction * filteringaction_new(int type, int account_id,
 
        action = g_new0(FilteringAction, 1);
 
+       /* NOTE:
+        * if type is MATCHACTION_CHANGE_SCORE, account_id = (-1, 0, 1) and
+        * labelcolor = the score value change
+        */
+
        action->type = type;
        action->account_id = account_id;
        if (destination) {
@@ -262,6 +267,17 @@ static gboolean filteringaction_apply(FilteringAction * action, MsgInfo * info)
                }
                return TRUE;
 
+       case MATCHACTION_CHANGE_SCORE:
+               /* NOTE:
+                * action->account_id is 0 if just assignment, -1 if decrement
+                * and 1 if increment by action->labelcolor 
+                * action->labelcolor has the score value change
+                */
+               info->score = action->account_id ==  1 ? info->score + action->labelcolor
+                           : action->account_id == -1 ? info->score - action->labelcolor
+                           : action->labelcolor; 
+               return TRUE;
+
        default:
                break;
        }
index 8066c54bc142ce2ec35235bbe0cca679aad04f98..fb0e84bed7802367fece1bbf5a9cf2783c653644 100644 (file)
@@ -123,7 +123,8 @@ static const MatchParser matchparser_tab[] = {
        {MATCHACTION_EXECUTE, "execute"},
        {MATCHACTION_COLOR, "color"},
        {MATCHACTION_REDIRECT, "redirect"},
-       {MATCHACTION_DELETE_ON_SERVER, "delete_on_server"}
+       {MATCHACTION_DELETE_ON_SERVER, "delete_on_server"},
+       {MATCHACTION_CHANGE_SCORE, "change_score"}
 };
 
 /*!
@@ -161,7 +162,7 @@ static void create_matchparser_hashtab(void)
        for (i = 0; i < sizeof matchparser_tab / sizeof matchparser_tab[0]; i++)
                g_hash_table_insert(matchparser_hashtab,
                                    matchparser_tab[i].str,
-                                   &matchparser_tab[i]);
+                                   (gpointer) &matchparser_tab[i]);
 }
 
 /*!
@@ -370,8 +371,8 @@ MatcherProp *matcherprop_unquote_new(gint criteria, const gchar *header,
         
         prop = matcherprop_new(criteria, header, matchtype, expr, value);
 
-        g_free(header);
-        g_free(expr);
+        g_free((gpointer) header);
+        g_free((gpointer) expr);
 
        return prop;
 }
@@ -388,7 +389,7 @@ MatcherProp *matcherprop_unquote_new(gint criteria, const gchar *header,
  *\return      gboolean TRUE if str matches the condition in the 
  *             matcher structure
  */
-static gboolean matcherprop_string_match(const MatcherProp *prop, const gchar *str)
+static gboolean matcherprop_string_match(MatcherProp *prop, const gchar *str)
 {
        gchar *str1;
        gchar *str2;
@@ -446,7 +447,7 @@ static gboolean matcherprop_string_match(const MatcherProp *prop, const gchar *s
  *\return      gboolean TRUE if command was executed succesfully
  */
 static gboolean matcherprop_match_execute(const MatcherProp *prop, 
-                                         const MsgInfo *info)
+                                         MsgInfo *info)
 {
        gchar *file;
        gchar *cmd;
@@ -477,8 +478,8 @@ static gboolean matcherprop_match_execute(const MatcherProp *prop,
  *
  *\return      gboolean TRUE if a match
  */
-gboolean matcherprop_match(const MatcherProp *prop, 
-                          const MsgInfo *info)
+gboolean matcherprop_match(MatcherProp *prop, 
+                          MsgInfo *info)
 {
        time_t t;
 
@@ -643,8 +644,8 @@ static void matcherlist_skip_headers(FILE *fp)
  *
  *\return      boolean TRUE if matching header
  */
-static gboolean matcherprop_match_one_header(const MatcherProp *matcher,
-                                            const gchar *buf)
+static gboolean matcherprop_match_one_header(MatcherProp *matcher,
+                                            gchar *buf)
 {
        gboolean result;
        Header *header;
@@ -730,7 +731,7 @@ static gboolean matcherprop_criteria_message(MatcherProp *matcher)
  *\return      gboolean TRUE if matching should stop
  */
 static gboolean matcherlist_match_one_header(MatcherList *matchers,
-                                            const gchar *buf)
+                                            gchar *buf)
 {
        GSList *l;
 
@@ -1062,13 +1063,13 @@ gboolean matcherlist_match(MatcherList *matchers, MsgInfo *info)
  *
  *\return      gchar * Newly allocated string
  */
-gchar *matcherprop_to_string(const MatcherProp *matcher)
+gchar *matcherprop_to_string(MatcherProp *matcher)
 {
        gchar *matcher_str = NULL;
        const gchar *criteria_str;
        const gchar *matchtype_str;
        int i;
-        char *expr;
+        const char *expr;
         char *header;
 
        criteria_str = NULL;
@@ -1113,7 +1114,7 @@ gchar *matcherprop_to_string(const MatcherProp *matcher)
        case MATCHCRITERIA_NOT_EXECUTE:
                 expr = matcher_escape_str(matcher->expr);
                matcher_str = g_strdup_printf("%s \"%s\"", criteria_str, expr);
-                g_free(expr);
+                g_free((gpointer) expr);
                 return matcher_str;
        }
 
@@ -1132,7 +1133,6 @@ gchar *matcherprop_to_string(const MatcherProp *matcher)
        case MATCHTYPE_REGEXP:
        case MATCHTYPE_REGEXPCASE:
                 expr = matcher_escape_str(matcher->expr);
-                header = matcher_escape_str(matcher->header);
                if (matcher->header)
                        matcher_str = g_strdup_printf
                                        ("%s \"%s\" %s \"%s\"",
@@ -1142,8 +1142,7 @@ gchar *matcherprop_to_string(const MatcherProp *matcher)
                        matcher_str = g_strdup_printf
                                        ("%s %s \"%s\"", criteria_str,
                                         matchtype_str, expr);
-                g_free(header);
-                g_free(expr);
+                g_free((gpointer) expr);
                break;
        }
 
index aeb6cc3a6002ae14aaf0715052274c0d3d6a88e6..4e7f94c3302535da95ffa91903419373c522a382 100644 (file)
@@ -118,6 +118,7 @@ enum {
        MA_(COLOR),
        MA_(REDIRECT),
        MA_(DELETE_ON_SERVER),
+       MA_(CHANGE_SCORE),
        /* boolean operations */
        MB_(OR),
        MB_(AND)
@@ -142,8 +143,8 @@ MatcherProp *matcherprop_parse              (gchar  **str);
 
 MatcherProp *matcherprop_copy          (const MatcherProp *src);
 
-gboolean matcherprop_match             (const MatcherProp      *prop, 
-                                        const MsgInfo          *info);
+gboolean matcherprop_match             (MatcherProp    *prop, 
+                                        MsgInfo        *info);
 
 MatcherList * matcherlist_new          (GSList         *matchers, 
                                         gboolean       bool_and);
@@ -161,7 +162,7 @@ gchar *matcher_parse_regexp         (gchar          **str);
 gchar *matcher_parse_str               (gchar          **str);
 const gchar *matcher_escape_str                (const gchar    *str);
 gchar *matcher_unescape_str            (gchar          *str);
-gchar *matcherprop_to_string           (const MatcherProp      *matcher);
+gchar *matcherprop_to_string           (MatcherProp    *matcher);
 gchar *matcherlist_to_string           (const MatcherList      *matchers);
 gchar *matching_build_command          (const gchar    *cmd, 
                                         MsgInfo        *info);
index bf99d19449e79f73eb4cf23a82ae1557b60148a1..e9d6a018061ae2d1101b7cf235dac86d57ee7e5f 100644 (file)
@@ -221,6 +221,7 @@ int matcher_parserwrap(void)
 %token MATCHER_LOCKED MATCHER_NOT_LOCKED
 %token MATCHER_COLORLABEL MATCHER_NOT_COLORLABEL
 %token MATCHER_IGNORE_THREAD MATCHER_NOT_IGNORE_THREAD
+%token MATCHER_CHANGE_SCORE
 
 %start file
 
@@ -944,6 +945,27 @@ MATCHER_EXECUTE MATCHER_STRING
        action_type = MATCHACTION_DELETE_ON_SERVER;
        action = filteringaction_new(action_type, 0, NULL, 0);
 }
+| MATCHER_CHANGE_SCORE MATCHER_STRING
+{
+       gint action_type = MATCHACTION_CHANGE_SCORE;
+       char *last_tok = NULL;
+       const gchar *first_tok;
+       long int chscore;
+       int change_type; /* -1 == decrement, 0 == assign, 1 == increment */     
+
+#define is_number(x) ( ((x) == '+') || ((x) == '-') || (isdigit((x))) ) 
+       /* find start */
+       for (first_tok = $2; *first_tok && !is_number(*first_tok); first_tok++)
+               ;            
+#undef is_number               
+       
+       chscore = strtol(first_tok, &last_tok, 10);
+       if (last_tok == first_tok || *last_tok == 0) 
+               chscore = 0;
+       change_type = *first_tok == '+' ? 1 : *first_tok == '-' ? -1 : 0;
+       action = filteringaction_new(MATCHACTION_CHANGE_SCORE, change_type,
+                                    NULL, chscore);
+}
 ;
 
 scoring_rule: