]> git.stg.codes - stg.git/blobdiff - stglibs/dotconfpp.lib/dotconfpp.cpp
convertor -> sgconv in docs.
[stg.git] / stglibs / dotconfpp.lib / dotconfpp.cpp
index 8ac254405b493b9229005e8da7b5eb0e15786fe2..391656a63c4103e1242dea7f2931752533b42ca7 100644 (file)
 #include <glob.h> // glob
 #include <string>
 
 #include <glob.h> // glob
 #include <string>
 
-#include "dotconfpp.h"
+#include "stg/dotconfpp.h"
 #include "mempool.h"
 
 DOTCONFDocumentNode::DOTCONFDocumentNode():previousNode(NULL), nextNode(NULL), parentNode(NULL), childNode(NULL),
 #include "mempool.h"
 
 DOTCONFDocumentNode::DOTCONFDocumentNode():previousNode(NULL), nextNode(NULL), parentNode(NULL), childNode(NULL),
-    values(NULL), valuesCount(0), 
+    values(NULL), valuesCount(0),
     name(NULL), lineNum(0), fileName(NULL), closed(true)
 {
 }
     name(NULL), lineNum(0), fileName(NULL), closed(true)
 {
 }
@@ -71,13 +71,13 @@ DOTCONFDocument::DOTCONFDocument(DOTCONFDocument::CaseSensitive caseSensitivity)
 
 DOTCONFDocument::~DOTCONFDocument()
 {
 
 DOTCONFDocument::~DOTCONFDocument()
 {
-    for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i != nodeTree.end(); i++){
+    for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i != nodeTree.end(); ++i){
         delete(*i);
     }
         delete(*i);
     }
-    for(std::list<char*>::iterator i = requiredOptions.begin(); i != requiredOptions.end(); i++){
+    for(std::list<char*>::iterator i = requiredOptions.begin(); i != requiredOptions.end(); ++i){
         free(*i);
     }
         free(*i);
     }
-    for(std::list<char*>::iterator i = processedFiles.begin(); i != processedFiles.end(); i++){
+    for(std::list<char*>::iterator i = processedFiles.begin(); i != processedFiles.end(); ++i){
         free(*i);
     }
     free(fileName);
         free(*i);
     }
     free(fileName);
@@ -117,15 +117,15 @@ int DOTCONFDocument::cleanupLine(char * line)
             *line = ' ';continue;
         }
         if(*line == '\\' && (*(line+1) == '"' || *(line+1) == '\'')){
             *line = ' ';continue;
         }
         if(*line == '\\' && (*(line+1) == '"' || *(line+1) == '\'')){
-            *bg++ = *(line+1); 
+            *bg++ = *(line+1);
             line+=2; continue;
         }
         if(*line == '\\' && *(line+1) == 'n'){
             line+=2; continue;
         }
         if(*line == '\\' && *(line+1) == 'n'){
-            *bg++ = '\n'; 
+            *bg++ = '\n';
             line+=2; continue;
         }
         if(*line == '\\' && *(line+1) == 'r'){
             line+=2; continue;
         }
         if(*line == '\\' && *(line+1) == 'r'){
-            *bg++ = '\r'; 
+            *bg++ = '\r';
             line+=2; continue;
         }
         if(*line == '\\' && (*(line+1) == '\n' || *(line+1) == '\r')){ //multiline
             line+=2; continue;
         }
         if(*line == '\\' && (*(line+1) == '\n' || *(line+1) == '\r')){ //multiline
@@ -170,7 +170,7 @@ int DOTCONFDocument::cleanupLine(char * line)
             continue;
         }
         *bg++ = *line++;
             continue;
         }
         *bg++ = *line++;
