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