source: libcfa/src/parseargs.hfa@ ce7d197

ADT ast-experimental
Last change on this file since ce7d197 was 481f882, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Added some missing headers and cleaned up some of the fork+exec stuff.

  • Property mode set to 100644
File size: 2.4 KB
Line 
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
18struct 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
27extern cfa_option last_option;
28
29static inline void ?{}( cfa_option & this ) {}
30
31forall(T & | { bool parse(const char *, T & ); })
32static 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
41forall(T &)
42static 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
51void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left );
52void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
53
54void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error) __attribute__ ((noreturn));
55void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error) __attribute__ ((noreturn));
56
57bool parse_yesno (const char *, bool & );
58bool parse_truefalse(const char *, bool & );
59bool parse_settrue (const char *, bool & );
60bool parse_setfalse (const char *, bool & );
61
62bool parse(const char *, const char * & );
63bool parse(const char *, int & );
64bool parse(const char *, unsigned & );
65bool parse(const char *, unsigned long & );
66bool parse(const char *, unsigned long long & );
67bool parse(const char *, double & );
Note: See TracBrowser for help on using the repository browser.