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