blob: 62358dff05d8d143414cfd338cbb4efab4b32d33 (
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_OPTPARSE_H
#define MLIB_OPTPARSE_H
#include <stddef.h>
#include "__charN_t.h"
#include "__rune.h"
#include "__u8view.h"
struct optparse {
bool _b;
int _subopt;
char **_argv;
int optind;
char errmsg[128];
struct u8view optarg;
};
enum op_argkind {
OPT_NONE,
OPT_OPT,
OPT_REQ,
};
struct op_option {
rune shortopt;
struct u8view longopt;
enum op_argkind argtype;
};
[[__nodiscard__]] rune optparse(struct optparse *, const struct op_option *,
size_t);
[[gnu::__always_inline__]]
static inline struct optparse
mkoptparser(char **argv)
{
return (struct optparse){
._argv = argv,
.optind = argv[0] != nullptr,
};
}
#endif /* !MLIB_OPTPARSE_H */
|