-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_opts.h
112 lines (95 loc) · 2.78 KB
/
get_opts.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
107
108
109
110
111
112
#ifndef INC_GET_OPTS_H
#define INC_GET_OPTS_H
typedef struct stringlist_elem {
char **sl;
unsigned int n;
} sl_elem;
typedef struct charlist_elem {
char *cl;
unsigned int n;
} cl_elem;
typedef struct intlist_elem {
int *il;
unsigned int n;
} il_elem;
typedef char opt_bool_t;
typedef char opt_char_t;
typedef char opt_type_t;
typedef char * opt_string_t;
typedef int opt_int_t;
typedef long opt_long_t;
typedef short opt_short_t;
typedef unsigned int opt_uint_t;
typedef unsigned long opt_ulong_t;
typedef unsigned short opt_ushort_t;
typedef char opt_toggle_t;
typedef int opt_increment_t;
typedef sl_elem * opt_stringlist_t;
typedef cl_elem * opt_charlist_t;
typedef il_elem * opt_intlist_t;
typedef void * opt_ptr_t;
typedef union _opt_value {
opt_int_t opt_int;
opt_long_t opt_long;
opt_short_t opt_short;
opt_uint_t opt_uint;
opt_ulong_t opt_ulong;
opt_ushort_t opt_ushort;
opt_bool_t opt_bool;
opt_char_t opt_char;
opt_string_t opt_string;
opt_toggle_t opt_toggle;
opt_increment_t opt_increment;
opt_stringlist_t opt_stringlist;
opt_charlist_t opt_charlist;
opt_intlist_t opt_intlist;
opt_ptr_t opt_ptr;
} opt_value;
typedef struct _opt {
opt_bool_t i_opt; /* should be 1 for all real options */
const char *s_opt;
const char *l_opt;
opt_type_t t_opt;
opt_value v_opt;
int (*f_opt)();
} opt;
typedef struct _optx {
opt_bool_t i_opt; /* should be 1 for all real options */
const char *s_opt;
const char *l_opt;
opt_type_t t_opt;
opt_value *v_opt;
int (*f_opt)();
const char *help;
} optx;
#define OPT_BOOL 0x00
#define OPT_CHAR 0x01
#define OPT_STRING 0x02
#define OPT_INT 0x03
#define OPT_LONG 0x04
#define OPT_SHORT 0x05
#define OPT_UINT 0x06
#define OPT_ULONG 0x07
#define OPT_USHORT 0x08
#define OPT_TOGGLE 0x09
#define OPT_INCREMENT 0x0A
#define OPT_STRINGLIST 0x0B
#define OPT_CHARLIST 0x0C
#define OPT_INTLIST 0x0D
#define OPT_PTR 0x0E
#define I_END 0x00
#define I_OPT 0x01
#define OPT_DELIM '-'
/* special variables */
extern opt o_end;
/* special preprocessor functions */
#define add_opt(name,s,l,t,v,f) opt name = {I_OPT,s,l,t,(opt_value)v,f}
#define put_opts(optionlist,opts...) opt *optionlist[] = { opts , &o_end}
extern int try_opt(char ***, opt **);
extern int get_opts(char ***, char **, char **, int, opt **);
extern void opt_free(char **);
extern void *new_list(opt_type_t t_list);
extern char opt_strcmp(const char*, const char*);
extern int gather_opt(char ***, opt **);
extern int get_opts_errormatic(char ***, char **, int, opt **);
#endif /* !INC_GET_OPTS_H */