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