1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright (c) 2010, Keith Wiles <keith.wiles@windriver.com>
12 #include <rte_string_fns.h>
13 #include "cmdline_parse.h"
14 #include "cmdline_parse_portlist.h"
16 struct cmdline_token_ops cmdline_token_portlist_ops = {
17 .parse = cmdline_parse_portlist,
18 .complete_get_nb = NULL,
19 .complete_get_elt = NULL,
20 .get_help = cmdline_get_help_portlist,
24 parse_set_list(cmdline_portlist_t *pl, size_t low, size_t high)
27 pl->map |= (1 << low++);
28 } while (low <= high);
32 parse_ports(cmdline_portlist_t *pl, const char *str)
35 const char *first, *last;
38 for (first = str, last = first;
39 first != NULL && last != NULL;
42 last = strchr(first, ',');
45 ps = strtoul(first, &end, 10);
46 if (errno != 0 || end == first ||
47 (end[0] != '-' && end[0] != 0 && end != last))
50 /* Support for N-M portlist format */
54 pe = strtoul(first, &end, 10);
55 if (errno != 0 || end == first ||
56 (end[0] != 0 && end != last))
62 if (ps > pe || pe >= sizeof (pl->map) * 8)
65 parse_set_list(pl, ps, pe);
72 cmdline_parse_portlist(__rte_unused cmdline_parse_token_hdr_t *tk,
73 const char *buf, void *res, unsigned ressize)
75 unsigned int token_len = 0;
76 char portlist_str[PORTLIST_TOKEN_SIZE+1];
77 cmdline_portlist_t *pl;
82 if (res && ressize < sizeof(cmdline_portlist_t))
87 while (!cmdline_isendoftoken(buf[token_len]) &&
88 (token_len < PORTLIST_TOKEN_SIZE))
91 if (token_len >= PORTLIST_TOKEN_SIZE)
94 strlcpy(portlist_str, buf, token_len + 1);
98 if (strcmp("all", portlist_str) == 0)
100 else if (parse_ports(pl, portlist_str) != 0)
108 cmdline_get_help_portlist(__rte_unused cmdline_parse_token_hdr_t *tk,
109 char *dstbuf, unsigned int size)
112 ret = snprintf(dstbuf, size, "range of ports as 3,4-6,8-19,20");