[7f389a5c] | 1 | #pragma once |
---|
| 2 | |
---|
| 3 | struct cfa_option { |
---|
[80d3b1b] | 4 | int val; // reserved |
---|
[7f389a5c] | 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 | |
---|
[fd54fef] | 16 | forall(T & | { bool parse(const char *, T & ); }) |
---|
[7f389a5c] | 17 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) { |
---|
[80d3b1b] | 18 | this.val = 0; |
---|
[7f389a5c] | 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 | |
---|
[fd54fef] | 26 | forall(T &) |
---|
[7f389a5c] | 27 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) { |
---|
[80d3b1b] | 28 | this.val = 0; |
---|
[7f389a5c] | 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 | |
---|
[7874d77] | 36 | void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left ); |
---|
[7f389a5c] | 37 | void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left ); |
---|
| 38 | |
---|
[419c434] | 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 | |
---|
[d411769c] | 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 & ); |
---|
[7f389a5c] | 46 | |
---|
| 47 | bool parse(const char *, const char * & ); |
---|
[7f6e9eb] | 48 | bool parse(const char *, int & ); |
---|
[53e4562] | 49 | bool parse(const char *, unsigned & ); |
---|
[56e8cb3] | 50 | bool parse(const char *, unsigned long & ); |
---|
| 51 | bool parse(const char *, unsigned long long & ); |
---|
[cd02108] | 52 | bool parse(const char *, double & ); |
---|