#include #include "parseconfig.hfa" bool comments( ifstream & in, char * name ) { while () { in | name; if ( fail( in ) ) return true; if ( name[0] != '#' ) break; in | nl; // ignore remainder of line } // for return false; } // comments // Process the configuration file to set the simulation parameters. void parse_config( const char * config_file, config_entry entries[], size_t num_entries ) { ifstream in; try { open( in, config_file ); // open the configuration file for input while () { char * key; char * value; if ( comments( in, key ) ) break; // eof ? // Should we just overwrite duplicate config entries? Having a hash map would make this much easier in | value; if ( value < 0 ) { close( in ); exit | "Error: file \"" | configFile | "\" parameter " | name | " value " | value | " must be non-negative."; } // if if ( fail( in ) ) break; in | nl; // ignore remainder of line } // for } catch( Open_Failure * ex; ex->istream == &in ) { exit | "Error: could not open input file \"" | config_file | "\""; } // try close( in ); // *** WE MUST ALLOW SOME SORT OF VALIDATION FUNCTIONALITY TOO!!! *** } // processConfigFile // Local Variables: // // tab-width: 4 // // compile-command: "cfa parseconfig.cfa" // // End: //