1 | #pragma once |
---|
2 | |
---|
3 | struct cfa_option { |
---|
4 | int val; // reserved |
---|
5 | char short_name; |
---|
6 | const char * long_name; |
---|
7 | const char * help; |
---|
8 | void * variable; |
---|
9 | bool (*parse)(const char *, void * ); |
---|
10 | }; |
---|
11 | |
---|
12 | extern cfa_option last_option; |
---|
13 | |
---|
14 | static inline void ?{}( cfa_option & this ) {} |
---|
15 | |
---|
16 | forall(dtype T | { bool parse(const char *, T & ); }) |
---|
17 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) { |
---|
18 | this.val = 0; |
---|
19 | this.short_name = short_name; |
---|
20 | this.long_name = long_name; |
---|
21 | this.help = help; |
---|
22 | this.variable = (void*)&variable; |
---|
23 | this.parse = (bool (*)(const char *, void * ))parse; |
---|
24 | } |
---|
25 | |
---|
26 | forall(dtype T) |
---|
27 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) { |
---|
28 | this.val = 0; |
---|
29 | this.short_name = short_name; |
---|
30 | this.long_name = long_name; |
---|
31 | this.help = help; |
---|
32 | this.variable = (void*)&variable; |
---|
33 | this.parse = (bool (*)(const char *, void * ))parse; |
---|
34 | } |
---|
35 | |
---|
36 | void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left ); |
---|
37 | void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left ); |
---|
38 | |
---|
39 | void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error) __attribute__ ((noreturn)); |
---|
40 | void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error) __attribute__ ((noreturn)); |
---|
41 | |
---|
42 | bool parse_yesno (const char *, bool & ); |
---|
43 | bool parse_truefalse(const char *, bool & ); |
---|
44 | bool parse_settrue (const char *, bool & ); |
---|
45 | bool parse_setfalse (const char *, bool & ); |
---|
46 | |
---|
47 | bool parse(const char *, const char * & ); |
---|
48 | bool parse(const char *, int & ); |
---|
49 | bool parse(const char *, unsigned & ); |
---|
50 | bool parse(const char *, unsigned long & ); |
---|
51 | bool parse(const char *, unsigned long long & ); |
---|
52 | bool parse(const char *, double & ); |
---|