diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp index 6a6fd458f5bffc0de151ae7bee081a1aa0ec0d6d..e02232391442528197b27154dfac1c6bf5ba294c 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.cpp +++ b/simulators/c++2/src_simulator/sim/Simulator.cpp @@ -1131,8 +1131,9 @@ int countLineNumber(std::string& filename){ std::string line; std::ifstream myfile(filename.c_str()); - while (std::getline(myfile, line)) - ++number_of_lines; + while (std::getline(myfile, line)){ + if (line != "") ++number_of_lines; + } std::cout << "Number of lines in text file: " << number_of_lines << std::endl; return number_of_lines; } @@ -1168,44 +1169,48 @@ ServerIF* Simulator::run(int iLen, char ** iArgs){ std::vector<std::string> parameters = readFromFile(aArgString); std::string aNewCmd; int previousTransTime = 0; - if(lineNumber != 0){ - for (int i = 0; i < lineNumber; i++){ - std::string channelName =_simComp->getChannelList(parameters[i*4+1]); - TMLChannel* t = _simComp->getChannelByName(channelName); - if(t != 0){ - aNewCmd += "1 5 " + parameters[i*4] + "; 6 " + to_string(t->getID()) + " 1 " + parameters[i*4+3] + "; "; + if((parameters.size() != (lineNumber*4)) != 0){ + std::cout << "Error: Wrong format, each line should contains 4 parameters.\n"; + } else { + if(lineNumber != 0){ + for (int i = 0; i < lineNumber; i++){ + std::string channelName =_simComp->getChannelList(parameters[i*4+1]); + TMLChannel* t = _simComp->getChannelByName(channelName); + if(t != 0){ + aNewCmd += "1 5 " + parameters[i*4] + "; 6 " + to_string(t->getID()) + " 1 " + parameters[i*4+3] + "; "; + } + else { + std::cout << "Error: Wrong channel name\n"; + previousTransTime++; + } } - else { - std::cout << "Error: Wrong channel name\n"; - previousTransTime++; + if(previousTransTime != lineNumber){ + aNewCmd += "1 0; 7 1 test.html; 1 7 100 100 test"; + } else { + aNewCmd = "1 0; 7 1 test.html; 1 7 100 100 test"; } - } - if(previousTransTime != lineNumber){ - aNewCmd += "1 0; 7 1 test.html; 1 7 100 100 test"; - } else { - aNewCmd = "1 0; 7 1 test.html; 1 7 100 100 test"; - } - std::cout<<"DecodeCommand "<< aNewCmd << std::endl; - std::ofstream aXmlOutFile1; - std::string aXmlFileName1 = getArgs("-oxml", "reply.xml", iLen, iArgs); - if (aXmlFileName1.empty()) aXmlOutFile1.open("/dev/null"); else aXmlOutFile1.open(aXmlFileName1.c_str()); - if (aXmlOutFile1.is_open()){ - std::string aNextCmd1; - std::istringstream iss1(aNewCmd+";"); - getline(iss1, aNextCmd1, ';'); - while (!(iss1.eof() || aNextCmd1.empty())){ - std::cout << "next cmd to execute: \"" << aNextCmd1 << "\"\n"; - decodeCommand(aNextCmd1, aXmlOutFile1); - getline(iss1, aNextCmd1, ';'); - } - aXmlOutFile1.close(); - } else{ - std::cout << "XML output file could not be opened, aborting.\n"; - } - } else { - std::cout << "Signal file contains nothing, aborting.\n"; - } + std::cout<<"DecodeCommand "<< aNewCmd << std::endl; + std::ofstream aXmlOutFile1; + std::string aXmlFileName1 = getArgs("-oxml", "reply.xml", iLen, iArgs); + if (aXmlFileName1.empty()) aXmlOutFile1.open("/dev/null"); else aXmlOutFile1.open(aXmlFileName1.c_str()); + if (aXmlOutFile1.is_open()){ + std::string aNextCmd1; + std::istringstream iss1(aNewCmd+";"); + getline(iss1, aNextCmd1, ';'); + while (!(iss1.eof() || aNextCmd1.empty())){ + std::cout << "next cmd to execute: \"" << aNextCmd1 << "\"\n"; + decodeCommand(aNextCmd1, aXmlOutFile1); + getline(iss1, aNextCmd1, ';'); + } + aXmlOutFile1.close(); + } else{ + std::cout << "XML output file could not be opened, aborting.\n"; + } + } else { + std::cout << "Signal file contains nothing, aborting.\n"; + } + } } aArgString =getArgs("-help", "help", iLen, iArgs); if (aArgString.empty()){