-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmce-command-line.h
91 lines (75 loc) · 2.69 KB
/
mce-command-line.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* @file mce-command-line.h
*
* Command line parameter parsing module for the Mode Control Entity
* <p>
* Copyright © 2014 Jolla Ltd.
* <p>
* @author Simo Piiroinen <[email protected]>
*
* mce is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* mce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mce. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MCE_COMMAND_LINE_H_
# define MCE_COMMAND_LINE_H_
# include <stdbool.h>
# ifdef __cplusplus
extern "C" {
# elif 0
} /* fool JED indentation ... */
# endif
/* ========================================================================= *
* TYPES
* ========================================================================= */
typedef struct mce_opt_t mce_opt_t;
/** Option handler callback
*
* Both with_arg and without_arg callbacks use this type. This allows
* the same callback function to be used for handling both. The arg
* is NULL only when without_arg handler is called.
*
* @param arg option arg or NULL
*
* @return false to stop command line parsing and return error from
* mce_command_line_parse(), or true to keep going
*/
typedef bool (*mce_opt_parser_fn)(const char *arg);
/** Information about command line option
*
* If both with_arg and witout_arg callbacks are defined, providing
* option argument is optional.
*/
struct mce_opt_t
{
/** Long option name; NULL for sentinel element */
const char *name;
/** Short option flag character; 0 for none */
int flag;
/** Description text for option argument; NULL if not used */
const char *values;
/** Usage information text for the option */
const char *usage;
/** Callback to use when option argument is provided */
mce_opt_parser_fn with_arg;
/** Callback to use when no option argument is provided */
mce_opt_parser_fn without_arg;
};
/* ========================================================================= *
* INTERFACE FUNCTIONS
* ========================================================================= */
void mce_command_line_usage(const mce_opt_t *opts, const char *arg);
void mce_command_line_usage_keys(const mce_opt_t *opts, char **keys);
bool mce_command_line_parse(const mce_opt_t *opts, int argc, char **argv);
# ifdef __cplusplus
};
# endif
#endif /* MCE_COMMAND_LINE_H_ */