diff options
47 files changed, 60 insertions, 138 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd96abf6..65ba4d98 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -305,8 +305,6 @@ SET(SRCS utils/sha256.h utils/stringutils.cpp utils/stringutils.h - utils/strprintf.cpp - utils/strprintf.h utils/mutex.h utils/xml.cpp utils/xml.h diff --git a/src/Makefile.am b/src/Makefile.am index aa6753f7..21766f34 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -258,8 +258,6 @@ tmw_SOURCES = gui/widgets/avatar.cpp \ utils/sha256.h \ utils/stringutils.cpp \ utils/stringutils.h \ - utils/strprintf.cpp \ - utils/strprintf.h \ utils/mutex.h \ utils/xml.cpp \ utils/xml.h \ diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 616529d5..d834e0a3 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -37,7 +37,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/strprintf.h" CommandHandler::CommandHandler() {} diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 0f622aca..5b393a06 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -40,7 +40,7 @@ #include "resources/iteminfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" BuyDialog::BuyDialog(): Window(_("Buy")), diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index 798c172e..b6473612 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -33,7 +33,7 @@ #include "gui/widgets/textfield.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include <string> #include <sstream> diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 42854896..39d992b2 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -34,7 +34,7 @@ #include "gui/widgets/label.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include <string> #include <sstream> diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 8513d573..79ec5c1a 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -46,7 +46,6 @@ #include "resources/colordb.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" #include <guichan/font.hpp> diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index afc349ea..ba69a9b3 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -56,7 +56,6 @@ #include "resources/colordb.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" #include <guichan/font.hpp> diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index f7acda04..81c2abd8 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -40,7 +40,6 @@ #include "utils/dtor.h" #include "utils/stringutils.h" -#include "utils/strprintf.h" #include <guichan/focushandler.hpp> #include <guichan/focuslistener.hpp> diff --git a/src/gui/gui.h b/src/gui/gui.h index d3fb3b60..e4e83468 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -19,12 +19,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef GUI -#define GUI +#ifndef GUI_H +#define GUI_H #include <guichan/gui.hpp> -#include "../guichanfwd.h" +#include "guichanfwd.h" class Graphics; class GuiConfigListener; @@ -130,4 +130,4 @@ extern SDLInput *guiInput; /**< GUI input */ */ extern gcn::Font *boldFont; -#endif +#endif // GUI_H diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 2b397ed7..fa28bc34 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -40,7 +40,7 @@ #include "resources/iteminfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include <guichan/font.hpp> #include <guichan/mouseinput.hpp> diff --git a/src/gui/itemamount.cpp b/src/gui/itemamount.cpp index 518eb761..b3089e34 100644 --- a/src/gui/itemamount.cpp +++ b/src/gui/itemamount.cpp @@ -35,7 +35,7 @@ #include "localplayer.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" ItemAmountWindow::ItemAmountWindow(Usage usage, Window *parent, Item *item, int maxRange): diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 96ac3d88..56f53908 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -38,14 +38,8 @@ class ProgressBar; class MiniStatusWindow : public Popup { public: - /** - * Constructor. - */ MiniStatusWindow(); - /** - * Draw this window. - */ void draw(gcn::Graphics *graphics); /** @@ -76,4 +70,3 @@ class MiniStatusWindow : public Popup }; #endif - diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 1fe231df..e62d9a31 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -35,7 +35,7 @@ #include "net/npchandler.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" NpcDialog::NpcDialog() : Window(_("NPC")), diff --git a/src/gui/partywindow.cpp b/src/gui/partywindow.cpp index 07f66a2f..b3c6c74c 100644 --- a/src/gui/partywindow.cpp +++ b/src/gui/partywindow.cpp @@ -28,7 +28,7 @@ #include "utils/dtor.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" PartyWindow::PartyWindow() : Window(_("Party")) { diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index c76a9065..b02e6f2a 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -43,7 +43,7 @@ #include "resources/iteminfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include <cassert> diff --git a/src/gui/register.cpp b/src/gui/register.cpp index dabf98fd..6dfc761d 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -38,7 +38,6 @@ #include "gui/widgets/textfield.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" void WrongDataNoticeListener::setTarget(gcn::TextField *textField) diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index f7762144..c9b9d649 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -40,7 +40,7 @@ #include "resources/iteminfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" SellDialog::SellDialog(): Window(_("Sell")), diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index d7a95120..44d4c91a 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -35,7 +35,7 @@ #include "utils/dtor.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include "utils/xml.h" static const char *SKILLS_FILE = _("skills.xml"); diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index b1665f59..f6eb0d58 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -31,7 +31,7 @@ #include "resources/resourcemanager.h" #include "utils/dtor.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include "utils/xml.h" #include <algorithm> diff --git a/src/gui/status.cpp b/src/gui/status.cpp index e91e6bd5..643f5330 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -36,7 +36,6 @@ #include "utils/gettext.h" #include "utils/mathutils.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" StatusWindow::StatusWindow(LocalPlayer *player): diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 2399efb4..b4e6e770 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -28,7 +28,6 @@ #include "localplayer.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" StatusWindow::StatusWindow(LocalPlayer *player): diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index aada0bb2..d779800b 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -43,7 +43,7 @@ #include "resources/iteminfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include <guichan/font.hpp> #include <guichan/mouseinput.hpp> diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 9e39645d..fa662d1a 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -42,7 +42,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/strprintf.h" #include <sstream> diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index c0959cc9..6775051e 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -35,7 +35,7 @@ #include "gui/widgets/textfield.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include <string> #include <sstream> diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index e96f7738..d55e5da8 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -38,7 +38,6 @@ #include "resources/itemdb.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" #include <guichan/widgets/tabbedarea.hpp> diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 57995ba1..ff3a23d1 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -278,7 +278,7 @@ void ScrollArea::drawRightButton(gcn::Graphics *graphics) void ScrollArea::drawVBar(gcn::Graphics *graphics) { - gcn::Rectangle dim = getVerticalBarDimension(); + const gcn::Rectangle dim = getVerticalBarDimension(); graphics->setColor(gcn::Color(0, 0, 0, 32)); graphics->fillRectangle(dim); graphics->setColor(gcn::Color(255, 255, 255)); @@ -286,7 +286,7 @@ void ScrollArea::drawVBar(gcn::Graphics *graphics) void ScrollArea::drawHBar(gcn::Graphics *graphics) { - gcn::Rectangle dim = getHorizontalBarDimension(); + const gcn::Rectangle dim = getHorizontalBarDimension(); graphics->setColor(gcn::Color(0, 0, 0, 32)); graphics->fillRectangle(dim); graphics->setColor(gcn::Color(255, 255, 255)); diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp index 5e005709..17ee3fc4 100644 --- a/src/gui/widgets/whispertab.cpp +++ b/src/gui/widgets/whispertab.cpp @@ -29,7 +29,7 @@ #include "net/net.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" WhisperTab::WhisperTab(const std::string &nick) : ChatTab(nick), diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h index a1a4b14c..0e2bf6b7 100644 --- a/src/gui/widgets/windowcontainer.h +++ b/src/gui/widgets/windowcontainer.h @@ -54,6 +54,6 @@ class WindowContainer : public Container Widgets mDeathList; }; -extern WindowContainer* windowContainer; +extern WindowContainer *windowContainer; #endif diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index e13af147..9c85af01 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -27,7 +27,7 @@ #include "gui/setup_keyboard.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" struct KeyData { diff --git a/src/main.cpp b/src/main.cpp index 9c8e2dca..31628dd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,7 +97,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/strprintf.h" #include <SDL_image.h> diff --git a/src/net/ea/adminhandler.cpp b/src/net/ea/adminhandler.cpp index c3f960c7..e1099a4d 100644 --- a/src/net/ea/adminhandler.cpp +++ b/src/net/ea/adminhandler.cpp @@ -36,7 +36,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/strprintf.h" #include <string> diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index db89e316..09eca6f9 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -36,7 +36,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/strprintf.h" #include <string> diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp index 0ba5c7f6..2c546472 100644 --- a/src/net/ea/gui/partytab.cpp +++ b/src/net/ea/gui/partytab.cpp @@ -31,7 +31,6 @@ #include "utils/dtor.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" PartyTab::PartyTab() : diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp index 4fdff023..6e707bf9 100644 --- a/src/net/ea/inventoryhandler.cpp +++ b/src/net/ea/inventoryhandler.cpp @@ -40,7 +40,6 @@ #include "resources/iteminfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" #include <SDL_types.h> diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp index d9093e16..40bfb364 100644 --- a/src/net/ea/loginhandler.cpp +++ b/src/net/ea/loginhandler.cpp @@ -32,7 +32,6 @@ #include "serverinfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" extern SERVER_INFO **server_info; diff --git a/src/net/ea/logouthandler.cpp b/src/net/ea/logouthandler.cpp index 19659a2f..4986fd4a 100644 --- a/src/net/ea/logouthandler.cpp +++ b/src/net/ea/logouthandler.cpp @@ -32,7 +32,6 @@ #include "serverinfo.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" Net::LogoutHandler *logoutHandler; diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index ced0e2c4..1a0a9e34 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -35,7 +35,7 @@ #include "net/ea/gui/partytab.h" #include "utils/gettext.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" PartyTab *partyTab = 0; Net::PartyHandler *partyHandler = 0; diff --git a/src/player.cpp b/src/player.cpp index d082719a..594b3680 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -35,7 +35,7 @@ #include "resources/itemdb.h" #include "resources/iteminfo.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" Player::Player(int id, int job, Map *map): Being(id, job, map), diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 807fa0a4..c698f597 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -28,7 +28,6 @@ #include "utils/dtor.h" #include "utils/gettext.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" #include "utils/xml.h" diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp index 5e9aa008..bc9728d0 100644 --- a/src/resources/wallpaper.cpp +++ b/src/resources/wallpaper.cpp @@ -23,7 +23,7 @@ #include "log.h" -#include "utils/strprintf.h" +#include "utils/stringutils.h" #include <algorithm> #include <cstring> diff --git a/src/units.cpp b/src/units.cpp index acdbd564..f865531a 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -23,7 +23,6 @@ #include "log.h" -#include "utils/strprintf.h" #include "utils/stringutils.h" #include "utils/xml.h" diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 57a0131e..c9428974 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -22,6 +22,8 @@ #include "utils/stringutils.h" #include <algorithm> +#include <cstdarg> +#include <cstdio> std::string &trim(std::string &str) { @@ -69,6 +71,28 @@ const char *ipToString(int address) return asciiIP; } +std::string strprintf(char const *format, ...) +{ + char buf[256]; + va_list(args); + va_start(args, format); + int nb = vsnprintf(buf, 256, format, args); + va_end(args); + if (nb < 256) + { + return buf; + } + // The static size was not big enough, try again with a dynamic allocation. + ++nb; + char *buf2 = new char[nb]; + va_start(args, format); + vsnprintf(buf2, nb, format, args); + va_end(args); + std::string res(buf2); + delete [] buf2; + return res; +} + std::string &removeBadChars(std::string &str) { std::string::size_type pos; diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 3af0bfa5..89d3d7e9 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -74,6 +74,17 @@ template<typename T> std::string toString(const T &arg) const char *ipToString(int address); /** + * A safe version of sprintf that returns a std::string of the result. + */ +std::string strprintf(char const *, ...) +#ifdef __GNUC__ + /* This attribute is nice: it even works through gettext invokation. For + example, gcc will complain that strprintf(_("%s"), 42) is ill-formed. */ + __attribute__((format(printf, 1, 2))) +#endif +; + +/** * Removes bad characters from a string * * @param str the string to remove the bad chars from diff --git a/src/utils/strprintf.cpp b/src/utils/strprintf.cpp deleted file mode 100644 index d960bc96..00000000 --- a/src/utils/strprintf.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2007 The Mana World Development Team - * - * This file is part of The Mana World. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "utils/strprintf.h" - -#include <cstdarg> -#include <cstdio> - -std::string strprintf(char const *format, ...) -{ - char buf[256]; - va_list(args); - va_start(args, format); - int nb = vsnprintf(buf, 256, format, args); - va_end(args); - if (nb < 256) - { - return buf; - } - // The static size was not big enough, try again with a dynamic allocation. - ++nb; - char *buf2 = new char[nb]; - va_start(args, format); - vsnprintf(buf2, nb, format, args); - va_end(args); - std::string res(buf2); - delete [] buf2; - return res; -} diff --git a/src/utils/strprintf.h b/src/utils/strprintf.h deleted file mode 100644 index 78e7a04c..00000000 --- a/src/utils/strprintf.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The Mana World - * Copyright (C) 2007 The Mana World Development Team - * - * This file is part of The Mana World. - * - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef UTILS_STRPRINTF_H -#define UTILS_STRPRINTF_H - -#include <string> - -std::string strprintf(char const *, ...) -#ifdef __GNUC__ - /* This attribute is nice: it even works through gettext invokation. For - example, gcc will complain that strprintf(_("%s"), 42) is ill-formed. */ - __attribute__((format(printf, 1, 2))) -#endif -; - -#endif @@ -1050,8 +1050,6 @@ </Unit> <Unit filename="src/utils/stringutils.cpp" /> <Unit filename="src/utils/stringutils.h" /> - <Unit filename="src/utils/strprintf.cpp" /> - <Unit filename="src/utils/strprintf.h" /> <Unit filename="src/utils/xml.cpp" /> <Unit filename="src/utils/xml.h" /> <Unit filename="src/vector.cpp" /> |