X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Fmatcher_parser_parse.y;h=41d1503f561f80abe4f3f2493fb901405e9f169b;hp=5031a8ca3d1f8375c11b91d752b330df1cbeeca0;hb=c70a9c4ee5ca60e547d6fb68c6eca59d281c9869;hpb=14e2ae896f8a6aae248ab5a06187ca47ad1c2d25 diff --git a/src/matcher_parser_parse.y b/src/matcher_parser_parse.y index 5031a8ca3..41d1503f5 100644 --- a/src/matcher_parser_parse.y +++ b/src/matcher_parser_parse.y @@ -1,11 +1,15 @@ %{ +#include "defs.h" + +#include + +#include "intl.h" +#include "utils.h" #include "filtering.h" #include "scoring.h" #include "matcher.h" #include "matcher_parser.h" #include "matcher_parser_lex.h" -#include "intl.h" -#include static gint error = 0; static gint bool_op = 0; @@ -28,41 +32,61 @@ static GSList ** prefs_filtering = NULL; static int matcher_parser_dialog = 0; -/* -void matcher_parser_init() + +/* ******************************************************************** */ + + + +void matcher_parser_start_parsing(FILE * f) { - prefs_filtering_clear(); - prefs_scoring_clear(); + matcher_parserrestart(f); + matcher_parserparse(); } -*/ - + FilteringProp * matcher_parser_get_filtering(gchar * str) { + void * bufstate; + + /* bad coding to enable the sub-grammar matching + in yacc */ matcher_parserlineno = 1; matcher_parser_dialog = 1; - matcher_parser_scan_string(str); - matcher_parserparse(); + bufstate = matcher_parser_scan_string(str); + if (matcher_parserparse() != 0) + filtering = NULL; matcher_parser_dialog = 0; + matcher_parser_delete_buffer(bufstate); return filtering; } ScoringProp * matcher_parser_get_scoring(gchar * str) { + void * bufstate; + + /* bad coding to enable the sub-grammar matching + in yacc */ matcher_parserlineno = 1; matcher_parser_dialog = 1; - matcher_parser_scan_string(str); - matcher_parserparse(); + bufstate = matcher_parser_scan_string(str); + if (matcher_parserparse() != 0) + scoring = NULL; matcher_parser_dialog = 0; + matcher_parser_delete_buffer(bufstate); return scoring; } MatcherList * matcher_parser_get_cond(gchar * str) { + void * bufstate; + + /* bad coding to enable the sub-grammar matching + in yacc */ matcher_parserlineno = 1; matcher_parser_dialog = 1; - matcher_parser_scan_string(str); + bufstate = matcher_parser_scan_string(str); matcher_parserparse(); matcher_parser_dialog = 0; + matcher_parser_delete_buffer(bufstate); return cond; } @@ -71,8 +95,6 @@ MatcherProp * matcher_parser_get_prop(gchar * str) MatcherList * list; MatcherProp * prop; - printf("get matcher\n"); - matcher_parserlineno = 1; list = matcher_parser_get_cond(str); if (list == NULL) @@ -89,7 +111,7 @@ MatcherProp * matcher_parser_get_prop(gchar * str) g_slist_free(list->matchers); g_free(list); - printf("prop: %p\n", prop); + return prop; } void matcher_parsererror(char * str) @@ -140,6 +162,7 @@ int matcher_parserwrap(void) %token MATCHER_MARK_AS_READ MATCHER_MARK_AS_UNREAD MATCHER_FORWARD %token MATCHER_FORWARD_AS_ATTACHMENT MATCHER_EOL MATCHER_STRING %token MATCHER_OR MATCHER_AND +%token MATCHER_COLOR MATCHER_SCORE_EQUAL MATCHER_BOUNCE MATCHER_DELETE_ON_SERVER %start file @@ -153,7 +176,7 @@ file: { if (!matcher_parser_dialog) { prefs_scoring = &global_scoring; - prefs_filtering = &global_filtering; + prefs_filtering = &global_processing; } } file_line_list; @@ -167,7 +190,10 @@ file_line_list file_line: section_notification | instruction -; +| error MATCHER_EOL +{ + yyerrok; +}; section_notification: MATCHER_SECTION MATCHER_EOL @@ -179,7 +205,7 @@ MATCHER_SECTION MATCHER_EOL item = folder_find_item_from_identifier(folder); if (item == NULL) { prefs_scoring = &global_scoring; - prefs_filtering = &global_scoring; + prefs_filtering = &global_processing; } else { prefs_scoring = &item->prefs->scoring; @@ -190,15 +216,34 @@ MATCHER_SECTION MATCHER_EOL ; instruction: -condition filtering_or_scoring MATCHER_EOL -| condition +condition end_instr_opt +| MATCHER_EOL +; + +end_instr_opt: +filtering_or_scoring end_action +| { - if (!matcher_parser_dialog) { - yyerror("parse error"); - return 1; + if (matcher_parser_dialog) + YYACCEPT; + else { + matcher_parsererror("parse error"); + YYERROR; + } +} +; + +end_action: +MATCHER_EOL +| +{ + if (matcher_parser_dialog) + YYACCEPT; + else { + matcher_parsererror("parse error"); + YYERROR; } } -| MATCHER_EOL ; filtering_or_scoring: @@ -547,6 +592,15 @@ MATCHER_ALL value = atoi($2); prop = matcherprop_new(criteria, NULL, 0, NULL, value); } +| MATCHER_SCORE_EQUAL MATCHER_INTEGER +{ + gint criteria = 0; + gint value = 0; + + criteria = MATCHCRITERIA_SCORE_EQUAL; + value = atoi($2); + prop = matcherprop_new(criteria, NULL, 0, NULL, value); +} | MATCHER_HEADER MATCHER_STRING { header = g_strdup($2); @@ -627,15 +681,6 @@ MATCHER_ALL expr = $3; prop = matcherprop_new(criteria, NULL, match_type, expr, 0); } -| MATCHER_NOT_MESSAGE match_type MATCHER_STRING -{ - gint criteria = 0; - gchar * expr = NULL; - - criteria = MATCHCRITERIA_NOT_MESSAGE; - expr = $3; - prop = matcherprop_new(criteria, NULL, match_type, expr, 0); -} | MATCHER_EXECUTE MATCHER_STRING { gint criteria = 0; @@ -664,7 +709,7 @@ MATCHER_EXECUTE MATCHER_STRING action_type = MATCHACTION_EXECUTE; cmd = $2; - action = filteringaction_new(action_type, 0, cmd); + action = filteringaction_new(action_type, 0, cmd, 0); } | MATCHER_MOVE MATCHER_STRING { @@ -673,7 +718,7 @@ MATCHER_EXECUTE MATCHER_STRING action_type = MATCHACTION_MOVE; destination = $2; - action = filteringaction_new(action_type, 0, destination); + action = filteringaction_new(action_type, 0, destination, 0); } | MATCHER_COPY MATCHER_STRING { @@ -682,42 +727,42 @@ MATCHER_EXECUTE MATCHER_STRING action_type = MATCHACTION_COPY; destination = $2; - action = filteringaction_new(action_type, 0, destination); + action = filteringaction_new(action_type, 0, destination, 0); } | MATCHER_DELETE { gint action_type = 0; action_type = MATCHACTION_DELETE; - action = filteringaction_new(action_type, 0, NULL); + action = filteringaction_new(action_type, 0, NULL, 0); } | MATCHER_MARK { gint action_type = 0; action_type = MATCHACTION_MARK; - action = filteringaction_new(action_type, 0, NULL); + action = filteringaction_new(action_type, 0, NULL, 0); } | MATCHER_UNMARK { gint action_type = 0; action_type = MATCHACTION_UNMARK; - action = filteringaction_new(action_type, 0, NULL); + action = filteringaction_new(action_type, 0, NULL, 0); } | MATCHER_MARK_AS_READ { gint action_type = 0; action_type = MATCHACTION_MARK_AS_READ; - action = filteringaction_new(action_type, 0, NULL); + action = filteringaction_new(action_type, 0, NULL, 0); } | MATCHER_MARK_AS_UNREAD { gint action_type = 0; action_type = MATCHACTION_MARK_AS_UNREAD; - action = filteringaction_new(action_type, 0, NULL); + action = filteringaction_new(action_type, 0, NULL, 0); } | MATCHER_FORWARD MATCHER_INTEGER MATCHER_STRING { @@ -726,9 +771,9 @@ MATCHER_EXECUTE MATCHER_STRING gint account_id = 0; action_type = MATCHACTION_FORWARD; - account_id = $2; + account_id = atoi($2); destination = $3; - action = filteringaction_new(action_type, account_id, destination); + action = filteringaction_new(action_type, account_id, destination, 0); } | MATCHER_FORWARD_AS_ATTACHMENT MATCHER_INTEGER MATCHER_STRING { @@ -737,9 +782,35 @@ MATCHER_EXECUTE MATCHER_STRING gint account_id = 0; action_type = MATCHACTION_FORWARD_AS_ATTACHMENT; - account_id = $2; + account_id = atoi($2); + destination = $3; + action = filteringaction_new(action_type, account_id, destination, 0); +} +| MATCHER_BOUNCE MATCHER_INTEGER MATCHER_STRING +{ + gchar * destination = NULL; + gint action_type = 0; + gint account_id = 0; + + action_type = MATCHACTION_BOUNCE; + account_id = atoi($2); destination = $3; - action = filteringaction_new(action_type, account_id, destination); + action = filteringaction_new(action_type, account_id, destination, 0); +} +| MATCHER_COLOR MATCHER_INTEGER +{ + gint action_type = 0; + gint color = 0; + + action_type = MATCHACTION_COLOR; + color = atoi($2); + action = filteringaction_new(action_type, 0, NULL, color); +} +| MATCHER_DELETE_ON_SERVER +{ + gint action_type = 0; + action_type = MATCHACTION_DELETE_ON_SERVER; + action = filteringaction_new(action_type, 0, NULL, 0); } ;