use GSList for rules

This commit is contained in:
Sascha Kruse 2013-02-16 10:41:06 +01:00
parent 51b2cb9d52
commit 6de8d785ff
2 changed files with 14 additions and 25 deletions

28
dunst.c
View File

@ -58,7 +58,6 @@
int height_limit; int height_limit;
rule_array rules;
/* index of colors fit to urgency level */ /* index of colors fit to urgency level */
static ColorSet *colors[3]; static ColorSet *colors[3];
static const char *color_strings[2][3]; static const char *color_strings[2][3];
@ -87,6 +86,7 @@ int next_notification_id = 1;
GQueue *queue = NULL; /* all new notifications get into here */ GQueue *queue = NULL; /* all new notifications get into here */
GQueue *displayed = NULL; /* currently displayed notifications */ GQueue *displayed = NULL; /* currently displayed notifications */
GQueue *history = NULL; /* history of displayed notifications */ GQueue *history = NULL; /* history of displayed notifications */
GSList *rules = NULL;
/* misc funtions */ /* misc funtions */
void apply_rules(notification * n); void apply_rules(notification * n);
@ -408,8 +408,8 @@ void ungrab_key(keyboard_shortcut * ks)
void apply_rules(notification * n) void apply_rules(notification * n)
{ {
for (int i = 0; i < rules.count; i++) { for (GSList *iter = rules; iter; iter = iter->next) {
rule_t *r = &(rules.rules[i]); rule_t *r = iter->data;
if ((!r->appname || !fnmatch(r->appname, n->appname, 0)) if ((!r->appname || !fnmatch(r->appname, n->appname, 0))
&& (!r->summary || !fnmatch(r->summary, n->summary, 0)) && (!r->summary || !fnmatch(r->summary, n->summary, 0))
&& (!r->body || !fnmatch(r->body, n->body, 0)) && (!r->body || !fnmatch(r->body, n->body, 0))
@ -1807,17 +1807,17 @@ void load_options(char *cmdline_config_path)
/* check for existing rule with same name */ /* check for existing rule with same name */
rule_t *r = NULL; rule_t *r = NULL;
for (int i = 0; i < rules.count; i++) for (GSList *iter = rules; iter; iter = iter->next) {
if (rules.rules[i].name && rule_t *match = iter->data;
strcmp(rules.rules[i].name, cur_section) == 0) if (match->name &&
r = &(rules.rules[i]); strcmp(match->name, cur_section) == 0)
r = match;
}
if (r == NULL) { if (r == NULL) {
rules.count++; r = g_malloc(sizeof(rule_t));
rules.rules = realloc(rules.rules,
rules.count * sizeof(rule_t));
r = &(rules.rules[rules.count-1]);
initrule(r); initrule(r);
rules = g_slist_insert(rules, r, 0);
} }
r->name = g_strdup(cur_section); r->name = g_strdup(cur_section);
@ -1865,9 +1865,9 @@ int main(int argc, char *argv[])
displayed = g_queue_new(); displayed = g_queue_new();
queue = g_queue_new(); queue = g_queue_new();
rules.count = LENGTH(default_rules); for (int i = 0; i < LENGTH(default_rules); i++) {
rules.rules = calloc(rules.count, sizeof(rule_t)); rules = g_slist_insert(rules, &(default_rules[i]), 0);
memcpy(rules.rules, default_rules, sizeof(rule_t) * rules.count); }
cmdline_load(argc, argv); cmdline_load(argc, argv);

11
dunst.h
View File

@ -59,11 +59,6 @@ typedef struct _notification {
struct { int count; char **strs; } *urls; struct { int count; char **strs; } *urls;
} notification; } notification;
typedef struct _notification_buffer {
char txt[BUFSIZ];
notification *n;
} notification_buffer;
typedef struct _rule_t { typedef struct _rule_t {
char *name; char *name;
/* filters */ /* filters */
@ -102,12 +97,6 @@ typedef struct r_line_cache {
r_line *lines; r_line *lines;
} r_line_cache; } r_line_cache;
typedef struct _rule_array {
int count;
rule_t *rules;
} rule_array;
extern int verbosity; extern int verbosity;
/* return id of notification */ /* return id of notification */