-    }    
+    }
 
     if(quoted && !multiline){
         error(curLine, fileName, "unterminated quote");
 
     if(quoted && !multiline){
         error(curLine, fileName, "unterminated quote");
@@ -188,7 +188,7 @@ int DOTCONFDocument::parseLine()
     DOTCONFDocumentNode * tagNode = NULL;
     bool newNode = false;
 
     DOTCONFDocumentNode * tagNode = NULL;
     bool newNode = false;
 
-    for(std::list<char*>::iterator i = words.begin(); i != words.end(); i++) {
+    for(std::list<char*>::iterator i = words.begin(); i != words.end(); ++i) {
         word = *i;
 
         if(*word == '<'){
         word = *i;
 
         if(*word == '<'){
@@ -217,7 +217,7 @@ int DOTCONFDocument::parseLine()
                 } else { //closing tag
                     nodeName+=2;
                     std::list<DOTCONFDocumentNode*>::reverse_iterator i=nodeTree.rbegin();
                 } else { //closing tag
                     nodeName+=2;
                     std::list<DOTCONFDocumentNode*>::reverse_iterator i=nodeTree.rbegin();
-                    for(; i!=nodeTree.rend(); i++){
+                    for(; i!=nodeTree.rend(); ++i){
                         if(!cmp_func(nodeName, (*i)->name) && !(*i)->closed){
                             (*i)->closed = true;
                             curParent = (*i)->parentNode;
                         if(!cmp_func(nodeName, (*i)->name) && !(*i)->closed){
                             (*i)->closed = true;
                             curParent = (*i)->parentNode;
@@ -259,7 +259,7 @@ int DOTCONFDocument::parseLine()
             tagNode->pushValue(nodeValue);
         }
     }
             tagNode->pushValue(nodeValue);
         }
     }
-    
+
     return 0;
 }
 int DOTCONFDocument::parseFile(DOTCONFDocumentNode * _parent)
     return 0;
 }
 int DOTCONFDocument::parseFile(DOTCONFDocumentNode * _parent)
@@ -270,11 +270,10 @@ int DOTCONFDocument::parseFile(DOTCONFDocumentNode * _parent)
     curParent = _parent;
 
     quoted = false;
     curParent = _parent;
 
     quoted = false;
-    size_t slen = 0;
 
     while(fgets(str, 511, file)){
         curLine++;
 
     while(fgets(str, 511, file)){
         curLine++;
-       slen = strlen(str);
+       size_t slen = strlen(str);
         if( slen >= 510 ){
             error(curLine, fileName, "warning: line too long");
         }
         if( slen >= 510 ){
             error(curLine, fileName, "warning: line too long");
         }
@@ -293,7 +292,7 @@ int DOTCONFDocument::parseFile(DOTCONFDocumentNode * _parent)
                 if(ret == -1){
                     break;
                 }
                 if(ret == -1){
                     break;
                 }
-            }            
+            }
         }
     }
 
         }
     }
 
