X-Git-Url: https://git.octo.it/?p=collection4.git;a=blobdiff_plain;f=src%2Futils_search.c;h=1a1be7d798f28ccab564d0d6c1ec30921e20c3a1;hp=e2a89f30a305896d2aec86620a11e01ac7ab8867;hb=d00ed057f5ca87431c18ecbf9c45364eb85c24f4;hpb=50e4d660056be2bd4fd96b4cc1c980df5064202d diff --git a/src/utils_search.c b/src/utils_search.c index e2a89f3..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" @@ -234,6 +235,19 @@ void search_destroy (search_info_t *si) /* {{{ */ array_destroy (si->terms); } /* }}} void search_destroy */ +_Bool search_has_selector (search_info_t *si) /* {{{ */ +{ + if (si == NULL) + return (0); + + if ((si->host != NULL) + || (si->plugin != NULL) || (si->plugin_instance != NULL) + || (si->type != NULL) || (si->type_instance != NULL)) + return (1); + + return (0); +} /* }}} _Bool search_has_selector */ + graph_ident_t *search_to_ident (search_info_t *si) /* {{{ */ { if (si == NULL) @@ -246,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) {