-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.h
106 lines (90 loc) · 1.73 KB
/
program.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef _PROG_PARSE_H
#define _PROG_PARSE_H
#include <linux/types.h>
#include <getopt.h>
#include <stdbool.h>
extern int print_word_wrapped(const char *s, int indent, int start);
enum flags_masks {
F_VERBOSE_MASK = 0xf,
F_VENDOR_SPEC_SHIFT = 4,
F_RESERVED_FIELDS_SHIFT = 5,
};
enum flags {
F_TERSE = 0,
F_NORMAL = 1,
F_VERBOSE = 2,
F_DETAILED = 3,
F_VENDOR_SPEC = 1 << F_VENDOR_SPEC_SHIFT,
F_RESERVED_FIELDS = 1 << F_RESERVED_FIELDS_SHIFT,
};
typedef uint8_t U8;
typedef uint16_t U16;
typedef uint32_t U32;
typedef uint64_t U64;
typedef void* U64_LIST;
typedef void* U32_LIST;
typedef void* U16_LIST;
typedef void* U8_LIST;
typedef int INC;
typedef int FMT;
typedef bool FLAG;
typedef char* STRING;
typedef FILE* FILE_A;
typedef FILE* FILE_R;
typedef FILE* FILE_W;
typedef FILE* FILE_AP;
typedef FILE* FILE_RP;
typedef FILE* FILE_WP;
enum output_format {
NORMAL,
JSON,
BINARY,
HEX,
};
enum option_type {
TYPE_U8,
TYPE_U16,
TYPE_U32,
TYPE_U64,
TYPE_FMT,
TYPE_U8_LIST,
TYPE_U16_LIST,
TYPE_U32_LIST,
TYPE_U64_LIST,
TYPE_STRING,
TYPE_FLAG,
TYPE_INC,
TYPE_FILE_A,
TYPE_FILE_R,
TYPE_FILE_W,
TYPE_FILE_AP,
TYPE_FILE_RP,
TYPE_FILE_WP,
TYPE_END,
};
struct command_option {
enum option_type type;
char *long_option;
char short_option;
char *desc;
char *meta;
void *value;
uint64_t limit;
bool deprecated;
};
struct command {
const char *name;
const char *short_desc;
const char *long_desc;
const char *usage;
int (*callback)(int argc, char ** argv, struct command *cmd);
bool deprecated;
struct command **subcommands;
struct command_option options[];
};
struct program {
char *version;
struct command command;
};
extern int parse_args(int argc, char **argv, struct command *command);
#endif /* _PROG_PARSE_H */