xref: /f-stack/dpdk/app/test-eventdev/parser.h (revision 2bfe3f2e)
1*2bfe3f2eSlogwang /*-
2*2bfe3f2eSlogwang  *   BSD LICENSE
3*2bfe3f2eSlogwang  *
4*2bfe3f2eSlogwang  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5*2bfe3f2eSlogwang  *   All rights reserved.
6*2bfe3f2eSlogwang  *
7*2bfe3f2eSlogwang  *   Redistribution and use in source and binary forms, with or without
8*2bfe3f2eSlogwang  *   modification, are permitted provided that the following conditions
9*2bfe3f2eSlogwang  *   are met:
10*2bfe3f2eSlogwang  *
11*2bfe3f2eSlogwang  *     * Redistributions of source code must retain the above copyright
12*2bfe3f2eSlogwang  *       notice, this list of conditions and the following disclaimer.
13*2bfe3f2eSlogwang  *     * Redistributions in binary form must reproduce the above copyright
14*2bfe3f2eSlogwang  *       notice, this list of conditions and the following disclaimer in
15*2bfe3f2eSlogwang  *       the documentation and/or other materials provided with the
16*2bfe3f2eSlogwang  *       distribution.
17*2bfe3f2eSlogwang  *     * Neither the name of Intel Corporation nor the names of its
18*2bfe3f2eSlogwang  *       contributors may be used to endorse or promote products derived
19*2bfe3f2eSlogwang  *       from this software without specific prior written permission.
20*2bfe3f2eSlogwang  *
21*2bfe3f2eSlogwang  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*2bfe3f2eSlogwang  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*2bfe3f2eSlogwang  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24*2bfe3f2eSlogwang  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25*2bfe3f2eSlogwang  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26*2bfe3f2eSlogwang  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27*2bfe3f2eSlogwang  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28*2bfe3f2eSlogwang  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29*2bfe3f2eSlogwang  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30*2bfe3f2eSlogwang  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31*2bfe3f2eSlogwang  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*2bfe3f2eSlogwang  */
33*2bfe3f2eSlogwang 
34*2bfe3f2eSlogwang #ifndef __INCLUDE_PARSER_H__
35*2bfe3f2eSlogwang #define __INCLUDE_PARSER_H__
36*2bfe3f2eSlogwang 
37*2bfe3f2eSlogwang #include <stdint.h>
38*2bfe3f2eSlogwang 
39*2bfe3f2eSlogwang #define PARSE_DELIMITER				" \f\n\r\t\v"
40*2bfe3f2eSlogwang 
41*2bfe3f2eSlogwang #define skip_white_spaces(pos)			\
42*2bfe3f2eSlogwang ({						\
43*2bfe3f2eSlogwang 	__typeof__(pos) _p = (pos);		\
44*2bfe3f2eSlogwang 	for ( ; isspace(*_p); _p++)		\
45*2bfe3f2eSlogwang 		;				\
46*2bfe3f2eSlogwang 	_p;					\
47*2bfe3f2eSlogwang })
48*2bfe3f2eSlogwang 
49*2bfe3f2eSlogwang static inline size_t
50*2bfe3f2eSlogwang skip_digits(const char *src)
51*2bfe3f2eSlogwang {
52*2bfe3f2eSlogwang 	size_t i;
53*2bfe3f2eSlogwang 
54*2bfe3f2eSlogwang 	for (i = 0; isdigit(src[i]); i++)
55*2bfe3f2eSlogwang 		;
56*2bfe3f2eSlogwang 
57*2bfe3f2eSlogwang 	return i;
58*2bfe3f2eSlogwang }
59*2bfe3f2eSlogwang 
60*2bfe3f2eSlogwang int parser_read_arg_bool(const char *p);
61*2bfe3f2eSlogwang 
62*2bfe3f2eSlogwang int parser_read_uint64(uint64_t *value, const char *p);
63*2bfe3f2eSlogwang int parser_read_uint32(uint32_t *value, const char *p);
64*2bfe3f2eSlogwang int parser_read_uint16(uint16_t *value, const char *p);
65*2bfe3f2eSlogwang int parser_read_uint8(uint8_t *value, const char *p);
66*2bfe3f2eSlogwang 
67*2bfe3f2eSlogwang int parser_read_uint64_hex(uint64_t *value, const char *p);
68*2bfe3f2eSlogwang int parser_read_uint32_hex(uint32_t *value, const char *p);
69*2bfe3f2eSlogwang int parser_read_uint16_hex(uint16_t *value, const char *p);
70*2bfe3f2eSlogwang int parser_read_uint8_hex(uint8_t *value, const char *p);
71*2bfe3f2eSlogwang 
72*2bfe3f2eSlogwang int parser_read_int32(int32_t *value, const char *p);
73*2bfe3f2eSlogwang 
74*2bfe3f2eSlogwang int parse_hex_string(char *src, uint8_t *dst, uint32_t *size);
75*2bfe3f2eSlogwang 
76*2bfe3f2eSlogwang int parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens);
77*2bfe3f2eSlogwang 
78*2bfe3f2eSlogwang int parse_lcores_list(bool lcores[], const char *corelist);
79*2bfe3f2eSlogwang #endif
80