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

Function parse_port_list

dpdk/app/test-pmd/config.c:5281–5334  ·  view source on GitHub ↗

* Parse the user input and obtain the list of forwarding ports * * @param[in] list * String containing the user input. User can specify * in these formats 1,3,5 or 1-3 or 1-2,5 or 3,5-6. * For example, if the user wants to use all the available * 4 ports in his system, then the input can be 0-3 or 0,1,2,3. * If the user wants to use only the ports 1,2 then the input * is 1,2.

Source from the content-addressed store, hash-verified

5279 * On failure, returns 0
5280 */
5281static unsigned int
5282parse_port_list(const char *list, unsigned int *values, unsigned int maxsize)
5283{
5284 unsigned int count = 0;
5285 char *end = NULL;
5286 int min, max;
5287 int value, i;
5288 unsigned int marked[maxsize];
5289
5290 if (list == NULL || values == NULL)
5291 return 0;
5292
5293 for (i = 0; i < (int)maxsize; i++)
5294 marked[i] = 0;
5295
5296 min = INT_MAX;
5297
5298 do {
5299 /*Remove the blank spaces if any*/
5300 while (isblank(*list))
5301 list++;
5302 if (*list == '\0')
5303 break;
5304 errno = 0;
5305 value = strtol(list, &end, 10);
5306 if (errno || end == NULL)
5307 return 0;
5308 if (value < 0 || value >= (int)maxsize)
5309 return 0;
5310 while (isblank(*end))
5311 end++;
5312 if (*end == '-' && min == INT_MAX) {
5313 min = value;
5314 } else if ((*end == ',') || (*end == '\0')) {
5315 max = value;
5316 if (min == INT_MAX)
5317 min = value;
5318 for (i = min; i <= max; i++) {
5319 if (count < maxsize) {
5320 if (marked[i])
5321 continue;
5322 values[count] = i;
5323 marked[i] = 1;
5324 count++;
5325 }
5326 }
5327 min = INT_MAX;
5328 } else
5329 return 0;
5330 list = end + 1;
5331 } while (*end != '\0');
5332
5333 return count;
5334}
5335
5336void
5337parse_fwd_portlist(const char *portlist)

Callers 1

parse_fwd_portlistFunction · 0.70

Calls 2

isblankFunction · 0.85
strtolFunction · 0.85

Tested by

no test coverage detected