1 /* 2 * Copyright (c) 2018 Oticon A/S 3 * Copyright (c) 2023 Nordic Semiconductor ASA 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 /** 9 * @file 10 * @brief API to the native simulator - native command line parsing utilities 11 * 12 * Note: The arguments structure definitions is kept fully compatible with Zephyr's native_posix 13 * and BabbleSim's command line options to enable to reuse components between them. 14 * And for APIs to be accessible thru a trivial shim. 15 */ 16 17 #ifndef NATIVE_SIMULATOR_NATIVE_SRC_NSI_CMDLINE_H 18 #define NATIVE_SIMULATOR_NATIVE_SRC_NSI_CMDLINE_H 19 20 #include <stdbool.h> 21 #include <stddef.h> 22 #include "nsi_cmdline_main_if.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /** 29 * Prototype for a callback function when an option is found: 30 * inputs: 31 * argv: Whole argv[i] option as received in main 32 * offset: Offset to the end of the option string 33 * (including a possible ':' or '=') 34 * If the option had a value, it would be placed in &argv[offset] 35 */ 36 typedef void (*option_found_callback_f)(char *argv, int offset); 37 38 /* 39 * Structure defining each command line option 40 */ 41 struct args_struct_t { 42 /* 43 * if manual is set nsi_cmd_args_parse*() will ignore it except for 44 * displaying it the help messages and initializing <dest> to its 45 * default 46 */ 47 bool manual; 48 /* For help messages, should it be wrapped in "[]" */ 49 bool is_mandatory; 50 /* It is just a switch: it does not have something to store after */ 51 bool is_switch; 52 /* Option name we search for: --<option> */ 53 char *option; 54 /* 55 * Name of the option destination in the help messages: 56 * "--<option>=<name>" 57 */ 58 char *name; 59 /* Type of option (see nsi_cmd_read_option_value()) */ 60 char type; 61 /* Pointer to where the read value will be stored (may be NULL) */ 62 void *dest; 63 /* Optional callback to be called when the switch is found */ 64 option_found_callback_f call_when_found; 65 /* Long description for the help messages */ 66 char *descript; 67 }; 68 69 #define ARG_TABLE_ENDMARKER \ 70 {false, false, false, NULL, NULL, 0, NULL, NULL, NULL} 71 72 void nsi_get_cmd_line_args(int *argc, char ***argv); 73 void nsi_get_test_cmd_line_args(int *argc, char ***argv); 74 void nsi_add_command_line_opts(struct args_struct_t *args); 75 76 #ifdef __cplusplus 77 } 78 #endif 79 80 #endif /* NATIVE_SIMULATOR_NATIVE_SRC_NSI_CMDLINE_H */ 81