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