From: Florian Forster Date: Fri, 25 Jun 2010 09:30:32 +0000 (+0200) Subject: src/graph.[ch]: Implement "graph_inst_find_all_matching". X-Git-Tag: v4.0.0~185 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1b6d2fdc7299279432f4b8cab32f3edf46177aab;p=collection4.git src/graph.[ch]: Implement "graph_inst_find_all_matching". --- diff --git a/src/graph.c b/src/graph.c index 4ed2d15..0802bee 100644 --- a/src/graph.c +++ b/src/graph.c @@ -342,6 +342,30 @@ graph_instance_t *graph_inst_find_matching (graph_config_t *cfg, /* {{{ */ return (NULL); } /* }}} graph_instance_t *graph_inst_find_matching */ +int graph_inst_find_all_matching (graph_config_t *cfg, /* {{{ */ + const graph_ident_t *ident, + graph_inst_callback_t callback, void *user_data) +{ + size_t i; + + if ((cfg == NULL) || (ident == NULL) || (callback == NULL)) + return (EINVAL); + + for (i = 0; i < cfg->instances_num; i++) + { + int status; + + if (!inst_matches_ident (cfg->instances[i], ident)) + continue; + + status = (*callback) (cfg, cfg->instances[i], user_data); + if (status != 0) + return (status); + } + + return (0); +} /* }}} int graph_inst_find_all_matching */ + int graph_inst_search (graph_config_t *cfg, const char *term, /* {{{ */ graph_inst_callback_t cb, void *user_data) diff --git a/src/graph.h b/src/graph.h index d303a85..0cb45d7 100644 --- a/src/graph.h +++ b/src/graph.h @@ -46,6 +46,10 @@ graph_instance_t *graph_inst_find_exact (graph_config_t *cfg, graph_instance_t *graph_inst_find_matching (graph_config_t *cfg, const graph_ident_t *ident); +int graph_inst_find_all_matching (graph_config_t *cfg, + const graph_ident_t *ident, + graph_inst_callback_t callback, void *user_data); + int graph_inst_search (graph_config_t *cfg, const char *term, graph_inst_callback_t callback, void *user_data);