source: libcfa/src/parseargs.hfa @ 4269d1b

Last change on this file since 4269d1b was d1abc63c, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Change parse args to use new arrays instead of C arrays.
Also added const ?? to arrays.

  • Property mode set to 100644
File size: 2.8 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
[d1abc63c]18#include <array.hfa>
19
[7f389a5c]20struct cfa_option {
[d1abc63c]21        int val; // reserved
22        char short_name;
23        const char * long_name;
24        const char * help;
25        void * variable;
26        bool (*parse)(const char *, void * );
[7f389a5c]27};
28
29extern cfa_option last_option;
30
31static inline void ?{}( cfa_option & this ) {}
32
[fd54fef]33forall(T & | { bool parse(const char *, T & ); })
[7f389a5c]34static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable ) {
[d1abc63c]35        this.val        = 0;
36        this.short_name = short_name;
37        this.long_name  = long_name;
38        this.help       = help;
39        this.variable   = (void*)&variable;
40        this.parse      = (bool (*)(const char *, void * ))parse;
[7f389a5c]41}
42
[fd54fef]43forall(T &)
[7f389a5c]44static inline void ?{}( cfa_option & this, char short_name, const char * long_name, const char * help, T & variable, bool (*parse)(const char *, T & )) {
[d1abc63c]45        this.val        = 0;
46        this.short_name = short_name;
47        this.long_name  = long_name;
48        this.help       = help;
49        this.variable   = (void*)&variable;
50        this.parse      = (bool (*)(const char *, void * ))parse;
[7f389a5c]51}
52
[7874d77]53void parse_args( cfa_option options[], size_t opt_count, const char * usage, char ** & left );
[7f389a5c]54void parse_args( int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, char ** & left );
55
[d1abc63c]56forall( [N] ) {
57        void parse_args( const array( cfa_option, N ) & options, const char * usage, char ** & left );
58        void parse_args( int argc, char * argv[], const array( cfa_option, N ) & options, const char * usage, char ** & left );
59}
60
[419c434]61void print_args_usage(cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
62void print_args_usage(int argc, char * argv[], cfa_option options[], size_t opt_count, const char * usage, bool error)  __attribute__ ((noreturn));
63
[d1abc63c]64forall( [N] ) {
65        void print_args_usage( const array(cfa_option, N ) & options, const char * usage, bool error)  __attribute__ ((noreturn));
66        void print_args_usage(int argc, char * argv[], const array( cfa_option, N ) & options, const char * usage, bool error)  __attribute__ ((noreturn));
67}
68
[d411769c]69bool parse_yesno    (const char *, bool & );
70bool parse_truefalse(const char *, bool & );
71bool parse_settrue  (const char *, bool & );
72bool parse_setfalse (const char *, bool & );
[7f389a5c]73
74bool parse(const char *, const char * & );
[7f6e9eb]75bool parse(const char *, int & );
[53e4562]76bool parse(const char *, unsigned & );
[56e8cb3]77bool parse(const char *, unsigned long & );
78bool parse(const char *, unsigned long long & );
[cd02108]79bool parse(const char *, double & );
Note: See TracBrowser for help on using the repository browser.