Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (c) 2023 NVIDIA Corporation & Affiliates 3 : : */ 4 : : 5 : : #include <stdio.h> 6 : : #include <stdint.h> 7 : : #include <inttypes.h> 8 : : #include <string.h> 9 : : #include <eal_export.h> 10 : : #include <rte_string_fns.h> 11 : : #include <stdlib.h> 12 : : 13 : : #include "cmdline_parse.h" 14 : : #include "cmdline_parse_bool.h" 15 : : 16 : : 17 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(cmdline_token_bool_ops, 25.03) 18 : : struct cmdline_token_ops cmdline_token_bool_ops = { 19 : : .parse = cmdline_parse_bool, 20 : : .complete_get_nb = NULL, 21 : : .complete_get_elt = NULL, 22 : : .get_help = cmdline_get_help_string, 23 : : }; 24 : : 25 : : static cmdline_parse_token_string_t cmd_parse_token_bool = { 26 : : { 27 : : &cmdline_token_string_ops, 28 : : 0 29 : : }, 30 : : { 31 : : "on#off" 32 : : } 33 : : }; 34 : : 35 : : /* parse string to bool */ 36 : : int 37 : 0 : cmdline_parse_bool(__rte_unused cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res, 38 : : __rte_unused unsigned int ressize) 39 : : { 40 : 0 : cmdline_fixed_string_t on_off = {0}; 41 [ # # ]: 0 : if (cmdline_token_string_ops.parse 42 : : (&cmd_parse_token_bool.hdr, srcbuf, on_off, sizeof(on_off)) < 0) 43 : : return -1; 44 : : 45 [ # # ]: 0 : if (strcmp((char *)on_off, "on") == 0) 46 : 0 : *(uint8_t *)res = 1; 47 [ # # ]: 0 : else if (strcmp((char *)on_off, "off") == 0) 48 : 0 : *(uint8_t *)res = 0; 49 : : 50 : 0 : return strlen(on_off); 51 : : }