From: Florian Forster Date: Sat, 26 Jun 2010 10:31:23 +0000 (+0200) Subject: src/graph_instance.[ch]: Implement "inst_ident_matches" in addition to "inst_matches_... X-Git-Tag: v4.0.0~183 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=95cad1f9e58e9f1a5480e62fc2cdd2c3de33a863;p=collection4.git src/graph_instance.[ch]: Implement "inst_ident_matches" in addition to "inst_matches_ident". --- diff --git a/src/graph.c b/src/graph.c index 0802bee..01f0791 100644 --- a/src/graph.c +++ b/src/graph.c @@ -336,7 +336,7 @@ graph_instance_t *graph_inst_find_matching (graph_config_t *cfg, /* {{{ */ return (NULL); for (i = 0; i < cfg->instances_num; i++) - if (inst_matches_ident (cfg->instances[i], ident)) + if (inst_ident_matches (cfg->instances[i], ident)) return (cfg->instances[i]); return (NULL); diff --git a/src/graph_ident.c b/src/graph_ident.c index cb9a361..36e066d 100644 --- a/src/graph_ident.c +++ b/src/graph_ident.c @@ -377,12 +377,8 @@ int ident_compare (const graph_ident_t *i0, /* {{{ */ _Bool ident_matches (const graph_ident_t *selector, /* {{{ */ const graph_ident_t *ident) { - if ((selector == NULL) && (ident == NULL)) + if ((selector == NULL) || (ident == NULL)) return (0); - else if (selector == NULL) - return (-1); - else if (ident == NULL) - return (1); if (!part_matches (selector->host, ident->host)) return (0); diff --git a/src/graph_instance.c b/src/graph_instance.c index 2d12873..5431589 100644 --- a/src/graph_instance.c +++ b/src/graph_instance.c @@ -419,13 +419,22 @@ int inst_compare_ident (graph_instance_t *inst, /* {{{ */ return (ident_compare (inst->select, ident)); } /* }}} int inst_compare_ident */ -_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */ +_Bool inst_ident_matches (graph_instance_t *inst, /* {{{ */ const graph_ident_t *ident) { if ((inst == NULL) || (ident == NULL)) return (0); return (ident_matches (inst->select, ident)); +} /* }}} _Bool inst_ident_matches */ + +_Bool inst_matches_ident (graph_instance_t *inst, /* {{{ */ + const graph_ident_t *ident) +{ + if ((inst == NULL) || (ident == NULL)) + return (0); + + return (ident_matches (ident, inst->select)); } /* }}} _Bool inst_matches_ident */ _Bool inst_matches_string (graph_config_t *cfg, /* {{{ */ diff --git a/src/graph_instance.h b/src/graph_instance.h index a6e7462..fa08dcd 100644 --- a/src/graph_instance.h +++ b/src/graph_instance.h @@ -32,7 +32,13 @@ graph_ident_t *inst_get_selector (graph_instance_t *inst); int inst_compare_ident (graph_instance_t *inst, const graph_ident_t *ident); -_Bool inst_matches_ident (graph_instance_t *inst, const graph_ident_t *ident); +/* Returns true if "ident" matches the instance's selector. */ +_Bool inst_ident_matches (graph_instance_t *inst, const graph_ident_t *ident); + +/* Returns true if the instance's selector matches the (more general) + * "selector" ident. */ +_Bool inst_matches_ident (graph_instance_t *inst, + const graph_ident_t *selector); _Bool inst_matches_string (graph_config_t *cfg, graph_instance_t *inst, const char *term);