• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Command line options parser.
3  *
4  * Copyright (C) 1999-2017, Broadcom Corporation
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  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  *
25  * <<Broadcom-WL-IPTag/Open:>>
26  *
27  * $Id: miniopt.h 514727 2014-11-12 03:02:48Z $
28  */
29 
30 
31 #ifndef MINI_OPT_H
32 #define MINI_OPT_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* ---- Include Files ---------------------------------------------------- */
39 
40 
41 /* ---- Constants and Types ---------------------------------------------- */
42 
43 #define MINIOPT_MAXKEY    128    /* Max options */
44 typedef struct miniopt {
45     /* These are persistent after miniopt_init() */
46     const char* name;        /* name for prompt in error strings */
47     const char* flags;        /* option chars that take no args */
48     bool longflags;        /* long options may be flags */
49     bool opt_end;        /* at end of options (passed a "--") */
50 
51     /* These are per-call to miniopt() */
52 
53     int consumed;        /* number of argv entries cosumed in
54                  * the most recent call to miniopt()
55                  */
56     bool positional;
57     bool good_int;        /* 'val' member is the result of a sucessful
58                  * strtol conversion of the option value
59                  */
60     char opt;
61     char key[MINIOPT_MAXKEY];
62     char* valstr;        /* positional param, or value for the option,
63                  * or null if the option had
64                  * no accompanying value
65                  */
66     uint uval;        /* strtol translation of valstr */
67     int  val;        /* strtol translation of valstr */
68 } miniopt_t;
69 
70 void miniopt_init(miniopt_t *t, const char* name, const char* flags, bool longflags);
71 int miniopt(miniopt_t *t, char **argv);
72 
73 
74 /* ---- Variable Externs ------------------------------------------------- */
75 /* ---- Function Prototypes ---------------------------------------------- */
76 
77 
78 #ifdef __cplusplus
79     }
80 #endif
81 
82 #endif  /* MINI_OPT_H  */
83