source: libcfa/src/parseargs.hfa @ 79e261b7

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

Libcfa parseargs now supports arguments that don't have short options

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#pragma once
2
3struct cfa_option {
4      int val; // reserved
5      char short_name;
6      const char * long_name;
7      const char * help;
8      void * variable;
9      bool (*parse)(const char *, void * );
10};
11
12extern cfa_option last_option;
13
14static inline void ?{}( cfa_option & this ) {}
15
16forall(dtype T | { bool parse(const char *, T & ); })
17static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) {
18      this.val        = 0;
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
26forall(dtype T)
27static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) {
28      this.val        = 0;
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
36void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left );
37void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
38
39void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
40void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
41
42bool parse_yesno    (const char *, bool & );
43bool parse_truefalse(const char *, bool & );
44bool parse_settrue  (const char *, bool & );
45bool parse_setfalse (const char *, bool & );
46
47bool parse(const char *, const char * & );
48bool parse(const char *, int & );
49bool parse(const char *, unsigned & );
50bool parse(const char *, unsigned long & );
51bool parse(const char *, unsigned long long & );
52bool parse(const char *, double & );
Note: See TracBrowser for help on using the repository browser.