Changeset 2441
- Timestamp:
- 12/08/22 08:56:39 (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS3/trunk/src/node/context.cpp
r2438 r2441 35 35 #include <chrono> 36 36 #include <random> 37 #include <unistd.h>38 37 39 38 namespace xios … … 163 162 if (attributes.end() != attributes.find("src")) 164 163 { 165 string srcString = attributes["src"].c_str(); 166 167 // check if environment variables 168 string srcKey; 169 if (srcString.find("${") == 0) // src start wit 170 { 171 size_t envVarStart = srcString.find("${")+2; // +2 for ${ 172 if (srcString.find("}") != std::string::npos) 173 { 174 size_t envVarEnd = srcString.find("}")-2; // -2 (start @ srcString begining, not after ${ 175 if(const char* var_path = std::getenv( srcString.substr( envVarStart, envVarEnd ).c_str() ) ) 176 { 177 srcKey=string(var_path)+"/"+srcString.substr( srcString.find("}")+1, srcString.size()-srcString.find("}") ); 178 } 179 else 180 { 181 ERROR("void CContext::parse(xml::CXMLNode & node)", 182 <<endl<< "The src key " << attributes["src"].c_str()<< " contains an undefined variable." ); 183 } 184 } 185 else 186 { 187 ERROR("void CContext::parse(xml::CXMLNode & node)", 188 <<endl<< "The src key " << attributes["src"].c_str()<< " not defined correctly." ); 189 } 190 } 191 else if (srcString.find("${") != 0) 192 { 193 ERROR("void CContext::parse(xml::CXMLNode & node)", 194 <<endl<< "The src key " << attributes["src"].c_str()<< " should start with $" ); 195 } 196 else if (srcString.find("$") != std::string::npos) 197 { 198 ERROR("void CContext::parse(xml::CXMLNode & node)", 199 <<endl<< "The src key " << attributes["src"].c_str()<< " need { and }." ); 200 } 201 else // standard behavor, without environment variable 202 { 203 srcKey = attributes["src"].c_str(); 204 } 205 206 StdIFStream ifs ( srcKey , StdIFStream::in ); 164 StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 207 165 if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 208 166 { 209 char currentPath[256];210 getcwd(currentPath, sizeof(currentPath));211 167 ERROR("void CContext::parse(xml::CXMLNode & node)", 212 <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file " 213 << "from iodef path : " << currentPath ); 168 <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 214 169 } 215 170 if (!ifs.good())
Note: See TracChangeset
for help on using the changeset viewer.