X-Git-Url: https://git.octo.it/?p=collection4.git;a=blobdiff_plain;f=src%2Fgraph_instance.c;h=90d175334b74ced9e79a5ff7f98f91e2b24fa9fb;hp=103be23860ba2b913633a9c11a4018989e670b26;hb=2c85f876c1b9d5c161694cfb03cf20773b74c844;hpb=0ab3085f89e64eecd67d3179ea87f0463e918a10 diff --git a/src/graph_instance.c b/src/graph_instance.c index 103be23..90d1753 100644 --- a/src/graph_instance.c +++ b/src/graph_instance.c @@ -1,8 +1,10 @@ #include #include #include +#include #include "graph_instance.h" +#include "graph_def.h" #include "graph_ident.h" #include "graph_list.h" #include "common.h" @@ -414,6 +416,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) { @@ -472,4 +506,25 @@ int inst_describe (graph_config_t *cfg, graph_instance_t *inst, /* {{{ */ return (0); } /* }}} int inst_describe */ +time_t inst_get_mtime (graph_instance_t *inst) /* {{{ */ +{ + size_t i; + time_t mtime; + + if (inst == NULL) + return (0); + + mtime = 0; + for (i = 0; i < inst->files_num; i++) + { + time_t tmp; + + tmp = ident_get_mtime (inst->files[i]); + if (mtime < tmp) + mtime = tmp; + } + + return (mtime); +} /* }}} time_t inst_get_mtime */ + /* vim: set sw=2 sts=2 et fdm=marker : */