MCPcopy Create free account
hub / github.com/F-Stack/f-stack / parse_set

Function parse_set

dpdk/examples/vm_power_manager/guest_cli/parse.c:23–86  ·  view source on GitHub ↗

* Parse elem, the elem could be single number/range or group * 1) A single number elem, it's just a simple digit. e.g. 9 * 2) A single range elem, two digits with a '-' between. e.g. 2-6 * 3) A group elem, combines multiple 1) or 2) e.g 0,2-4,6 * Within group, '-' used for a range separator; * ',' used for a single number. */

Source from the content-addressed store, hash-verified

21 * ',' used for a single number.
22 */
23int
24parse_set(const char *input, uint16_t set[], unsigned int num)
25{
26 unsigned int idx;
27 const char *str = input;
28 char *end = NULL;
29 unsigned int min, max;
30
31 memset(set, 0, num * sizeof(uint16_t));
32
33 while (isblank(*str))
34 str++;
35
36 /* only digit or left bracket is qualify for start point */
37 if (!isdigit(*str) || *str == '\0')
38 return -1;
39
40 while (isblank(*str))
41 str++;
42 if (*str == '\0')
43 return -1;
44
45 min = num;
46 do {
47
48 /* go ahead to the first digit */
49 while (isblank(*str))
50 str++;
51 if (!isdigit(*str))
52 return -1;
53
54 /* get the digit value */
55 errno = 0;
56 idx = strtoul(str, &end, 10);
57 if (errno || end == NULL || idx >= num)
58 return -1;
59
60 /* go ahead to separator '-' and ',' */
61 while (isblank(*end))
62 end++;
63 if (*end == '-') {
64 if (min == num)
65 min = idx;
66 else /* avoid continuous '-' */
67 return -1;
68 } else if ((*end == ',') || (*end == '\0')) {
69 max = idx;
70
71 if (min == num)
72 min = idx;
73
74 for (idx = RTE_MIN(min, max);
75 idx <= RTE_MAX(min, max); idx++) {
76 set[idx] = 1;
77 }
78 min = num;
79 } else
80 return -1;

Callers 1

parse_argsFunction · 0.70

Calls 4

memsetFunction · 0.85
isblankFunction · 0.85
isdigitFunction · 0.85
strtoulFunction · 0.85

Tested by

no test coverage detected