1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
13 #include <cmdline_parse.h>
14 #include <cmdline_parse_ipaddr.h>
16 #include <rte_string_fns.h>
18 #include "parse_obj_list.h"
20 /* This file is an example of extension of libcmdline. It provides an
21 * example of objects stored in a list. */
23 struct cmdline_token_ops token_obj_list_ops = {
24 .parse = parse_obj_list,
25 .complete_get_nb = complete_get_nb_obj_list,
26 .complete_get_elt = complete_get_elt_obj_list,
27 .get_help = get_help_obj_list,
31 parse_obj_list(cmdline_parse_token_hdr_t *tk, const char *buf, void *res,
34 struct token_obj_list *tk2 = (struct token_obj_list *)tk;
35 struct token_obj_list_data *tkd = &tk2->obj_list_data;
37 unsigned int token_len = 0;
42 if (res && ressize < sizeof(struct object *))
45 while(!cmdline_isendoftoken(buf[token_len]))
48 SLIST_FOREACH(o, tkd->list, next) {
49 if (token_len != strnlen(o->name, OBJ_NAME_LEN_MAX))
51 if (strncmp(buf, o->name, token_len))
55 if (!o) /* not found */
58 /* store the address of object in structure */
60 *(struct object **)res = o;
65 int complete_get_nb_obj_list(cmdline_parse_token_hdr_t *tk)
67 struct token_obj_list *tk2 = (struct token_obj_list *)tk;
68 struct token_obj_list_data *tkd = &tk2->obj_list_data;
72 SLIST_FOREACH(o, tkd->list, next) {
78 int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk,
79 int idx, char *dstbuf, unsigned int size)
81 struct token_obj_list *tk2 = (struct token_obj_list *)tk;
82 struct token_obj_list_data *tkd = &tk2->obj_list_data;
87 SLIST_FOREACH(o, tkd->list, next) {
94 len = strnlen(o->name, OBJ_NAME_LEN_MAX);
99 strlcpy(dstbuf, o->name, size);
105 int get_help_obj_list(__rte_unused cmdline_parse_token_hdr_t *tk,
106 char *dstbuf, unsigned int size)
108 snprintf(dstbuf, size, "Obj-List");