Changeset 2441 for XIOS3/trunk/src


Ignore:
Timestamp:
12/08/22 08:56:39 (19 months ago)
Author:
jderouillat
Message:

Reverse partially commit 2438 : the integration of environment variables in XML soures inclusion (not XIOS_IODEF_PATH).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS3/trunk/src/node/context.cpp

    r2438 r2441  
    3535#include <chrono> 
    3636#include <random> 
    37 #include <unistd.h> 
    3837 
    3938namespace xios 
     
    163162      if (attributes.end() != attributes.find("src")) 
    164163      { 
    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 ); 
    207165         if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 
    208166         { 
    209             char currentPath[256]; 
    210             getcwd(currentPath, sizeof(currentPath)); 
    211167            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" ); 
    214169         } 
    215170         if (!ifs.good()) 
Note: See TracChangeset for help on using the changeset viewer.