summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-10-20 20:31:24 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-10-20 20:31:24 +0000
commitae19d7dd48477ea14dcadb94f07374a5fb2b5fda (patch)
treeb9fa90250fc351d7cbcd1d29e9ab6f85746f7e50 /lib/command.c
parente8d5696d45a0f713b080f8b06f462febb5d38057 (diff)
lib: Add helper function for working with argv, update bgpd to use it
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c20
1 files changed, 20 insertions, 0 deletions
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,