mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-02-20 00:10:09 -05:00
Introduce np_find_regmatch()
This commit is contained in:
parent
d31a696cad
commit
1f694195b4
2 changed files with 26 additions and 0 deletions
|
|
@ -29,6 +29,7 @@
|
|||
#include "common.h"
|
||||
#include "utils_disk.h"
|
||||
#include "gl/fsusage.h"
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
np_add_name (struct name_list **list, const char *name)
|
||||
|
|
@ -207,6 +208,30 @@ np_find_name (struct name_list *list, const char *name)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/* Returns TRUE if name is in list */
|
||||
bool
|
||||
np_find_regmatch (struct regex_list *list, const char *name)
|
||||
{
|
||||
int len;
|
||||
regmatch_t m;
|
||||
|
||||
if (name == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
len = strlen(name);
|
||||
|
||||
for (; list; list = list->next) {
|
||||
/* Emulate a full match as if surrounded with ^( )$
|
||||
by checking whether the match spans the whole name */
|
||||
if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
np_seen_name(struct name_list *list, const char *name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ void np_add_name (struct name_list **list, const char *name);
|
|||
int np_find_name (struct name_list *list, const char *name);
|
||||
int np_seen_name (struct name_list *list, const char *name);
|
||||
int np_add_regex (struct regex_list **list, const char *regex, int cflags);
|
||||
bool np_find_regmatch (struct regex_list *list, const char *name);
|
||||
struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
|
||||
struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
|
||||
struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev);
|
||||
|
|
|
|||
Loading…
Reference in a new issue