cleaning readConfigFile

This commit is contained in:
Erik Frojdh 2018-10-12 09:57:46 +02:00
parent c3289a973f
commit 4cdd766a8e

View File

@ -918,48 +918,33 @@ int multiSlsDetector::readConfigurationFile(const std::string& fname) {
char* args[100]; char* args[100];
char myargs[100][1000]; char myargs[100][1000];
std::cout << "Loading configuration file: " << fname << std::endl;
std::cout << "config file name " << fname << std::endl; std::ifstream input_file;
input_file.open(fname, std::ios_base::in);
std::ifstream infile; if (input_file.is_open()) {
infile.open(fname.c_str(), std::ios_base::in); std::string current_line;
if (infile.is_open()) { while (input_file.good()) {
std::string tmp_line; getline(input_file, current_line);
while (infile.good()) { if (current_line.find('#') != std::string::npos)
getline(infile, tmp_line); current_line.erase(current_line.find('#'));
// remove comments that come after
if (tmp_line.find('#') != std::string::npos)
tmp_line.erase(tmp_line.find('#'));
#ifdef VERBOSE #ifdef VERBOSE
std::cout << "tmp_line after removing comments:" << tmp_line << std::endl; std::cout << "current_line after removing comments:" << current_line << std::endl;
#endif #endif
if (tmp_line.length() > 1) { if (current_line.length() > 1) {
std::istringstream ssstr(tmp_line); std::istringstream line_stream(current_line);
int iargval = 0; int n_arguments = 0;
std::string sargname; std::string current_argument;
while (ssstr.good()) { while (line_stream.good()) {
ssstr >> sargname; line_stream >> current_argument;
#ifdef VERBOSE strcpy(myargs[n_arguments], current_argument.c_str());
std::cout << iargval << " " << sargname << std::endl; args[n_arguments] = myargs[n_arguments];
#endif ++n_arguments;
strcpy(myargs[iargval], sargname.c_str());
args[iargval] = myargs[iargval];
#ifdef VERBOSE
std::cout << "--" << iargval << " " << args[iargval] << std::endl;
#endif
++iargval;
} }
#ifdef VERBOSE multiSlsDetectorClient(n_arguments, args, PUT_ACTION, this);
std::cout << std::endl;
for (int ia = 0; ia < iargval; ia++)
std::cout << args[ia] << " ??????? ";
std::cout << std::endl;
#endif
multiSlsDetectorClient(iargval, args, PUT_ACTION, this);
} }
} }
infile.close(); input_file.close();
} else { } else {
std::cout << "Error opening configuration file " << fname << " for reading" << std::endl; std::cout << "Error opening configuration file " << fname << " for reading" << std::endl;
setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR); setErrorMask(getErrorMask() | MULTI_CONFIG_FILE_ERROR);