xref: /dpdk/examples/cmdline/parse_obj_list.h (revision aaa662e75c23c61a1d79bd4d1f9f35b4967c39db)
1af75078fSIntel /*-
2af75078fSIntel  *   BSD LICENSE
3af75078fSIntel  *
4e9d48c00SBruce Richardson  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5af75078fSIntel  *   All rights reserved.
6af75078fSIntel  *
7af75078fSIntel  *   Redistribution and use in source and binary forms, with or without
8af75078fSIntel  *   modification, are permitted provided that the following conditions
9af75078fSIntel  *   are met:
10af75078fSIntel  *
11af75078fSIntel  *     * Redistributions of source code must retain the above copyright
12af75078fSIntel  *       notice, this list of conditions and the following disclaimer.
13af75078fSIntel  *     * Redistributions in binary form must reproduce the above copyright
14af75078fSIntel  *       notice, this list of conditions and the following disclaimer in
15af75078fSIntel  *       the documentation and/or other materials provided with the
16af75078fSIntel  *       distribution.
17af75078fSIntel  *     * Neither the name of Intel Corporation nor the names of its
18af75078fSIntel  *       contributors may be used to endorse or promote products derived
19af75078fSIntel  *       from this software without specific prior written permission.
20af75078fSIntel  *
21af75078fSIntel  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22af75078fSIntel  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23af75078fSIntel  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24af75078fSIntel  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25af75078fSIntel  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26af75078fSIntel  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27af75078fSIntel  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28af75078fSIntel  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29af75078fSIntel  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30af75078fSIntel  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31af75078fSIntel  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32af75078fSIntel  */
33af75078fSIntel 
34af75078fSIntel /*
35af75078fSIntel  * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
36af75078fSIntel  * All rights reserved.
37af75078fSIntel  * Redistribution and use in source and binary forms, with or without
38af75078fSIntel  * modification, are permitted provided that the following conditions are met:
39af75078fSIntel  *
40af75078fSIntel  *     * Redistributions of source code must retain the above copyright
41af75078fSIntel  *       notice, this list of conditions and the following disclaimer.
42af75078fSIntel  *     * Redistributions in binary form must reproduce the above copyright
43af75078fSIntel  *       notice, this list of conditions and the following disclaimer in the
44af75078fSIntel  *       documentation and/or other materials provided with the distribution.
45af75078fSIntel  *     * Neither the name of the University of California, Berkeley nor the
46af75078fSIntel  *       names of its contributors may be used to endorse or promote products
47af75078fSIntel  *       derived from this software without specific prior written permission.
48af75078fSIntel  *
49af75078fSIntel  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
50af75078fSIntel  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
51af75078fSIntel  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
52af75078fSIntel  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
53af75078fSIntel  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
54af75078fSIntel  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55af75078fSIntel  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
56af75078fSIntel  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57af75078fSIntel  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
58af75078fSIntel  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59af75078fSIntel  */
60af75078fSIntel 
61af75078fSIntel #ifndef _PARSE_OBJ_LIST_H_
62af75078fSIntel #define _PARSE_OBJ_LIST_H_
63af75078fSIntel 
64af75078fSIntel /* This file is an example of extension of libcmdline. It provides an
65af75078fSIntel  * example of objects stored in a list. */
66af75078fSIntel 
67af75078fSIntel #include <sys/queue.h>
68af75078fSIntel #include <cmdline_parse.h>
69af75078fSIntel 
70af75078fSIntel #define OBJ_NAME_LEN_MAX 64
71af75078fSIntel 
72af75078fSIntel struct object {
73af75078fSIntel 	SLIST_ENTRY(object) next;
74af75078fSIntel 	char name[OBJ_NAME_LEN_MAX];
75af75078fSIntel 	cmdline_ipaddr_t ip;
76af75078fSIntel };
77af75078fSIntel 
78af75078fSIntel /* define struct object_list */
79af75078fSIntel SLIST_HEAD(object_list, object);
80af75078fSIntel 
81af75078fSIntel /* data is a pointer to a list */
82af75078fSIntel struct token_obj_list_data {
83af75078fSIntel 	struct object_list *list;
84af75078fSIntel };
85af75078fSIntel 
86af75078fSIntel struct token_obj_list {
87af75078fSIntel 	struct cmdline_token_hdr hdr;
88af75078fSIntel 	struct token_obj_list_data obj_list_data;
89af75078fSIntel };
90af75078fSIntel typedef struct token_obj_list parse_token_obj_list_t;
91af75078fSIntel 
92af75078fSIntel extern struct cmdline_token_ops token_obj_list_ops;
93af75078fSIntel 
94*aaa662e7SAlan Carew int parse_obj_list(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res,
95*aaa662e7SAlan Carew 	unsigned ressize);
96af75078fSIntel int complete_get_nb_obj_list(cmdline_parse_token_hdr_t *tk);
97af75078fSIntel int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk, int idx,
98af75078fSIntel 			      char *dstbuf, unsigned int size);
99af75078fSIntel int get_help_obj_list(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size);
100af75078fSIntel 
101af75078fSIntel #define TOKEN_OBJ_LIST_INITIALIZER(structure, field, obj_list_ptr)  \
102af75078fSIntel {								    \
103af75078fSIntel 	.hdr = {						    \
104af75078fSIntel 		.ops = &token_obj_list_ops,			    \
105af75078fSIntel 		.offset = offsetof(structure, field),		    \
106af75078fSIntel 	},							    \
107af75078fSIntel 		.obj_list_data = {				    \
108af75078fSIntel 		.list = obj_list_ptr,				    \
109af75078fSIntel 	},							    \
110af75078fSIntel }
111af75078fSIntel 
112af75078fSIntel #endif /* _PARSE_OBJ_LIST_H_ */
113