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 <rte_string_fns.h> 10 : : #include <stdlib.h> 11 : : 12 : : #include "cmdline_parse.h" 13 : : #include "cmdline_parse_bool.h" 14 : : 15 : : 16 : : struct cmdline_token_ops cmdline_token_bool_ops = { 17 : : .parse = cmdline_parse_bool, 18 : : .complete_get_nb = NULL, 19 : : .complete_get_elt = NULL, 20 : : .get_help = cmdline_get_help_string, 21 : : }; 22 : : 23 : : static cmdline_parse_token_string_t cmd_parse_token_bool = { 24 : : { 25 : : &cmdline_token_string_ops, 26 : : 0 27 : : }, 28 : : { 29 : : "on#off" 30 : : } 31 : : }; 32 : : 33 : : /* parse string to bool */ 34 : : int 35 : 0 : cmdline_parse_bool(__rte_unused cmdline_parse_token_hdr_t *tk, const char *srcbuf, void *res, 36 : : __rte_unused unsigned int ressize) 37 : : { 38 : 0 : cmdline_fixed_string_t on_off = {0}; 39 [ # # ]: 0 : if (cmdline_token_string_ops.parse 40 : : (&cmd_parse_token_bool.hdr, srcbuf, on_off, sizeof(on_off)) < 0) 41 : : return -1; 42 : : 43 [ # # ]: 0 : if (strcmp((char *)on_off, "on") == 0) 44 : 0 : *(uint8_t *)res = 1; 45 [ # # ]: 0 : else if (strcmp((char *)on_off, "off") == 0) 46 : 0 : *(uint8_t *)res = 0; 47 : : 48 : 0 : return strlen(on_off); 49 : : }