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
RevLine 
[1896c1f]1#include <fstream.hfa>
[16f9aca]2#include "parseconfig.hfa"
3
[2c2d32b]4bool comments( ifstream & in, char * name ) {
[181ef73]5        while () {
[1896c1f]6                in | name;
7          if ( fail( in ) ) return true;
[2c2d32b]8          if ( name[0] != '#' ) break;
[1896c1f]9                in | nl;        // ignore remainder of line
[16f9aca]10        } // for
11        return false;
12} // comments
13
14// Process the configuration file to set the simulation parameters.
[4df8fef5]15void parse_config( const char * config_file, config_entry entries[], size_t num_entries ) {
16        ifstream in;
[c2016b6]17        try {
[4df8fef5]18                open( in, config_file );                                                        // open the configuration file for input
[16f9aca]19
[ff3be413]20                while () {
[4df8fef5]21                        char * key;
22                        char * value;
23                  if ( comments( in, key ) ) break;                     // eof ?
[ff3be413]24                        // Should we just overwrite duplicate config entries? Having a hash map would make this much easier
[1896c1f]25                        in | value;
[16f9aca]26                        if ( value < 0 ) {
[3c124da]27                                close( in );
[1896c1f]28                                exit | "Error: file \"" | configFile | "\" parameter " | name
[31337d8]29                                         | " value " | value | " must be non-negative.";
[16f9aca]30                        } // if
[1896c1f]31                  if ( fail( in ) ) break;
32                        in | nl; // ignore remainder of line
[16f9aca]33                } // for
[1896c1f]34        } catch( Open_Failure * ex; ex->istream == &in ) {
[4df8fef5]35                exit | "Error: could not open input file \"" | config_file | "\"";
[16f9aca]36        } // try
[ff3be413]37        close( in );
38        // *** WE MUST ALLOW SOME SORT OF VALIDATION FUNCTIONALITY TOO!!! ***
[16f9aca]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.