From 483f21fec53fb4b525593f209d2454f41f78906b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 28 Jul 2010 17:15:57 +0200 Subject: [PATCH] src/utils_search.[ch]: Implement "search_from_ident". --- src/utils_search.c | 33 +++++++++++++++++++++++++++++++++ src/utils_search.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/utils_search.c b/src/utils_search.c index aa157e6..1a1be7d 100644 --- a/src/utils_search.c +++ b/src/utils_search.c @@ -28,6 +28,7 @@ #include #include "utils_search.h" +#include "graph_ident.h" #include "graph_instance.h" #include "utils_array.h" @@ -259,6 +260,38 @@ graph_ident_t *search_to_ident (search_info_t *si) /* {{{ */ (si->type_instance == NULL) ? ANY_TOKEN : si->type_instance)); } /* }}} graph_ident_t *search_to_ident */ +search_info_t *search_from_ident (const graph_ident_t *ident) /* {{{ */ +{ + search_info_t *si; + + if (ident == NULL) + return (NULL); + + si = malloc (sizeof (*si)); + if (si == NULL) + return (NULL); + memset (si, 0, sizeof (*si)); + si->terms = NULL; + +#define COPY_FIELD(f) do { \ + const char *tmp = ident_get_##f (ident); \ + if (tmp == NULL) \ + si->f = NULL; \ + else \ + si->f = strdup (tmp); \ +} while (0) + + COPY_FIELD(host); + COPY_FIELD(plugin); + COPY_FIELD(plugin_instance); + COPY_FIELD(type); + COPY_FIELD(type_instance); + +#undef COPY_FIELD + + return (si); +} /* }}} search_info_t *search_from_ident */ + _Bool search_graph_title_matches (search_info_t *si, /* {{{ */ const char *title) { diff --git a/src/utils_search.h b/src/utils_search.h index 746edcc..62ab6ce 100644 --- a/src/utils_search.h +++ b/src/utils_search.h @@ -38,6 +38,7 @@ void search_destroy (search_info_t *si); _Bool search_has_selector (search_info_t *si); graph_ident_t *search_to_ident (search_info_t *si); +search_info_t *search_from_ident (const graph_ident_t *ident); _Bool search_graph_title_matches (search_info_t *si, const char *title); -- 2.30.2