blob: 970b2286c2bc2d1ca8dcaf8709e3a575b1f25720 (
plain) (
blame)
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
|
#ifndef MLIB_CLI_H
#define MLIB_CLI_H
#include <stddef.h>
#include "_attrs.h"
#include "_rune.h"
#include "_uNview.h"
struct optparser {
bool _b;
int _subopt;
char **_argv;
int optind;
char errmsg[128];
u8view_t optarg;
};
enum cliarg {
CLI_NONE,
CLI_OPT,
CLI_REQ,
};
struct cli_option {
rune shortopt;
u8view_t longopt;
enum cliarg argtype;
};
[[nodiscard]] rune optparse(struct optparser *, const struct cli_option *,
size_t);
[[_mlib_inline]]
static inline struct optparser
mkoptparser(char **argv)
{
return (struct optparser){
._argv = argv,
.optind = argv[0] != nullptr,
};
}
#endif /* !MLIB_CLI_H */
|