int CfgFile::getKeyValue(std::string &sLine, const size_t startPos) { // we found the key now get the value size_t valueBegin = sLine.find_first_not_of(" =\t", startPos); if (valueBegin == std::string::npos) return 1; // syntax error, we ignore the block (comment or end of line) size_t valueEnd; if (sLine[valueBegin] == '\"') { // find a second '"' which is not escaped valueBegin++; valueEnd = findFirstNotEscapedOf(sLine, "\"", valueBegin); if (valueEnd == std::string::npos) return 1; // syntax error, we ignore the block (comment or end of line) sLine = sLine.substr(valueBegin, valueEnd - valueBegin); unescapeString(sLine); } else { valueEnd = sLine.find_last_not_of(" \t"); if (valueEnd == std::string::npos) return 1; // syntax error, we ignore the block (comment or end of line) valueEnd++; sLine = sLine.substr(valueBegin, valueEnd - valueBegin); removeWhite(sLine); unescapeString(sLine); } return 0; }
void PrepinReader::read_prep(string fn) { /*** clear maps ***/ advtype.clear(); pc.clear(); keys.clear(); /*** read file ***/ //printf("Reading file '%s'\n", fn.c_str()); string filename="parameters/"+fn; string line; file.open(filename.c_str()); if(!file) { printf("WARNING: could not read parameter file '%s'!",fn.c_str()); return; } bool go = false; while(!file.eof()) { getline(file, line); /*** break line into words ***/ words.clear(); char temp[300]; istringstream stream(line.c_str()); while(stream>>temp) words.push_back(removeWhite(string(temp))); /*** new residue ***/ if(words[1] == "INT") { go = true; amino = words[0]; } if(words.size() == 0) go = false; if(go == true) if(words.size() > 4 && words[1] != "DUMM") { string key1; key1 = words[1]; /*** to avoid confusion when reading molecule prepins***/ if(amino=="SUB") amino=""; string collectKey = amino + " " + key1; keys.push_back(collectKey); string tmpAdvType; tmpAdvType = words[2]; advtype[collectKey]=tmpAdvType; double tmpPartialCharge; istringstream instr(words[10]); instr >> tmpPartialCharge; pc[collectKey]=tmpPartialCharge; // cout << "Found key:" << collectKey << " " << tmpAdvType << " " << tmpPartialCharge << endl; } }
void Control::interpretator(string line) { /*** Transforms to lower case ***/ //transform(line.begin(), line.end(), line.begin(),::tolower); /*** check for commentation ***/ string checkComment(line,0,1); if(checkComment == "#" || line.size()<2) return; /*** replaces '{' and '}' with ' { ' and ' } ' ***/ for(unsigned int i=0; i<line.size(); i++) { if(string(line,i,1) =="{") { line.replace(i, 1, string(" { "),0,3); i++; } else if(string(line,i,1)=="}") { line.replace(i, 1, string(" } "),0,3); i++; } } /*** break command into words ***/ vector<string> words; words.clear(); char temp[300]; istringstream stream(line.c_str()); while(stream>>temp) words.push_back(removeWhite(string(temp))); /*** check for lines with only white space ***/ if(words.size() < 1) return; /* printf("Control has the words:\n"); for(int i=0;i<words.size();i++) printf("'%s' ",words[i].c_str()); printf("\n"); */ try { string com = words.at(0); if(com == "load") { if(words.size() > 2) load(words.at(1), words.at(2)); else { char no[6]; sprintf(no, "%d", soups.size()); load(words.at(1), string("AutoSoup") + string(no)); } } else if(com == "loadtosoup") { if(words.size() > 3) loadToSoup(atoi(words.at(1).c_str()), words.at(2), words.at(3)); else { char no[6]; sprintf(no, "%d", soups.size()); load(words.at(1), string("AutoSoup") + string(no)); } } else if(com == "stat") stat(); else if(com == "list") list(); else if(com == "clear") clear(); else if(com == "task") doTask(words); else if(com == "script") do_script(words); else if(com == "exit") return; else printf("Don't understand the command '%s'!\n",words.at(0).c_str()); } catch (...) { printf("The command %s caused a critical error!\n",line.c_str()); } }