First attempt at a search infrastructure.
[collection4.git] / graph_instance.c
index d9821d0..e1e0a36 100644 (file)
@@ -3,6 +3,7 @@
 #include <errno.h>
 
 #include "graph_instance.h"
+#include "graph_def.h"
 #include "graph_ident.h"
 #include "graph_list.h"
 #include "common.h"
@@ -288,20 +289,9 @@ int inst_get_rrdargs (graph_config_t *cfg, /* {{{ */
   if ((cfg == NULL) || (inst == NULL) || (args == NULL))
     return (EINVAL);
 
-/* FIXME: Re-enable title and vertical label stuff. */
-#if 0
-  if (cfg->title != NULL)
-  {
-    array_append (args, "-t");
-    array_append (args, cfg->title);
-  }
-
-  if (cfg->vertical_label != NULL)
-  {
-    array_append (args, "-v");
-    array_append (args, cfg->vertical_label);
-  }
-#endif
+  status = graph_get_rrdargs (cfg, inst, args);
+  if (status != 0)
+    return (status);
 
   defs = graph_get_defs (cfg);
   if (defs == NULL)
@@ -425,6 +415,38 @@ int inst_foreach (graph_instance_t *inst, /* {{{ */
   return (0);
 } /* }}} int inst_foreach */
 
+int inst_search (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */
+    const char *term, inst_callback_t cb, void *user_data)
+{
+  graph_instance_t *ptr;
+  char buffer[1024];
+  int status;
+
+  if ((inst == NULL) || (cb == NULL))
+    return (EINVAL);
+
+  for (ptr = inst; ptr != NULL; ptr = ptr->next)
+  {
+    status = inst_describe (cfg, ptr, buffer, sizeof (buffer));
+    if (status != 0)
+    {
+      fprintf (stderr, "inst_search: inst_describe failed\n");
+      return (status);
+    }
+
+    /* no match */
+    if (strstr (buffer, term) == NULL)
+      continue;
+
+    /* match */
+    status = (*cb) (ptr, user_data);
+    if (status != 0)
+      return (status);
+  }
+
+  return (0);
+} /* }}} int inst_search */
+
 graph_instance_t *inst_find_matching (graph_instance_t *inst, /* {{{ */
     const graph_ident_t *ident)
 {