Changeset 1896c1f for libcfa/src/parseconfig.cfa
- 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:
- c3c76cd
- Parents:
- 16f9aca
- git-author:
- Jacob Prud'homme <jafprudhomme@…> (06/15/21 11:06:25)
- git-committer:
- Jacob Prud'homme <jafprudhomme@…> (08/31/21 01:49:09)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/parseconfig.cfa
r16f9aca r1896c1f 1 #include <iostream> 2 #include <fstream> 1 #include <fstream.hfa> 3 2 #include <limits> // numeric_limits 4 3 using namespace std; … … 7 6 static bool comments( ifstream & in, string & name ) { 8 7 for ( ;; ) { 9 in >>name;10 if ( in.fail() ) return true;8 in | name; 9 if ( fail( in ) ) return true; 11 10 if ( name.substr(0,1) != "#" ) break; 12 in .ignore( numeric_limits<int>::max(), '\n' ); // ignore remainder of line11 in | nl; // ignore remainder of line 13 12 } // for 14 13 return false; … … 16 15 17 16 // Process the configuration file to set the simulation parameters. 18 void p rocessConfigFile( const char *configFile, ConfigParms & cparms ) {17 void parseConfig( const char * configFile, ConfigParms & cparms ) { 19 18 enum { Parmnum = 11 }; 20 19 struct { … … 40 39 41 40 try { 42 ifstream in( configFile ); // open the configuration file for input 41 ifstream in; 42 43 open( in, configFile ); // open the configuration file for input 43 44 44 45 for ( cnt = 0 ; cnt < Parmnum; cnt += 1 ) { // parameter names can appear in any order … … 47 48 if ( posn == Parmnum ) break; // configuration not found ? 48 49 if ( parms[posn].used ) break; // duplicate configuration ? 49 in >>value;50 in | value; 50 51 if ( value < 0 ) { 51 c err << "Error: file \"" << configFile << "\" parameter " << name52 << " value " << value << " must be non-negative." << endl;53 exit( EXIT_FAILURE );52 close( in ); 53 exit | "Error: file \"" | configFile | "\" parameter " | name 54 | " value " | value | " must be non-negative."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 54 55 } // if 55 if ( in.fail() ) break;56 in.ignore( numeric_limits<int>::max(), '\n' ); // ignore remainder of line56 if ( fail( in ) ) break; 57 in | nl; // ignore remainder of line 57 58 numOfParm += 1; 58 59 parms[posn].used = true; … … 61 62 62 63 if ( numOfParm != Parmnum ) { 63 c err << "Error: file \"" << configFile << "\" is corrupt." << endl;64 exit ( EXIT_FAILURE );64 close( in ); 65 exit | "Error: file \"" | configFile | "\" is corrupt."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 65 66 } // if 66 67 if ( ! comments( in, name ) ) { // ! eof ? 67 c err << "Error: file \"" << configFile << "\" has extraneous data." << endl;68 exit ( EXIT_FAILURE );68 close( in ); 69 exit | "Error: file \"" | configFile | "\" has extraneous data."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 69 70 } // if 70 } catch( uFile::Failure &) {71 c err << "Error: could not open input file \"" << configFile << "\"" << endl;72 exit ( EXIT_FAILURE );71 } catch( Open_Failure * ex; ex->istream == &in ) { 72 close( in ); 73 exit | "Error: could not open input file \"" | configFile | "\""; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 73 74 } // try 74 75 75 if (cparms.numStops < 2) { 76 cerr << "Error: file \"" << configFile << "\" parameter NumStops value " 77 << cparms.numStops << " must be at least 2." << endl; 78 exit( EXIT_FAILURE ); 76 close( in ); 77 78 if ( cparms.numStops < 2 ) { 79 exit | "Error: file \"" | configFile | "\" parameter NumStops value " 80 | cparms.numStops | " must be at least 2."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 79 81 } 80 if (cparms.numStudents < 1) { 81 cerr << "Error: file \"" << configFile << "\" parameter NumStudents value " 82 << cparms.numStudents << " must be at least 1." << endl; 83 exit( EXIT_FAILURE ); 84 } 85 if (cparms.numCouriers < 1) { 86 cerr << "Error: file \"" << configFile << "\" parameter NumCouriers value " 87 << cparms.numCouriers << " must be at least 1." << endl; 88 exit( EXIT_FAILURE ); 89 } 82 if ( cparms.numStudents < 1 ) { 83 exit | "Error: file \"" | configFile | "\" parameter NumStudents value " 84 | cparms.numStudents | " must be at least 1."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 85 } 86 if ( cparms.numCouriers < 1 ) { 87 exit | "Error: file \"" | configFile | "\" parameter NumCouriers value " 88 | cparms.numCouriers | " must be at least 1."; // *** DOES THIS PRINT TO STDERR??? IT MUST!!! *** // 89 } 90 90 } // processConfigFile 91 91
Note: See TracChangeset
for help on using the changeset viewer.