source: libcfa/src/parseconfig.cfa @ 4df8fef5

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationpthread-emulationqualifiedEnum
Last change on this file since 4df8fef5 was 4df8fef5, checked in by Jacob Prud'homme <jafprudhomme@…>, 3 years ago

Restructured parseconfig to work like parseargs

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <fstream.hfa>
2#include "parseconfig.hfa"
3
4bool comments( ifstream & in, char * name ) {
5        while () {
6                in | name;
7          if ( fail( in ) ) return true;
8          if ( name[0] != '#' ) break;
9                in | nl;        // ignore remainder of line
10        } // for
11        return false;
12} // comments
13
14// Process the configuration file to set the simulation parameters.
15void parse_config( const char * config_file, config_entry entries[], size_t num_entries ) {
16        ifstream in;
17        try {
18                open( in, config_file );                                                        // open the configuration file for input
19
20                while () {
21                        char * key;
22                        char * value;
23                  if ( comments( in, key ) ) break;                     // eof ?
24                        // Should we just overwrite duplicate config entries? Having a hash map would make this much easier
25                        in | value;
26                        if ( value < 0 ) {
27                                close( in );
28                                exit | "Error: file \"" | configFile | "\" parameter " | name
29                                         | " value " | value | " must be non-negative.";
30                        } // if
31                  if ( fail( in ) ) break;
32                        in | nl; // ignore remainder of line
33                } // for
34        } catch( Open_Failure * ex; ex->istream == &in ) {
35                exit | "Error: could not open input file \"" | config_file | "\"";
36        } // try
37        close( in );
38        // *** WE MUST ALLOW SOME SORT OF VALIDATION FUNCTIONALITY TOO!!! ***
39} // processConfigFile
40
41// Local Variables: //
42// tab-width: 4 //
43// compile-command: "cfa parseconfig.cfa" //
44// End: //
Note: See TracBrowser for help on using the repository browser.