source: libcfa/src/parseargs.hfa@ d0fa494

ADT ast-experimental
Last change on this file since d0fa494 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
RevLine 
[481f882]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//
[7f389a5c]16#pragma once
17
18struct cfa_option {
[80d3b1b]19 int val; // reserved
[7f389a5c]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
[fd54fef]31forall(T & | { bool parse(const char *, T & ); })
[7f389a5c]32static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) {
[80d3b1b]33 this.val = 0;
[7f389a5c]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
[fd54fef]41forall(T &)
[7f389a5c]42static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) {
[80d3b1b]43 this.val = 0;
[7f389a5c]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
[7874d77]51void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left );
[7f389a5c]52void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
53
[419c434]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
[d411769c]57bool parse_yesno (const char *, bool & );
58bool parse_truefalse(const char *, bool & );
59bool parse_settrue (const char *, bool & );
60bool parse_setfalse (const char *, bool & );
[7f389a5c]61
62bool parse(const char *, const char * & );
[7f6e9eb]63bool parse(const char *, int & );
[53e4562]64bool parse(const char *, unsigned & );
[56e8cb3]65bool parse(const char *, unsigned long & );
66bool parse(const char *, unsigned long long & );
[cd02108]67bool parse(const char *, double & );
Note: See TracBrowser for help on using the repository browser.