1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 Intel Corporation.
3 * Copyright(c) 2017 Cavium, Inc.
19 #include <rte_errno.h>
20 #include <rte_string_fns.h>
28 case '0': case '1': case '2': case '3': case '4': case '5':
29 case '6': case '7': case '8': case '9':
31 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
33 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
41 parser_read_arg_bool(const char *p)
43 p = skip_white_spaces(p);
46 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
47 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
52 if (((p[0] == 'o') && (p[1] == 'n')) ||
53 ((p[0] == 'O') && (p[1] == 'N'))) {
58 if (((p[0] == 'n') && (p[1] == 'o')) ||
59 ((p[0] == 'N') && (p[1] == 'O'))) {
64 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
65 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
70 p = skip_white_spaces(p);
79 parser_read_uint64(uint64_t *value, const char *p)
84 p = skip_white_spaces(p);
88 val = strtoul(p, &next, 10);
110 p = skip_white_spaces(p);
119 parser_read_int32(int32_t *value, const char *p)
124 p = skip_white_spaces(p);
128 val = strtol(p, &next, 10);
137 parser_read_uint64_hex(uint64_t *value, const char *p)
142 p = skip_white_spaces(p);
144 val = strtoul(p, &next, 16);
148 p = skip_white_spaces(next);
157 parser_read_uint32(uint32_t *value, const char *p)
160 int ret = parser_read_uint64(&val, p);
165 if (val > UINT32_MAX)
173 parser_read_uint32_hex(uint32_t *value, const char *p)
176 int ret = parser_read_uint64_hex(&val, p);
181 if (val > UINT32_MAX)
189 parser_read_uint16(uint16_t *value, const char *p)
192 int ret = parser_read_uint64(&val, p);
197 if (val > UINT16_MAX)
205 parser_read_uint16_hex(uint16_t *value, const char *p)
208 int ret = parser_read_uint64_hex(&val, p);
213 if (val > UINT16_MAX)
221 parser_read_uint8(uint8_t *value, const char *p)
224 int ret = parser_read_uint64(&val, p);
237 parser_read_uint8_hex(uint8_t *value, const char *p)
240 int ret = parser_read_uint64_hex(&val, p);
253 parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens)
257 if ((string == NULL) ||
262 for (i = 0; i < *n_tokens; i++) {
263 tokens[i] = strtok_r(string, PARSE_DELIMITER, &string);
264 if (tokens[i] == NULL)
268 if ((i == *n_tokens) &&
269 (strtok_r(string, PARSE_DELIMITER, &string) != NULL))
277 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
282 /* Check input parameters */
290 if (((len & 3) != 0) ||
295 for (c = src; *c != 0; c++) {
296 if ((((*c) >= '0') && ((*c) <= '9')) ||
297 (((*c) >= 'A') && ((*c) <= 'F')) ||
298 (((*c) >= 'a') && ((*c) <= 'f')))
304 /* Convert chars to bytes */
305 for (i = 0; i < *size; i++)
306 dst[i] = get_hex_val(src[2 * i]) * 16 +
307 get_hex_val(src[2 * i + 1]);
313 parse_lcores_list(bool lcores[], int lcores_num, const char *corelist)
319 if (corelist == NULL)
321 while (isblank(*corelist))
323 i = strlen(corelist);
324 while ((i > 0) && isblank(corelist[i - 1]))
327 /* Get list of lcores */
330 while (isblank(*corelist))
332 if (*corelist == '\0')
334 idx = strtoul(corelist, &end, 10);
335 if (idx < 0 || idx > lcores_num)
340 while (isblank(*end))
344 } else if ((*end == ',') || (*end == '\0')) {
346 if (min == RTE_MAX_LCORE)
348 for (idx = min; idx <= max; idx++) {
349 if (lcores[idx] == 1)
358 } while (*end != '\0');