xref: /dpdk/lib/cmdline/cmdline_parse_string.h (revision d5d13ef979c83d33518c70727b5a4ef091bd8134)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation.
399a2dd95SBruce Richardson  * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
499a2dd95SBruce Richardson  * All rights reserved.
599a2dd95SBruce Richardson  */
699a2dd95SBruce Richardson 
799a2dd95SBruce Richardson #ifndef _PARSE_STRING_H_
899a2dd95SBruce Richardson #define _PARSE_STRING_H_
999a2dd95SBruce Richardson 
1099a2dd95SBruce Richardson #include <cmdline_parse.h>
1199a2dd95SBruce Richardson 
1299a2dd95SBruce Richardson #ifdef __cplusplus
1399a2dd95SBruce Richardson extern "C" {
1499a2dd95SBruce Richardson #endif
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson /* size of a parsed string */
1799a2dd95SBruce Richardson #define STR_TOKEN_SIZE 128
1899a2dd95SBruce Richardson 
1999a2dd95SBruce Richardson /* size of a parsed multi string */
2099a2dd95SBruce Richardson #define STR_MULTI_TOKEN_SIZE 4096
2199a2dd95SBruce Richardson 
2299a2dd95SBruce Richardson typedef char cmdline_fixed_string_t[STR_TOKEN_SIZE];
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson typedef char cmdline_multi_string_t[STR_MULTI_TOKEN_SIZE];
2599a2dd95SBruce Richardson 
2699a2dd95SBruce Richardson struct cmdline_token_string_data {
2799a2dd95SBruce Richardson 	const char *str;
2899a2dd95SBruce Richardson };
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson struct cmdline_token_string {
3199a2dd95SBruce Richardson 	struct cmdline_token_hdr hdr;
3299a2dd95SBruce Richardson 	struct cmdline_token_string_data string_data;
3399a2dd95SBruce Richardson };
3499a2dd95SBruce Richardson typedef struct cmdline_token_string cmdline_parse_token_string_t;
3599a2dd95SBruce Richardson 
3699a2dd95SBruce Richardson extern struct cmdline_token_ops cmdline_token_string_ops;
3799a2dd95SBruce Richardson 
3899a2dd95SBruce Richardson int cmdline_parse_string(cmdline_parse_token_hdr_t *tk, const char *srcbuf,
3999a2dd95SBruce Richardson 	void *res, unsigned ressize);
4099a2dd95SBruce Richardson int cmdline_complete_get_nb_string(cmdline_parse_token_hdr_t *tk);
4199a2dd95SBruce Richardson int cmdline_complete_get_elt_string(cmdline_parse_token_hdr_t *tk, int idx,
4299a2dd95SBruce Richardson 				    char *dstbuf, unsigned int size);
4399a2dd95SBruce Richardson int cmdline_get_help_string(cmdline_parse_token_hdr_t *tk, char *dstbuf,
4499a2dd95SBruce Richardson 			    unsigned int size);
4599a2dd95SBruce Richardson 
4699a2dd95SBruce Richardson /**
4799a2dd95SBruce Richardson  * Token marked as TOKEN_STRING_MULTI takes entire parsing string
4899a2dd95SBruce Richardson  * until “#” sign appear. Everything after “#” sign is treated as a comment.
4999a2dd95SBruce Richardson  *
5099a2dd95SBruce Richardson  * Note:
51*d5d13ef9SThomas Monjalon  * In this case second parameter of TOKEN_STRING_INITIALIZER
52*d5d13ef9SThomas Monjalon  * must be a type of cmdline_multi_string_t.
5399a2dd95SBruce Richardson  */
5499a2dd95SBruce Richardson #define TOKEN_STRING_MULTI ""
5599a2dd95SBruce Richardson 
5699a2dd95SBruce Richardson #define TOKEN_STRING_INITIALIZER(structure, field, string)  \
5799a2dd95SBruce Richardson {                                                           \
5899a2dd95SBruce Richardson 	/* hdr */                                               \
5999a2dd95SBruce Richardson 	{                                                       \
6099a2dd95SBruce Richardson 		&cmdline_token_string_ops,      /* ops */           \
6199a2dd95SBruce Richardson 		offsetof(structure, field),     /* offset */        \
6299a2dd95SBruce Richardson 	},                                                      \
6399a2dd95SBruce Richardson 	/* string_data */                                       \
6499a2dd95SBruce Richardson 	{                                                       \
6599a2dd95SBruce Richardson 		string,                         /* str */           \
6699a2dd95SBruce Richardson 	},                                                      \
6799a2dd95SBruce Richardson }
6899a2dd95SBruce Richardson 
6999a2dd95SBruce Richardson #ifdef __cplusplus
7099a2dd95SBruce Richardson }
7199a2dd95SBruce Richardson #endif
7299a2dd95SBruce Richardson 
7399a2dd95SBruce Richardson #endif /* _PARSE_STRING_H_ */
74