File: cmdline_parse_bool.c

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (51 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2023 NVIDIA Corporation & Affiliates
 */

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <eal_export.h>
#include <rte_string_fns.h>
#include <stdlib.h>

#include "cmdline_parse.h"
#include "cmdline_parse_bool.h"


RTE_EXPORT_EXPERIMENTAL_SYMBOL(cmdline_token_bool_ops, 25.03)
struct cmdline_token_ops cmdline_token_bool_ops = {
	.parse = cmdline_parse_bool,
	.complete_get_nb = NULL,
	.complete_get_elt = NULL,
	.get_help = cmdline_get_help_string,
};

static cmdline_parse_token_string_t cmd_parse_token_bool = {
	{
		&cmdline_token_string_ops,
		0
	},
	{
		"on#off"
	}
};

/* parse string to bool */
int
cmdline_parse_bool(__rte_unused cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res,
	__rte_unused unsigned int ressize)
{
	cmdline_fixed_string_t on_off = {0};
	if (cmdline_token_string_ops.parse
			(&cmd_parse_token_bool.hdr, srcbuf, on_off, sizeof(on_off)) < 0)
		return -1;

	if (strcmp((char *)on_off, "on") == 0)
		*(uint8_t *)res = 1;
	else if (strcmp((char *)on_off, "off") == 0)
		*(uint8_t *)res = 0;

	return strlen(on_off);
}