@@ -304,16 +303,14 @@ int DOTCONFDocument::checkConfig(const std::list<DOTCONFDocumentNode*>::iterator
 {
     int ret = 0;
 
 {
     int ret = 0;
 
-    DOTCONFDocumentNode * tagNode = NULL;
-    int vi = 0;
-    for(std::list<DOTCONFDocumentNode*>::iterator i = from; i != nodeTree.end(); i++){
-        tagNode = *i;
+    for(std::list<DOTCONFDocumentNode*>::iterator i = from; i != nodeTree.end(); ++i){
+        DOTCONFDocumentNode * tagNode = *i;
         if(!tagNode->closed){
             error(tagNode->lineNum, tagNode->fileName, "unclosed tag %s", tagNode->name);
             ret = -1;
             break;
         }
         if(!tagNode->closed){
             error(tagNode->lineNum, tagNode->fileName, "unclosed tag %s", tagNode->name);
             ret = -1;
             break;
         }
-        vi = 0;
+        int vi = 0;
         while( vi < tagNode->valuesCount ){
             //if((tagNode->values[vi])[0] == '$' && (tagNode->values[vi])[1] == '{' && strchr(tagNode->values[vi], '}') ){
             if(strstr(tagNode->values[vi], "${") && strchr(tagNode->values[vi], '}') ){
         while( vi < tagNode->valuesCount ){
             //if((tagNode->values[vi])[0] == '$' && (tagNode->values[vi])[1] == '{' && strchr(tagNode->values[vi], '}') ){
             if(strstr(tagNode->values[vi], "${") && strchr(tagNode->values[vi], '}') ){
@@ -334,12 +331,12 @@ int DOTCONFDocument::checkConfig(const std::list<DOTCONFDocumentNode*>::iterator
 }
 
 int DOTCONFDocument::setContent(const char * _fileName)
 }
 
 int DOTCONFDocument::setContent(const char * _fileName)
-{    
+{
     int ret = 0;
     char realpathBuf[PATH_MAX];
 
     if(realpath(_fileName, realpathBuf) == NULL){
     int ret = 0;
     char realpathBuf[PATH_MAX];
 
     if(realpath(_fileName, realpathBuf) == NULL){
-        error(0, _fileName, "realpath('%s') failed: %s", _fileName, strerror(errno));
+        error(0, _fileName, "%s", strerror(errno));
         return -1;
     }
 
         return -1;
     }
 
@@ -366,11 +363,11 @@ int DOTCONFDocument::setContent(const char * _fileName)
     }
 
     ret = parseFile();
     }
 
     ret = parseFile();
-    
+
     (void) fclose(file);
 
     if(!ret){
     (void) fclose(file);
 
     if(!ret){
-    
+
         if( (ret = checkConfig(nodeTree.begin())) == -1){
             return -1;
         }
         if( (ret = checkConfig(nodeTree.begin())) == -1){
             return -1;
         }
@@ -378,7 +375,7 @@ int DOTCONFDocument::setContent(const char * _fileName)
         std::list<DOTCONFDocumentNode*>::iterator from;
         DOTCONFDocumentNode * tagNode = NULL;
         int vi = 0;
         std::list<DOTCONFDocumentNode*>::iterator from;
         DOTCONFDocumentNode * tagNode = NULL;
         int vi = 0;
-        for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); i++){
+        for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){
             tagNode = *i;
             if(!cmp_func("IncludeFile", tagNode->name)){
                 vi = 0;
             tagNode = *i;
             if(!cmp_func("IncludeFile", tagNode->name)){
                 vi = 0;
@@ -426,7 +423,7 @@ int DOTCONFDocument::setContent(const char * _fileName)
                             }
 
                             bool processed = false;
                             }
 
                             bool processed = false;
-                            for(std::list<char*>::const_iterator itInode = processedFiles.begin(); itInode != processedFiles.end(); itInode++){
+                            for(std::list<char*>::const_iterator itInode = processedFiles.begin(); itInode != processedFiles.end(); ++itInode){
                                 if(!strcmp(*itInode, realpathBuf)){
                                     processed = true;
                                     break;
                                 if(!strcmp(*itInode, realpathBuf)){
                                     processed = true;
                                     break;
@@ -445,8 +442,8 @@ int DOTCONFDocument::setContent(const char * _fileName)
                             }
                             //free(fileName);
                             fileName = strdup(realpathBuf);
                             }
                             //free(fileName);
                             fileName = strdup(realpathBuf);
-                            from = nodeTree.end(); from--;
-                            
+                            from = nodeTree.end(); --from;
+
                             if(tagNode->parentNode){
                                 DOTCONFDocumentNode * nd = tagNode->parentNode->childNode;
                                 while(nd){
                             if(tagNode->parentNode){
                                 DOTCONFDocumentNode * nd = tagNode->parentNode->childNode;
                                 while(nd){
@@ -458,7 +455,7 @@ int DOTCONFDocument::setContent(const char * _fileName)
                                 curPrev = nd;
                             }
                             ret = parseFile(tagNode->parentNode);
                                 curPrev = nd;
                             }
                             ret = parseFile(tagNode->parentNode);
-                            
+
                             //ret = parseFile(tagNode->parentNode);
                             (void) fclose(file);
                             if(ret == -1)
                             //ret = parseFile(tagNode->parentNode);
                             (void) fclose(file);
                             if(ret == -1)
@@ -488,9 +485,9 @@ int DOTCONFDocument::setContent(const char * _fileName)
 
 int DOTCONFDocument::checkRequiredOptions()
 {
 
 int DOTCONFDocument::checkRequiredOptions()
 {
-    for(std::list<char*>::const_iterator ci = requiredOptions.begin(); ci != requiredOptions.end(); ci++){
+    for(std::list<char*>::const_iterator ci = requiredOptions.begin(); ci != requiredOptions.end(); ++ci){
         bool matched = false;
         bool matched = false;
-        for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); i++){            
+        for(std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){
             if(!cmp_func((*i)->name, *ci)){
                 matched = true;
                 break;
             if(!cmp_func((*i)->name, *ci)){
                 matched = true;
                 break;
@@ -517,9 +514,9 @@ void DOTCONFDocument::error(int lineNum, const char * fileName, const char * fmt
     char * buf = (char*)mempool->alloc(len);
 
     if(lineNum)
     char * buf = (char*)mempool->alloc(len);
 
     if(lineNum)
-        (void) snprintf(buf, len, "DOTCONF++: file '%s', line %d: %s\n", fileName, lineNum, msg);
+        (void) snprintf(buf, len, "File '%s', line %d: %s\n", fileName, lineNum, msg);
     else
     else
-        (void) snprintf(buf, len, "DOTCONF++: file '%s':  %s\n", fileName, msg);
+        (void) snprintf(buf, len, "File '%s':  %s\n", fileName, msg);
 
     if (errorCallback) {
         errorCallback(errorCallbackData, buf);
 
     if (errorCallback) {
         errorCallback(errorCallbackData, buf);
@@ -565,9 +562,8 @@ char * DOTCONFDocument::getSubstitution(char * macro, int lineNum)
         buf = mempool->strdup(subs);
     } else {
         std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin();
         buf = mempool->strdup(subs);
     } else {
         std::list<DOTCONFDocumentNode*>::iterator i = nodeTree.begin();
-        DOTCONFDocumentNode * tagNode = NULL;
-        for(; i!=nodeTree.end(); i++){            
-            tagNode = *i;
+        for(; i!=nodeTree.end(); ++i){
+            DOTCONFDocumentNode * tagNode = *i;
             if(!cmp_func(tagNode->name, variable)){
                 if(tagNode->valuesCount != 0){
                     buf = mempool->strdup(tagNode->values[0]);
             if(!cmp_func(tagNode->name, variable)){
                 if(tagNode->valuesCount != 0){
                     buf = mempool->strdup(tagNode->values[0]);
@@ -633,7 +629,7 @@ const DOTCONFDocumentNode * DOTCONFDocument::getFirstNode() const
 const DOTCONFDocumentNode * DOTCONFDocument::findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode, const DOTCONFDocumentNode * startNode) const
 {
     //printf("nodeName=%s, cont=%s, start=%s\n", nodeName, containingNode!=NULL?containingNode->name:"NULL", startNode!=NULL?startNode->name:"NULL");
 const DOTCONFDocumentNode * DOTCONFDocument::findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode, const DOTCONFDocumentNode * startNode) const
 {
     //printf("nodeName=%s, cont=%s, start=%s\n", nodeName, containingNode!=NULL?containingNode->name:"NULL", startNode!=NULL?startNode->name:"NULL");
-    
+
     std::list<DOTCONFDocumentNode*>::const_iterator i = nodeTree.begin();
 
     if(startNode == NULL)
     std::list<DOTCONFDocumentNode*>::const_iterator i = nodeTree.begin();
 
     if(startNode == NULL)
@@ -641,12 +637,12 @@ const DOTCONFDocumentNode * DOTCONFDocument::findNode(const char * nodeName, con
 
     if(startNode != NULL){
         while( i != nodeTree.end() && (*i) != startNode ){
 
     if(startNode != NULL){
         while( i != nodeTree.end() && (*i) != startNode ){
-            i++;
+            ++i;
         }
         }
-        if( i != nodeTree.end() ) i++;
+        if( i != nodeTree.end() ) ++i;
     }
 
     }
 
-    for(; i!=nodeTree.end(); i++){
+    for(; i!=nodeTree.end(); ++i){
         //if(parentNode != NULL && (*i)->parentNode != parentNode){
        if((*i)->parentNode != parentNode){
             continue;
         //if(parentNode != NULL && (*i)->parentNode != parentNode){
        if((*i)->parentNode != parentNode){
             continue;