1 /* 2 * Command line options parser. 3 * 4 * Copyright (C) 2020, Broadcom. 5 * 6 * Unless you and Broadcom execute a separate written software license 7 * agreement governing use of this software, this software is licensed to you 8 * under the terms of the GNU General Public License version 2 (the "GPL"), 9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the 10 * following added to such license: 11 * 12 * As a special exception, the copyright holders of this software give you 13 * permission to link this software with independent modules, and to copy and 14 * distribute the resulting executable under terms of your choice, provided that 15 * you also meet, for each linked independent module, the terms and conditions of 16 * the license of that module. An independent module is a module which is not 17 * derived from this software. The special exception does not apply to any 18 * modifications of the software. 19 * 20 * 21 * <<Broadcom-WL-IPTag/Dual:>> 22 */ 23 24 #ifndef MINI_OPT_H 25 #define MINI_OPT_H 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* ---- Include Files ---------------------------------------------------- */ 32 33 /* ---- Constants and Types ---------------------------------------------- */ 34 35 #define MINIOPT_MAXKEY 128 /* Max options */ 36 typedef struct miniopt { 37 38 /* These are persistent after miniopt_init() */ 39 const char* name; /* name for prompt in error strings */ 40 const char* flags; /* option chars that take no args */ 41 bool longflags; /* long options may be flags */ 42 bool opt_end; /* at end of options (passed a "--") */ 43 44 /* These are per-call to miniopt() */ 45 46 int consumed; /* number of argv entries cosumed in 47 * the most recent call to miniopt() 48 */ 49 bool positional; 50 bool good_int; /* 'val' member is the result of a sucessful 51 * strtol conversion of the option value 52 */ 53 char opt; 54 char key[MINIOPT_MAXKEY]; 55 char* valstr; /* positional param, or value for the option, 56 * or null if the option had 57 * no accompanying value 58 */ 59 uint uval; /* strtol translation of valstr */ 60 int val; /* strtol translation of valstr */ 61 } miniopt_t; 62 63 void miniopt_init(miniopt_t *t, const char* name, const char* flags, bool longflags); 64 int miniopt(miniopt_t *t, char **argv); 65 66 /* ---- Variable Externs ------------------------------------------------- */ 67 /* ---- Function Prototypes ---------------------------------------------- */ 68 69 #ifdef __cplusplus 70 } 71 #endif 72 73 #endif /* MINI_OPT_H */ 74