Changeset 462 for XIOS


Ignore:
Timestamp:
01/21/14 09:40:14 (10 years ago)
Author:
ymipsl
Message:

Enhancement :

  • Improving error message occuring along the xml parsing : position (line number, column) is now indicated
  • New executable : parse_xml.exe : parse the xml files and reports potential error

YM

Location:
XIOS/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/bld.cfg

    r452 r462  
    3030bld::lib xios 
    3131bld::target libxios.a 
    32 #bld::target test.exe 
    33 bld::target generate_fortran_interface.exe  
    34 bld::target xios_server.exe test_cs.exe test_client.exe test_unstruct.exe 
     32#bld::target generate_fortran_interface.exe  
     33bld::target xios_server.exe test_client.exe parse_xml.exe 
    3534bld::exe_dep 
    3635 
  • XIOS/trunk/src/group_parser.hpp

    r347 r462  
    2020         { 
    2121            StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 
     22            if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 
     23               ERROR(" void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 
     24                     <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 
    2225            if (!ifs.good()) 
    2326               ERROR("CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 
    2427                     << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); 
    25             xml::CXMLParser::ParseInclude(ifs, *this); 
     28            xml::CXMLParser::ParseInclude(ifs, attributes["src"].c_str(), *this); 
    2629         } 
    2730      } 
  • XIOS/trunk/src/group_template_impl.hpp

    r446 r462  
    490490         { 
    491491            StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 
     492            if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 
     493               ERROR("void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 
     494                     <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 
     495             
    492496            if (!ifs.good()) 
    493497               ERROR("CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)", 
    494498                     << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); 
    495             xml::CXMLParser::ParseInclude(ifs, *this); 
     499            xml::CXMLParser::ParseInclude(ifs, attributes["src"].c_str(), *this); 
    496500         } 
    497501      } 
  • XIOS/trunk/src/node/context.cpp

    r461 r462  
    110110      { 
    111111         StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in ); 
     112         if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 
     113            ERROR("void CContext::parse(xml::CXMLNode & node)", 
     114                  <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" ); 
    112115         if (!ifs.good()) 
    113116            ERROR("CContext::parse(xml::CXMLNode & node)", 
    114117                  << "[ filename = " << attributes["src"] << " ] Bad xml stream !"); 
    115          xml::CXMLParser::ParseInclude(ifs, *this); 
     118         xml::CXMLParser::ParseInclude(ifs, attributes["src"], *this); 
    116119      } 
    117120 
  • XIOS/trunk/src/xml_parser.cpp

    r352 r462  
    1616      { 
    1717         StdIFStream ifs ( filename.c_str() , StdIFStream::in ); 
    18          CXMLParser::ParseStream(ifs); 
     18         if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 ) 
     19           ERROR("void CXMLParser::ParseFile(const StdString & filename)", 
     20                  <<endl<< "Can not open <"<<filename<<"> file" ); 
     21 
     22         CXMLParser::ParseStream(ifs, filename); 
    1923      } 
    2024 
     
    2226      { 
    2327         StdIStringStream iss ( xmlContent /*, StdIStringStream::in*/ ); 
    24          CXMLParser::ParseStream(iss); 
     28         CXMLParser::ParseStream(iss,"string"); 
    2529      } 
    2630 
    27       void CXMLParser::ParseStream(StdIStream & stream) 
     31      void CXMLParser::ParseStream(StdIStream & stream, const string& fluxId) 
    2832      { 
    2933         if (!stream.good()) 
     
    3135                  << "Bad xml stream !"); 
    3236         StdOStringStream oss; 
    33          while(!stream.eof() && !stream.fail ()) 
    34             oss.put(stream.get()); 
     37         while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); 
     38         const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 
    3539         try 
    3640         { 
    37             //const StdString xmlcontent( oss.str(), 0, oss.str().size()-2); //<POURQUOI ? 
    38             const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 
    3941            rapidxml::xml_document<char> doc; 
    4042            doc.parse<0>(const_cast<char*>(xmlcontent.c_str())); 
     
    5860                  if (attributes.end() == attributes.find("id")) 
    5961                  {   
    60                      DEBUG("Le context ne sera pas traité car il n'est pas identifié !"); 
     62                     DEBUG("The context will not be processed because it is not identified (missing id)"); 
    6163                     continue;  
    6264                  } 
     
    6870                  if(hasctxt) 
    6971                  {   
    70                      DEBUG("Le context ne sera pas traité car " 
    71                            << "il existe déjà un autre context possédant le même nom !"); 
     72                     DEBUG("The context will not be processed because it exist an other context with the same id" ); 
    7273                     continue;  
    7374                  } 
     
    8485         catch (rapidxml::parse_error & exc) 
    8586         { 
    86             ERROR("CXMLParser::ParseStream(StdIStream & stream)", 
    87                   << "RapidXML error : " << exc.what() << " !"); 
     87            const char* ptr = exc.where<char>() ; 
     88            const char* begin = xmlcontent.c_str() ; 
     89            const char* content=oss.str().c_str() ; 
     90            size_t pos=ptr-begin ; 
     91            int lineNumber = 1 ; 
     92            int columnNumber = 0 ; 
     93            const char* line; 
     94            const char* endLine; 
     95             
     96            for(const char* i=content;i<content+pos; ++i, ++columnNumber) if (*i=='\n') { lineNumber++ ; line=i ; columnNumber=0 ;} 
     97            for(endLine=content+pos; *endLine!='\n' && *endLine!='\0' ; ++endLine) ; 
     98            string strLine(line,endLine-line) ; 
     99                   
     100            ERROR("CXMLParser::ParseStream(StdIStream & stream)", << endl 
     101                  << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl 
     102                  << strLine<<endl 
     103                  << string(columnNumber-1,'x')<<'^'<<endl 
     104                  <<" Error : " << exc.what() ) 
    88105         } 
    89106      } 
  • XIOS/trunk/src/xml_parser.hpp

    r352 r462  
    1919            static void ParseFile(const StdString & filename); 
    2020            static void ParseString(const StdString & xmlContent); 
    21             static void ParseStream(StdIStream & stream); 
     21            static void ParseStream(StdIStream & stream, const string& fluxId); 
    2222            template <class T> 
    23                static void ParseInclude(StdIStream & stream, T & object); 
     23               static void ParseInclude(StdIStream & stream, const string& fluxId, T & object); 
    2424 
    2525      }; //class CXMLParser 
  • XIOS/trunk/src/xml_parser_decl.cpp

    r352 r462  
    1313  namespace xml 
    1414  { 
    15     template void CXMLParser::ParseInclude<CContext>(StdIStream & stream, CContext& object) ; 
     15    template void CXMLParser::ParseInclude<CContext>(StdIStream & stream, const string& fluxId, CContext& object) ; 
    1616  
    1717 #   define macro(T) \ 
    18     template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(StdIStream & stream, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ; 
     18    template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(StdIStream & stream, const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ; 
    1919     
    2020    macro( Context )  
  • XIOS/trunk/src/xml_parser_impl.hpp

    r352 r462  
    99   namespace xml 
    1010   { 
    11      template <class T> void CXMLParser::ParseInclude(StdIStream & stream, T& object) 
     11     template <class T> void CXMLParser::ParseInclude(StdIStream & stream, const string& fluxId,  T& object) 
    1212      { 
    1313         StdOStringStream oss; 
    14          while(!stream.eof() && !stream.fail ()) 
    15             oss.put(stream.get()); 
     14         while(!stream.eof() && !stream.fail ()) oss.put(stream.get()); 
     15         const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 
    1616         try 
    1717         { 
    18             const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 ); 
    1918            rapidxml::xml_document<char> doc; 
    2019            doc.parse<0>(const_cast<char*>(xmlcontent.c_str())); 
     
    2423         catch (rapidxml::parse_error & exc) 
    2524         { 
    26             ERROR("CXMLParser::ParseStream(StdIStream & stream)", 
    27                   << "RapidXML error : " << exc.what() << " !"); 
     25             const char* ptr = exc.where<char>() ; 
     26            const char* begin = xmlcontent.c_str() ; 
     27            const char* content=oss.str().c_str() ; 
     28            size_t pos=ptr-begin ; 
     29            int lineNumber = 1 ; 
     30            int columnNumber = 0 ; 
     31            const char* line; 
     32            const char* endLine; 
     33             
     34            for(const char* i=content;i<content+pos; ++i, ++columnNumber) if (*i=='\n') { lineNumber++ ; line=i ; columnNumber=0 ;} 
     35            for(endLine=content+pos; *endLine!='\n' && *endLine!='\0' ; ++endLine) ; 
     36            string strLine(line,endLine-line) ; 
     37                   
     38            ERROR("CXMLParser::ParseStream(StdIStream & stream)", << endl 
     39                  << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl 
     40                  << strLine<<endl 
     41                  << string(columnNumber-1,'x')<<'^'<<endl 
     42                  <<" Error : " << exc.what() ) 
    2843         } 
    2944      } 
Note: See TracChangeset for help on using the changeset viewer.