1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation. 3 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org> 4 * All rights reserved. 5 */ 6 7 #ifndef _PARSE_OBJ_LIST_H_ 8 #define _PARSE_OBJ_LIST_H_ 9 10 /* This file is an example of extension of libcmdline. It provides an 11 * example of objects stored in a list. */ 12 13 #include <sys/queue.h> 14 #include <cmdline_parse.h> 15 #include <cmdline_parse_string.h> 16 17 #define OBJ_NAME_LEN_MAX sizeof(cmdline_fixed_string_t) 18 19 struct object { 20 SLIST_ENTRY(object) next; 21 char name[OBJ_NAME_LEN_MAX]; 22 cmdline_ipaddr_t ip; 23 }; 24 25 /* define struct object_list */ 26 SLIST_HEAD(object_list, object); 27 28 /* data is a pointer to a list */ 29 struct token_obj_list_data { 30 struct object_list *list; 31 }; 32 33 struct token_obj_list { 34 struct cmdline_token_hdr hdr; 35 struct token_obj_list_data obj_list_data; 36 }; 37 typedef struct token_obj_list parse_token_obj_list_t; 38 39 extern struct cmdline_token_ops token_obj_list_ops; 40 41 int parse_obj_list(cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res, 42 unsigned ressize); 43 int complete_get_nb_obj_list(cmdline_parse_token_hdr_t *tk); 44 int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk, int idx, 45 char *dstbuf, unsigned int size); 46 int get_help_obj_list(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int size); 47 48 #define TOKEN_OBJ_LIST_INITIALIZER(structure, field, obj_list_ptr) \ 49 { \ 50 .hdr = { \ 51 .ops = &token_obj_list_ops, \ 52 .offset = offsetof(structure, field), \ 53 }, \ 54 .obj_list_data = { \ 55 .list = obj_list_ptr, \ 56 }, \ 57 } 58 59 #endif /* _PARSE_OBJ_LIST_H_ */ 60