Changeset ff3be413


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:
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)
Message:

Removed code specific to CS 343 assignment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/parseconfig.cfa

    r50dcfad rff3be413  
    1414// Process the configuration file to set the simulation parameters.
    1515void parseConfig( const char * configFile, ConfigParms & cparms ) {
    16         enum { Parmnum = 11 };
    17         struct {
    18                 const char * name;                                                              // configuration name
    19                 bool used;                                                                              // already supplied ?
    20                 unsigned int & value;                                                   // location to put configuration value
    21         } 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 
    3816                ifstream in;
    3917        try {
    4018                open( in, configFile );                                                 // open the configuration file for input
    4119
    42                 for ( cnt; Parmnum ) {                                                  // parameter names can appear in any order
     20                while () {
    4321                  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
    4723                        in | value;
    4824                        if ( value < 0 ) {
     
    5329                  if ( fail( in ) ) break;
    5430                        in | nl; // ignore remainder of line
    55                         ++numOfParm;
    56                         parms[posn].used = true;
    57                         parms[posn].value = value;
    5831                } // for
    5932        } catch( Open_Failure * ex; ex->istream == &in ) {
    6033                exit | "Error: could not open input file \"" | configFile | "\""; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** //
    6134        } // 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!!! ***
    7737} // processConfigFile
    7838
Note: See TracChangeset for help on using the changeset viewer.