Changeset 4df8fef5


Ignore:
Timestamp:
Aug 31, 2021, 1:49:09 AM (3 years ago)
Author:
Jacob Prud'homme <jafprudhomme@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
Children:
5e0e488
Parents:
31337d8
git-author:
Jacob Prud'homme <jafprudhomme@…> (07/13/21 12:36:19)
git-committer:
Jacob Prud'homme <jafprudhomme@…> (08/31/21 01:49:09)
Message:

Restructured parseconfig to work like parseargs

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseconfig.cfa

    r31337d8 r4df8fef5  
    1313
    1414// Process the configuration file to set the simulation parameters.
    15 void parseConfig( const char * configFile, ConfigParms & cparms ) {
    16                 ifstream in;
     15void parse_config( const char * config_file, config_entry entries[], size_t num_entries ) {
     16        ifstream in;
    1717        try {
    18                 open( in, configFile );                                                 // open the configuration file for input
     18                open( in, config_file );                                                        // open the configuration file for input
    1919
    2020                while () {
    21                   if ( comments( in, name ) ) break;                    // eof ?
     21                        char * key;
     22                        char * value;
     23                  if ( comments( in, key ) ) break;                     // eof ?
    2224                        // Should we just overwrite duplicate config entries? Having a hash map would make this much easier
    2325                        in | value;
     
    3133                } // for
    3234        } catch( Open_Failure * ex; ex->istream == &in ) {
    33                 exit | "Error: could not open input file \"" | configFile | "\"";
     35                exit | "Error: could not open input file \"" | config_file | "\"";
    3436        } // try
    3537        close( in );
  • libcfa/src/parseconfig.hfa

    r31337d8 r4df8fef5  
    1515}; // ConfigParms
    1616
    17 void parseConfig( const char * configFile, ConfigParms & cparms );
     17struct config_entry {
     18        const char * key;
     19        void * variable;
     20        bool (*parse)(const char *, void *);
     21};
     22
     23static inline void ?{}( config_entry & this ) {}
     24
     25forall(T & | { bool parse(const char *, T & ); })
     26static inline void ?{}( config_entry & this, const char * key, T & variable ) {
     27        this.key      = key;
     28        this.variable = (void *)&variable;
     29        this.parse    = (bool (*)(const char *, void *))parse;
     30}
     31
     32forall(T &)
     33static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) {
     34        this.key      = key;
     35        this.variable = (void *)&variable;
     36        this.parse    = (bool (*)(const char *, void *))parse;
     37}
     38
     39void parse_config( const char * config_file, config_entry entries[], size_t num_entries );
    1840
    1941// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.