1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // parseargs.cfa -- PUBLIC |
---|
8 | // API for arguments parsing (argc, argv) |
---|
9 | // |
---|
10 | // Author : Thierry Delisle |
---|
11 | // Created On : Wed Oct 12 15:28:01 2022 |
---|
12 | // Last Modified By : |
---|
13 | // Last Modified On : |
---|
14 | // Update Count : |
---|
15 | // |
---|
16 | #pragma once |
---|
17 | |
---|
18 | struct cfa_option { |
---|
19 | int val; // reserved |
---|
20 | char short_name; |
---|
21 | const char * long_name; |
---|
22 | const char * help; |
---|
23 | void * variable; |
---|
24 | bool (*parse)(const char *, void * ); |
---|
25 | }; |
---|
26 | |
---|
27 | extern cfa_option last_option; |
---|
28 | |
---|
29 | static inline void ?{}( cfa_option & this ) {} |
---|
30 | |
---|
31 | forall(T & | { bool parse(const char *, T & ); }) |
---|
32 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) { |
---|
33 | this.val = 0; |
---|
34 | this.short_name = short_name; |
---|
35 | this.long_name = long_name; |
---|
36 | this.help = help; |
---|
37 | this.variable = (void*)&variable; |
---|
38 | this.parse = (bool (*)(const char *, void * ))parse; |
---|
39 | } |
---|
40 | |
---|
41 | forall(T &) |
---|
42 | static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) { |
---|
43 | this.val = 0; |
---|
44 | this.short_name = short_name; |
---|
45 | this.long_name = long_name; |
---|
46 | this.help = help; |
---|
47 | this.variable = (void*)&variable; |
---|
48 | this.parse = (bool (*)(const char *, void * ))parse; |
---|
49 | } |
---|
50 | |
---|
51 | void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left ); |
---|
52 | void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left ); |
---|
53 | |
---|
54 | void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error) __attribute__ ((noreturn)); |
---|
55 | void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error) __attribute__ ((noreturn)); |
---|
56 | |
---|
57 | bool parse_yesno (const char *, bool & ); |
---|
58 | bool parse_truefalse(const char *, bool & ); |
---|
59 | bool parse_settrue (const char *, bool & ); |
---|
60 | bool parse_setfalse (const char *, bool & ); |
---|
61 | |
---|
62 | bool parse(const char *, const char * & ); |
---|
63 | bool parse(const char *, int & ); |
---|
64 | bool parse(const char *, unsigned & ); |
---|
65 | bool parse(const char *, unsigned long & ); |
---|
66 | bool parse(const char *, unsigned long long & ); |
---|
67 | bool parse(const char *, double & ); |
---|