From ae19d7dd48477ea14dcadb94f07374a5fb2b5fda Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 20 Oct 2016 20:31:24 +0000 Subject: lib: Add helper function for working with argv, update bgpd to use it Signed-off-by: Quentin Young --- lib/command.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 914641724f..3416bcd1c7 100644 --- a/lib/command.c +++ b/lib/command.c @@ -193,6 +193,26 @@ argv_concat (struct cmd_token **argv, int argc, int shift) return str; } +/** + * Convenience function for accessing argv data. + * + * @param argc + * @param argv + * @param text definition snippet of the desired token + * @param index the starting index, and where to store the + * index of the found token if it exists + * @return 1 if found, 0 otherwise + */ +int +argv_find (struct cmd_token **argv, int argc, const char *text, int *index) +{ + int found = 0; + for (int i = *index; i < argc && found == 0; i++) + if ((found = strmatch (text, argv[i]->text))) + *index = i; + return found; +} + /* Install top node of command vector. */ void install_node (struct cmd_node *node, -- cgit v1.2.3