xref: /aosp_15_r20/external/marisa-trie/tools/cmdopt.h (revision ab8db090fce404b23716c4c9194221ee27efe31c)
1*ab8db090SAndroid Build Coastguard Worker #ifndef MARISA_CMDOPT_H_
2*ab8db090SAndroid Build Coastguard Worker #define MARISA_CMDOPT_H_
3*ab8db090SAndroid Build Coastguard Worker 
4*ab8db090SAndroid Build Coastguard Worker #ifdef __cplusplus
5*ab8db090SAndroid Build Coastguard Worker extern "C" {
6*ab8db090SAndroid Build Coastguard Worker #endif
7*ab8db090SAndroid Build Coastguard Worker 
8*ab8db090SAndroid Build Coastguard Worker typedef struct cmdopt_option_ {
9*ab8db090SAndroid Build Coastguard Worker   // `name' specifies the name of this option.
10*ab8db090SAndroid Build Coastguard Worker   // An array of options must be terminated with an option whose name == NULL.
11*ab8db090SAndroid Build Coastguard Worker   const char *name;
12*ab8db090SAndroid Build Coastguard Worker 
13*ab8db090SAndroid Build Coastguard Worker   // `has_name' specifies whether an option takes an argument or not.
14*ab8db090SAndroid Build Coastguard Worker   // 0 specifies that this option does not have any argument.
15*ab8db090SAndroid Build Coastguard Worker   // 1 specifies that this option has an argument.
16*ab8db090SAndroid Build Coastguard Worker   // 2 specifies that this option may have an argument.
17*ab8db090SAndroid Build Coastguard Worker   int  has_arg;
18*ab8db090SAndroid Build Coastguard Worker 
19*ab8db090SAndroid Build Coastguard Worker   // `flag' specifies an integer variable which is overwritten by cmdopt_next()
20*ab8db090SAndroid Build Coastguard Worker   // with its return value.
21*ab8db090SAndroid Build Coastguard Worker   int *flag;
22*ab8db090SAndroid Build Coastguard Worker 
23*ab8db090SAndroid Build Coastguard Worker   // `val' specifies a return value of cmdopt_next(). This value is returned
24*ab8db090SAndroid Build Coastguard Worker   // when cmdopt_next() finds this option.
25*ab8db090SAndroid Build Coastguard Worker   int  val;
26*ab8db090SAndroid Build Coastguard Worker } cmdopt_option;
27*ab8db090SAndroid Build Coastguard Worker 
28*ab8db090SAndroid Build Coastguard Worker typedef struct cmdopt_t_ {
29*ab8db090SAndroid Build Coastguard Worker   // Command line arguments.
30*ab8db090SAndroid Build Coastguard Worker   int    argc;
31*ab8db090SAndroid Build Coastguard Worker   char **argv;
32*ab8db090SAndroid Build Coastguard Worker 
33*ab8db090SAndroid Build Coastguard Worker   // Option settings.
34*ab8db090SAndroid Build Coastguard Worker   const cmdopt_option *longopts;
35*ab8db090SAndroid Build Coastguard Worker   const char          *optstring;
36*ab8db090SAndroid Build Coastguard Worker 
37*ab8db090SAndroid Build Coastguard Worker   int   optind;     // Index of the next argument.
38*ab8db090SAndroid Build Coastguard Worker   char *nextchar;   // Next character.
39*ab8db090SAndroid Build Coastguard Worker   char *optarg;     // Argument of the last option.
40*ab8db090SAndroid Build Coastguard Worker   int   optopt;     // Label of the last option.
41*ab8db090SAndroid Build Coastguard Worker   char *optlong;    // Long option.
42*ab8db090SAndroid Build Coastguard Worker   int   opterr;     // Warning level (0: nothing, 1: warning, 2: all).
43*ab8db090SAndroid Build Coastguard Worker   int   longindex;  // Index of the last long option.
44*ab8db090SAndroid Build Coastguard Worker   int   optnum;     // Number of options.
45*ab8db090SAndroid Build Coastguard Worker } cmdopt_t;
46*ab8db090SAndroid Build Coastguard Worker 
47*ab8db090SAndroid Build Coastguard Worker // cmdopt_init() initializes a cmdopt_t for successive cmdopt_next()s.
48*ab8db090SAndroid Build Coastguard Worker void cmdopt_init(cmdopt_t *h, int argc, char **argv,
49*ab8db090SAndroid Build Coastguard Worker     const char *optstring, const cmdopt_option *longopts);
50*ab8db090SAndroid Build Coastguard Worker 
51*ab8db090SAndroid Build Coastguard Worker // cmdopt_get() analyzes command line arguments and gets the next option.
52*ab8db090SAndroid Build Coastguard Worker int cmdopt_get(cmdopt_t *h);
53*ab8db090SAndroid Build Coastguard Worker 
54*ab8db090SAndroid Build Coastguard Worker #ifdef  __cplusplus
55*ab8db090SAndroid Build Coastguard Worker }  // extern "C"
56*ab8db090SAndroid Build Coastguard Worker #endif
57*ab8db090SAndroid Build Coastguard Worker 
58*ab8db090SAndroid Build Coastguard Worker #endif  // MARISA_CMDOPT_H_
59