[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    A simple patch
From:       Pupeno <pupeno () pupeno ! com ! ar>
Date:       2002-04-23 23:48:58
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In this file I include a patch I've made katesyntaxdocument.cpp and 
katesyntaxdocument.h.
I didn't really modify the functionality but I tidy it up to work as better as 
posible with Kate hiding/showing system of blocks, I've tidy up the 
indentation and that kind of the stuff and I've added lot's of comments as 
I'm understanding what it does, please check them to see if I didn't 
missunderstood something, ok ?
I prepeare the documentation so kdoc can build the api documentation.
I've also added some comments spoting posible problems that can be the causes 
of some crashes while reading bad hl definitions.
I didn't understand some functions, please, explain me what they do so I can 
continue with my work.
My intentions are to fix the problem of Kate not storing the custom colors for 
the hl mode list and then work on making it more robust so Kate wouldn't 
crash when reading xml files and making debugin of xml more easy as Joseph 
told me.
thank you! See you!
- -- 
Pupeno: pupeno@pupeno.com.ar
http://www.pupeno.com.ar
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8xfLsWhjnmGRO4vQRAmxpAJ9KOGM99myoTZGPwdgI93tUSJFzLgCgggUT
nWXiFj5oCTv3YthTBH/aBVo=
=wkYz
-----END PGP SIGNATURE-----

["katesyntaxpatch.diff" (text/x-diff)]

Index: katesyntaxdocument.cpp
===================================================================
RCS file: /home/kde/kdelibs/kate/part/katesyntaxdocument.cpp,v
retrieving revision 1.8
diff -u -3 -p -u -r1.8 katesyntaxdocument.cpp
--- katesyntaxdocument.cpp	22 Apr 2002 19:04:33 -0000	1.8
+++ katesyntaxdocument.cpp	24 Apr 2002 02:40:45 -0000
@@ -29,50 +29,73 @@
 #include <kapp.h>
 #include <kconfig.h>
 
-SyntaxDocument::SyntaxDocument() : QDomDocument()
-{
-  currentFile="";
+/** Constructor
+    Sets the current file to nothing and build the ModeList \
(katesyntaxhighlightingrc) +Pupeno */
+SyntaxDocument::SyntaxDocument() : QDomDocument(){
+  // There's no current file
+  currentFile="";           
+  // Let's build the Mode List (katesyntaxhighlightingrc)
   setupModeList();
   myModeList.setAutoDelete( true );
 }
 
-void SyntaxDocument::setIdentifier(const QString& identifier)
-{
-  if (currentFile!=identifier)
-  {
-    QFile f( identifier );
-
-    if ( f.open(IO_ReadOnly) )
-    {
-      setContent(&f);
-      currentFile=identifier;
+/** If the open hl file is different from the one needed, it opens
+    the new one and assign some other things.
+    identifier = File name and path of the new xml needed
+Pupeno */
+void SyntaxDocument::setIdentifier(const QString& identifier){
+  // if the current file is the same as the new one don't do anything.
+  if(currentFile!=identifier){
+    // let's open the new file
+    QFile f( identifier );                                            
+    
+    if ( f.open(IO_ReadOnly) ){
+      // Let's parse the contets of the xml file
+      /* The result of this function should be check for robustness, 
+         a false returned means a parse error */
+      setContent(&f);                           
+      // Ok, now the current file is the pretended one (identifier)
+      currentFile=identifier;                                      
+      // Close the file, is not longer needed
       f.close();
     }
-    else
+    else {                                   
+      // Oh o, we couldn't open the file.
       KMessageBox::error( 0L, i18n("Can't open %1").arg(identifier) );
+    }
   }
 }
 
-SyntaxDocument::~SyntaxDocument()
-{
+/** Destructor
+Pupeno */
+SyntaxDocument::~SyntaxDocument(){
 }
 
-void SyntaxDocument::setupModeList(bool force)
-{
+/** Generate the list of hl modes, store them in myModeList
+    force: if true forces to rebuild the Mode List from the xml files (instead of \
katesyntax...rc) +Pupeno */
+void SyntaxDocument::setupModeList(bool force){
+  // If there's something in myModeList the Mode List was already built so, don't do \
it again  if (myModeList.count() > 0) return;
-
+  
+  // We'll store the ModeList in katesyntaxhighlightingrc
   KConfig config("katesyntaxhighlightingrc");
+                                   
+  // Let's get a list of all the xml files for hl
   KStandardDirs *dirs = KGlobal::dirs();
-
   QStringList list=dirs->findAllResources("data","kate/syntax/*.xml",false,true);
-
-  for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
-  {
+  
+  // Let's iterate trhu the list and build the Mode List
+  for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )  {
+    // Each file has a group called:
     QString Group="Highlighting_Cache"+*it;
-
-    if ((config.hasGroup(Group)) && (!force))
-    {
-      config.setGroup(Group);
+    
+    // If the group exist and we're not forced to read the xml file, let's build \
myModeList for katesyntax..rc                                        +    if \
((config.hasGroup(Group)) && (!force)){ +      // Let's go to this group
+      config.setGroup(Group);  
+      // Let's make a new syntaxModeListItem to instert in myModeList from the \
information in katesyntax..rc  syntaxModeListItem *mli=new syntaxModeListItem;
       mli->name = config.readEntry("name","");
       mli->section = i18n(config.readEntry("section","").utf8());
@@ -80,154 +103,173 @@ void SyntaxDocument::setupModeList(bool 
       mli->extension = config.readEntry("extension","");
       mli->version = config.readEntry("version","");
       mli->identifier = *it;
+      // Apend the item to the list
       myModeList.append(mli);
-    }
-    else
-    {
+    } 
+    else {
+      // We're forced to read the xml files or the mode doesn't exist in the \
katesyntax...rc  QFile f(*it);
 
-      if (f.open(IO_ReadOnly))
-      {
+      if (f.open(IO_ReadOnly)) {
+        // Ok we opened the file, let's read the contents and close the file
+        /* the return of setContent should be checked because a false return shows a \
parsing error */  setContent(&f);
         f.close();
         QDomElement n = documentElement();
-        if (!n.isNull())
-        {
+        if (!n.isNull()){
+          // What does this do ???? Pupeno
           QDomElement e=n.toElement();
-
-          if (e.tagName()=="language")
-          {
+          
+          // If the 'first' tag is language, go on 
+          if (e.tagName()=="language"){
+            // let's make the mode list item.
             syntaxModeListItem *mli=new syntaxModeListItem;
-            mli->name = e.attribute("name");
+            mli->name = e.attribute("name"); 
+            // Is this safe for translators ? I mean, they must add by hand the \
transalation for each section. +            // This could be done by a switch or ifs \
with the allowed sections but a new +            // section will can't be added \
without recompiling and it's not a very versatil +            // way, adding a new \
section (from the xml files) would break the translations. +            // Why don't \
we store everything in english internaly and we translate it just when showing it.  \
mli->section = i18n(e.attribute("section").utf8());  mli->mimetype = \
e.attribute("mimetype");  mli->extension = e.attribute("extensions");
-	    mli->version = e.attribute("version");	
-
-            if (mli->section.isEmpty())
+            mli->version = e.attribute("version");	
+            
+            // I think this solves the proble, everything not in the .po is Other.
+            if (mli->section.isEmpty()){
               mli->section=i18n("Other");
+             }
 
             mli->identifier = *it;
-
+            
+            // Now let's write or overwrite (if force==true) the entry in \
katesyntax...rc  config.setGroup(Group);
             config.writeEntry("name",mli->name);
             config.writeEntry("section",mli->section);
             config.writeEntry("mimetype",mli->mimetype);
             config.writeEntry("extension",mli->extension);
-	    config.writeEntry("version",mli->version);
+            config.writeEntry("version",mli->version);
+            // Append the new item to the list.
             myModeList.append(mli);
           }
         }
       }
     }
   }
-
+  // Syncronize with the file katesyntax...rc
   config.sync();
 }
 
-SyntaxModeList SyntaxDocument::modeList()
-{
+/** Get the mode list
+Pupeno */
+SyntaxModeList SyntaxDocument::modeList(){
   return myModeList;
 }
 
-bool SyntaxDocument::nextGroup( syntaxContextData* data)
-{
-  if(!data) return false;
+bool SyntaxDocument::nextGroup( syntaxContextData* data){
+  if(!data){
+    return false;
+  }
 
-  if (data->currentGroup.isNull())
+  if (data->currentGroup.isNull()){
     data->currentGroup=data->parent.firstChild().toElement();
-  else
+  }
+  else {
     data->currentGroup=data->currentGroup.nextSibling().toElement();
+  }
 
   data->item=QDomElement();
 
-  if (data->currentGroup.isNull())
+  if (data->currentGroup.isNull()){
     return false;
-  else
+  }
+  else {
     return true;
+  }
 }
 
-bool SyntaxDocument::nextItem( syntaxContextData* data)
-{
+bool SyntaxDocument::nextItem( syntaxContextData* data){
   if(!data) return false;
 
-  if (data->item.isNull())
+  if (data->item.isNull()){
     data->item=data->currentGroup.firstChild().toElement();
-  else
+  }
+  else {
     data->item=data->item.nextSibling().toElement();
+  }
 
-  if (data->item.isNull())
+  if (data->item.isNull()){
     return false;
-  else
+  }
+  else {
     return true;
+  }
 }
 
-QString SyntaxDocument::groupItemData( const syntaxContextData* data,const QString& \
                name)
-{
-  if(!data)
+QString SyntaxDocument::groupItemData( const syntaxContextData* data,const QString& \
name){ +  if(!data){
     return QString::null;
+  }
 
-  if ( (!data->item.isNull()) && (name.isEmpty()))
-    return data->item.tagName();
+  if ( (!data->item.isNull()) && (name.isEmpty())){
+    return data->item.tagName();                   
+  }
 
-  if (!data->item.isNull())
+  if (!data->item.isNull()){
     return data->item.attribute(name);
-  else
+  }
+  else {
     return QString();
+  }
 }
 
-QString SyntaxDocument::groupData( const syntaxContextData* data,const QString& \
                name)
-{
-  if(!data)
+QString SyntaxDocument::groupData( const syntaxContextData* data,const QString& \
name){ +  if(!data){
     return QString::null;
+  }
 
-  if (!data->currentGroup.isNull())
+  if (!data->currentGroup.isNull()){
     return data->currentGroup.attribute(name);
-  else
+  }
+  else {
     return QString::null;
+  }
 }
 
-void SyntaxDocument::freeGroupInfo( syntaxContextData* data)
-{
-  if (data)
+void SyntaxDocument::freeGroupInfo( syntaxContextData* data){
+  if (data){
     delete data;
+  }
 }
 
-syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data)
-{
+syntaxContextData* SyntaxDocument::getSubItems(syntaxContextData* data){
   syntaxContextData *retval=new syntaxContextData;
 
-  if (data != 0)
-  {
+  if (data != 0){
     retval->parent=data->currentGroup;
     retval->currentGroup=data->item;
     retval->item=QDomElement();
-   }
+  }
 
   return retval;
 }
 
-syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const \
                QString &Config)
-{
+syntaxContextData* SyntaxDocument::getConfig(const QString& mainGroupName, const \
QString &Config){  QDomElement docElem = documentElement();
   QDomNode n = docElem.firstChild();
 
-  while (!n.isNull())
-  {
+  while(!n.isNull()){
     kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl;
     QDomElement e=n.toElement();
 
-    if (e.tagName().compare(mainGroupName)==0 )
-    {
+    if (e.tagName().compare(mainGroupName)==0 ){
       QDomNode n1=e.firstChild();
 
-      while (!n1.isNull())
-      {
+      while (!n1.isNull()){
         kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl;
         QDomElement e1=n1.toElement();
 
-        if (e1.tagName()==Config)
-        {
+        if (e1.tagName()==Config){
           syntaxContextData *data=new ( syntaxContextData);
           data->item=e1;
           return data;
@@ -249,27 +291,22 @@ syntaxContextData* SyntaxDocument::getCo
 
 
 
-syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const \
                QString &group)
-{
+syntaxContextData* SyntaxDocument::getGroupInfo(const QString& mainGroupName, const \
QString &group){  QDomElement docElem = documentElement();
   QDomNode n = docElem.firstChild();
 
-  while (!n.isNull())
-  {
+  while (!n.isNull()){
     kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (outer loop) " <<endl;
     QDomElement e=n.toElement();
 
-    if (e.tagName().compare(mainGroupName)==0 )
-    {
+    if (e.tagName().compare(mainGroupName)==0 ){
       QDomNode n1=e.firstChild();
 
-      while (!n1.isNull())
-      {
+      while (!n1.isNull()){
         kdDebug(13010)<<"in SyntaxDocument::getGroupInfo (inner loop) " <<endl;
         QDomElement e1=n1.toElement();
 
-        if (e1.tagName()==group+"s")
-        {
+        if (e1.tagName()==group+"s"){
           syntaxContextData *data=new ( syntaxContextData);
           data->parent=e1;
           return data;
@@ -290,32 +327,28 @@ syntaxContextData* SyntaxDocument::getGr
 }
 
 
-QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& \
                type,bool clearList)
-{
+QStringList& SyntaxDocument::finddata(const QString& mainGroup,const QString& \
type,bool clearList){  QDomElement e  = documentElement();
-  if (clearList)
+  if (clearList){
     m_data.clear();
+  }
 
-  for(QDomNode n=e.firstChild(); !n.isNull(); n=n.nextSibling())
-  {
-    if (n.toElement().tagName()==mainGroup)
-    {
+  for(QDomNode n=e.firstChild(); !n.isNull(); n=n.nextSibling()){
+    if (n.toElement().tagName()==mainGroup){
       QDomNodeList nodelist1=n.toElement().elementsByTagName("list");
 
-      for (uint l=0; l<nodelist1.count();l++)
-      {
-        if (nodelist1.item(l).toElement().attribute("name")==type)
-        {
+      for (uint l=0; l<nodelist1.count();l++){
+        if (nodelist1.item(l).toElement().attribute("name")==type){
           n=nodelist1.item(l).toElement();
           QDomNodeList childlist=n.childNodes();
 
-          for (uint i=0; i<childlist.count();i++)
+          for (uint i=0; i<childlist.count();i++){
             m_data+=childlist.item(i).toElement().text().stripWhiteSpace();
+          }
 
           break;
         }
       }
-
       break;
     }
   }
Index: katesyntaxdocument.h
===================================================================
RCS file: /home/kde/kdelibs/kate/part/katesyntaxdocument.h,v
retrieving revision 1.6
diff -u -3 -p -u -r1.6 katesyntaxdocument.h
--- katesyntaxdocument.h	22 Apr 2002 19:04:33 -0000	1.6
+++ katesyntaxdocument.h	24 Apr 2002 02:40:45 -0000
@@ -20,16 +20,19 @@
 #ifndef _KATE_SYNTAXDOCUMENT_H_
 #define _KATE_SYNTAXDOCUMENT_H_
 
+//BEGING INCLUDES
 #include "kateglobal.h"
 
 #include <qdom.h>
 #include <qptrlist.h>
 #include <qstringlist.h>
+//END INCLUDES
 
 class QStringList;
 
-class syntaxModeListItem
-{
+/** Information about each syntax hl Mode 
+Pupeno */
+class syntaxModeListItem{
   public:
     QString name;
     QString section;
@@ -39,8 +42,8 @@ class syntaxModeListItem
     QString version;
 };
 
-class syntaxContextData
-{
+
+class syntaxContextData{
   public:
     QDomElement parent;
     QDomElement currentGroup;
@@ -49,13 +52,23 @@ class syntaxContextData
 
 typedef QPtrList<syntaxModeListItem> SyntaxModeList;
 
-class SyntaxDocument : public QDomDocument
-{
+/** Store and manage the information about Syntax Highlighting.
+Pupeno */
+class SyntaxDocument : public QDomDocument{
   public:
+    /** Constructor
+        Sets the current file to nothing and build the ModeList \
(katesyntaxhighlightingrc) +    Pupeno */
     SyntaxDocument();
+    
+    /** Desctructor
+    Pupeno */
     ~SyntaxDocument();
 
     QStringList& finddata(const QString& mainGroup,const QString& type,bool \
clearList=true); +    
+    /** Get the mode list
+    Pupeno */
     SyntaxModeList modeList();
 
     syntaxContextData* getGroupInfo(const QString& langName, const QString &group);
@@ -66,11 +79,22 @@ class SyntaxDocument : public QDomDocume
     syntaxContextData* getSubItems(syntaxContextData* data);
     QString groupItemData(const syntaxContextData* data,const QString& name);
     QString groupData(const syntaxContextData* data,const QString& name);
+    
+    /** If the open hl file is different from the one needed, it opens
+        the new one and assign some other things.
+         identifier = File name and path of the new xml needed
+    Pupeno */
     void setIdentifier(const QString& identifier);
 
   private:
-     void setupModeList(bool force=false);
-     QString currentFile;
+    /** Generate the list of hl modes, store them in myModeList
+        force: if true forces to rebuild the Mode List from the xml files (instead \
of katesyntax...rc) +    Pupeno */
+    void setupModeList(bool force=false);
+    QString currentFile;
+    
+    /** List of mode items 
+    Pupeno */
     SyntaxModeList myModeList;
     QStringList m_data;
 };


_______________________________________________
kwrite-devel mailing list
kwrite-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kwrite-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic