source: libcfa/src/parseargs.hfa @ 18f0b70

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 18f0b70 was 419c434, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Added support for printing the usage as parseargs would,
without the option --help or an error in parsing args.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#pragma once
2
3struct 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
11extern cfa_option last_option;
12
13static inline void ?{}( cfa_option & this ) {}
14
15forall(dtype T | { bool parse(const char *, T & ); })
16static 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
24forall(dtype T)
25static 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
33void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left );
34void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
35
36void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
37void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
38
39bool parse_yesno   (const char *, bool & );
40bool parse_settrue (const char *, bool & );
41bool parse_setfalse(const char *, bool & );
42
43bool parse(const char *, const char * & );
44bool parse(const char *, int & );
45bool parse(const char *, unsigned & );
46bool parse(const char *, unsigned long & );
47bool parse(const char *, unsigned long long & );
48bool parse(const char *, double & );
Note: See TracBrowser for help on using the repository browser.