- Timestamp:
- Aug 31, 2021, 1:49:09 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
- Children:
- 31337d8
- Parents:
- 50dcfad
- git-author:
- Jacob Prud'homme <jafprudhomme@…> (07/06/21 11:59:58)
- git-committer:
- Jacob Prud'homme <jafprudhomme@…> (08/31/21 01:49:09)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseconfig.cfa
r50dcfad rff3be413 14 14 // Process the configuration file to set the simulation parameters. 15 15 void parseConfig( const char * configFile, ConfigParms & cparms ) { 16 enum { Parmnum = 11 };17 struct {18 const char * name; // configuration name19 bool used; // already supplied ?20 unsigned int & value; // location to put configuration value21 } parms[Parmnum] = {22 { "StopCost", false, cparms.stopCost },23 { "NumStudents", false, cparms.numStudents },24 { "NumStops", false, cparms.numStops },25 { "MaxNumStudents", false, cparms.maxNumStudents },26 { "TimerDelay", false, cparms.timerDelay },27 { "MaxStudentDelay", false, cparms.maxStudentDelay },28 { "MaxStudentTrips", false, cparms.maxStudentTrips },29 { "GroupoffDelay", false, cparms.groupoffDelay },30 { "ConductorDelay", false, cparms.conductorDelay },31 { "ParentalDelay", false, cparms.parentalDelay },32 { "NumCouriers", false, cparms.numCouriers },33 };34 char * name;35 int value;36 unsigned int cnt, posn, numOfParm = 0;37 38 16 ifstream in; 39 17 try { 40 18 open( in, configFile ); // open the configuration file for input 41 19 42 for ( cnt; Parmnum ) { // parameter names can appear in any order20 while () { 43 21 if ( comments( in, name ) ) break; // eof ? 44 for ( posn; posn < Parmnum && name != parms[posn].name; ++posn ); // linear search 45 if ( posn == Parmnum ) break; // configuration not found ? 46 if ( parms[posn].used ) break; // duplicate configuration ? 22 // Should we just overwrite duplicate config entries? Having a hash map would make this much easier 47 23 in | value; 48 24 if ( value < 0 ) { … … 53 29 if ( fail( in ) ) break; 54 30 in | nl; // ignore remainder of line 55 ++numOfParm;56 parms[posn].used = true;57 parms[posn].value = value;58 31 } // for 59 32 } catch( Open_Failure * ex; ex->istream == &in ) { 60 33 exit | "Error: could not open input file \"" | configFile | "\""; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 61 34 } // try 62 63 close( in ); 64 65 if ( cparms.numStops < 2 ) { 66 exit | "Error: file \"" | configFile | "\" parameter NumStops value " 67 | cparms.numStops | " must be at least 2."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 68 } 69 if ( cparms.numStudents < 1 ) { 70 exit | "Error: file \"" | configFile | "\" parameter NumStudents value " 71 | cparms.numStudents | " must be at least 1."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 72 } 73 if ( cparms.numCouriers < 1 ) { 74 exit | "Error: file \"" | configFile | "\" parameter NumCouriers value " 75 | cparms.numCouriers | " must be at least 1."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 76 } 35 close( in ); 36 // *** WE MUST ALLOW SOME SORT OF VALIDATION FUNCTIONALITY TOO!!! *** 77 37 } // processConfigFile 78 38
Note: See TracChangeset
for help on using the changeset viewer.