diff options
Diffstat (limited to 'src/shared/Config')
-rw-r--r-- | src/shared/Config/Config.cpp | 118 | ||||
-rw-r--r-- | src/shared/Config/Config.h | 20 | ||||
-rw-r--r-- | src/shared/Config/ConfigEnv.h | 4 | ||||
-rw-r--r-- | src/shared/Config/Makefile.am | 42 | ||||
-rw-r--r-- | src/shared/Config/dotconfpp/dotconfpp.cpp | 36 | ||||
-rw-r--r-- | src/shared/Config/dotconfpp/dotconfpp.h | 13 | ||||
-rw-r--r-- | src/shared/Config/dotconfpp/mempool.cpp | 6 |
7 files changed, 101 insertions, 138 deletions
diff --git a/src/shared/Config/Config.cpp b/src/shared/Config/Config.cpp index 4f9402b5f01..b56b804b50a 100644 --- a/src/shared/Config/Config.cpp +++ b/src/shared/Config/Config.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -60,118 +60,48 @@ bool Config::Reload() return true; } -bool Config::GetString(const char* name, std::string *value) -{ - if(!mConf) - return false; - - DOTCONFDocumentNode const *node = mConf->findNode(name); - if(!node || !node->getValue()) - return false; - - *value = node->getValue(); - - return true; -} - -bool Config::GetString(const char* name, char const **value) -{ - if(!mConf) - return false; - - DOTCONFDocumentNode const *node = mConf->findNode(name); - if(!node || !node->getValue()) - return false; - - *value = node->getValue(); - - return true; -} - - -std::string Config::GetStringDefault(const char* name, const char* def) +std::string Config::GetStringDefault(const char * name, std::string def) { if(!mConf) return std::string(def); - - DOTCONFDocumentNode const *node = mConf->findNode(name); + const DOTCONFDocumentNode * node = mConf->findNode(name); if(!node || !node->getValue()) return std::string(def); - return std::string(node->getValue()); -} - +}; -bool Config::GetBool(const char* name, bool *value) +bool Config::GetBoolDefault(const char * name, const bool def) { if(!mConf) return false; - - DOTCONFDocumentNode const *node = mConf->findNode(name); + const DOTCONFDocumentNode * node = mConf->findNode(name); if(!node || !node->getValue()) - return false; - - const char* str = node->getValue(); + return def; + const char * str = node->getValue(); if(strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 || strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 || strcmp(str, "1") == 0) - { - *value = true; - } + return true; else - *value = false; - - return true; -} - - -bool Config::GetBoolDefault(const char* name, const bool def) -{ - bool val; - return GetBool(name, &val) ? val : def; -} - + return false; +}; -bool Config::GetInt(const char* name, int *value) +int32 Config::GetIntDefault(const char * name, const int32 def) { if(!mConf) - return false; - - DOTCONFDocumentNode const *node = mConf->findNode(name); + return def; + const DOTCONFDocumentNode * node = mConf->findNode(name); if(!node || !node->getValue()) - return false; - - *value = atoi(node->getValue()); - - return true; -} - + return def; + return atoi(node->getValue()); +}; -bool Config::GetFloat(const char* name, float *value) +float Config::GetFloatDefault(const char * name, const float def) { if(!mConf) - return false; - - DOTCONFDocumentNode const *node = mConf->findNode(name); + return def; + const DOTCONFDocumentNode * node = mConf->findNode(name); if(!node || !node->getValue()) - return false; - - *value = atof(node->getValue()); - - return true; -} - - -int Config::GetIntDefault(const char* name, const int def) -{ - int val; - return GetInt(name, &val) ? val : def; -} - - -float Config::GetFloatDefault(const char* name, const float def) -{ - float val; - return (GetFloat(name, &val) ? val : def); -} - + return def; + return atof(node->getValue()); +}; diff --git a/src/shared/Config/Config.h b/src/shared/Config/Config.h index 4dbff1b1153..7070e6180c0 100644 --- a/src/shared/Config/Config.h +++ b/src/shared/Config/Config.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,18 +35,10 @@ class TRINITY_DLL_SPEC Config bool SetSource(const char *file, bool ignorecase = true); bool Reload(); - bool GetString(const char* name, std::string *value); - bool GetString(const char* name, char const **value); - std::string GetStringDefault(const char* name, const char* def); - - bool GetBool(const char* name, bool *value); - bool GetBoolDefault(const char* name, const bool def = false); - - bool GetInt(const char* name, int *value); - int GetIntDefault(const char* name, const int def); - - bool GetFloat(const char* name, float *value); - float GetFloatDefault(const char* name, const float def); + std::string GetStringDefault(const char * name, std::string def); + bool GetBoolDefault(const char * name, const bool def); + int32 GetIntDefault(const char * name, const int32 def); + float GetFloatDefault(const char * name, const float def); std::string GetFilename() const { return mFilename; } private: diff --git a/src/shared/Config/ConfigEnv.h b/src/shared/Config/ConfigEnv.h index eaa86c882df..75209a7fc6b 100644 --- a/src/shared/Config/ConfigEnv.h +++ b/src/shared/Config/ConfigEnv.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/shared/Config/Makefile.am b/src/shared/Config/Makefile.am new file mode 100644 index 00000000000..4854095b98c --- /dev/null +++ b/src/shared/Config/Makefile.am @@ -0,0 +1,42 @@ +# Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> +# +# Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## Process this file with automake to produce Makefile.in + +## Sub-directories to parse + +## CPP flags for includes, defines, etc. +AM_CPPFLAGS = $(TRINI_INCLUDES) -I$(top_builddir)/src/shared -I$(srcdir) -I$(srcdir)/../../../dep/include -I$(srcdir)/../../framework -I$(srcdir)/../../shared -I$(srcdir)/../../../dep/include/g3dlite + +## Build MaNGOS shared library and its parts as convenience library. +# All libraries will be convenience libraries. Might be changed to shared +# later. +noinst_LIBRARIES = libmangosconfig.a + +libmangosconfig_a_SOURCES = \ + dotconfpp/dotconfpp.cpp \ + dotconfpp/dotconfpp.h \ + dotconfpp/mempool.cpp \ + dotconfpp/mempool.h \ + Config.cpp \ + Config.h \ + ConfigEnv.h + +# VC++ project workspace for dotconfpp +EXTRA_DIST = \ + ConfigLibrary.vcproj diff --git a/src/shared/Config/dotconfpp/dotconfpp.cpp b/src/shared/Config/dotconfpp/dotconfpp.cpp index 3e2aa8683fe..e779637256e 100644 --- a/src/shared/Config/dotconfpp/dotconfpp.cpp +++ b/src/shared/Config/dotconfpp/dotconfpp.cpp @@ -3,6 +3,18 @@ #include "dotconfpp.h" +#ifdef WIN32 +#define PATH_MAX _MAX_PATH +#define strcasecmp stricmp +#define realpath(path,resolved_path) _fullpath(resolved_path, path, _MAX_PATH) +#include <io.h> +#else +#include <unistd.h> +#include <limits.h> +#include <stdint.h> +#include <strings.h> +#endif + #if !defined(R_OK) #define R_OK 04 #endif @@ -55,13 +67,13 @@ DOTCONFDocument::DOTCONFDocument(DOTCONFDocument::CaseSensitive caseSensitivity) 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); } - 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); } - 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); @@ -138,7 +150,7 @@ int DOTCONFDocument::cleanupLine(char * line) quoted = !quoted; ++line; continue; } - if(isspace(*line) && !quoted){ + if(isspace((unsigned char)*line) && !quoted){ *bg++ = 0; if(strlen(start)){ @@ -154,7 +166,7 @@ int DOTCONFDocument::cleanupLine(char * line) words.push_back(word); } start = bg; - while(isspace(*++line)) {} + while(isspace((unsigned char)*++line)) {} continue; } @@ -177,7 +189,7 @@ int DOTCONFDocument::parseLine() 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 == '<'){ @@ -295,7 +307,7 @@ int DOTCONFDocument::checkConfig(const std::list<DOTCONFDocumentNode*>::iterator DOTCONFDocumentNode * tagNode = NULL; int vi = 0; - for(std::list<DOTCONFDocumentNode*>::iterator i = from; i != nodeTree.end(); i++){ + for(std::list<DOTCONFDocumentNode*>::iterator i = from; i != nodeTree.end(); ++i){ tagNode = *i; if(!tagNode->closed){ error(tagNode->lineNum, tagNode->fileName, "unclosed tag %s", tagNode->name); @@ -359,7 +371,7 @@ int DOTCONFDocument::setContent(const char * _fileName) 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("DOTCONFPPIncludeFile", tagNode->name)){ vi = 0; @@ -374,7 +386,7 @@ int DOTCONFDocument::setContent(const char * _fileName) } 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; @@ -417,9 +429,9 @@ int DOTCONFDocument::setContent(const char * _fileName) 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; - 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; @@ -567,7 +579,7 @@ const DOTCONFDocumentNode * DOTCONFDocument::findNode(const char * nodeName, con if( i != nodeTree.end() ) ++i; } - for(; i!=nodeTree.end(); i++){ + for(; i!=nodeTree.end(); ++i){ if((*i)->parentNode != parentNode){ continue; diff --git a/src/shared/Config/dotconfpp/dotconfpp.h b/src/shared/Config/dotconfpp/dotconfpp.h index 7887f86ccc1..51455854ee7 100644 --- a/src/shared/Config/dotconfpp/dotconfpp.h +++ b/src/shared/Config/dotconfpp/dotconfpp.h @@ -15,19 +15,6 @@ #include <sys/types.h> #include <sys/stat.h> -#ifdef WIN32 -#define PATH_MAX _MAX_PATH -#define snprintf _snprintf -#define strcasecmp stricmp -#define realpath(path,resolved_path) _fullpath(resolved_path, path, _MAX_PATH) -#include <io.h> -#else -#include <unistd.h> -#include <limits.h> -#include <stdint.h> -#include <strings.h> -#endif - #include "mempool.h" class DOTCONFDocument; diff --git a/src/shared/Config/dotconfpp/mempool.cpp b/src/shared/Config/dotconfpp/mempool.cpp index 487dae0bd0a..cec8e8d119f 100644 --- a/src/shared/Config/dotconfpp/mempool.cpp +++ b/src/shared/Config/dotconfpp/mempool.cpp @@ -22,7 +22,7 @@ AsyncDNSMemPool::AsyncDNSMemPool(size_t _defaultSize): AsyncDNSMemPool::~AsyncDNSMemPool() { - for(size_t i = 0; i<chunksCount; i++){ + for(size_t i = 0; i<chunksCount; ++i){ delete chunks[i]; } ::free(chunks); @@ -53,7 +53,7 @@ void AsyncDNSMemPool::addNewChunk(size_t size) void * AsyncDNSMemPool::alloc(size_t size) { PoolChunk * chunk = NULL; - for(size_t i = 0; i<chunksCount; i++){ + for(size_t i = 0; i<chunksCount; ++i){ chunk = chunks[i]; if((chunk->size - chunk->pos) >= size){ chunk->pos += size; @@ -71,7 +71,7 @@ void AsyncDNSMemPool::free() size_t psz = 0; ++poolUsageCounter; - for(size_t i = 0; i<chunksCount; i++){ + for(size_t i = 0; i<chunksCount; ++i){ pu += chunks[i]->pos; psz += chunks[i]->size; chunks[i]->pos = 0; |