#include "defs.h"
#include <glib.h>
+#include <glib/gi18n.h>
-#include "intl.h"
#include "utils.h"
#include "filtering.h"
#include "matcher.h"
static GSList *matchers_list = NULL;
+static gchar *name = NULL;
static MatcherList *cond;
-static gint score = 0;
static GSList *action_list = NULL;
static FilteringAction *action = NULL;
enum {
MATCHER_PARSE_FILE,
MATCHER_PARSE_NO_EOL,
+ MATCHER_PARSE_NAME,
MATCHER_PARSE_CONDITION,
MATCHER_PARSE_FILTERING_ACTION,
};
void * matcher_parser_scan_string(const char * str);
-FilteringProp *matcher_parser_get_filtering(const gchar *str)
+FilteringProp *matcher_parser_get_filtering(gchar *str)
{
void *bufstate;
+ void *tmp_str = NULL;
+
+ /* little hack to allow passing rules with no names */
+ if (!strncmp(str, "rulename ", 9))
+ tmp_str = g_strdup(str);
+ else
+ tmp_str = g_strconcat("rulename \"\" ", str, NULL);
/* bad coding to enable the sub-grammar matching
in yacc */
matcher_parse_op = MATCHER_PARSE_NO_EOL;
matcher_parserrestart(NULL);
matcher_parser_init();
- bufstate = matcher_parser_scan_string((const char *) str);
+ bufstate = matcher_parser_scan_string((const char *) tmp_str);
matcher_parser_switch_to_buffer(bufstate);
if (matcher_parserparse() != 0)
filtering = NULL;
matcher_parse_op = MATCHER_PARSE_FILE;
matcher_parser_delete_buffer(bufstate);
+ g_free(tmp_str);
return filtering;
}
return !(ret % 2);
}
-MatcherList *matcher_parser_get_cond(const gchar *str)
+MatcherList *matcher_parser_get_name(gchar *str)
+{
+ void *bufstate;
+
+ if (!check_quote_symetry(str)) {
+ cond = NULL;
+ return cond;
+ }
+
+ /* bad coding to enable the sub-grammar matching
+ in yacc */
+ matcher_parserlineno = 1;
+ matcher_parse_op = MATCHER_PARSE_NAME;
+ matcher_parserrestart(NULL);
+ matcher_parser_init();
+ bufstate = matcher_parser_scan_string(str);
+ matcher_parserparse();
+ matcher_parse_op = MATCHER_PARSE_FILE;
+ matcher_parser_delete_buffer(bufstate);
+ return cond;
+}
+
+MatcherList *matcher_parser_get_cond(gchar *str)
{
void *bufstate;
return cond;
}
-GSList *matcher_parser_get_action_list(const gchar *str)
+GSList *matcher_parser_get_action_list(gchar *str)
{
void *bufstate;
return action_list;
}
-MatcherProp *matcher_parser_get_prop(const gchar *str)
+MatcherProp *matcher_parser_get_prop(gchar *str)
{
MatcherList *list;
MatcherProp *prop;
char *str;
int value;
}
-
%token MATCHER_ALL MATCHER_UNREAD MATCHER_NOT_UNREAD
%token MATCHER_NEW MATCHER_NOT_NEW MATCHER_MARKED
%token MATCHER_NOT_MARKED MATCHER_DELETED MATCHER_NOT_DELETED
%start file
+%token MATCHER_RULENAME
%token <str> MATCHER_STRING
%token <str> MATCHER_SECTION
%token <str> MATCHER_INTEGER
;
instruction:
-condition filtering MATCHER_EOL
-| condition filtering
+name condition filtering MATCHER_EOL
+| name condition filtering
{
if (matcher_parse_op == MATCHER_PARSE_NO_EOL)
YYACCEPT;
else {
- matcher_parsererror("parse error");
+ matcher_parsererror("parse error a");
+ YYERROR;
+ }
+}
+| name
+{
+ if (matcher_parse_op == MATCHER_PARSE_NAME)
+ YYACCEPT;
+ else {
+ matcher_parsererror("parse error b");
YYERROR;
}
}
if (matcher_parse_op == MATCHER_PARSE_CONDITION)
YYACCEPT;
else {
- matcher_parsererror("parse error");
+ matcher_parsererror("parse error c");
YYERROR;
}
}
if (matcher_parse_op == MATCHER_PARSE_FILTERING_ACTION)
YYACCEPT;
else {
- matcher_parsererror("parse error");
+ matcher_parsererror("parse error d");
YYERROR;
}
}
| MATCHER_EOL
;
+name:
+MATCHER_RULENAME MATCHER_STRING
+{
+ name = g_strdup($2);
+}
+;
+
filtering:
filtering_action_list
{
- filtering = filteringprop_new(cond, action_list);
-
+ filtering = filteringprop_new(name, cond, action_list);
+ g_free(name);
+ name = NULL;
if (enable_compatibility) {
prefs_filtering = &filtering_rules;
if (action_list != NULL) {
gint criteria = 0;
criteria = MATCHCRITERIA_PARTIAL;
- prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, "SC-Partially-Retrieved", 0);
+ prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
}
| MATCHER_NOT_PARTIAL
{
gint criteria = 0;
criteria = MATCHCRITERIA_NOT_PARTIAL;
- prop = matcherprop_new(criteria, NULL, MATCHTYPE_MATCH, "SC-Partially-Retrieved", 0);
+ prop = matcherprop_new(criteria, NULL, 0, NULL, 0);
}
| MATCHER_COLORLABEL MATCHER_INTEGER
{