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