From 261ff1fa32cb75254d68d214f13f8a5aaec33962 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 5 Feb 2012 17:30:36 +0300 Subject: Move language functions to langs.cpp and langs.h files. --- src/utils/langs.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++ src/utils/langs.h | 38 +++++++++++++++++++++ src/utils/stringutils.cpp | 56 ------------------------------ src/utils/stringutils.h | 6 ---- 4 files changed, 125 insertions(+), 62 deletions(-) create mode 100644 src/utils/langs.cpp create mode 100644 src/utils/langs.h (limited to 'src/utils') diff --git a/src/utils/langs.cpp b/src/utils/langs.cpp new file mode 100644 index 000000000..2efbd781a --- /dev/null +++ b/src/utils/langs.cpp @@ -0,0 +1,87 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#include "utils/langs.h" + +#include "configuration.h" + +#include +#include +#include +#include +#include + +#include "debug.h" + +std::vector getLang() +{ + std::vector langs; + + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return langs; + lang = lng; + } + + int dot = lang.find("."); + if (dot != (signed)std::string::npos) + lang = lang.substr(0, dot); + langs.push_back(lang); + dot = lang.find("_"); + if (dot != (signed)std::string::npos) + langs.push_back(lang.substr(0, dot)); + return langs; +} + +std::string getLangSimple() +{ + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return ""; + return lng; + } + return lang; +} + +std::string getLangShort() +{ + std::string lang = config.getValue("lang", "").c_str(); + if (lang.empty()) + { + char *lng = getenv("LANG"); + if (!lng) + return ""; + lang = lng; + } + + int dot = lang.find("."); + if (dot != (signed)std::string::npos) + lang = lang.substr(0, dot); + dot = lang.find("_"); + if (dot != (signed)std::string::npos) + return lang.substr(0, dot); + return lang; +} diff --git a/src/utils/langs.h b/src/utils/langs.h new file mode 100644 index 000000000..c3f2f1398 --- /dev/null +++ b/src/utils/langs.h @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2007-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#ifndef UTILS_LANGS_H +#define UTILS_LANGS_H + +#include +#include +#include +#include +#include + +std::vector getLang(); + +std::string getLangSimple(); + +std::string getLangShort(); + +#endif // UTILS_LANGS_H diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 08bcac9e6..b07a4e367 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -486,62 +486,6 @@ std::string combineDye2(std::string file, std::string dye) } } -std::vector getLang() -{ - std::vector langs; - - std::string lang = config.getValue("lang", "").c_str(); - if (lang.empty()) - { - char *lng = getenv("LANG"); - if (!lng) - return langs; - lang = lng; - } - - int dot = lang.find("."); - if (dot != (signed)std::string::npos) - lang = lang.substr(0, dot); - langs.push_back(lang); - dot = lang.find("_"); - if (dot != (signed)std::string::npos) - langs.push_back(lang.substr(0, dot)); - return langs; -} - -std::string getLangSimple() -{ - std::string lang = config.getValue("lang", "").c_str(); - if (lang.empty()) - { - char *lng = getenv("LANG"); - if (!lng) - return ""; - return lng; - } - return lang; -} - -std::string getLangShort() -{ - std::string lang = config.getValue("lang", "").c_str(); - if (lang.empty()) - { - char *lng = getenv("LANG"); - if (!lng) - return ""; - lang = lng; - } - - int dot = lang.find("."); - if (dot != (signed)std::string::npos) - lang = lang.substr(0, dot); - dot = lang.find("_"); - if (dot != (signed)std::string::npos) - return lang.substr(0, dot); - return lang; -} - std::string packList(std::list &list) { std::list::const_iterator i = list.begin(); diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 0b22ef847..a685a9b17 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -186,12 +186,6 @@ std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); -std::vector getLang(); - -std::string getLangSimple(); - -std::string getLangShort(); - std::string packList(std::list &list); std::list unpackList(const std::string &str); -- cgit v1.2.3-60-g2f50 From 8db4a7da23c36718152ca29cfb067bcfc759a92f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 5 Feb 2012 17:38:54 +0300 Subject: Move path functions from stringutils to paths. --- src/gui/logindialog.cpp | 1 + src/gui/updaterwindow.cpp | 1 + src/main.cpp | 1 + src/net/ea/loginhandler.cpp | 1 + src/utils/paths.cpp | 10 ++++++++++ src/utils/paths.h | 2 ++ src/utils/stringutils.cpp | 10 ---------- src/utils/stringutils.h | 2 -- 8 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src/utils') diff --git a/src/gui/logindialog.cpp b/src/gui/logindialog.cpp index ef8fd6bf0..cafc4f72c 100644 --- a/src/gui/logindialog.cpp +++ b/src/gui/logindialog.cpp @@ -41,6 +41,7 @@ #include "net/net.h" #include "utils/gettext.h" +#include "utils/paths.h" #include "utils/stringutils.h" #include "debug.h" diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 28bd8467c..3aaf93557 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -42,6 +42,7 @@ #include "resources/resourcemanager.h" #include "utils/gettext.h" +#include "utils/paths.h" #include "utils/stringutils.h" #include "utils/xml.h" diff --git a/src/main.cpp b/src/main.cpp index 5025d6d29..dc87ca9e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ #include #include +#include "utils/paths.h" #include "utils/stringutils.h" #include "utils/xml.h" diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index 291a92906..39a920f03 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -28,6 +28,7 @@ #include "utils/dtor.h" #include "utils/gettext.h" +#include "utils/paths.h" #include "debug.h" diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 8decb6e95..faa1882e6 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -55,3 +55,13 @@ bool isRealPath(const std::string &str) std::string path = getRealPath(str); return str == path; } + +bool checkPath(std::string path) +{ + if (path.empty()) + return true; + return path.find("../") == std::string::npos + && path.find("..\\") == std::string::npos + && path.find("/..") == std::string::npos + && path.find("\\..") == std::string::npos; +} diff --git a/src/utils/paths.h b/src/utils/paths.h index 804900587..f92fcdcb5 100644 --- a/src/utils/paths.h +++ b/src/utils/paths.h @@ -27,4 +27,6 @@ std::string getRealPath(const std::string &str); bool isRealPath(const std::string &str); +bool checkPath(std::string path); + #endif // UTILS_PATHS_H diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index b07a4e367..16542526f 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -592,13 +592,3 @@ std::string &removeProtocol(std::string &url) url = url.substr(i + 3); return url; } - -bool checkPath(std::string path) -{ - if (path.empty()) - return true; - return path.find("../") == std::string::npos - && path.find("..\\") == std::string::npos - && path.find("/..") == std::string::npos - && path.find("\\..") == std::string::npos; -} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index a685a9b17..7b512b081 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -204,6 +204,4 @@ bool findCutFirst(std::string &str1, std::string str2); std::string &removeProtocol(std::string &url); -bool checkPath(std::string path); - #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-60-g2f50 From bf435a79408d89072f5872ab98449949a8a077b0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 3 Feb 2012 15:53:55 +0300 Subject: Add own translation system. --- src/CMakeLists.txt | 6 + src/Makefile.am | 6 + src/client.cpp | 5 + src/game.cpp | 2 + src/utils/langs.h | 3 + src/utils/stringutils.cpp | 7 + src/utils/stringutils.h | 2 + src/utils/translation/podict.cpp | 55 +++++++ src/utils/translation/podict.h | 59 +++++++ src/utils/translation/poparser.cpp | 221 +++++++++++++++++++++++++++ src/utils/translation/poparser.h | 78 ++++++++++ src/utils/translation/translationmanager.cpp | 72 +++++++++ src/utils/translation/translationmanager.h | 39 +++++ src/utils/xml.cpp | 12 ++ src/utils/xml.h | 6 + 15 files changed, 573 insertions(+) create mode 100644 src/utils/translation/podict.cpp create mode 100644 src/utils/translation/podict.h create mode 100644 src/utils/translation/poparser.cpp create mode 100644 src/utils/translation/poparser.h create mode 100644 src/utils/translation/translationmanager.cpp create mode 100644 src/utils/translation/translationmanager.h (limited to 'src/utils') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96c1eac67..3289aed66 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -443,6 +443,12 @@ SET(SRCS resources/spritedef.cpp resources/wallpaper.cpp resources/wallpaper.h + utils/translation/podict.cpp + utils/translation/podict.h + utils/translation/poparser.cpp + utils/translation/poparser.h + utils/translation/translationmanager.cpp + utils/translation/translationmanager.h utils/base64.cpp utils/base64.h utils/checkutils.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e9af09463..204c21bfc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -448,6 +448,12 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ resources/spritedef.cpp \ resources/wallpaper.cpp \ resources/wallpaper.h \ + utils/translation/podict.cpp \ + utils/translation/podict.h \ + utils/translation/poparser.cpp \ + utils/translation/poparser.h \ + utils/translation/translationmanager.cpp \ + utils/translation/translationmanager.h \ utils/base64.cpp \ utils/base64.h \ utils/checkutils.cpp \ diff --git a/src/client.cpp b/src/client.cpp index c21194834..cb65c3b60 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -101,6 +101,8 @@ #include "utils/paths.h" #include "utils/stringutils.h" +#include "utils/translation/translationmanager.h" + #include "test/testlauncher.h" #include "test/testmain.h" @@ -458,6 +460,8 @@ void Client::gameInit() //resman->selectSkin(); + TranslationManager::loadCurrentLang(); + std::string iconFile = branding.getValue("appIcon", "icons/manaplus"); #ifdef WIN32 iconFile += ".ico"; @@ -1050,6 +1054,7 @@ int Client::gameExec() logger->log1("State: CONNECT SERVER"); mCurrentDialog = new ConnectionDialog( _("Connecting to server"), STATE_SWITCH_SERVER); + TranslationManager::loadCurrentLang(); break; case STATE_LOGIN: diff --git a/src/game.cpp b/src/game.cpp index 0d5c1113e..cd54f9c98 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -104,6 +104,8 @@ #include "utils/gettext.h" #include "utils/mkdir.h" +#include "utils/translation/translationmanager.h" + #include #include diff --git a/src/utils/langs.h b/src/utils/langs.h index c3f2f1398..3b9f49f71 100644 --- a/src/utils/langs.h +++ b/src/utils/langs.h @@ -29,6 +29,9 @@ #include #include +typedef std::vector LangVect; +typedef LangVect::const_iterator LangIter; + std::vector getLang(); std::string getLangSimple(); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 16542526f..becb2124d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -592,3 +592,10 @@ std::string &removeProtocol(std::string &url) url = url.substr(i + 3); return url; } + +bool strStartWith(std::string str1, std::string str2) +{ + if (str1.size() < str2.size()) + return false; + return str1.substr(0, str2.size()) == str2; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 7b512b081..398737179 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -204,4 +204,6 @@ bool findCutFirst(std::string &str1, std::string str2); std::string &removeProtocol(std::string &url); +bool strStartWith(std::string str, std::string start); + #endif // UTILS_STRINGUTILS_H diff --git a/src/utils/translation/podict.cpp b/src/utils/translation/podict.cpp new file mode 100644 index 000000000..0be0b279f --- /dev/null +++ b/src/utils/translation/podict.cpp @@ -0,0 +1,55 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#include "utils/translation/podict.h" + +#include + +#include "localconsts.h" +#include "logger.h" + +#include "debug.h" + +std::string empty; + +PoDict *translator = nullptr; + +PoDict::PoDict(std::string lang) : + mLang(lang) +{ +} + +PoDict::~PoDict() +{ +} + +const std::string PoDict::getStr(std::string &str) +{ + if (mPoLines.find(str) == mPoLines.end()) + return str; + return mPoLines[str]; +} + +const char *PoDict::getChar(const char *str) +{ + if (mPoLines.find(str) == mPoLines.end()) + return str; + return mPoLines[str].c_str(); +} diff --git a/src/utils/translation/podict.h b/src/utils/translation/podict.h new file mode 100644 index 000000000..0b7dd726c --- /dev/null +++ b/src/utils/translation/podict.h @@ -0,0 +1,59 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#ifndef UTILS_TRANSLATION_PODICT_H +#define UTILS_TRANSLATION_PODICT_H + +#include +#include + +typedef std::map PoMap; + +class PoDict +{ + public: + PoDict(std::string lang); + + ~PoDict(); + + const std::string getStr(std::string &str); + + const char *getChar(const char *str); + + protected: + friend class PoParser; + + PoMap *getMap() + { return &mPoLines; } + + void set(std::string key, std::string value) + { mPoLines[key] = value; } + + void setLang(std::string lang) + { mLang = lang; } + + private: + PoMap mPoLines; + std::string mLang; +}; + +extern PoDict *translator; + +#endif // UTILS_TRANSLATION_PODICT_H diff --git a/src/utils/translation/poparser.cpp b/src/utils/translation/poparser.cpp new file mode 100644 index 000000000..24d2ee4d4 --- /dev/null +++ b/src/utils/translation/poparser.cpp @@ -0,0 +1,221 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#include "utils/translation/poparser.h" + +#include "resources/resourcemanager.h" + +#include "utils/stringutils.h" + +#include "localconsts.h" +#include "logger.h" + +#include +#include + +#include "debug.h" + +PoParser::PoParser() : + mDict(nullptr), + mReadingId(false), + mReadingStr(false) +{ +} + +void PoParser::openFile() +{ + ResourceManager *resman = ResourceManager::getInstance(); + int size; + char *buf = static_cast(resman->loadFile(getFileName(mLang), size)); + + mFile.str(std::string(buf, size)); + free(buf); +} + +PoDict *PoParser::load(std::string lang) +{ + setLang(lang); + mDict = getDict(); + + openFile(); + + mMsgId = ""; + mMsgStr = ""; + + // cycle by msgid+msgstr + while (readLine()) + { + // reading msgid + while (readMsgId()) + { + if (!readLine()) + break; + } + + if (!mMsgId.empty()) + { + // if we got msgid then reading msgstr + while (readMsgStr()) + { + if (!readLine()) + break; + } + } + + if (!mMsgId.empty() && !mMsgStr.empty()) + { +// logger->log("add key: " + mMsgId); +// logger->log("add value: " + mMsgStr); + + // store key and value + mDict->set(mMsgId, mMsgStr); + } + + mMsgId = ""; + mMsgStr = ""; + } + + return mDict; +} + +bool PoParser::readLine() +{ + char line[1001]; + if (!mFile.getline(line, 1000)) + return false; + mLine = line; + return true; +} + +bool PoParser::readMsgId() +{ + // if we reading msgstr then stop here + if (mReadingStr) + return false; + + const std::string msgId1 = "msgid \""; + + // check if in reading process + if (mReadingId) + { + // if we get empty line in file then stop reading + if (mLine.empty()) + { + mReadingId = false; + return false; + } + else if (checkLine()) + { + // reading text from: "text" + mMsgId += mLine.substr(1, mLine.size() - 2); + mLine = ""; + return true; + } + // stop reading in other case + mReadingId = false; + return false; + } + else + { + // check line start from msgid " + if (strStartWith(mLine, msgId1)) + { + mReadingId = true; + // reading text from: msgid "text" + mMsgId += mLine.substr(msgId1.size(), + mLine.size() - 1 - msgId1.size()); + mLine = ""; + return true; + } + // stop reading if we dont read msgid before + return mMsgId.empty(); + } +} + +bool PoParser::readMsgStr() +{ + const std::string msgStr1 = "msgstr \""; + + // check if in reading process + if (mReadingStr) + { + // if we get empty line in file then stop reading + if (mLine.empty()) + { + mReadingStr = false; + return false; + } + if (checkLine()) + { + // reading text from: "text" + mMsgStr += mLine.substr(1, mLine.size() - 2); + mLine = ""; + return true; + } + // stop reading in other case + mReadingStr = false; + } + else + { + // check line start from msgstr " + if (strStartWith(mLine, msgStr1)) + { + mReadingStr = true; + // reading text from: msgid "text" + mMsgStr += mLine.substr(msgStr1.size(), + mLine.size() - 1 - msgStr1.size()); + mLine = ""; + return true; + } + } + + // stop reading in other case + return false; +} + +bool PoParser::checkLine() +{ + // check is line in format: "text" + return mLine.size() > 2 && mLine[0] == '\"' + && mLine[mLine.size() - 1] == '\"'; +} + +PoDict *PoParser::getEmptyDict() +{ + return new PoDict(""); +} + +bool PoParser::checkLang(std::string lang) const +{ + // check is po file exists + ResourceManager *resman = ResourceManager::getInstance(); + return resman->exists(getFileName(lang)); +} + +std::string PoParser::getFileName(std::string lang) const +{ + // get po file name from lang name + return strprintf("translations/%s.po", lang.c_str()); +} + +PoDict *PoParser::getDict() +{ + return new PoDict(mLang); +} diff --git a/src/utils/translation/poparser.h b/src/utils/translation/poparser.h new file mode 100644 index 000000000..799cd2fe7 --- /dev/null +++ b/src/utils/translation/poparser.h @@ -0,0 +1,78 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#ifndef UTILS_TRANSLATION_POPARSER_H +#define UTILS_TRANSLATION_POPARSER_H + +#include "utils/translation/podict.h" + +#include +#include + +class PoParser +{ + public: + PoParser(); + + PoDict *load(std::string fileName); + + bool checkLang(std::string lang) const; + + static PoDict *getEmptyDict(); + + private: + void setLang(std::string lang) + { mLang = lang; } + + void openFile(); + + bool readLine(); + + bool readMsgId(); + + bool readMsgStr(); + + bool checkLine(); + + std::string getFileName(std::string lang) const; + + PoDict *getDict(); + + // current lang + std::string mLang; + + // po file object + std::istringstream mFile; + + // current line from po file + std::string mLine; + + std::string mMsgId; + + std::string mMsgStr; + + PoDict *mDict; + + bool mReadingId; + + bool mReadingStr; +}; + +#endif // UTILS_TRANSLATION_POPARSER_H diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp new file mode 100644 index 000000000..b4ae0d949 --- /dev/null +++ b/src/utils/translation/translationmanager.cpp @@ -0,0 +1,72 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#include "utils/translation/translationmanager.h" + +#include "utils/langs.h" + +#include "utils/translation/podict.h" +#include "utils/translation/poparser.h" + +#include + +#include "localconsts.h" +#include "logger.h" + +#include "debug.h" + +void TranslationManager::init() +{ + if (translator) + delete translator; + translator = PoParser::getEmptyDict(); +} + +void TranslationManager::loadCurrentLang() +{ + if (translator) + delete translator; + translator = loadLang(getLang()); +} + +PoDict *TranslationManager::loadLang(LangVect lang) +{ + std::string name = ""; + PoParser parser; + + LangIter it = lang.begin(); + LangIter it_end = lang.end(); + + for (; it != it_end; ++ it) + { + if (*it == "C") + continue; + + if (parser.checkLang(*it)) + { + name = *it; + break; + } + } + if (!name.empty()) + return parser.load(name); + logger->log("can't find client data translation"); + return PoParser::getEmptyDict(); +} diff --git a/src/utils/translation/translationmanager.h b/src/utils/translation/translationmanager.h new file mode 100644 index 000000000..de3875b0a --- /dev/null +++ b/src/utils/translation/translationmanager.h @@ -0,0 +1,39 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#ifndef UTILS_TRANSLATION_MANAGER_H +#define UTILS_TRANSLATION_MANAGER_H + +#include +#include + +class PoDict; + +class TranslationManager +{ + public: + static PoDict *loadLang(std::vector lang); + + static void init(); + + static void loadCurrentLang(); +}; + +#endif // UTILS_TRANSLATION_MANAGER_H diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 420915d8f..140da72df 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -26,6 +26,8 @@ #include "resources/resourcemanager.h" +#include "utils/translation/podict.h" + #include #include #include @@ -148,6 +150,16 @@ namespace XML return def; } + std::string langProperty(XmlNodePtr node, const char *name, + const std::string &def) + { + std::string str = getProperty(node, name, def); + if (!translator) + return str; + + return translator->getStr(str); + } + bool getBoolProperty(XmlNodePtr node, const char* name, bool def) { xmlChar *prop = xmlGetProp(node, BAD_CAST name); diff --git a/src/utils/xml.h b/src/utils/xml.h index f623fa618..eb5ee88b0 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -91,6 +91,12 @@ namespace XML std::string getProperty(XmlNodePtr node, const char *name, const std::string &def); + /** + * Gets a translated string property from an XmlNodePtr. + */ + std::string langProperty(XmlNodePtr node, const char *name, + const std::string &def); + /** * Gets a boolean property from an XmlNodePtr. */ -- cgit v1.2.3-60-g2f50 From 8e6ef0d196a2c9772225f2ac061721e11370d2e9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 6 Feb 2012 02:45:35 +0300 Subject: Fix memory leak on exit. --- src/client.cpp | 2 ++ src/utils/translation/translationmanager.cpp | 6 ++++++ src/utils/translation/translationmanager.h | 2 ++ 3 files changed, 10 insertions(+) (limited to 'src/utils') diff --git a/src/client.cpp b/src/client.cpp index cb65c3b60..3e8eef6ed 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -798,6 +798,8 @@ void Client::gameClear() //delete logger; //logger = nullptr; + TranslationManager::close(); + mInstance = nullptr; } diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp index b4ae0d949..1b68cc91d 100644 --- a/src/utils/translation/translationmanager.cpp +++ b/src/utils/translation/translationmanager.cpp @@ -46,6 +46,12 @@ void TranslationManager::loadCurrentLang() translator = loadLang(getLang()); } +void TranslationManager::close() +{ + delete translator; + translator = nullptr; +} + PoDict *TranslationManager::loadLang(LangVect lang) { std::string name = ""; diff --git a/src/utils/translation/translationmanager.h b/src/utils/translation/translationmanager.h index de3875b0a..39702f4f4 100644 --- a/src/utils/translation/translationmanager.h +++ b/src/utils/translation/translationmanager.h @@ -33,6 +33,8 @@ class TranslationManager static void init(); + static void close(); + static void loadCurrentLang(); }; -- cgit v1.2.3-60-g2f50 From ff5e17ff14a78af31d9d23cd1dfdb5404f9a8fa9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 8 Feb 2012 00:49:41 +0300 Subject: Fix code style with new tool. --- src/avatar.cpp | 2 +- src/being.cpp | 7 ++-- src/client.cpp | 2 +- src/configuration.cpp | 2 +- src/debug/debug_new.cpp | 16 ++++----- src/defaults.h | 20 +++++------ src/graphics.cpp | 6 ++-- src/gui/botcheckerwindow.cpp | 3 +- src/gui/chatwindow.cpp | 4 +-- src/gui/confirmdialog.cpp | 1 - src/gui/debugwindow.cpp | 2 +- src/gui/itempopup.cpp | 2 +- src/gui/npcpostdialog.cpp | 2 +- src/gui/palette.cpp | 4 ++- src/gui/setup_relations.cpp | 3 +- src/gui/setup_video.cpp | 2 +- src/gui/statuswindow.cpp | 2 +- src/gui/textdialog.cpp | 2 +- src/gui/viewport.h | 4 ++- src/gui/whoisonline.cpp | 2 +- src/gui/widgets/avatarlistbox.cpp | 2 +- src/gui/widgets/battletab.h | 3 -- src/gui/widgets/chattab.cpp | 2 +- src/gui/widgets/container.cpp | 2 +- src/gui/widgets/dropdown.h | 1 - src/gui/widgets/inventoryfilter.cpp | 2 +- src/gui/widgets/layout.h | 4 +-- src/gui/widgets/setupitem.cpp | 1 - src/gui/widgets/setuptab.cpp | 2 +- src/gui/widgets/shoplistbox.cpp | 2 +- src/gui/widgets/slider.cpp | 1 - src/gui/widgets/tablemodel.cpp | 1 - src/gui/widgets/textfield.cpp | 22 ++++++------ src/gui/widgets/tradetab.h | 3 -- src/guichan/actionevent.cpp | 1 - src/guichan/event.cpp | 1 - src/guichan/include/guichan/actionevent.hpp | 1 - src/guichan/include/guichan/color.hpp | 2 +- src/guichan/include/guichan/gui.hpp | 9 +++-- src/guichan/include/guichan/sdl/sdlpixel.hpp | 6 ++-- src/guichan/keyinput.cpp | 1 - src/guichan/sdl/sdlgraphics.cpp | 4 +-- src/guichan/selectionevent.cpp | 1 - src/guichan/widgets/checkbox.cpp | 1 - src/guichan/widgets/dropdown.cpp | 1 - src/guichan/widgets/icon.cpp | 18 +++++----- src/guichan/widgets/tab.cpp | 1 - src/localconsts.h | 2 +- src/localplayer.cpp | 16 ++++----- src/logger.cpp | 2 +- src/map.cpp | 6 ++-- src/maplayer.cpp | 6 ++-- src/mumblemanager.cpp | 4 +-- src/net/ea/beinghandler.cpp | 6 ++++ src/net/ea/gui/partytab.cpp | 1 - src/net/ea/inventoryhandler.cpp | 2 +- src/net/manaserv/chathandler.cpp | 2 +- src/net/manaserv/guildhandler.cpp | 2 +- src/net/manaserv/playerhandler.cpp | 3 +- src/net/net.cpp | 1 - src/net/tmwa/gui/guildtab.cpp | 1 - src/net/tmwa/gui/partytab.cpp | 1 - src/net/tmwa/network.cpp | 4 +-- src/openglgraphics.cpp | 6 ++-- src/playerrelations.cpp | 5 ++- src/resources/image.cpp | 10 +++--- src/resources/mapreader.cpp | 4 +-- src/resources/resourcemanager.cpp | 54 ++++++++++++++-------------- src/resources/specialdb.cpp | 3 +- src/spellmanager.cpp | 3 +- src/textcommand.h | 2 +- src/units.cpp | 10 +++--- src/utils/base64.cpp | 4 +-- src/utils/physfsrwops.h | 1 - src/utils/stringutils.cpp | 8 ++--- src/vector.h | 4 +-- 76 files changed, 172 insertions(+), 184 deletions(-) (limited to 'src/utils') diff --git a/src/avatar.cpp b/src/avatar.cpp index 9a4831f18..54d7c6e79 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -61,4 +61,4 @@ std::string Avatar::getAdditionString() const return " - " + getIp(); else return ""; -} \ No newline at end of file +} diff --git a/src/being.cpp b/src/being.cpp index 9edfaad7b..92d01097b 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -295,9 +295,9 @@ Being::~Being() { config.removeListener("visiblenames", this); - delete[] mSpriteRemap; + delete [] mSpriteRemap; mSpriteRemap = nullptr; - delete[] mSpriteHide; + delete [] mSpriteHide; mSpriteHide = nullptr; delete mSpeechBubble; @@ -993,7 +993,6 @@ void Being::setAction(Action action, int attackType A_UNUSED) case DIRECTION_RIGHT: rotation = 270; break; default: break; } - ; if (particleEngine) { Particle *p = particleEngine->addEffect( @@ -2404,7 +2403,7 @@ void Being::searchSlotValueItr(std::vector::iterator &it, int &idx, // logger->log("searching %d", val); it = slotRemap.begin(); idx = 0; - while(it != slotRemap.end()) + while (it != slotRemap.end()) { // logger->log("testing %d", *it); if (*it == val) diff --git a/src/client.cpp b/src/client.cpp index 3e8eef6ed..54a0b6224 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -502,7 +502,7 @@ void Client::gameInit() GraphicsVertexes::setLoadAsOpenGL(useOpenGL); // Create the graphics context - switch(useOpenGL) + switch (useOpenGL) { case 0: mainGraphics = new Graphics; diff --git a/src/configuration.cpp b/src/configuration.cpp index 39e0c75d4..254a3fea8 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -161,7 +161,7 @@ void Configuration::cleanDefaults() for (DefaultsData::const_iterator iter = mDefaultsData->begin(); iter != mDefaultsData->end(); ++iter) { - delete(iter->second); + delete (iter->second); } mDefaultsData->clear(); delete mDefaultsData; diff --git a/src/debug/debug_new.cpp b/src/debug/debug_new.cpp index 3bc02b3e5..9e30d30d9 100644 --- a/src/debug/debug_new.cpp +++ b/src/debug/debug_new.cpp @@ -533,7 +533,7 @@ static void* alloc_mem(size_t size, const char* file, int line, bool is_array) * @param pointer pointer to delete * @param addr pointer to the caller * @param is_array flag indicating whether it is invoked by a - * delete[] call + * delete [] call */ static void free_pointer(void* pointer, void* addr, bool is_array) { @@ -558,9 +558,9 @@ static void free_pointer(void* pointer, void* addr, bool is_array) { const char* msg; if (is_array) - msg = "delete[] after new"; + msg = "delete [] after new"; else - msg = "delete after new[]"; + msg = "delete after new []"; fast_mutex_autolock lock(new_output_lock); fprintf(new_output_fp, "%s: pointer %p (size %u)\n\tat ", @@ -800,7 +800,7 @@ void operator delete(void* pointer) throw() free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, false); } -void operator delete[](void* pointer) throw() +void operator delete [](void* pointer) throw() { free_pointer(pointer, _DEBUG_NEW_CALLER_ADDRESS, true); } @@ -820,7 +820,7 @@ void operator delete(void* pointer, const char* file, int line) throw() operator delete(pointer); } -void operator delete[](void* pointer, const char* file, int line) throw() +void operator delete [](void* pointer, const char* file, int line) throw() { if (new_verbose_flag) { @@ -831,7 +831,7 @@ void operator delete[](void* pointer, const char* file, int line) throw() print_position(file, line); fprintf(new_output_fp, ")\n"); } - operator delete[](pointer); + operator delete [](pointer); } void operator delete(void* pointer, const std::nothrow_t&) throw() @@ -839,9 +839,9 @@ void operator delete(void* pointer, const std::nothrow_t&) throw() operator delete(pointer, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); } -void operator delete[](void* pointer, const std::nothrow_t&) throw() +void operator delete [](void* pointer, const std::nothrow_t&) throw() { - operator delete[](pointer, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); + operator delete [](pointer, (char*)_DEBUG_NEW_CALLER_ADDRESS, 0); } #endif // HAVE_PLACEMENT_DELETE diff --git a/src/defaults.h b/src/defaults.h index 1d979e928..850e15d37 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -26,18 +26,16 @@ #include #include "variabledata.h" -using namespace Mana; - typedef std::map DefaultsData; -VariableData* createData(int defData); -VariableData* createData(double defData); -VariableData* createData(float defData); -VariableData* createData(const std::string &defData); -VariableData* createData(const char* defData); -VariableData* createData(bool defData); -DefaultsData* getConfigDefaults(); -DefaultsData* getBrandingDefaults(); -DefaultsData* getPathsDefaults(); +Mana::VariableData* createData(int defData); +Mana::VariableData* createData(double defData); +Mana::VariableData* createData(float defData); +Mana::VariableData* createData(const std::string &defData); +Mana::VariableData* createData(const char* defData); +Mana::VariableData* createData(bool defData); +Mana::DefaultsData* getConfigDefaults(); +Mana::DefaultsData* getBrandingDefaults(); +Mana::DefaultsData* getPathsDefaults(); #endif diff --git a/src/graphics.cpp b/src/graphics.cpp index 5848d8c14..635cc6ab9 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -719,10 +719,10 @@ int Graphics::SDL_FakeUpperBlit(SDL_Surface *src, SDL_Rect *srcrect, /* Make sure the surfaces aren't locked */ if (!src || !dst) - return(-1); + return -1; if (src->locked || dst->locked) - return(-1); + return -1; /* If the destination rectangle is nullptr, use the entire dest surface */ if (!dstrect) @@ -841,7 +841,7 @@ void Graphics::fillRectangle(const gcn::Rectangle& rectangle) Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); - switch(bpp) + switch (bpp) { case 1: for (y = y1; y < y2; y++) diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index 2043b4fe3..4a092ab55 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -53,7 +53,8 @@ #define TIME_COLUMN 1 #define ROW_HEIGHT 12 -// The following column widths really shouldn't be hardcoded but should scale with the size of the widget... excep +// The following column widths really shouldn't be hardcoded but should +// scale with the size of the widget... excep // that, right now, the widget doesn't exactly scale either. #define NAME_COLUMN_WIDTH 185 #define TIME_COLUMN_WIDTH 70 diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 6831ad5b6..452d2420e 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -594,7 +594,7 @@ void ChatWindow::ignoreAllWhispers() PlayerRelation::IGNORED); } - delete(iter->second); + delete (iter->second); iter->second = nullptr; } } @@ -1122,7 +1122,7 @@ std::string ChatWindow::addColors(std::string &msg) int cMap[] = {1, 4, 5, 2, 3, 6, 7, 9, 0, 8}; // rainbow - switch(mChatColor) + switch (mChatColor) { case 11: msg = removeColors(msg); diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index cf9d541ad..22acf5116 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -112,4 +112,3 @@ void ConfirmDialog::action(const gcn::ActionEvent &event) scheduleDelete(); } } - diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index d13545bea..19db5540a 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -396,4 +396,4 @@ void NetDebugTab::logic() PacketCounters::getInBytes())); mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"), PacketCounters::getOutBytes())); -} \ No newline at end of file +} diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 9a9e5f50d..d96aa564f 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -282,4 +282,4 @@ void ItemPopup::mouseMoved(gcn::MouseEvent &event) setVisible(false); mLastName = ""; mLastColor = 1; -} \ No newline at end of file +} diff --git a/src/gui/npcpostdialog.cpp b/src/gui/npcpostdialog.cpp index 6bcb62baf..b2ffb312c 100644 --- a/src/gui/npcpostdialog.cpp +++ b/src/gui/npcpostdialog.cpp @@ -128,4 +128,4 @@ void NpcPostDialog::closeAll() for (; it != it_end; ++it) (*it)->close(); -} \ No newline at end of file +} diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index fe14cd2d4..3b36fa6ce 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -39,7 +39,8 @@ const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); Palette::Palettes Palette::mInstances; -const gcn::Color Palette::RAINBOW_COLORS[7] = { +const gcn::Color Palette::RAINBOW_COLORS[7] = +{ gcn::Color(255, 0, 0), gcn::Color(255, 153, 0), gcn::Color(255, 255, 0), @@ -48,6 +49,7 @@ const gcn::Color Palette::RAINBOW_COLORS[7] = { gcn::Color(51, 0, 153), gcn::Color(153, 0, 153) }; + /** Number of Elemets of RAINBOW_COLORS */ const int Palette::RAINBOW_COLOR_COUNT = 7; diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index 571856a14..47d53620c 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -50,7 +50,8 @@ #define RELATION_CHOICE_COLUMN 1 #define ROW_HEIGHT 12 -// The following column widths really shouldn't be hardcoded but should scale with the size of the widget... except +// The following column widths really shouldn't be hardcoded +// but should scale with the size of the widget... except // that, right now, the widget doesn't exactly scale either. #define NAME_COLUMN_WIDTH 230 #define RELATION_CHOICE_COLUMN_WIDTH 80 diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 9a5b30ea7..6b3d6d4d3 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -743,4 +743,4 @@ void Setup_Video::action(const gcn::ActionEvent &event) void Setup_Video::externalUpdated() { -} \ No newline at end of file +} diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 86964383a..3fbec4f35 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -286,7 +286,7 @@ void StatusWindow::processEvent(Mana::Channels channel A_UNUSED, if (event.getName() == Mana::EVENT_UPDATEATTRIBUTE) { - switch(event.getInt("id")) + switch (event.getInt("id")) { case HP: case MAX_HP: updateHPBar(mHpBar, true); diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp index b30c9eb82..d7d3d5eeb 100644 --- a/src/gui/textdialog.cpp +++ b/src/gui/textdialog.cpp @@ -126,4 +126,4 @@ void TextDialog::close() { keyboard.setEnabled(mEnabledKeyboard); scheduleDelete(); -} \ No newline at end of file +} diff --git a/src/gui/viewport.h b/src/gui/viewport.h index f3035b5df..ccb8124ba 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -90,7 +90,9 @@ class Viewport : public WindowContainer, public gcn::MouseListener, void logic(); /** - * Toggles whether the path debug graphics are shown. normal, debug with all images and grid, debug with out big images and with out grid. + * Toggles whether the path debug graphics are shown. normal, + * debug with all images and grid, debug with out big images + * and with out grid. */ void toggleDebugPath(); diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 205a1aae1..104e4d7f1 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -138,7 +138,7 @@ WhoIsOnline::~WhoIsOnline() mMemoryBuffer = nullptr; // Remove possibly leftover temporary download - delete[] mCurlError; + delete []mCurlError; std::set::iterator itd = mOnlinePlayers.begin(); std::set::iterator itd_end = mOnlinePlayers.end(); diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 2e3472515..822e71805 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -403,4 +403,4 @@ void AvatarListBox::optionChanged(const std::string &value) mShowGender = config.getBoolValue("showgender"); else if (value == "showlevel") mShowLevel = config.getBoolValue("showlevel"); -} \ No newline at end of file +} diff --git a/src/gui/widgets/battletab.h b/src/gui/widgets/battletab.h index 8d85e739e..2a034a166 100644 --- a/src/gui/widgets/battletab.h +++ b/src/gui/widgets/battletab.h @@ -43,6 +43,3 @@ class BattleTab : public ChatTab extern BattleTab *battleChatTab; #endif - - - diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 6d5dfc9dd..018e35030 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -467,4 +467,4 @@ void ChatTab::addNewRow(std::string &line) addRow(line); } mScrollArea->logic(); -} \ No newline at end of file +} diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index 80028a62f..106112956 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -47,4 +47,4 @@ bool Container::safeRemove(gcn::Widget* widget) } } return false; -} \ No newline at end of file +} diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index a769678ca..5896042fa 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -102,4 +102,3 @@ class DropDown : public gcn::DropDown }; #endif // end DROPDOWN_H - diff --git a/src/gui/widgets/inventoryfilter.cpp b/src/gui/widgets/inventoryfilter.cpp index 216c2bea0..515682cb6 100644 --- a/src/gui/widgets/inventoryfilter.cpp +++ b/src/gui/widgets/inventoryfilter.cpp @@ -58,4 +58,4 @@ void InventoryFilter::action(const gcn::ActionEvent &event) { (*iter)->action(event); } -} \ No newline at end of file +} diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h index 046d09b59..3c42554b6 100644 --- a/src/gui/widgets/layout.h +++ b/src/gui/widgets/layout.h @@ -37,8 +37,8 @@ class LayoutCell; class ContainerPlacer { public: - ContainerPlacer(gcn::Container *c = nullptr, LayoutCell *l = nullptr): - mContainer(c), mCell(l) + ContainerPlacer(gcn::Container *c = nullptr, LayoutCell *lc = nullptr): + mContainer(c), mCell(lc) {} /** diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 059b05ba2..56ce0a25a 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -455,7 +455,6 @@ void SetupItemIntTextField::apply(std::string eventName) } - SetupItemLabel::SetupItemLabel(std::string text, std::string description, SetupTabScroll *parent, bool separator) : SetupItem(text, description, "", parent, "", "", true), diff --git a/src/gui/widgets/setuptab.cpp b/src/gui/widgets/setuptab.cpp index b3863c134..d4ae46eb8 100644 --- a/src/gui/widgets/setuptab.cpp +++ b/src/gui/widgets/setuptab.cpp @@ -31,4 +31,4 @@ SetupTab::SetupTab() void SetupTab::externalUpdated() { -} \ No newline at end of file +} diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 71e373d70..ab6400149 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -191,4 +191,4 @@ void ShopListBox::mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED) return; mItemPopup->hide(); -} \ No newline at end of file +} diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index ed667e194..c6b57858c 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -298,4 +298,3 @@ void Slider::mouseExited(gcn::MouseEvent& event A_UNUSED) { mHasMouse = false; } - diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp index 5216fb89c..bc5d2ead6 100644 --- a/src/gui/widgets/tablemodel.cpp +++ b/src/gui/widgets/tablemodel.cpp @@ -173,4 +173,3 @@ int StaticTableModel::getHeight() const { return mColumns * mHeight; } - diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 4dba2eb57..e207b0613 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -208,29 +208,29 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) } else if (!mMaximum || mText.size() < mMaximum) { - int l; + int len; if (val < 128) - l = 1; // 0xxxxxxx + len = 1; // 0xxxxxxx else if (val < 0x800) - l = 2; // 110xxxxx 10xxxxxx + len = 2; // 110xxxxx 10xxxxxx else if (val < 0x10000) - l = 3; // 1110xxxx 10xxxxxx 10xxxxxx + len = 3; // 1110xxxx 10xxxxxx 10xxxxxx else - l = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + len = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx char buf[4]; - for (int i = 0; i < l; ++i) + for (int i = 0; i < len; ++ i) { - buf[i] = static_cast(val >> (6 * (l - i - 1))); + buf[i] = static_cast(val >> (6 * (len - i - 1))); if (i > 0) buf[i] = static_cast((buf[i] & 63) | 128); } - if (l > 1) - buf[0] |= static_cast(255 << (8 - l)); + if (len > 1) + buf[0] |= static_cast(255 << (8 - len)); - mText.insert(mCaretPosition, std::string(buf, buf + l)); - mCaretPosition += l; + mText.insert(mCaretPosition, std::string(buf, buf + len)); + mCaretPosition += len; } } diff --git a/src/gui/widgets/tradetab.h b/src/gui/widgets/tradetab.h index 06add3ee0..44922c31a 100644 --- a/src/gui/widgets/tradetab.h +++ b/src/gui/widgets/tradetab.h @@ -46,6 +46,3 @@ class TradeTab : public ChatTab extern TradeTab *tradeChatTab; #endif - - - diff --git a/src/guichan/actionevent.cpp b/src/guichan/actionevent.cpp index a91c6dec0..7348587d7 100644 --- a/src/guichan/actionevent.cpp +++ b/src/guichan/actionevent.cpp @@ -69,4 +69,3 @@ namespace gcn return mId; } } - diff --git a/src/guichan/event.cpp b/src/guichan/event.cpp index 691240d11..5983af7e7 100644 --- a/src/guichan/event.cpp +++ b/src/guichan/event.cpp @@ -68,4 +68,3 @@ namespace gcn return mSource; } } - diff --git a/src/guichan/include/guichan/actionevent.hpp b/src/guichan/include/guichan/actionevent.hpp index 96a2d1364..a6c54f516 100644 --- a/src/guichan/include/guichan/actionevent.hpp +++ b/src/guichan/include/guichan/actionevent.hpp @@ -112,4 +112,3 @@ namespace gcn } #endif // GCN_ACTIONEVENT_HPP - diff --git a/src/guichan/include/guichan/color.hpp b/src/guichan/include/guichan/color.hpp index a051c3569..6f0cfc1ff 100644 --- a/src/guichan/include/guichan/color.hpp +++ b/src/guichan/include/guichan/color.hpp @@ -139,7 +139,7 @@ namespace gcn */ bool operator!=(const Color& color) const; - /** + /** * Output operator for output. * * @param out The stream to output to. diff --git a/src/guichan/include/guichan/gui.hpp b/src/guichan/include/guichan/gui.hpp index d8c9c7555..b2be75141 100644 --- a/src/guichan/include/guichan/gui.hpp +++ b/src/guichan/include/guichan/gui.hpp @@ -65,10 +65,15 @@ namespace gcn /** * @mainpage * @section Introduction - * This documentation is mostly intended as a reference to the API. If you want to get started with Guichan, we suggest you check out the programs in the examples directory of the Guichan release. + * This documentation is mostly intended as a reference to the API. + * If you want to get started with Guichan, we suggest you check out + * the programs in the examples directory of the Guichan release. * @n * @n - * This documentation is, and will always be, work in progress. If you find any errors, typos or inconsistencies, or if you feel something needs to be explained in more detail - don't hesitate to tell us. + * This documentation is, and will always be, work in progress. + * If you find any errors, typos or inconsistencies, or if you feel + * something needs to be explained in more detail - don't hesitate to + * tell us. */ /** diff --git a/src/guichan/include/guichan/sdl/sdlpixel.hpp b/src/guichan/include/guichan/sdl/sdlpixel.hpp index 663c2059d..a0221ca7c 100644 --- a/src/guichan/include/guichan/sdl/sdlpixel.hpp +++ b/src/guichan/include/guichan/sdl/sdlpixel.hpp @@ -72,7 +72,7 @@ namespace gcn unsigned int color = 0; - switch(bpp) + switch (bpp) { case 1: color = *p; @@ -127,7 +127,7 @@ namespace gcn Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); - switch(bpp) + switch (bpp) { case 1: *p = pixel; @@ -234,7 +234,7 @@ namespace gcn Uint32 pixel = SDL_MapRGB(surface->format, color.r, color.g, color.b); - switch(bpp) + switch (bpp) { case 1: *p = pixel; diff --git a/src/guichan/keyinput.cpp b/src/guichan/keyinput.cpp index 3f5ebc124..35e8b6168 100644 --- a/src/guichan/keyinput.cpp +++ b/src/guichan/keyinput.cpp @@ -134,4 +134,3 @@ namespace gcn mNumericPad = numpad; } } - diff --git a/src/guichan/sdl/sdlgraphics.cpp b/src/guichan/sdl/sdlgraphics.cpp index 79c65da9f..c8cec6370 100644 --- a/src/guichan/sdl/sdlgraphics.cpp +++ b/src/guichan/sdl/sdlgraphics.cpp @@ -289,7 +289,7 @@ namespace gcn mColor.r, mColor.g, mColor.b); - switch(bpp) + switch (bpp) { case 1: for (; x1 <= x2; ++x1) @@ -400,7 +400,7 @@ namespace gcn Uint32 pixel = SDL_MapRGB(mTarget->format, mColor.r, mColor.g, mColor.b); - switch(bpp) + switch (bpp) { case 1: for (; y1 <= y2; ++y1) diff --git a/src/guichan/selectionevent.cpp b/src/guichan/selectionevent.cpp index 784252230..8c8a3f28f 100644 --- a/src/guichan/selectionevent.cpp +++ b/src/guichan/selectionevent.cpp @@ -63,4 +63,3 @@ namespace gcn } } - diff --git a/src/guichan/widgets/checkbox.cpp b/src/guichan/widgets/checkbox.cpp index ab0b19e00..c7ec3e1e0 100644 --- a/src/guichan/widgets/checkbox.cpp +++ b/src/guichan/widgets/checkbox.cpp @@ -138,4 +138,3 @@ namespace gcn distributeActionEvent(); } } - diff --git a/src/guichan/widgets/dropdown.cpp b/src/guichan/widgets/dropdown.cpp index 40abaf41f..ead4e7815 100644 --- a/src/guichan/widgets/dropdown.cpp +++ b/src/guichan/widgets/dropdown.cpp @@ -422,4 +422,3 @@ namespace gcn } } } - diff --git a/src/guichan/widgets/icon.cpp b/src/guichan/widgets/icon.cpp index c85ada7c3..dca3400ba 100644 --- a/src/guichan/widgets/icon.cpp +++ b/src/guichan/widgets/icon.cpp @@ -56,16 +56,16 @@ namespace gcn { - Icon::Icon() - : mImage(nullptr) - , mInternalImage(false) + Icon::Icon() : + mImage(nullptr), + mInternalImage(false) { setSize(0, 0); } - Icon::Icon(const std::string& filename) - : mImage(nullptr), - mInternalImage(false) + Icon::Icon(const std::string& filename) : + mImage(nullptr), + mInternalImage(false) { mImage = Image::load(filename); mInternalImage = true; @@ -73,9 +73,9 @@ namespace gcn mImage->getHeight()); } - Icon::Icon(const Image* image) - : mImage(image), - mInternalImage(false) + Icon::Icon(const Image* image) : + mImage(image), + mInternalImage(false) { setSize(mImage->getWidth(), mImage->getHeight()); diff --git a/src/guichan/widgets/tab.cpp b/src/guichan/widgets/tab.cpp index 96a347607..8afc248c5 100644 --- a/src/guichan/widgets/tab.cpp +++ b/src/guichan/widgets/tab.cpp @@ -116,4 +116,3 @@ namespace gcn mHasMouse = false; } } - diff --git a/src/localconsts.h b/src/localconsts.h index 2d0eb5dea..de67c3850 100644 --- a/src/localconsts.h +++ b/src/localconsts.h @@ -30,4 +30,4 @@ #define A_UNUSED __attribute__ ((unused)) #else #define A_UNUSED -#endif \ No newline at end of file +#endif diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 81c988d53..bb0c087d5 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -2338,7 +2338,7 @@ void LocalPlayer::crazyMove() { bool oldDisableCrazyMove = mDisableCrazyMove; mDisableCrazyMove = true; - switch(mCrazyMoveType) + switch (mCrazyMoveType) { case 1: crazyMove1(); @@ -2449,7 +2449,7 @@ void LocalPlayer::crazyMove3() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(1, 1); @@ -2483,7 +2483,7 @@ void LocalPlayer::crazyMove4() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(7, 0); @@ -2503,7 +2503,7 @@ void LocalPlayer::crazyMove5() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(0, 7); @@ -2523,7 +2523,7 @@ void LocalPlayer::crazyMove6() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(3, 0); @@ -2567,7 +2567,7 @@ void LocalPlayer::crazyMove7() if (mAction == MOVE) return; - switch(mCrazyMoveState) + switch (mCrazyMoveState) { case 0: move(1, 1); @@ -3045,7 +3045,7 @@ bool LocalPlayer::pickUpItems(int pickUpType) return status; int x1, y1, x2, y2; - switch(pickUpType) + switch (pickUpType) { case 1: switch (mDirection) @@ -3206,7 +3206,7 @@ void LocalPlayer::magicAttack() if (!Client::limitPackets(PACKET_CHAT)) return; - switch(mMagicAttackType) + switch (mMagicAttackType) { //flar W00 case 0: diff --git a/src/logger.cpp b/src/logger.cpp index a2df9a911..1541616f2 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -186,7 +186,7 @@ void Logger::log(const char *log_text, ...) debugChatTab->chatLog(buf, BY_LOGGER); // Delete temporary buffer - delete[] buf; + delete [] buf; } void Logger::error(const std::string &error_text) diff --git a/src/map.cpp b/src/map.cpp index a9aed4531..3ea9989a4 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -181,9 +181,9 @@ Map::~Map() config.removeListener("beingopacity", this); // delete metadata, layers, tilesets and overlays - delete[] mMetaTiles; + delete [] mMetaTiles; for (int i = 0; i < NB_BLOCKTYPES; i++) - delete[] mOccupation[i]; + delete [] mOccupation[i]; mFringeLayer = nullptr; delete_all(mLayers); @@ -1435,7 +1435,7 @@ void Map::clearIndexedTilesets() return; mTilesetsIndexed = false; - delete[] mIndexedTilesets; + delete [] mIndexedTilesets; mIndexedTilesetsSize = 0; } diff --git a/src/maplayer.cpp b/src/maplayer.cpp index 3e9c47968..514a35858 100644 --- a/src/maplayer.cpp +++ b/src/maplayer.cpp @@ -56,7 +56,7 @@ MapLayer::MapLayer(int x, int y, int width, int height, bool fringeLayer): MapLayer::~MapLayer() { config.removeListener("highlightAttackRange", this); - delete[] mTiles; + delete [] mTiles; delete_all(mTempRows); mTempRows.clear(); } @@ -534,7 +534,7 @@ SpecialLayer::~SpecialLayer() delete mTiles[f]; mTiles[f] = nullptr; } - delete[] mTiles; + delete [] mTiles; } MapItem* SpecialLayer::getTile(int x, int y) const @@ -722,7 +722,7 @@ void MapItem::draw(Graphics *graphics, int x, int y, int dx, int dy) if (mImage) graphics->drawImage(mImage, x, y); - switch(mType) + switch (mType) { case ROAD: case CROSS: diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp index 100b600b4..7e857a52b 100644 --- a/src/mumblemanager.cpp +++ b/src/mumblemanager.cpp @@ -182,7 +182,7 @@ void MumbleManager::setAction(int action) if (!mLinkedMem) return; - switch(action) + switch (action) { case 0: /* STAND */ case 1: /* WALK */ @@ -228,7 +228,7 @@ void MumbleManager::setPos(int tileX, int tileY, int direction) // Unit vector pointing out of the avatars eyes // (here Front looks into scene). - switch(direction) + switch (direction) { case 4: /* UP */ mLinkedMemCache.fAvatarFront[0] = 0.0f; diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 84bd03bb1..d9e7e7506 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -511,6 +511,12 @@ void BeingHandler::processBeingAction(Net::MessageIn &msg) } break; + case 0x01: // dead + break; + // tmw server can send here garbage? +// if (srcBeing) +// srcBeing->setAction(Being::DEAD); + case 0x02: // Sit if (srcBeing) { diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp index cf62af459..d5e344ac2 100644 --- a/src/net/ea/gui/partytab.cpp +++ b/src/net/ea/gui/partytab.cpp @@ -242,4 +242,3 @@ void PartyTab::saveToLogFile(std::string &msg) } } // namespace Ea - diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index 4c4fb760c..d870eff38 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -330,7 +330,7 @@ void InventoryHandler::processPlayerInventoryAdd(Net::MessageIn &msg) { Item *item = inventory->getItem(index); - if (item && item->getId() == itemId) + if (item && item->getId() == itemId) amount += item->getQuantity(); if (serverVersion < 1 && identified > 1) diff --git a/src/net/manaserv/chathandler.cpp b/src/net/manaserv/chathandler.cpp index f0a23127c..12451e6f6 100644 --- a/src/net/manaserv/chathandler.cpp +++ b/src/net/manaserv/chathandler.cpp @@ -293,7 +293,7 @@ void ChatHandler::handleChannelEvent(Net::MessageIn &msg) if (channel) { - switch(eventId) + switch (eventId) { case CHAT_EVENT_NEW_PLAYER: channel->getTab()->chatLog(strprintf(_("%s entered the " diff --git a/src/net/manaserv/guildhandler.cpp b/src/net/manaserv/guildhandler.cpp index dfd2ed3cf..aa82d6dcd 100644 --- a/src/net/manaserv/guildhandler.cpp +++ b/src/net/manaserv/guildhandler.cpp @@ -153,7 +153,7 @@ void GuildHandler::handleMessage(Net::MessageIn &msg) Guild *guild = player_node->getGuild(guildId); if (guild) { - switch(eventId) + switch (eventId) { case GUILD_EVENT_NEW_PLAYER: member = guild->addMember(name); diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp index aa79d4d41..b2609cf02 100644 --- a/src/net/manaserv/playerhandler.cpp +++ b/src/net/manaserv/playerhandler.cpp @@ -151,8 +151,7 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg) PlayerInfo::setAttribute(CORR_POINTS, msg.readInt16()); Particle* effect = particleEngine->addEffect( paths.getStringValue("particles") - + paths.getStringValue("levelUpEffectFile") - , 0, 0); + + paths.getStringValue("levelUpEffectFile"), 0, 0); player_node->controlParticle(effect); } break; diff --git a/src/net/net.cpp b/src/net/net.cpp index 713b6aa7e..75bc35b72 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -202,4 +202,3 @@ ServerInfo::Type getNetworkType() } } // namespace Net - diff --git a/src/net/tmwa/gui/guildtab.cpp b/src/net/tmwa/gui/guildtab.cpp index af90f5c6b..496ba64f5 100644 --- a/src/net/tmwa/gui/guildtab.cpp +++ b/src/net/tmwa/gui/guildtab.cpp @@ -53,4 +53,3 @@ GuildTab::~GuildTab() } } // namespace TmwAthena - diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp index d0738e79c..02bcfd54f 100644 --- a/src/net/tmwa/gui/partytab.cpp +++ b/src/net/tmwa/gui/partytab.cpp @@ -56,4 +56,3 @@ PartyTab::~PartyTab() } } // namespace TmwAthena - diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index 31329eafb..6e9e367c0 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -133,8 +133,8 @@ Network::~Network() mMutex = nullptr; mInstance = nullptr; - delete[] mInBuffer; - delete[] mOutBuffer; + delete []mInBuffer; + delete []mOutBuffer; SDLNet_Quit(); } diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 2c3d914b0..bcf46e18b 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -61,9 +61,9 @@ OpenGLGraphics::OpenGLGraphics(): OpenGLGraphics::~OpenGLGraphics() { - delete[] mFloatTexArray; - delete[] mIntTexArray; - delete[] mIntVertArray; + delete [] mFloatTexArray; + delete [] mIntTexArray; + delete [] mIntVertArray; } void OpenGLGraphics::setSync(bool sync) diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 6b5cb0199..38062c352 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -103,7 +103,8 @@ class PlayerConfSerialiser : static PlayerConfSerialiser player_conf_serialiser; // stateless singleton -const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = { +const unsigned int PlayerRelation::RELATION_PERMISSIONS[RELATIONS_NR] = +{ /* NEUTRAL */ 0, // we always fall back to the defaults anyway /* FRIEND */ EMOTE | SPEECH_FLOAT | SPEECH_LOG | WHISPER | TRADE, /* DISREGARDED*/ EMOTE | SPEECH_FLOAT, @@ -531,8 +532,6 @@ public: Uint8 mEmotion; }; - - std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 6f9042029..0ac11f114 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -250,14 +250,14 @@ Image *Image::createTextSurface(SDL_Surface *tmpImage, float alpha) // We also delete the alpha channel since // it's not used. - delete[] alphaChannel; + delete [] alphaChannel; alphaChannel = nullptr; } if (!image) { logger->log1("Error: Image convert failed."); - delete[] alphaChannel; + delete [] alphaChannel; return nullptr; } @@ -295,7 +295,7 @@ void Image::unload() SDL_FreeSurface(mSDLSurface); mSDLSurface = nullptr; - delete[] mAlphaChannel; + delete [] mAlphaChannel; mAlphaChannel = nullptr; } @@ -689,14 +689,14 @@ Image *Image::_SDLload(SDL_Surface *tmpImage) // We also delete the alpha channel since // it's not used. - delete[] alphaChannel; + delete [] alphaChannel; alphaChannel = nullptr; } if (!image) { logger->log1("Error: Image convert failed."); - delete[] alphaChannel; + delete [] alphaChannel; return nullptr; } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 1ddb74f20..eec14685d 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -503,7 +503,7 @@ void MapReader::readLayer(XmlNodePtr node, Map *map) const char *charStart = reinterpret_cast(xmlChars); if (!charStart) { - delete[] charData; + delete [] charData; return; } @@ -526,7 +526,7 @@ void MapReader::readLayer(XmlNodePtr node, Map *map) static_cast(strlen(reinterpret_cast( charData))), &binLen); - delete[] charData; + delete [] charData; xmlFree(xmlChars); if (binData) diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index c26526b97..7adeaa268 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -404,19 +404,19 @@ struct ResourceLoader { if (!v) return nullptr; - ResourceLoader *l = static_cast< ResourceLoader * >(v); - SDL_RWops *rw = PHYSFSRWOPS_openRead(l->path.c_str()); + ResourceLoader *rl = static_cast< ResourceLoader * >(v); + SDL_RWops *rw = PHYSFSRWOPS_openRead(rl->path.c_str()); if (!rw) return nullptr; - Resource *res = l->fun(rw); + Resource *res = rl->fun(rw); return res; } }; Resource *ResourceManager::load(const std::string &path, loader fun) { - ResourceLoader l = { this, path, fun }; - return get(path, ResourceLoader::load, &l); + ResourceLoader rl = { this, path, fun }; + return get(path, ResourceLoader::load, &rl); } Music *ResourceManager::getMusic(const std::string &idPath) @@ -438,11 +438,11 @@ struct DyedImageLoader if (!v) return nullptr; - DyedImageLoader *l = static_cast< DyedImageLoader * >(v); - if (!l->manager) + DyedImageLoader *rl = static_cast< DyedImageLoader * >(v); + if (!rl->manager) return nullptr; - std::string path = l->path; + std::string path = rl->path; std::string::size_type p = path.find('|'); Dye *d = nullptr; if (p != std::string::npos) @@ -465,8 +465,8 @@ struct DyedImageLoader Image *ResourceManager::getImage(const std::string &idPath) { - DyedImageLoader l = { this, idPath }; - return static_cast(get(idPath, DyedImageLoader::load, &l)); + DyedImageLoader rl = { this, idPath }; + return static_cast(get(idPath, DyedImageLoader::load, &rl)); } /* @@ -475,8 +475,8 @@ Image *ResourceManager::getSkinImage(const std::string &idPath) if (mSelectedSkin.empty()) return getImage(idPath); - DyedImageLoader l = { this, mSelectedSkin + idPath }; - void *ptr = get(idPath, DyedImageLoader::load, &l); + DyedImageLoader rl = { this, mSelectedSkin + idPath }; + void *ptr = get(idPath, DyedImageLoader::load, &rl); if (ptr) return static_cast(ptr); else @@ -494,14 +494,14 @@ struct ImageSetLoader if (!v) return nullptr; - ImageSetLoader *l = static_cast< ImageSetLoader * >(v); - if (!l->manager) + ImageSetLoader *rl = static_cast< ImageSetLoader * >(v); + if (!rl->manager) return nullptr; - Image *img = l->manager->getImage(l->path); + Image *img = rl->manager->getImage(rl->path); if (!img) return nullptr; - ImageSet *res = new ImageSet(img, l->w, l->h); + ImageSet *res = new ImageSet(img, rl->w, rl->h); img->decRef(); return res; } @@ -510,10 +510,10 @@ struct ImageSetLoader ImageSet *ResourceManager::getImageSet(const std::string &imagePath, int w, int h) { - ImageSetLoader l = { this, imagePath, w, h }; + ImageSetLoader rl = { this, imagePath, w, h }; std::stringstream ss; ss << imagePath << "[" << w << "x" << h << "]"; - return static_cast(get(ss.str(), ImageSetLoader::load, &l)); + return static_cast(get(ss.str(), ImageSetLoader::load, &rl)); } struct SpriteDefLoader @@ -525,17 +525,17 @@ struct SpriteDefLoader if (!v) return nullptr; - SpriteDefLoader *l = static_cast< SpriteDefLoader * >(v); - return SpriteDef::load(l->path, l->variant); + SpriteDefLoader *rl = static_cast< SpriteDefLoader * >(v); + return SpriteDef::load(rl->path, rl->variant); } }; SpriteDef *ResourceManager::getSprite(const std::string &path, int variant) { - SpriteDefLoader l = { path, variant }; + SpriteDefLoader rl = { path, variant }; std::stringstream ss; ss << path << "[" << variant << "]"; - return static_cast(get(ss.str(), SpriteDefLoader::load, &l)); + return static_cast(get(ss.str(), SpriteDefLoader::load, &rl)); } void ResourceManager::release(Resource *res) @@ -723,10 +723,10 @@ struct RescaledLoader { if (!v) return nullptr; - RescaledLoader *l = static_cast< RescaledLoader * >(v); - if (!l->manager) + RescaledLoader *rl = static_cast< RescaledLoader * >(v); + if (!rl->manager || !rl->image) return nullptr; - Image *rescaled = l->image->SDLgetScaledImage(l->width, l->height); + Image *rescaled = rl->image->SDLgetScaledImage(rl->width, rl->height); if (!rescaled) return nullptr; return rescaled; @@ -740,7 +740,7 @@ Image *ResourceManager::getRescaled(Image *image, int width, int height) std::string idPath = image->getIdPath() + strprintf( "_rescaled%dx%d", width, height); - RescaledLoader l = { this, image, width, height }; - Image *img = static_cast(get(idPath, RescaledLoader::load, &l)); + RescaledLoader rl = { this, image, width, height }; + Image *img = static_cast(get(idPath, RescaledLoader::load, &rl)); return img; } diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index b1a3a9c4d..664d2c73d 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -36,7 +36,7 @@ namespace SpecialInfo::TargetMode SpecialDB::targetModeFromString(const std::string& str) { - if (str == "self") return SpecialInfo::TARGET_SELF; + if (str == "self") return SpecialInfo::TARGET_SELF; else if (str == "friend") return SpecialInfo::TARGET_FRIEND; else if (str == "enemy") return SpecialInfo::TARGET_ENEMY; else if (str == "being") return SpecialInfo::TARGET_BEING; @@ -131,4 +131,3 @@ SpecialInfo *SpecialDB::get(int id) return i->second; return nullptr; } - diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 7c4c444f0..ebdff6382 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -66,7 +66,8 @@ TextCommand* SpellManager::getSpellByItem(int itemId) void SpellManager::fillSpells() { -//id, std::string name, std::string symbol, ST type, int basicLvl, MagicSchool school, int schoolLvl, int mana) +//id, std::string name, std::string symbol, ST type, int basicLvl, +// MagicSchool school, int schoolLvl, int mana) addSpell(new TextCommand(0, "lum", "#lum", "heal with lifestones", ALLOWTARGET, "", 1, SKILL_MAGIC_LIFE, 0, 6)); diff --git a/src/textcommand.h b/src/textcommand.h index 27b44cc7a..6677b97e9 100644 --- a/src/textcommand.h +++ b/src/textcommand.h @@ -153,7 +153,7 @@ class TextCommand { mCommandType = commandType; } bool isEmpty() const - { return mCommand == "" && mSymbol == "" ; } + { return mCommand == "" && mSymbol == ""; } Image *getImage() const { return mImage; } diff --git a/src/units.cpp b/src/units.cpp index 804512dbd..1440cff9f 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -150,12 +150,12 @@ void Units::loadUnits() } // Add one more level for saftey - struct UnitLevel ll; - ll.symbol = ""; - ll.count = INT_MAX; - ll.round = 0; + struct UnitLevel lev; + lev.symbol = ""; + lev.count = INT_MAX; + lev.round = 0; - ud.levels.push_back(ll); + ud.levels.push_back(lev); if (type == "weight") units[UNIT_WEIGHT] = ud; diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp index 24a3a58e3..cd7d59cdb 100644 --- a/src/utils/base64.cpp +++ b/src/utils/base64.cpp @@ -125,7 +125,7 @@ unsigned char *php3_base64_decode(const unsigned char *string, continue; ch = static_cast(chp - base64_table); - switch(i % 4) + switch (i % 4) { case 0: result[j] = ch << 2; @@ -151,7 +151,7 @@ unsigned char *php3_base64_decode(const unsigned char *string, /* mop things up if we ended on a boundary */ if (ch == base64_pad) { - switch(i % 4) + switch (i % 4) { case 0: case 1: diff --git a/src/utils/physfsrwops.h b/src/utils/physfsrwops.h index efa004ac6..1f52f40aa 100644 --- a/src/utils/physfsrwops.h +++ b/src/utils/physfsrwops.h @@ -79,4 +79,3 @@ SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle); #endif /* include-once blocker */ /* end of physfsrwops.h ... */ - diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index becb2124d..5e7bf19a0 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -405,7 +405,7 @@ std::set splitToIntSet(const std::string &text, char separator) std::set tokens; std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) tokens.insert(atoi(item.c_str())); return tokens; @@ -416,7 +416,7 @@ std::list splitToIntList(const std::string &text, char separator) std::list tokens; std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) tokens.push_back(atoi(item.c_str())); return tokens; @@ -429,7 +429,7 @@ std::list splitToStringList(const std::string &text, std::list tokens; std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) tokens.push_back(item); return tokens; @@ -440,7 +440,7 @@ void splitToStringVector(std::vector &tokens, { std::stringstream ss(text); std::string item; - while(std::getline(ss, item, separator)) + while (std::getline(ss, item, separator)) { item = trim(item); if (!item.empty()) diff --git a/src/vector.h b/src/vector.h index 744b235c0..2caf48418 100644 --- a/src/vector.h +++ b/src/vector.h @@ -185,8 +185,8 @@ class Vector */ Vector normalized() const { - const float l = length(); - return Vector(x / l, y / l, z / l); + const float len = length(); + return Vector(x / len, y / len, z / len); } float x, y, z; -- cgit v1.2.3-60-g2f50 From bb156df11431e3eb286ddd3311adf1ac710945e0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 11 Feb 2012 19:39:06 +0300 Subject: Remove some unneeded includes. --- build/makecheck4 | 2 +- src/actorspritemanager.cpp | 2 -- src/being.cpp | 1 - src/being.h | 1 - src/client.cpp | 2 -- src/compoundsprite.cpp | 3 ++- src/flooritem.cpp | 2 +- src/graphics.cpp | 1 - src/gui/ministatuswindow.h | 1 - src/guichanfwd.h | 6 ------ src/itemshortcut.cpp | 1 - src/localplayer.cpp | 5 ----- src/net/charhandler.h | 2 -- src/net/ea/playerhandler.cpp | 1 + src/net/playerhandler.h | 1 - src/net/tmwa/playerhandler.cpp | 1 + src/utils/stringutils.cpp | 2 -- 17 files changed, 6 insertions(+), 28 deletions(-) (limited to 'src/utils') diff --git a/build/makecheck4 b/build/makecheck4 index 852986459..5c77d7f3a 100755 --- a/build/makecheck4 +++ b/build/makecheck4 @@ -1,5 +1,5 @@ #!/bin/bash -../../checkheaders/checkheaders ../src 2>tmp.txt +../../checkheaders/checkheaders --skip debug.h ../src 2>tmp.txt sed '/(style): Header not found/d' tmp.txt >makecheck4.txt rm tmp.txt diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 89a592005..803a30e7e 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -31,8 +31,6 @@ #include "gui/chatwindow.h" #include "gui/equipmentwindow.h" -#include "gui/killstats.h" -#include "gui/skilldialog.h" #include "gui/socialwindow.h" #include "gui/viewport.h" diff --git a/src/being.cpp b/src/being.cpp index 92d01097b..47a74c7b2 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -40,7 +40,6 @@ #include "sound.h" #include "sprite.h" #include "text.h" -#include "statuseffect.h" #include "gui/buydialog.h" #include "gui/buyselldialog.h" diff --git a/src/being.h b/src/being.h index a52963746..0b9257e83 100644 --- a/src/being.h +++ b/src/being.h @@ -27,7 +27,6 @@ #include "configlistener.h" #include "equipment.h" #include "map.h" -#include "particlecontainer.h" #include "position.h" #include "vector.h" diff --git a/src/client.cpp b/src/client.cpp index 023eb5353..a7825a835 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -69,7 +69,6 @@ #include "gui/worldselectdialog.h" #include "gui/widgets/button.h" -#include "gui/widgets/chattab.h" #include "gui/widgets/desktop.h" #include "net/charhandler.h" @@ -80,7 +79,6 @@ #include "net/loginhandler.h" #include "net/net.h" #include "net/npchandler.h" -#include "net/packetcounters.h" #include "net/partyhandler.h" #include "net/worldinfo.h" diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 61fb3d4e0..62ef2d01c 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -24,11 +24,12 @@ #include "configuration.h" #include "game.h" #include "graphics.h" + #ifdef USE_OPENGL #include "openglgraphics.h" #include "opengl1graphics.h" #endif -#include "localplayer.h" + #include "map.h" #include "resources/image.h" diff --git a/src/flooritem.cpp b/src/flooritem.cpp index 111019546..f126f336b 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -31,7 +31,7 @@ #include "gui/gui.h" #include "gui/sdlfont.h" -#include "net/net.h" +//#include "net/net.h" #include "resources/itemdb.h" #include "resources/iteminfo.h" diff --git a/src/graphics.cpp b/src/graphics.cpp index 635cc6ab9..e98b1a283 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -24,7 +24,6 @@ #include "graphicsvertexes.h" #include "logger.h" -#include "map.h" #include "resources/image.h" #include "resources/imageloader.h" diff --git a/src/gui/ministatuswindow.h b/src/gui/ministatuswindow.h index ba2cf7b2d..eb6ded7dd 100644 --- a/src/gui/ministatuswindow.h +++ b/src/gui/ministatuswindow.h @@ -27,7 +27,6 @@ #include "listener.h" #include "gui/widgets/popup.h" -#include "gui/widgets/window.h" #include diff --git a/src/guichanfwd.h b/src/guichanfwd.h index b3808d8ba..7ccc221b4 100644 --- a/src/guichanfwd.h +++ b/src/guichanfwd.h @@ -27,11 +27,6 @@ namespace gcn { class ActionEvent; class ActionListener; - class AllegroFont; - class AllegroGraphics; - class AllegroImage; - class AllegroImageLoader; - class AllegroInput; class BasicContainer; class Button; class CheckBox; @@ -70,7 +65,6 @@ namespace gcn class MouseEvent; class MouseInput; class MouseListener; - class OpenGLAllegroImageLoader; class OpenGLGraphics; class OpenGLImage; class OpenGLSDLImageLoader; diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index f267dd755..fedb92257 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -24,7 +24,6 @@ #include "inventory.h" #include "item.h" #include "itemshortcut.h" -#include "localplayer.h" #include "playerinfo.h" #include "spellmanager.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 01e8c1ae8..99108bd3a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -41,21 +41,16 @@ #include "simpleanimation.h" #include "sound.h" #include "statuseffect.h" -#include "text.h" #include "dropshortcut.h" #include "gui/chatwindow.h" #include "gui/gui.h" -#include "gui/inventorywindow.h" -#include "gui/killstats.h" #include "gui/ministatuswindow.h" #include "gui/okdialog.h" #include "gui/outfitwindow.h" -#include "gui/palette.h" #include "gui/shopwindow.h" #include "gui/skilldialog.h" #include "gui/socialwindow.h" -#include "gui/statuswindow.h" #include "gui/theme.h" #include "gui/userpalette.h" #include "gui/viewport.h" diff --git a/src/net/charhandler.h b/src/net/charhandler.h index 492e27e55..cee319719 100644 --- a/src/net/charhandler.h +++ b/src/net/charhandler.h @@ -26,8 +26,6 @@ #include "localplayer.h" #include "playerinfo.h" -#include "net/logindata.h" - #include #include diff --git a/src/net/ea/playerhandler.cpp b/src/net/ea/playerhandler.cpp index 76a7b0dbc..27aa4da80 100644 --- a/src/net/ea/playerhandler.cpp +++ b/src/net/ea/playerhandler.cpp @@ -22,6 +22,7 @@ #include "net/ea/playerhandler.h" +#include "localplayer.h" #include "logger.h" #include "party.h" #include "playerinfo.h" diff --git a/src/net/playerhandler.h b/src/net/playerhandler.h index 6ae912102..aa5d2b793 100644 --- a/src/net/playerhandler.h +++ b/src/net/playerhandler.h @@ -25,7 +25,6 @@ #include "being.h" #include "flooritem.h" -#include "localplayer.h" namespace Net { diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 16e833ec9..bfe9eea42 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -23,6 +23,7 @@ #include "net/tmwa/playerhandler.h" #include "configuration.h" +#include "client.h" #include "logger.h" #include "net/messagein.h" diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 5e7bf19a0..798690602 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -22,8 +22,6 @@ #include "utils/stringutils.h" -#include "configuration.h" - #include #include #include -- cgit v1.2.3-60-g2f50 From 541bd299d521666d7d02b4f36b75f31dd8a2d64f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 12 Feb 2012 01:23:09 +0300 Subject: Fix some possible errors in string untils. --- src/utils/stringutils.cpp | 34 +++++++++++++++++++++++----------- src/utils/stringutils.h | 2 +- 2 files changed, 24 insertions(+), 12 deletions(-) (limited to 'src/utils') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 798690602..9184ba79d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -105,6 +105,7 @@ std::string strprintf(char const *format, ...) return res; } +/* std::string &removeBadChars(std::string &str) { std::string::size_type pos; @@ -118,6 +119,7 @@ std::string &removeBadChars(std::string &str) return str; } +*/ std::string removeColors(std::string msg) { @@ -316,27 +318,37 @@ void getSafeUtf8String(std::string text, char *buf) std::string getFileName(std::string path) { - size_t pos = path.rfind("/"); - if (pos == std::string::npos) - pos = path.rfind("\\"); - if (pos == std::string::npos) + size_t pos1 = path.rfind("/"); + size_t pos2 = path.rfind("\\"); + if (pos1 == std::string::npos) + pos1 = pos2; + else if (pos2 != std::string::npos && pos2 > pos1) + pos1 = pos2; + + if (pos1 == std::string::npos) return path; - return path.substr(pos + 1); + return path.substr(pos1 + 1); } std::string getFileDir(std::string path) { - size_t pos = path.rfind("/"); - if (pos == std::string::npos) - pos = path.rfind("\\"); - if (pos == std::string::npos) - return ""; - return path.substr(0, pos); + size_t pos1 = path.rfind("/"); + size_t pos2 = path.rfind("\\"); + if (pos1 == std::string::npos) + pos1 = pos2; + else if (pos2 != std::string::npos && pos2 > pos1) + pos1 = pos2; + + if (pos1 == std::string::npos) + return path; + return path.substr(0, pos1); } std::string& replaceAll(std::string& context, const std::string& from, const std::string& to) { + if (from.empty()) + return context; size_t lookHere = 0; size_t foundHere; while ((foundHere = context.find(from, lookHere)) != std::string::npos) diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 398737179..47d495dd0 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -103,7 +103,7 @@ std::string strprintf(char const *, ...) * @param str the string to remove the bad chars from * @return a reference to the string without bad chars */ -std::string &removeBadChars(std::string &str); +//std::string &removeBadChars(std::string &str); /** * Removes colors from a string -- cgit v1.2.3-60-g2f50 From 6d3f7abf7fa4502b0de347c69a81e1c65e0cae19 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 12 Feb 2012 01:23:48 +0300 Subject: Add unit tests for stringutils. --- src/Makefile.am | 9 +- src/utils/stringutils_unittest.cc | 517 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 522 insertions(+), 4 deletions(-) create mode 100644 src/utils/stringutils_unittest.cc (limited to 'src/utils') diff --git a/src/Makefile.am b/src/Makefile.am index 62b762af6..3fad9f3ce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,10 +21,6 @@ else manaplus_SOURCES = endif -if ENABLE_UNITTESTS -manaplus_CXXFLAGS += -DUNITTESTS -endif - if USE_INTERNALGUICHAN manaplus_CXXFLAGS += -DUSE_INTERNALGUICHAN manaplus_SOURCES += guichan/include/guichan/actionevent.hpp \ @@ -785,6 +781,11 @@ manaplus_SOURCES += \ mumblemanager.cpp \ mumblemanager.h +if ENABLE_UNITTESTS +manaplus_CXXFLAGS += -DUNITTESTS +manaplus_SOURCES += \ + utils/stringutils_unittest.cc +endif EXTRA_DIST = CMakeLists.txt \ winver.h.in \ diff --git a/src/utils/stringutils_unittest.cc b/src/utils/stringutils_unittest.cc new file mode 100644 index 000000000..81030631a --- /dev/null +++ b/src/utils/stringutils_unittest.cc @@ -0,0 +1,517 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * 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 + * 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, see . + */ + +#include "utils/stringutils.h" + +#include "gtest/gtest.h" + +#include +#include +#include + +#include "debug.h" + +TEST(stringuntils, trim1) +{ + std::string str = "str"; + EXPECT_EQ("str", trim(str)); + + str = " str"; + EXPECT_EQ("str", trim(str)); + EXPECT_EQ("str", trim(str)); + + str = " str this IS Long Стринг " + "~!@#$%^&*()_+`-=[]\\{}|;':\",./<>? "; + EXPECT_EQ("str this IS Long Стринг ~!@#$%^&*()_+`-=[]\\{}|;':\",./<>?", + trim(str)); + + str = ""; + EXPECT_EQ("", trim(str)); +} + +TEST(stringuntils, toLower1) +{ + std::string str = "str"; + EXPECT_EQ("str", toLower(str)); + + str = " StR"; + EXPECT_EQ(" str", toLower(str)); + + str = " str this IS Long " + "~!@#$%^&*()_+`-=[]\\{}|;':\",./<>? "; + + EXPECT_EQ(" str this is long ~!@#$%^&*()_+`-=[]\\{}|;':\",./<>? ", + toLower(str)); + + str = ""; + EXPECT_EQ("", toLower(str)); +} + +TEST(stringuntils, toUpper1) +{ + std::string str = "str"; + EXPECT_EQ("STR", toUpper(str)); + + str = " StR"; + EXPECT_EQ(" STR", toUpper(str)); + + str = " str this IS Long " + "~!@#$%^&*()_+`-=[]\\{}|;':,./<>? "; + + EXPECT_EQ(" STR THIS IS LONG ~!@#$%^&*()_+`-=[]\\{}|;':,./<>? ", + toUpper(str)); + + str = ""; + EXPECT_EQ("", toUpper(str)); +} + +TEST(stringuntils, atox1) +{ + std::string str = "0x10"; + EXPECT_EQ(16, atox(str)); + + str = "0x0"; + EXPECT_EQ(0, atox(str)); + + str = "0x1"; + EXPECT_EQ(1, atox(str)); + + str = "0x0x0x0x0x0x0x0"; + EXPECT_EQ(0, atox(str)); + + str = "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + atox(str); + + str = ""; + int k = atox(str); + + str = "0"; + k = atox(str); + + str = "0x"; + k = atox(str); +} + +TEST(stringuntils, ipToString1) +{ + EXPECT_EQ("0.0.0.0", std::string(ipToString(0))); + EXPECT_EQ("219.255.210.73", std::string(ipToString(1238564827))); +} + +TEST(stringuntils, removeColors1) +{ + EXPECT_EQ("", removeColors("")); + EXPECT_EQ("#", removeColors("#")); + EXPECT_EQ("##", removeColors("##")); + EXPECT_EQ("", removeColors("##1")); + EXPECT_EQ("2", removeColors("##12")); + EXPECT_EQ("1##", removeColors("1##")); + EXPECT_EQ("1", removeColors("1##2")); + EXPECT_EQ("13", removeColors("1##23")); + EXPECT_EQ("#1#2", removeColors("#1#2")); + EXPECT_EQ("#1", removeColors("#1##2")); +} + +TEST(stringuntils, compareStrI1) +{ + std::string str1 = ""; + std::string str2 = ""; + EXPECT_TRUE(compareStrI(str1, str2) == 0); + + str1 = "test"; + str2 = "test"; + EXPECT_TRUE(compareStrI(str1, str2) == 0); + + str1 = "test"; + str2 = "test1"; + EXPECT_TRUE(compareStrI(str1, str2) < 0); + + str1 = "test"; + str2 = "aest1"; + EXPECT_TRUE(compareStrI(str1, str2) > 0); +} + +TEST(stringuntils, isWordSeparator1) +{ + EXPECT_TRUE(isWordSeparator(' ')); + EXPECT_TRUE(isWordSeparator(',')); + EXPECT_TRUE(isWordSeparator('.')); + EXPECT_TRUE(isWordSeparator('\"')); + EXPECT_TRUE(!isWordSeparator(0)); + EXPECT_TRUE(!isWordSeparator('a')); + EXPECT_TRUE(!isWordSeparator('-')); +} + +TEST(stringuntils, findSameSubstring) +{ + std::string str1 = ""; + std::string str2 = ""; + + EXPECT_EQ("", findSameSubstring("", "")); + + str1 = "test line"; + str2 = "test line"; + EXPECT_EQ("test line", findSameSubstring(str1, str2)); + + str1 = "test li"; + str2 = "test line"; + EXPECT_EQ("test li", findSameSubstring(str1, str2)); + + str1 = "test li"; + str2 = "est li"; + EXPECT_EQ("", findSameSubstring(str1, str2)); +} + +TEST(stringuntils, findSameSubstringI) +{ + std::string str1 = ""; + std::string str2 = ""; + + EXPECT_EQ("", findSameSubstringI("", "")); + + str1 = "tEst line"; + str2 = "tesT line"; + EXPECT_EQ("tEst line", findSameSubstringI(str1, str2)); + + str1 = "test Li"; + str2 = "test lINe"; + EXPECT_EQ("test Li", findSameSubstringI(str1, str2)); + + str1 = "teSt li"; + str2 = "est li"; + EXPECT_EQ("", findSameSubstringI(str1, str2)); +} + +TEST(stringuntils, findI1) +{ + EXPECT_EQ(0, findI("", "")); + EXPECT_EQ(std::string::npos, findI("test", "line")); + EXPECT_EQ(0, findI("test line", "t")); + EXPECT_EQ(0, findI("test line", "te")); + EXPECT_EQ(3, findI("test line", "t l")); +} + +TEST(stringuntils, findI2) +{ + std::vector vect1; + vect1.push_back("test"); + vect1.push_back("line"); + vect1.push_back("qwe"); + + EXPECT_EQ(std::string::npos, findI("", vect1)); + EXPECT_EQ(0, findI("test", vect1)); + EXPECT_EQ(0, findI("tesT lIne", vect1)); + EXPECT_EQ(5, findI("teoT line", vect1)); + EXPECT_EQ(std::string::npos, findI("zzz", vect1)); +} + +TEST(stringuntils, encodeStr1) +{ + std::string str = encodeStr(10, 1); + EXPECT_EQ(10, decodeStr(str)); + + str = encodeStr(10, 2); + EXPECT_EQ(10, decodeStr(str)); + + str = encodeStr(100, 3); + EXPECT_EQ(100, decodeStr(str)); + + str = encodeStr(1000, 4); + EXPECT_EQ(1000, decodeStr(str)); +} + +TEST(stringuntils, extractNameFromSprite1) +{ + EXPECT_EQ("", extractNameFromSprite("")); + EXPECT_EQ("test", extractNameFromSprite("test")); + EXPECT_EQ("test", extractNameFromSprite("test.qwe")); + EXPECT_EQ("line", extractNameFromSprite("test/line.zzz")); +} + +TEST(stringuntils, removeSpriteIndex1) +{ + EXPECT_EQ("", removeSpriteIndex("")); + EXPECT_EQ("test", removeSpriteIndex("test")); + EXPECT_EQ("test", removeSpriteIndex("test[1]")); + EXPECT_EQ("line", removeSpriteIndex("test/line[12]")); +} + +TEST(stringuntils, getFileName1) +{ + EXPECT_EQ("", getFileName("")); + EXPECT_EQ("file", getFileName("file")); + EXPECT_EQ("file", getFileName("test/file1\\file")); + EXPECT_EQ("file", getFileName("test\\file1/file")); + EXPECT_EQ("", getFileName("file/")); + EXPECT_EQ("file", getFileName("/file")); +} + +TEST(stringuntils, getFileDir1) +{ + EXPECT_EQ("", getFileDir("")); + EXPECT_EQ("file", getFileDir("file")); + EXPECT_EQ("test/file1", getFileDir("test/file1\\file")); + EXPECT_EQ("test\\file1", getFileDir("test\\file1/file")); + EXPECT_EQ("file", getFileDir("file/")); + EXPECT_EQ("", getFileDir("/file")); +} + +TEST(stringuntils, replaceAll1) +{ + std::string str1 = ""; + std::string str2 = ""; + std::string str3 = ""; + + EXPECT_EQ("", replaceAll(str1, str2, str3)); + + str1 = "this is test line"; + str2 = ""; + str3 = ""; + EXPECT_EQ("this is test line", replaceAll(str1, str2, str3)); + + str1 = "this is test line"; + str2 = "is "; + str3 = ""; + EXPECT_EQ("thtest line", replaceAll(str1, str2, str3)); + + str1 = "this is test line"; + str2 = ""; + str3 = "1"; + EXPECT_EQ("this is test line", replaceAll(str1, str2, str3)); +} + +TEST(stringuntils, getBoolFromString1) +{ + EXPECT_TRUE(getBoolFromString("true")); + EXPECT_TRUE(!getBoolFromString("false")); + EXPECT_TRUE(getBoolFromString("1")); + EXPECT_TRUE(!getBoolFromString("0")); +} + +TEST(stringuntils, replaceSpecialChars1) +{ + std::string str; + + str = ""; + replaceSpecialChars(str); + EXPECT_EQ("", str); + + str = "test"; + replaceSpecialChars(str); + EXPECT_EQ("test", str); + + str = "&"; + replaceSpecialChars(str); + EXPECT_EQ("&", str); + + str = "&1"; + replaceSpecialChars(str); + EXPECT_EQ("&1", str); + + str = "&33"; + replaceSpecialChars(str); + EXPECT_EQ("&33", str); + + str = "&33;"; + replaceSpecialChars(str); + EXPECT_EQ("!", str); + + str = "1&33;"; + replaceSpecialChars(str); + EXPECT_EQ("1!", str); + + str = "&33;2"; + replaceSpecialChars(str); + EXPECT_EQ("!2", str); + + str = "&33;&"; + replaceSpecialChars(str); + EXPECT_EQ("!&", str); + + str = "test line&33;"; + replaceSpecialChars(str); + EXPECT_EQ("test line!", str); +} + +TEST(stringuntils, combineDye1) +{ + EXPECT_EQ("", combineDye("", "")); + EXPECT_EQ("test", combineDye("test", "")); + EXPECT_EQ("|line", combineDye("", "line")); + EXPECT_EQ("test|line", combineDye("test", "line")); +} + +TEST(stringuntils, combineDye2) +{ + EXPECT_EQ("", combineDye2("", "")); + EXPECT_EQ("test", combineDye2("test", "")); + EXPECT_EQ("", combineDye2("", "line")); + EXPECT_EQ("test.xml", combineDye2("test.xml", "123")); + EXPECT_EQ("test.xml|#43413d,59544f,7a706c", + combineDye2("test.xml|#43413d,59544f,7a706c", "")); + EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;", + combineDye2("test.xml|#43413d,59544f,7a706c", "W")); + EXPECT_EQ("test.xml|#43413d,59544f,7a706c:W;#123456:B;", + combineDye2("test.xml|#43413d,59544f,7a706c;#123456", "W;B")); +} + +TEST(stringuntils, packList1) +{ + std::list list; + EXPECT_EQ("", packList(list)); + + list.push_back(""); + EXPECT_EQ("|", packList(list)); + + list.clear(); + list.push_back("test"); + EXPECT_EQ("test", packList(list)); + + list.push_back("line"); + EXPECT_EQ("test|line", packList(list)); + + list.push_back("2"); + EXPECT_EQ("test|line|2", packList(list)); +} + +TEST(stringuntils, stringToHexPath1) +{ + std::string str; + + str = ""; + EXPECT_EQ("", stringToHexPath(str)); + + str = "a"; + EXPECT_EQ("%61/", stringToHexPath(str)); + + str = "ab"; + EXPECT_EQ("%61/%62", stringToHexPath(str)); + + str = "abc"; + EXPECT_EQ("%61/%62%63", stringToHexPath(str)); + + str = "abcd"; + EXPECT_EQ("%61/%62%63%64", stringToHexPath(str)); +} + +TEST(stringuntils, deleteCharLeft1) +{ + std::string str; + unsigned int pos = 0; + + str = ""; + deleteCharLeft(str, nullptr); + EXPECT_EQ("", str); + + str = "test line"; + pos = 4; + deleteCharLeft(str, &pos); + EXPECT_EQ("tes line", str); + + str = "тест line"; + pos = 8; + deleteCharLeft(str, &pos); + EXPECT_EQ("тес line", str); +} + +TEST(stringuntils, findLast1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findLast(str, "")); + + str = "test line"; + EXPECT_TRUE(findLast(str, "line")); + + str = "test line"; + EXPECT_TRUE(!findLast(str, "lin")); +} + +TEST(stringuntils, findFirst1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findFirst(str, "")); + + str = "test line"; + EXPECT_TRUE(findFirst(str, "test")); + + str = "test line"; + EXPECT_TRUE(!findFirst(str, "est")); +} + +TEST(stringuntils, findCutLast1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findCutLast(str, "")); + EXPECT_EQ("", str); + + str = "test line"; + EXPECT_TRUE(findCutLast(str, "line")); + EXPECT_EQ("test ", str); + + str = "test line"; + EXPECT_TRUE(!findCutLast(str, "lin")); + EXPECT_EQ("test line", str); +} + +TEST(stringuntils, findCutFirst1) +{ + std::string str; + + str = ""; + EXPECT_TRUE(findCutFirst(str, "")); + EXPECT_EQ("", str); + + str = "test line"; + EXPECT_TRUE(findCutFirst(str, "test")); + EXPECT_EQ(" line", str); + + str = "test line"; + EXPECT_TRUE(!findCutFirst(str, "est")); + EXPECT_EQ("test line", str); +} + +TEST(stringuntils, removeProtocol1) +{ + std::string str; + + str = ""; + EXPECT_EQ("", removeProtocol(str)); + + str = "http://"; + EXPECT_EQ("", removeProtocol(str)); + + str = "http://test"; + EXPECT_EQ("test", removeProtocol(str)); +} + +TEST(stringuntils, strStartWith1) +{ + EXPECT_TRUE(strStartWith("", "")); + EXPECT_TRUE(!strStartWith("", "1")); + EXPECT_TRUE(strStartWith("test line", "test")); + EXPECT_TRUE(strStartWith("test line", "test line")); + EXPECT_TRUE(!strStartWith("test line", "est")); +} -- cgit v1.2.3-60-g2f50 From 624b07bf0ee70794240135bb403e9dfb879749c4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 15 Feb 2012 02:35:06 +0300 Subject: Add function to fix dir separator. --- src/gui/sdlfont.cpp | 11 ++++++++--- src/gui/sdlfont.h | 4 ++-- src/utils/paths.cpp | 12 +++++++++++- src/utils/paths.h | 2 ++ 4 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src/utils') diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 0e69db026..7e0114cb8 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -27,6 +27,7 @@ #include "graphics.h" #include "logger.h" #include "main.h" +#include "utils/paths.h" #include "resources/image.h" #include "resources/resourcemanager.h" @@ -98,7 +99,7 @@ typedef std::list::iterator CacheIterator; static int fontCounter; -SDLFont::SDLFont(const std::string &filename, int size, int style) : +SDLFont::SDLFont(std::string filename, int size, int style) : mCreateCounter(0), mDeleteCounter(0) { @@ -117,13 +118,16 @@ SDLFont::SDLFont(const std::string &filename, int size, int style) : } ++fontCounter; + + fixDirSeparators(filename); mFont = TTF_OpenFont(resman->getPath(filename).c_str(), size); if (!mFont) { logger->log("Error finding font " + filename); + std::string backFile = "fonts/dejavusans.ttf"; mFont = TTF_OpenFont(resman->getPath( - "fonts/dejavusans.ttf").c_str(), size); + fixDirSeparators(backFile)).c_str(), size); if (!mFont) { throw GCN_EXCEPTION("SDLSDLFont::SDLSDLFont: " + @@ -148,7 +152,7 @@ SDLFont::~SDLFont() } } -void SDLFont::loadFont(const std::string &filename, int size, int style) +void SDLFont::loadFont(std::string filename, int size, int style) { ResourceManager *resman = ResourceManager::getInstance(); @@ -159,6 +163,7 @@ void SDLFont::loadFont(const std::string &filename, int size, int style) return; } + fixDirSeparators(filename); TTF_Font *font = TTF_OpenFont(resman->getPath(filename).c_str(), size); if (!font) diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h index 6fcad34d4..77e3761e7 100644 --- a/src/gui/sdlfont.h +++ b/src/gui/sdlfont.h @@ -53,14 +53,14 @@ class SDLFont : public gcn::Font * @param filename Font filename. * @param size Font size. */ - SDLFont(const std::string &filename, int size, int style = 0); + SDLFont(std::string filename, int size, int style = 0); /** * Destructor. */ ~SDLFont(); - void loadFont(const std::string &filename, int size, int style = 0); + void loadFont(std::string filename, int size, int style = 0); void createSDLTextChunk(SDLTextChunk *chunk); diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index faa1882e6..04f553ca9 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -20,10 +20,12 @@ #include "utils/paths.h" +#include "utils/stringutils.h" + #include #include #include - +#include #include #ifdef WIN32 @@ -65,3 +67,11 @@ bool checkPath(std::string path) && path.find("/..") == std::string::npos && path.find("\\..") == std::string::npos; } + +std::string &fixDirSeparators(std::string &str) +{ + if (*PHYSFS_getDirSeparator() == '/') + return str; + + return replaceAll(str, "/", "\\"); +} diff --git a/src/utils/paths.h b/src/utils/paths.h index f92fcdcb5..b89671adc 100644 --- a/src/utils/paths.h +++ b/src/utils/paths.h @@ -29,4 +29,6 @@ bool isRealPath(const std::string &str); bool checkPath(std::string path); +std::string &fixDirSeparators(std::string &str); + #endif // UTILS_PATHS_H -- cgit v1.2.3-60-g2f50 From 4cd44430deb5a7efc030839a133fe8510327fc24 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 17 Feb 2012 21:31:08 +0300 Subject: Update servers list once a day. --- src/gui/serverdialog.cpp | 15 ++++++++++++++- src/gui/serverdialog.h | 4 ++++ src/utils/stringutils.cpp | 14 ++++++++++++++ src/utils/stringutils.h | 2 ++ 4 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src/utils') diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 55eda908e..da61e105b 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -305,7 +305,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir): loadServers(true); - if (mServers.empty()) + if (needUpdateServers()) downloadServerList(); } @@ -487,6 +487,8 @@ void ServerDialog::downloadServerList() mDownload->setFile(mDir + "/" + branding.getStringValue( "onlineServerFile")); mDownload->start(); + + config.setValue("serverslistupdate", getDateString()); } void ServerDialog::loadServers(bool addNew) @@ -742,3 +744,14 @@ void ServerDialog::updateServer(ServerInfo server, int index) { saveCustomServers(server, index); } + +bool ServerDialog::needUpdateServers() +{ + if (mServers.empty() || config.getStringValue("serverslistupdate") + != getDateString()) + { + return true; + } + + return false; +} diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index c23fb8776..61620364c 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -138,12 +138,16 @@ class ServerDialog : public Window, * Called to load a list of available server from an online xml file. */ void downloadServerList(); + void loadServers(bool addNew = true); void loadCustomServers(); + void saveCustomServers(const ServerInfo ¤tServer = ServerInfo(), int index = -1); + bool needUpdateServers(); + static int downloadUpdate(void *ptr, DownloadStatus status, size_t total, size_t remaining); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 9184ba79d..2be1e5b77 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -609,3 +609,17 @@ bool strStartWith(std::string str1, std::string str2) return false; return str1.substr(0, str2.size()) == str2; } + +std::string getDateString() +{ + char buffer[80]; + + time_t rawtime; + struct tm *timeinfo; + + time (&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer, 79, "%Y-%m-%d", timeinfo); + return std::string(buffer); +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 47d495dd0..31ee6d51f 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -206,4 +206,6 @@ std::string &removeProtocol(std::string &url); bool strStartWith(std::string str, std::string start); +std::string getDateString(); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-60-g2f50 From 2257406db0fd374e929def04525671c2826306c2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 18 Feb 2012 02:06:44 +0300 Subject: Fix code style. --- src/animatedsprite.cpp | 7 ++++++- src/game.cpp | 4 ++-- src/graphics.cpp | 2 +- src/gui/emotepopup.cpp | 9 ++++++--- src/gui/setup_video.cpp | 1 - src/gui/spellpopup.cpp | 2 -- src/gui/viewport.cpp | 2 +- src/gui/whoisonline.cpp | 2 +- src/gui/widgets/browserbox.cpp | 2 +- src/gui/widgets/textbox.cpp | 4 ++-- src/localplayer.cpp | 8 ++------ src/resources/dye.cpp | 2 +- src/resources/image.cpp | 18 ++++++++++++++---- src/resources/specialdb.cpp | 1 - src/utils/process.cpp | 2 +- 15 files changed, 38 insertions(+), 28 deletions(-) (limited to 'src/utils') diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 11329b321..6b791fdd4 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -214,7 +214,12 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time) } } if (fail) - mFrameTime = mFrame->delay + 1; + { + if (mFrame) + mFrameTime = mFrame->delay + 1; + else + mFrameTime ++; + } } return true; } diff --git a/src/game.cpp b/src/game.cpp index 6adf62f12..e016d02ff 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1420,7 +1420,7 @@ void Game::handleMoveAndAttack(SDL_Event &event, bool wasDown) Net::getPlayerHandler()->setDirection(direction); } } - direction = 0; +// direction = 0; } else { @@ -1695,7 +1695,7 @@ void Game::handleInput() { if (emoteShortcut) emoteShortcut->useEmote(emotion); - used = true; +// used = true; setValidSpeed(); return; } diff --git a/src/graphics.cpp b/src/graphics.cpp index e98b1a283..5241bbcc6 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -112,7 +112,7 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, if (mTarget->format) { logger->log("Bits per pixel: %d", mTarget->format->BytesPerPixel); - bpp = mTarget->format->BytesPerPixel; +// bpp = mTarget->format->BytesPerPixel; } const SDL_VideoInfo *vi = SDL_GetVideoInfo(); diff --git a/src/gui/emotepopup.cpp b/src/gui/emotepopup.cpp index a286f78e8..39017ac91 100644 --- a/src/gui/emotepopup.cpp +++ b/src/gui/emotepopup.cpp @@ -197,12 +197,15 @@ void EmotePopup::recalculateSize() ++mRowCount; if (mRowCount) + { mColumnCount = emoteCount / mRowCount; + if (emoteCount % mRowCount > 0) + ++ mColumnCount; + } else + { mColumnCount = 1; - - if (emoteCount % mRowCount > 0) - ++mColumnCount; + } setContentSize(mColumnCount * gridWidth, mRowCount * gridHeight); } diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 6b3d6d4d3..cc3063a68 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -228,7 +228,6 @@ static const char *speechModeToString(Being::Speech mode) case Being::NAME_IN_BUBBLE: return _("Bubbles with names"); } - return ""; } const char *Setup_Video::overlayDetailToString(int detail) diff --git a/src/gui/spellpopup.cpp b/src/gui/spellpopup.cpp index 66d69b197..48037f03e 100644 --- a/src/gui/spellpopup.cpp +++ b/src/gui/spellpopup.cpp @@ -114,8 +114,6 @@ void SpellPopup::view(int x, int y) { if (y > getHeight() + distance) posY = y - getHeight() - distance; - else - y = 0; } setPosition(posX, posY); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 2e1e15c92..d4c188bfb 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -879,7 +879,7 @@ bool Viewport::isPopupMenuVisible() void Viewport::moveCameraToActor(int actorId, int x, int y) { - if (!player_node) + if (!player_node || !actorSpriteManager) return; Actor *actor = actorSpriteManager->findBeing(actorId); diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 1efa9c22d..7e4f02426 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -230,7 +230,7 @@ void WhoIsOnline::updateWindow(std::vector &friends, if (addedFromSection == true && !disregard.empty()) { mBrowserBox->addRow("---"); - addedFromSection = false; +// addedFromSection = false; } for (int i = 0; i < static_cast(disregard.size()); i++) { diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 5856a91b1..49b73a76a 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -655,7 +655,7 @@ std::string BrowserBox::getTextAtPos(const int x, const int y) return ""; // mouse position ourside of correct widget (outside of tab) textX = x - textX; - textY = y - textY; +// textY = y - textY; std::string str = ""; diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index a4bc3bc09..575036612 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -116,14 +116,14 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) mMinWidth = minWidth; wrappedStream.clear(); wrappedStream.str(""); - spacePos = 0; +// spacePos = 0; lastNewlinePos = 0; newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) newlinePos = text.size(); line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); - width = 0; +// width = 0; break; } else diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0576c8ddb..4675f80cf 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -3168,15 +3168,11 @@ void LocalPlayer::specialMove(unsigned char direction) && getInvertDirection() <= 4) && !mIsServerBuggy) { - int max; - if (getInvertDirection() == 2) - max = 10; - else - max = 30; - if (mAction == MOVE) return; + int max; + if (getInvertDirection() == 2) max = 5; else if (getInvertDirection() == 4) diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 6800c5170..eec5916c4 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -309,7 +309,7 @@ void Dye::instantiate(std::string &target, const std::string &palettes) { s << palettes.substr(pal_pos); s << target.substr(next_pos); - pal_pos = std::string::npos; + //pal_pos = std::string::npos; break; } s << palettes.substr(pal_pos, pal_next_pos - pal_pos); diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 0ac11f114..1e2bd6b51 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -885,10 +885,20 @@ SubImage::SubImage(Image *parent, SDL_Surface *image, mBounds.y = static_cast(y); mBounds.w = static_cast(width); mBounds.h = static_cast(height); - mInternalBounds.x = mParent->mBounds.x; - mInternalBounds.y = mParent->mBounds.y; - mInternalBounds.w = mParent->mBounds.w; - mInternalBounds.h = mParent->mBounds.h; + if (mParent) + { + mInternalBounds.x = mParent->mBounds.x; + mInternalBounds.y = mParent->mBounds.y; + mInternalBounds.w = mParent->mBounds.w; + mInternalBounds.h = mParent->mBounds.h; + } + else + { + mInternalBounds.x = 0; + mInternalBounds.y = 0; + mInternalBounds.w = 1; + mInternalBounds.h = 1; + } mUseAlphaCache = false; } diff --git a/src/resources/specialdb.cpp b/src/resources/specialdb.cpp index 664d2c73d..50ea773bc 100644 --- a/src/resources/specialdb.cpp +++ b/src/resources/specialdb.cpp @@ -129,5 +129,4 @@ SpecialInfo *SpecialDB::get(int id) return nullptr; else return i->second; - return nullptr; } diff --git a/src/utils/process.cpp b/src/utils/process.cpp index 4a2081514..fd0ec0fa8 100644 --- a/src/utils/process.cpp +++ b/src/utils/process.cpp @@ -130,7 +130,7 @@ int execFile(std::string pathName, std::string name, } else if (!sleep_pid) { // sleep pid - sleep (timeOut); + sleep (waitTime); // printf ("time out\n"); exit(-1); } -- cgit v1.2.3-60-g2f50 From df434dec8da2ec25b0ce19445cc80885ad85e0f3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 18 Feb 2012 03:18:11 +0300 Subject: Fix compilation for windows. --- src/utils/stringutils.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/utils') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 2be1e5b77..2f478a909 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -28,6 +28,8 @@ #include #include +#include + #include "debug.h" static int UTF8_MAX_SIZE = 10; -- cgit v1.2.3-60-g2f50