X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d1d9452a687184ac6b992fadc77e89c8a308e388..d12e0d85ae649d5c903a61c1150f4e6c48f96309:/stglibs/dotconfpp.lib/dotconfpp.cpp diff --git a/stglibs/dotconfpp.lib/dotconfpp.cpp b/stglibs/dotconfpp.lib/dotconfpp.cpp index caf5a590..391656a6 100644 --- a/stglibs/dotconfpp.lib/dotconfpp.cpp +++ b/stglibs/dotconfpp.lib/dotconfpp.cpp @@ -23,7 +23,7 @@ #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) { } @@ -117,15 +117,15 @@ int DOTCONFDocument::cleanupLine(char * line) *line = ' ';continue; } if(*line == '\\' && (*(line+1) == '"' || *(line+1) == '\'')){ - *bg++ = *(line+1); + *bg++ = *(line+1); line+=2; continue; } if(*line == '\\' && *(line+1) == 'n'){ - *bg++ = '\n'; + *bg++ = '\n'; line+=2; continue; } if(*line == '\\' && *(line+1) == 'r'){ - *bg++ = '\r'; + *bg++ = '\r'; line+=2; continue; } if(*line == '\\' && (*(line+1) == '\n' || *(line+1) == '\r')){ //multiline @@ -170,7 +170,7 @@ int DOTCONFDocument::cleanupLine(char * line) continue; } *bg++ = *line++; - } + } if(quoted && !multiline){ error(curLine, fileName, "unterminated quote"); @@ -259,7 +259,7 @@ int DOTCONFDocument::parseLine() tagNode->pushValue(nodeValue); } } - + return 0; } int DOTCONFDocument::parseFile(DOTCONFDocumentNode * _parent) @@ -292,7 +292,7 @@ int DOTCONFDocument::parseFile(DOTCONFDocumentNode * _parent) if(ret == -1){ break; } - } + } } } @@ -331,12 +331,12 @@ int DOTCONFDocument::checkConfig(const std::list::iterator } int DOTCONFDocument::setContent(const char * _fileName) -{ +{ 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; } @@ -363,11 +363,11 @@ int DOTCONFDocument::setContent(const char * _fileName) } ret = parseFile(); - + (void) fclose(file); if(!ret){ - + if( (ret = checkConfig(nodeTree.begin())) == -1){ return -1; } @@ -443,7 +443,7 @@ int DOTCONFDocument::setContent(const char * _fileName) //free(fileName); fileName = strdup(realpathBuf); from = nodeTree.end(); --from; - + if(tagNode->parentNode){ DOTCONFDocumentNode * nd = tagNode->parentNode->childNode; while(nd){ @@ -455,7 +455,7 @@ int DOTCONFDocument::setContent(const char * _fileName) curPrev = nd; } ret = parseFile(tagNode->parentNode); - + //ret = parseFile(tagNode->parentNode); (void) fclose(file); if(ret == -1) @@ -487,7 +487,7 @@ int DOTCONFDocument::checkRequiredOptions() { for(std::list::const_iterator ci = requiredOptions.begin(); ci != requiredOptions.end(); ++ci){ bool matched = false; - for(std::list::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){ + for(std::list::iterator i = nodeTree.begin(); i!=nodeTree.end(); ++i){ if(!cmp_func((*i)->name, *ci)){ matched = true; break; @@ -514,9 +514,9 @@ void DOTCONFDocument::error(int lineNum, const char * fileName, const char * fmt 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 - (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); @@ -562,7 +562,7 @@ char * DOTCONFDocument::getSubstitution(char * macro, int lineNum) buf = mempool->strdup(subs); } else { std::list::iterator i = nodeTree.begin(); - for(; i!=nodeTree.end(); ++i){ + for(; i!=nodeTree.end(); ++i){ DOTCONFDocumentNode * tagNode = *i; if(!cmp_func(tagNode->name, variable)){ if(tagNode->valuesCount != 0){ @@ -629,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"); - + std::list::const_iterator i = nodeTree.begin(); if(startNode == NULL)