src/NFinput/rnfRunner.cpp
// reads in the RNF file, and overwrites any argument it finds
reads in the RNF file, and overwrites any argument it finds
reads in the RNF file and overwrites any argument it finds
bool NFinput::readRNFfile(map<string,string> &argMap, vector<string> &commands, bool verbose)
{
	if (argMap.find("rnf")!=argMap.end())
	{
		string filename = argMap.find("rnf")->second;
		if(!filename.empty())
		{
			ifstream rnfFile(filename.c_str());
			string line; int lineCounter=0;
			bool started = false; bool ended = false;
			if (rnfFile.is_open()) {
				while (! rnfFile.eof() ) {
					lineCounter++;
					getline(rnfFile,line);
					NFutil::trim(line);
					string::size_type pos = line.find_first_of("#");
					if(pos!=string::npos) {
						line = line.substr(0,pos);
						NFutil::trim(line);
					}
					if(line.size()==0) { continue; }
					pos = line.find("begin");
					if(pos!=string::npos) {
						started = true;
						continue;
					}
					pos = line.find("end");
					if(pos!=string::npos) {
						ended = true;
						break;
					}
					if(started) {
						commands.push_back(line);
						continue;
					}
					pos = line.find_first_of("-");
					if(pos==string::npos || pos!=0) {
						cout<<"\nSyntax error in rnf file: '"<<filename<<"' on line ["<<lineCounter<<"]\n";
						cout<<"   >> "+line+"\n";
						cout<<"   This line gives no argument and is not commented out."<<endl;
						break;
					}
					string::size_type firstWhiteSpace = line.find_first_of(" \t");
					string argName = "";
					string argValue = "";
					if(firstWhiteSpace==string::npos) {
						argName = line.substr(1,line.size()-1);
						argValue = "";
					} else {
						argName = line.substr(1,firstWhiteSpace-1);
						argValue = line.substr(firstWhiteSpace,line.size()-1);
						NFutil::trim(argValue);
					}
					if(argName=="sim" || argName=="eq") {
						cout<<"\nWarning in RNF file: '"<<filename<<"' on line ["<<lineCounter<<"]\n";
						cout<<"   >> "+line+"\n";
						cout<<"   The "<<argName<<" argument cannot be used in an RNF script.  Instead, add the\n";
						cout<<"   "<<argName<<" command to the execution block.  See the NFsim manual for details.\n"<<endl;
						continue;
					} else if(argName=="oSteps") {
						cout<<"\nWarning in RNF file: '"<<filename<<"' on line ["<<lineCounter<<"]\n";
						cout<<"   >> "+line+"\n";
						cout<<"   The oSteps argument cannot be used in an RNF script.  Instead, the\n";
						cout<<"   output steps should be specified with the sim command in the \n";
						cout<<"   execution block.  See the NFsim manual for details.\n"<<endl;
						continue;
					}
					if(argMap.find(argName)!=argMap.end()) {
						cout<<"\nSyntax error in rnf file: '"<<filename<<"' on line ["<<lineCounter<<"]\n";
						cout<<"   >> "+line+"\n";
						cout<<"   This argument was previously defined either in the actual command line\n";
						cout<<"   or directly in this RNF file."<<endl;
						break;
					}
					argMap[argName] = argValue;
				}
				if(!ended && started) {
					cout<<"\nSyntax error in RNF file: '"<<filename<<"' on line ["<<lineCounter<<"]\n";
					cout<<"   Execution block starting with 'begin' tag is not properly closed with an 'end' tag."<<endl;
					return false;
				}
				rnfFile.close();
			}
			else {
				cout<<"\n   Error when opening the rnf file named: '"<<filename.c_str()<<"'"<<endl;
				cout<<"   File not found or is not accessible."<<endl;
				return false;
			}
		}
	} else {
		cout<<"\nCouldn't open the rnf file.  No -rnf [filename] flag given."<<endl;
		return false;
	}
	return true;
}
bool NFinput :: readRNFfile ( map < string , string > & argMap , vector < string > & commands , bool verbose ) { if ( argMap . find ( " " ) != argMap . end ( ) ) { string filename = argMap . find ( " " ) -> second ; if ( ! filename . empty ( ) ) { ifstream rnfFile ( filename . c_str ( ) ) ; string line ; int lineCounter = 0 ; bool started = false ; bool ended = false ; if ( rnfFile . is_open ( ) ) { while ( ! rnfFile . eof ( ) ) { lineCounter ++ ; getline ( rnfFile , line ) ; NFutil :: trim ( line ) ; string :: size_type pos = line . find_first_of ( " " ) ; if ( pos != string :: npos ) { line = line . substr ( 0 , pos ) ; NFutil :: trim ( line ) ; } if ( line . size ( ) == 0 ) { continue ; } pos = line . find ( " " ) ; if ( pos != string :: npos ) { started = true ; continue ; } pos = line . find ( " " ) ; if ( pos != string :: npos ) { ended = true ; break ; } if ( started ) { commands . push_back ( line ) ; continue ; } pos = line . find_first_of ( " " ) ; if ( pos == string :: npos || pos != 0 ) { cout << " \n " << filename << " " << lineCounter << " \n " ; cout << " " + line + " \n " ; cout << " " << endl ; break ; } string :: size_type firstWhiteSpace = line . find_first_of ( " \t " ) ; string argName = " " ; string argValue = " " ; if ( firstWhiteSpace == string :: npos ) { argName = line . substr ( 1 , line . size ( ) - 1 ) ; argValue = " " ; } else { argName = line . substr ( 1 , firstWhiteSpace - 1 ) ; argValue = line . substr ( firstWhiteSpace , line . size ( ) - 1 ) ; NFutil :: trim ( argValue ) ; } if ( argName == " " || argName == " " ) { cout << " \n " << filename << " " << lineCounter << " \n " ; cout << " " + line + " \n " ; cout << " " << argName << " \n " ; cout << " " << argName << " \n " << endl ; continue ; } else if ( argName == " " ) { cout << " \n " << filename << " " << lineCounter << " \n " ; cout << " " + line + " \n " ; cout << " \n " ; cout << " \n " ; cout << " \n " << endl ; continue ; } if ( argMap . find ( argName ) != argMap . end ( ) ) { cout << " \n " << filename << " " << lineCounter << " \n " ; cout << " " + line + " \n " ; cout << " \n " ; cout << " " << endl ; break ; } argMap [ argName ] = argValue ; } if ( ! ended && started ) { cout << " \n " << filename << " " << lineCounter << " \n " ; cout << " " << endl ; return false ; } rnfFile . close ( ) ; } else { cout << " \n " << filename . c_str ( ) << " " << endl ; cout << " " << endl ; return false ; } } } else { cout << " \n " << endl ; return false ; } return true ; }
reads in the RNF file, and overwrites any argument it finds
reads in the RNF file and overwrites any argument it finds
//open up the file //If the file is open, start reading in the details... //Loop over the lines //First, grab the line //identify and remove comments //cout<<"identified the comment."<<endl; //Skip empty lines (which will also skip entire comment lines) //Identify the start tag... //	cout<<"found begin, all parameters have been found."<<endl; //Stop once we get to the end tag //	cout<<"found end, ending the parse."<<endl; //If we are reading in the execution block, just add it to //the list - it will be handled later by the system //	cout<<"["<<lineCounter<<"]: '"<<line<<"'"<<endl; //Make sure that we have an argument //	cout<<"got argname: '"<<argName<<"'"<<endl; //	cout<<"got argname: '"<<argName<<"'"<<endl; //	cout<<"got argvalue: '"<<argValue<<"'"<<endl; //Throw out some warnings if we are setting arguments in an improper way //that don't do anything //Make sure we haven't defined the argument yet //Properly close the input stream //if we got here, then we did something right...