diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command.c | 20 | ||||
| -rw-r--r-- | lib/command.h | 1 |
2 files changed, 21 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, diff --git a/lib/command.h b/lib/command.h index aad0c6b3e6..0e2d27f19c 100644 --- a/lib/command.h +++ b/lib/command.h @@ -408,6 +408,7 @@ extern void install_element (enum node_type, struct cmd_element *); string with a space between each element (allocated using XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */ extern char *argv_concat (struct cmd_token **argv, int argc, int shift); +extern int argv_find (struct cmd_token **argv, int argc, const char *text, int *index); extern vector cmd_make_strvec (const char *); extern void cmd_free_strvec (vector); |
