source: libcfa/src/parseargs.hfa @ d411769c

arm-ehjacob/cs343-translationnew-ast-unique-expr
Last change on this file since d411769c was d411769c, checked in by Thierry Delisle <tdelisle@…>, 12 months ago

Added a new boolean parser

  • Property mode set to 100644
File size: 1.9 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_truefalse(const char *, bool & );
41bool parse_settrue  (const char *, bool & );
42bool parse_setfalse (const char *, bool & );
43
44bool parse(const char *, const char * & );
45bool parse(const char *, int & );
46bool parse(const char *, unsigned & );
47bool parse(const char *, unsigned long & );
48bool parse(const char *, unsigned long long & );
49bool parse(const char *, double & );
Note: See TracBrowser for help on using the repository browser.