From 24bb4f515ccc894895e0e54f9d8753ac4e782087 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 24 Jun 2013 21:17:45 +0200 Subject: [PATCH] [DEV] start move to exml --- sources/appl/Highlight/Highlight.cpp | 115 +++++++------------- sources/appl/Highlight/Highlight.h | 6 +- sources/appl/Highlight/HighlightPattern.cpp | 32 +++--- sources/appl/Highlight/HighlightPattern.h | 4 +- sources/appl/init.cpp | 7 +- 5 files changed, 63 insertions(+), 101 deletions(-) diff --git a/sources/appl/Highlight/Highlight.cpp b/sources/appl/Highlight/Highlight.cpp index 6a46b64..df8f51d 100644 --- a/sources/appl/Highlight/Highlight.cpp +++ b/sources/appl/Highlight/Highlight.cpp @@ -16,7 +16,7 @@ #define __class__ "Highlight" -void Highlight::ParseRules(TiXmlNode *child, etk::Vector &mListPatern, int32_t level) +void Highlight::ParseRules(exml::Element* child, etk::Vector &mListPatern, int32_t level) { // Create the patern ... HighlightPattern *myPattern = new HighlightPattern(); @@ -28,99 +28,62 @@ void Highlight::ParseRules(TiXmlNode *child, etk::Vector &mLi -Highlight::Highlight(etk::UString &xmlFilename) +Highlight::Highlight(const etk::UString& _xmlFilename) { - TiXmlDocument XmlDocument; - - etk::FSNode fileName(xmlFilename); - if (false == fileName.Exist()) { - APPL_ERROR("File Does not exist : " << fileName); - return; + exml::Document doc; + if (doc.Load(_fileName)==false) { + EWOL_ERROR(" can not load file XML : " << _fileName); + return false; } - int32_t fileSize = fileName.FileSize(); - if (0==fileSize) { - APPL_ERROR("This file is empty : " << fileName); - return; + exml::Element* root = (exml::Element*)doc.GetNamed("EdnLang"); + if (NULL == root ) { + EWOL_ERROR("[" << GetId() << "] {" << GetObjectType() << "} (l ?) main node not find: \"composer\" ..."); + return false; } - if (false == fileName.FileOpenRead()) { - APPL_ERROR("Can not open the file : " << fileName); - return; - } - // allocate data - char * fileBuffer = new char[fileSize+5]; - if (NULL == fileBuffer) { - APPL_ERROR("Error Memory allocation size=" << fileSize); - return; - } - memset(fileBuffer, 0, (fileSize+5)*sizeof(char)); - // load data from the file : - fileName.FileRead(fileBuffer, 1, fileSize); - // close the file: - fileName.FileClose(); - // load the XML from the memory - bool loadError = XmlDocument.Parse((const char*)fileBuffer, 0, TIXML_ENCODING_UTF8); - if (false == loadError) { - APPL_ERROR( "can not load Hightlight XML: PARSING error: \"" << xmlFilename << "\""); - return; - } - - - TiXmlElement* root = XmlDocument.FirstChildElement( "EdnLang" ); - if (NULL == root) { - APPL_ERROR( "can not load Hightlight XML: main node not find: \"EdnLang\""); - return; - } - int32_t level1 = 0; int32_t level2 = 0; - TiXmlNode * child = root->FirstChild(); - while(NULL != child) - { - if (child->Type()==TiXmlNode::TINYXML_COMMENT) { - // nothing to do ... - } else if (!strcmp(child->Value(), "ext")) { - const char *myData = child->ToElement()->GetText(); + // parse all the elements : + for(int32_t iii=0; iii< _node->Size(); iii++) { + exml::Element* child = (exml::Element*)_node->Get(iii); + if (child==NULL) { + continue; + } + if (child->GetValue() == "ext") { + const char *myData = child->GetText(); if (NULL != myData) { //APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", child->Row(), child->Value() , myData); etk::UString * myEdnData = new etk::UString(myData); m_listExtentions.PushBack(myEdnData); } - } else if (!strcmp(child->Value(), "pass1")) { + } else if (child->GetValue()=="pass1") { // Get sub Nodes ... - TiXmlNode *passChild = child->FirstChild(); - while (NULL != passChild) { - if (passChild->Type()==TiXmlNode::TINYXML_COMMENT) { - // nothing to do ... - } else if (!strcmp(passChild->Value(), "rule")) { - ParseRules(passChild, m_listHighlightPass1, level1++); - } else { - APPL_ERROR("(l "<< passChild->Row() << ") node not suported : \""<< passChild->Value() << "\" must be [rule]" ); + for(int32_t jjj=0; jjj< child->Size(); jjj++) { + exml::Element* passChild = (exml::Element*)child->Get(jjj); + if (passChild==NULL) { + continue; } - // get the next node element : - passChild = passChild->NextSibling(); + if (passChild->GetValue() != "rule") { + APPL_ERROR("(l "<< passChild->Pos() << ") node not suported : \""<< passChild->GetValue() << "\" must be [rule]" ); + continue; + } + ParseRules(passChild, m_listHighlightPass1, level1++); } - } else if (!strcmp(child->Value(), "pass2")) { + } else if (child->GetValue() == "pass2") { // Get sub Nodes ... - TiXmlNode *passChild = child->FirstChild(); - while (NULL != passChild) { - if (passChild->Type()==TiXmlNode::TINYXML_COMMENT) { - // nothing to do ... - } else if (!strcmp(passChild->Value(), "rule")) { - ParseRules(passChild, m_listHighlightPass2, level2++); - } else { - APPL_ERROR("(l "<< passChild->Row() << ") node not suported : \""<< passChild->Value() << "\" must be [rule]" ); + for(int32_t jjj=0; jjj< child->Size(); jjj++) { + exml::Element* passChild = (exml::Element*)child->Get(jjj); + if (passChild==NULL) { + continue; } - // get the next node element : - passChild = passChild->NextSibling(); + if (passChild->GetValue() != "rule") { + APPL_ERROR("(l "<< passChild->Pos() << ") node not suported : \""<< passChild->GetValue() << "\" must be [rule]" ); + continue; + } + ParseRules(passChild, m_listHighlightPass2, level2++); } } else { - APPL_ERROR("(l "<< child->Row() << ") node not suported : \""<< child->Value() << "\" must be [ext,pass1,pass2]" ); + APPL_ERROR("(l "<< child->Pos() << ") node not suported : \""<< child->GetValue() << "\" must be [ext,pass1,pass2]" ); } - // get the next node element : - child = child->NextSibling(); - } - if (NULL != fileBuffer) { - delete[] fileBuffer; } } diff --git a/sources/appl/Highlight/Highlight.h b/sources/appl/Highlight/Highlight.h index 14553a0..b7b5b0f 100644 --- a/sources/appl/Highlight/Highlight.h +++ b/sources/appl/Highlight/Highlight.h @@ -29,12 +29,12 @@ extern "C" { #include #include #include -#include +#include class Highlight { public: // Constructeur - Highlight(etk::UString &xmlFilename); + Highlight(const etk::UString& _xmlFilename); ~Highlight(void); bool HasExtention(etk::UString &ext); bool FileNameCompatible(etk::FSNode &fileName); @@ -50,7 +50,7 @@ class Highlight { etk::Vector &metaData, etk::Buffer &buffer); private: - void ParseRules(TiXmlNode *child, etk::Vector &mListPatern, int32_t level); + void ParseRules(exml::Element* child, etk::Vector &mListPatern, int32_t level); etk::UString m_styleName; //!< curent style name (like "c++" or "c" or "script Bash") etk::Vector m_listExtentions; //!< List of possible extention for this high-light, like : ".c", ".cpp", ".h" etk::Vector m_listHighlightPass1; //!< List of ALL hightlight modules (pass 1 ==> when we load and wride data on the buffer) diff --git a/sources/appl/Highlight/HighlightPattern.cpp b/sources/appl/Highlight/HighlightPattern.cpp index 68ee4ba..cb1c78f 100644 --- a/sources/appl/Highlight/HighlightPattern.cpp +++ b/sources/appl/Highlight/HighlightPattern.cpp @@ -107,7 +107,7 @@ void HighlightPattern::Display(void) m_subPatern[i]->Display(); } } -void HighlightPattern::ParseRules(TiXmlNode *child, int32_t level) +void HighlightPattern::ParseRules(exml::Element *child, int32_t level) { //-------------------------------------------------------------------------------------------- /* @@ -120,51 +120,51 @@ void HighlightPattern::ParseRules(TiXmlNode *child, int32_t level) */ //-------------------------------------------------------------------------------------------- // process attribute - const char *highLightName = child->ToElement()->Attribute("name"); + etk::UString highLightName = child->GetAttribute("name"); etk::UString myEdnDataTmp = "???"; - if (NULL != highLightName) { + if (highLightName.Size()!=0) { myEdnDataTmp = highLightName; } SetName(myEdnDataTmp); SetLevel(level); - TiXmlElement *xChild = child->FirstChildElement("color"); + exml::Element* xChild = (exml::Element*)child->GetNamed("color"); if (NULL != xChild) { - const char *myData = xChild->GetText(); - if (myData) { + etk::UString myData = xChild->GetText(); + if (myData.Size()!=0) { //APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData); etk::UString myEdnData = myData; SetColor(myEdnData); } } - xChild = child->FirstChildElement("start"); + xChild = (exml::Element*)child->GetNamed("start"); if (NULL != xChild) { - const char *myData = xChild->GetText(); - if (myData) { + etk::UString myData = xChild->GetText(); + if (myData.Size()!=0) { //APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData); etk::UString myEdnData = myData; SetPaternStart(myEdnData); } } - xChild = child->FirstChildElement("end"); + xChild = (exml::Element*)child->GetNamed("end"); if (NULL != xChild) { - const char *myData = xChild->GetText(); - if (myData) { + etk::UString myData = xChild->GetText(); + if (myData.Size()!=0) { //APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData); etk::UString myEdnData = myData; SetPaternStop(myEdnData); } } - xChild = child->FirstChildElement("EscapeChar"); + xChild = (exml::Element*)child->GetNamed("EscapeChar"); if (NULL != xChild) { - const char *myData = xChild->GetText(); - if (myData) { + etk::UString myData = xChild->GetText(); + if (myData.Size()!=0) { //APPL_INFO(PFX"(l %d) node fined : %s=\"%s\"", xChild->Row(), xChild->Value() , myData); etk::UString myEdnData = myData; SetEscapeChar(myEdnData); } } - xChild = child->FirstChildElement("rule"); + xChild = (exml::Element*)child->GetNamed("rule"); if (NULL != xChild) { /* // Create the patern ... diff --git a/sources/appl/Highlight/HighlightPattern.h b/sources/appl/Highlight/HighlightPattern.h index c7b1d7f..405305c 100644 --- a/sources/appl/Highlight/HighlightPattern.h +++ b/sources/appl/Highlight/HighlightPattern.h @@ -17,7 +17,7 @@ class HighlightPattern; #include #include #include -#include +#include #include typedef enum { @@ -50,7 +50,7 @@ class HighlightPattern { void Display(void); resultFind_te Find(int32_t start, int32_t stop, colorInformation_ts &resultat, etk::Buffer &buffer); Colorize * GetColor(void) { return m_color; }; - void ParseRules(TiXmlNode *child, int32_t level); + void ParseRules(exml::Element *child, int32_t level); void ReloadColor(void); diff --git a/sources/appl/init.cpp b/sources/appl/init.cpp index a5165d4..cd354f9 100644 --- a/sources/appl/init.cpp +++ b/sources/appl/init.cpp @@ -84,7 +84,6 @@ void APP_Init(void) // set the application icon ... ewol::SetIcon("DATA:icon.png"); - // init ALL Singleton : //(void)CTagsManager::getInstance(); BufferManager::Init(); @@ -137,7 +136,7 @@ void APP_Init(void) } } - APPL_INFO("==> Init Edn (END)"); + APPL_INFO("==> Init "PROJECT_NAME" (END)"); } @@ -146,7 +145,7 @@ void APP_Init(void) */ void APP_UnInit(void) { - APPL_INFO("==> Un-Init Edn (START)"); + APPL_INFO("==> Un-Init "PROJECT_NAME" (START)"); if (NULL != basicWindows) { delete(basicWindows); @@ -162,6 +161,6 @@ void APP_UnInit(void) BufferManager::UnInit(); APPL_INFO("Stop ColorizeManager"); ColorizeManager::UnInit(); - APPL_INFO("==> Un-Init Edn (END)"); + APPL_INFO("==> Un-Init "PROJECT_NAME" (END)"); }