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 <netinet/in.h>
15 #include <cmdline_parse.h>
16 #include <cmdline_parse_ipaddr.h>
18 #include <rte_string_fns.h>
20 #include "parse_obj_list.h"
22 /* This file is an example of extension of libcmdline. It provides an
23 * example of objects stored in a list. */
25 struct cmdline_token_ops token_obj_list_ops
= {
26 .parse
= parse_obj_list
,
27 .complete_get_nb
= complete_get_nb_obj_list
,
28 .complete_get_elt
= complete_get_elt_obj_list
,
29 .get_help
= get_help_obj_list
,
33 parse_obj_list(cmdline_parse_token_hdr_t
*tk
, const char *buf
, void *res
,
36 struct token_obj_list
*tk2
= (struct token_obj_list
*)tk
;
37 struct token_obj_list_data
*tkd
= &tk2
->obj_list_data
;
39 unsigned int token_len
= 0;
44 if (res
&& ressize
< sizeof(struct object
*))
47 while(!cmdline_isendoftoken(buf
[token_len
]))
50 SLIST_FOREACH(o
, tkd
->list
, next
) {
51 if (token_len
!= strnlen(o
->name
, OBJ_NAME_LEN_MAX
))
53 if (strncmp(buf
, o
->name
, token_len
))
57 if (!o
) /* not found */
60 /* store the address of object in structure */
62 *(struct object
**)res
= o
;
67 int complete_get_nb_obj_list(cmdline_parse_token_hdr_t
*tk
)
69 struct token_obj_list
*tk2
= (struct token_obj_list
*)tk
;
70 struct token_obj_list_data
*tkd
= &tk2
->obj_list_data
;
74 SLIST_FOREACH(o
, tkd
->list
, next
) {
80 int complete_get_elt_obj_list(cmdline_parse_token_hdr_t
*tk
,
81 int idx
, char *dstbuf
, unsigned int size
)
83 struct token_obj_list
*tk2
= (struct token_obj_list
*)tk
;
84 struct token_obj_list_data
*tkd
= &tk2
->obj_list_data
;
89 SLIST_FOREACH(o
, tkd
->list
, next
) {
96 len
= strnlen(o
->name
, OBJ_NAME_LEN_MAX
);
101 snprintf(dstbuf
, size
, "%s", o
->name
);
107 int get_help_obj_list(__attribute__((unused
)) cmdline_parse_token_hdr_t
*tk
,
108 char *dstbuf
, unsigned int size
)
110 snprintf(dstbuf
, size
, "Obj-List");