source: libcfa/src/parseargs.hfa @ 90ecade

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 90ecade 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
RevLine 
[7f389a5c]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
[7874d77]33void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left );
[7f389a5c]34void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
35
[419c434]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
[7f389a5c]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 * & );
[7f6e9eb]44bool parse(const char *, int & );
[53e4562]45bool parse(const char *, unsigned & );
[56e8cb3]46bool parse(const char *, unsigned long & );
47bool parse(const char *, unsigned long long & );
[cd02108]48bool parse(const char *, double & );
Note: See TracBrowser for help on using the repository browser.