From: Florian Forster Date: Mon, 14 Jun 2010 15:09:01 +0000 (+0200) Subject: graph_ident.[ch]: ident_copy_with_selector: More fine-grained control over what wildc... X-Git-Tag: v4.0.0~280 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=379b04abccb88f539f4532c825537831cc6660dc;p=collection4.git graph_ident.[ch]: ident_copy_with_selector: More fine-grained control over what wildcards are replaced. --- diff --git a/graph_ident.c b/graph_ident.c index 9a52003..9252ebe 100644 --- a/graph_ident.c +++ b/graph_ident.c @@ -28,32 +28,29 @@ struct graph_ident_s /* {{{ */ * Private functions */ static char *part_copy_with_selector (const char *selector, /* {{{ */ - const char *part, _Bool keep_all_selector) + const char *part, unsigned int flags) { if ((selector == NULL) || (part == NULL)) return (NULL); - if (IS_ANY (part)) + if ((flags & IDENT_FLAG_REPLACE_ANY) && IS_ANY (part)) return (NULL); - if (!keep_all_selector && IS_ALL (part)) + if ((flags & IDENT_FLAG_REPLACE_ALL) && IS_ALL (part)) return (NULL); - /* ANY in the graph selection => concrete value in the instance. */ - if (IS_ANY (selector)) + /* Replace the ANY and ALL flags if requested and if the selecter actually + * *is* that flag. */ + if ((flags & IDENT_FLAG_REPLACE_ANY) && IS_ANY (selector)) return (strdup (part)); - if (IS_ALL (selector)) - { - if (keep_all_selector) - return (strdup (ALL_TOKEN)); - else - return (strdup (part)); - } + if ((flags & IDENT_FLAG_REPLACE_ALL) && IS_ALL (selector)) + return (strdup (part)); if (strcmp (selector, part) != 0) return (NULL); + /* Otherwise (no replacement), return a copy of the selector. */ return (strdup (selector)); } /* }}} char *part_copy_with_selector */ @@ -129,7 +126,7 @@ graph_ident_t *ident_create (const char *host, /* {{{ */ return (ret); } /* }}} graph_ident_t *ident_create */ -graph_ident_t *ident_clone (const graph_ident_t *ident) +graph_ident_t *ident_clone (const graph_ident_t *ident) /* {{{ */ { return (ident_create (ident->host, ident->plugin, ident->plugin_instance, @@ -137,7 +134,7 @@ graph_ident_t *ident_clone (const graph_ident_t *ident) } /* }}} graph_ident_t *ident_clone */ graph_ident_t *ident_copy_with_selector (const graph_ident_t *selector, /* {{{ */ - const graph_ident_t *ident, _Bool keep_all_selector) + const graph_ident_t *ident, unsigned int flags) { graph_ident_t *ret; @@ -155,8 +152,7 @@ graph_ident_t *ident_copy_with_selector (const graph_ident_t *selector, /* {{{ * ret->type_instance = NULL; #define COPY_PART(p) do { \ - ret->p = part_copy_with_selector (selector->p, ident->p, \ - keep_all_selector); \ + ret->p = part_copy_with_selector (selector->p, ident->p, flags); \ if (ret->p == NULL) \ { \ free (ret->host); \ diff --git a/graph_ident.h b/graph_ident.h index 09f3f07..abc451d 100644 --- a/graph_ident.h +++ b/graph_ident.h @@ -9,8 +9,10 @@ graph_ident_t *ident_create (const char *host, const char *type, const char *type_instance); graph_ident_t *ident_clone (const graph_ident_t *ident); +#define IDENT_FLAG_REPLACE_ALL 0x01 +#define IDENT_FLAG_REPLACE_ANY 0x02 graph_ident_t *ident_copy_with_selector (const graph_ident_t *selector, - const graph_ident_t *ident, _Bool keep_all_selector); + const graph_ident_t *ident, unsigned int flags); void ident_destroy (graph_ident_t *ident); diff --git a/graph_list.c b/graph_list.c index 0a93477..8c5e715 100644 --- a/graph_list.c +++ b/graph_list.c @@ -217,7 +217,7 @@ static graph_instance_t *instance_create (graph_config_t *cfg, /* {{{ */ memset (i, 0, sizeof (*i)); i->select = ident_copy_with_selector (cfg->select, file, - /* keep_all_selector = */ 1); + IDENT_FLAG_REPLACE_ANY); i->files = NULL; i->files_num = 0;