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