1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
11 * Parse elem, the elem could be single number/range or group
12 * 1) A single number elem, it's just a simple digit. e.g. 9
13 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
14 * 3) A group elem, combines multiple 1) or 2) e.g 0,2-4,6
15 * Within group, '-' used for a range separator;
16 * ',' used for a single number.
19 parse_set(const char *input, uint16_t set[], unsigned int num)
22 const char *str = input;
24 unsigned int min, max;
26 memset(set, 0, num * sizeof(uint16_t));
31 /* only digit or left bracket is qualify for start point */
32 if (!isdigit(*str) || *str == '\0')
43 /* go ahead to the first digit */
49 /* get the digit value */
51 idx = strtoul(str, &end, 10);
52 if (errno || end == NULL || idx >= num)
55 /* go ahead to separator '-' and ',' */
61 else /* avoid continuous '-' */
63 } else if ((*end == ',') || (*end == '\0')) {
69 for (idx = RTE_MIN(min, max);
70 idx <= RTE_MAX(min, max); idx++) {
78 } while (*end != '\0');