bool CProcessConfigReader::GetConfigurationAndPreserveSpace(std::string sAppName, STRING_LIST &Params) { Params.clear(); int nBrackets = 0; Params.clear(); Reset(); std::string sKey = "PROCESSCONFIG="+sAppName; if(GoTo(sKey)) { std::string sBracket = GetNextValidLine(); if(sBracket.find("{")==0) { nBrackets++; while(!GetFile()->eof()) { std::string sLine = GetNextValidLine(); MOOSTrimWhiteSpace(sLine); if(sLine.find("}")!=0) { std::string sVal(sLine); std::string sTok = MOOSChomp(sVal, "="); MOOSTrimWhiteSpace(sTok); MOOSTrimWhiteSpace(sVal); if (!sTok.empty()) { if (!sVal.empty()) { Params.push_back(sTok+"="+sVal); } else if(sLine.find("[")!=std::string::npos || sLine.find("]")!=std::string::npos) { Params.push_back(sLine); } } } else { return true; } //quick error check - we don't allow nested { on single lines if(sLine.find("{")==0) { MOOSTrace("CProcessConfigReader::GetConfiguration() missing \"}\" syntax error in mission file\n"); } } } } return false; }
/// READ STRINGS bool CProcessConfigReader::GetConfigurationParam(std::string sAppName,std::string sParam, std::string &sVal) { Reset(); //remember all names we were asked for.... std::string sl = sParam; MOOSToLower(sl); m_Audit[sAppName].insert(sl); STRING_LIST sParams; if(GetConfigurationAndPreserveSpace( sAppName, sParams)) { STRING_LIST::iterator p; for(p = sParams.begin(); p!=sParams.end(); p++) { std::string sTmp = *p; std::string sTok = MOOSChomp(sTmp,"="); MOOSTrimWhiteSpace(sTok); if (sTmp.empty()) return false; if(MOOSStrCmp(sTok,sParam)) { MOOSTrimWhiteSpace(sTmp); sVal=sTmp; return true; } } } return false; }
bool MOOSAppDocumentation::xmlToMoosvar(XMLElement *xmlmoosvar, MOOSVarDescription &moosvar, string &item_error) { string value; XMLElement *element; // Name element = xmlmoosvar->FirstChildElement("name"); if(element == NULL) { item_error = "moosvar/name"; return false; } value = element->GetText(); MOOSTrimWhiteSpace(value); moosvar.setName(value); // Type element = xmlmoosvar->FirstChildElement("type"); if(element == NULL) { item_error = "moosvar/type"; return false; } value = element->GetText(); MOOSTrimWhiteSpace(value); moosvar.setType(value); // Info element = xmlmoosvar->FirstChildElement("info"); if(element == NULL) { item_error = "moosvar/info"; return false; } value = element->GetText(); MOOSTrimWhiteSpace(value); moosvar.setInfo(value); return true; }
bool CProcessConfigReader::GetConfiguration(std::string sAppName, STRING_LIST &Params) { int nBrackets = 0; Params.clear(); Reset(); std::string sKey = "PROCESSCONFIG="+sAppName; if(GoTo(sKey)) { std::string sBracket = GetNextValidLine(); if(sBracket.find("{")==0) { nBrackets++; while(!GetFile()->eof()) { std::string sLine = GetNextValidLine(); MOOSRemoveChars(sLine," \t\r"); if(sLine.find("}")!=0) { #if(1) // jckerken 8-12-2004 // ignore if param = <empty string> std::string sTmp(sLine); std::string sTok = MOOSChomp(sTmp, "="); MOOSTrimWhiteSpace(sTok); // Handle potential whitespaces. MOOSTrimWhiteSpace(sTmp); if (sTok.size() > 0) { MOOSTrimWhiteSpace(sTmp); if (!sTmp.empty()) { Params.push_front(sTok+std::string("=")+sTmp); // Was: sLine } else if(sLine.find("[")!=std::string::npos || sLine.find("]")!=std::string::npos) { Params.push_front(sTok+std::string("=")+sTmp); // Was: sLine } } else { Params.push_front(sTok+std::string("=")+sTmp); // Was: sLine } #else Params.push_front(sLine); #endif } else { return true; } //quick error check - we don't allow nested { on single lines if(sLine.find("{")==0) { MOOSTrace("CProcessConfigReader::GetConfiguration() missing \"}\" syntax error in mission file\n"); } } } } return false; }
// This is a rewrite of MOOSValFromString from MOOSUtilityFunctions.cpp. It // adds support for specifying the token for which key value pairs are // separated. Also now returns a list of strings through the out parameter // to allow for detection of multiple copies of the key. bool ValsFromString(std::list<std::string> &sVal, const std::string &sStr, const std::string &sTk, bool bInsensitive /*=true*/, const std::string delimiter /*=","*/) { const char *whitespace = " \t"; if(sTk.find(delimiter) != std::string::npos) return false; size_t nPos = std::string::npos; size_t k = 0; while((nPos = MOOSStrFind(sStr.substr(k), sTk, bInsensitive)) != std::string::npos) { nPos += k; // We have the start of the token at nPos. We need to be careful here = // there could be many spaces between token and '='. size_t nEqualsPos = sStr.find('=', nPos); size_t nLastDelim = sStr.find_last_of(delimiter, nPos); size_t nLastChar; if(nLastDelim == std::string::npos) nLastChar = sStr.find_first_not_of(whitespace, 0); // Starting from previous delimiter, when is the first non-whitespace char? else nLastChar = sStr.find_first_not_of(whitespace, nLastDelim + 1); if(nLastChar != nPos) { // Extra chars found k = nPos + 1; continue; } // Look for a "=" if(nEqualsPos != std::string::npos) { // There should only be whitespace twixt token and equals std::string t = sStr.substr(nPos + sTk.size(), nEqualsPos - (nPos + sTk.size())); MOOSTrimWhiteSpace(t); if(!t.empty()) { //k = nEqualsPos; k = nPos + 1; continue; } //sVal.clear(); //sVal = ""; int nDelimPos = sStr.find(delimiter, nEqualsPos); std::string sub = sStr.substr(nEqualsPos + 1, nDelimPos - nEqualsPos - 1); MOOSTrimWhiteSpace(sub); sVal.push_front(sub); //sVal.append(sStr, nEqualsPos + 1, nDelimPos - nEqualsPos - 1); k = nPos + 1; continue; //return true; } else return false; } /* while */ if (sVal.empty()) return false; else return true; } /* ValsFromString */
bool MOOSAppDocumentation::parseXML(string &item_error) { // Parsing... XMLElement *element; XMLNode *root = m_xml_doc->FirstChildElement("moosapp"); if(root == NULL) { item_error = "moosapp"; return false; } // Info section { XMLElement *info_section = root->FirstChildElement("info"); if(info_section == NULL) { item_error = "info"; return false; } // Organization element = info_section->FirstChildElement("organization"); if(element == NULL) { item_error = "organization"; return false; } m_info_organization = element->GetText(); MOOSTrimWhiteSpace(m_info_organization); // Date element = info_section->FirstChildElement("date"); if(element == NULL) { item_error = "date"; return false; } m_info_date = element->GetText(); MOOSTrimWhiteSpace(m_info_date); // Licence element = info_section->FirstChildElement("licence"); if(element == NULL) { item_error = "licence"; return false; } m_info_licence = element->GetText(); MOOSTrimWhiteSpace(m_info_licence); // Authors element = info_section->FirstChildElement("authors"); if(element == NULL) { item_error = "authors"; return false; } XMLElement *author = element->FirstChildElement("author"); while(author != NULL) { string author_name; author_name = author->GetText(); MOOSTrimWhiteSpace(author_name); m_info_authors.push_back(author_name); author = author->NextSiblingElement("author"); } } // Documentation section { XMLElement *documentation_section = root->FirstChildElement("documentation"); if(documentation_section == NULL) { item_error = "documentation"; return false; } // Synopsis element = documentation_section->FirstChildElement("synopsis"); if(element == NULL) { item_error = "synopsis"; return false; } m_synopsis = element->GetText(); MOOSTrimWhiteSpace(m_synopsis); // Optional comments element = documentation_section->FirstChildElement("optional-comments"); if(element == NULL) { item_error = "optional-comments"; return false; } m_optional_comments = element->GetText(); MOOSTrimWhiteSpace(m_optional_comments); // Suggested improvements element = documentation_section->FirstChildElement("suggested-improvements"); if(element == NULL) { item_error = "suggested-improvements"; return false; } m_suggested_improvements = element->GetText(); MOOSTrimWhiteSpace(m_suggested_improvements); // Interface { XMLElement *interface_subsection = documentation_section->FirstChildElement("interface"); if(interface_subsection == NULL) { item_error = "interface"; return false; } // Subscriptions XMLElement *subscriptions_subsection = interface_subsection->FirstChildElement("subscriptions"); if(subscriptions_subsection == NULL) { item_error = "subscriptions"; return false; } XMLElement *moosvar_xml = subscriptions_subsection->FirstChildElement("moosvar"); while(moosvar_xml != NULL) { MOOSVarDescription moosvar; if(!xmlToMoosvar(moosvar_xml, moosvar, item_error)) { return false; } m_subscriptions.push_back(moosvar); moosvar_xml = moosvar_xml->NextSiblingElement("moosvar"); } // Publications XMLElement *publications_subsection = interface_subsection->FirstChildElement("publications"); if(publications_subsection == NULL) { item_error = "publications"; return false; } moosvar_xml = publications_subsection->FirstChildElement("moosvar"); while(moosvar_xml != NULL) { MOOSVarDescription moosvar; if(!xmlToMoosvar(moosvar_xml, moosvar, item_error)) { return false; } m_publications.push_back(moosvar); moosvar_xml = moosvar_xml->NextSiblingElement("moosvar"); } } } return true; }