widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #02591
[Merge] lp:~widelands-dev/widelands/boost_format into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/boost_format into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/boost_format/+merge/229366
Replaced most instances of snprintf with boost::format or std::to_string.
Fixed a bug in txts/README.lua
--
https://code.launchpad.net/~widelands-dev/widelands/boost_format/+merge/229366
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/boost_format into lp:widelands.
=== modified file 'src/editor/tools/editor_info_tool.cc'
--- src/editor/tools/editor_info_tool.cc 2014-07-14 10:45:44 +0000
+++ src/editor/tools/editor_info_tool.cc 2014-08-03 18:56:48 +0000
@@ -78,10 +78,9 @@
buf += std::string("• ") + (boost::format(_("Caps:%s")) % temp).str() + "\n";
if (f.get_owned_by() > 0) {
- buf += std::string("• ");
- char buf1[1024];
- snprintf(buf1, sizeof(buf1), _("Owned by: %u"), f.get_owned_by());
- buf += std::string(buf1) + "\n";
+ buf += std::string("• ") +
+ (boost::format(_("Owned by: Player %u"))
+ % static_cast<unsigned int>(f.get_owned_by())).str() + "\n";
} else {
buf += std::string("• ") + _("Owned by: —") + "\n";
}
=== modified file 'src/editor/ui_menus/editor_main_menu_load_map.cc'
--- src/editor/ui_menus/editor_main_menu_load_map.cc 2014-07-20 07:43:07 +0000
+++ src/editor/ui_menus/editor_main_menu_load_map.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,7 @@
#include <cstdio>
#include <memory>
+#include <string>
#include <boost/format.hpp>
@@ -169,12 +170,11 @@
m_descr ->set_text
(_(map.get_description()) + (map.get_hint().empty() ? "" : (std::string("\n") + _(map.get_hint()))));
- char buf[200];
- sprintf(buf, "%i", map.get_nrplayers());
- m_nrplayers->set_text(buf);
+ m_nrplayers->set_text(std::to_string(static_cast<unsigned int>(map.get_nrplayers())));
- sprintf(buf, "%ix%i", map.get_width(), map.get_height());
- m_size ->set_text(buf);
+ m_size ->set_text((boost::format(_("%1$ix%2$i"))
+ % static_cast<int>(map.get_width())
+ % static_cast<int>(map.get_height())).str().c_str());
} else {
m_name ->set_text("");
m_author ->set_text("");
=== modified file 'src/editor/ui_menus/editor_main_menu_map_options.cc'
--- src/editor/ui_menus/editor_main_menu_map_options.cc 2014-07-14 10:45:44 +0000
+++ src/editor/ui_menus/editor_main_menu_map_options.cc 2014-08-03 18:56:48 +0000
@@ -20,6 +20,9 @@
#include "editor/ui_menus/editor_main_menu_map_options.h"
#include <cstdio>
+#include <string>
+
+#include <boost/format.hpp>
#include "base/i18n.h"
#include "editor/editorinteractive.h"
@@ -113,13 +116,12 @@
void Main_Menu_Map_Options::update() {
const Widelands::Map & map = eia().egbase().map();
- char buf[200];
- sprintf(buf, "%ix%i", map.get_width(), map.get_height());
- m_size->set_text(buf);
+ m_size ->set_text((boost::format(_("%1$ix%2$i"))
+ % static_cast<int>(map.get_width())
+ % static_cast<int>(map.get_height())).str().c_str());
m_author->setText(map.get_author());
m_name ->setText(map.get_name());
- sprintf(buf, "%i", map.get_nrplayers());
- m_nrplayers->set_text(buf);
+ m_nrplayers->set_text(std::to_string(static_cast<unsigned int>(map.get_nrplayers())));
m_descr ->set_text(map.get_description());
}
=== modified file 'src/editor/ui_menus/editor_main_menu_new_map.cc'
--- src/editor/ui_menus/editor_main_menu_new_map.cc 2014-06-18 13:20:33 +0000
+++ src/editor/ui_menus/editor_main_menu_new_map.cc 2014-08-03 18:56:48 +0000
@@ -24,6 +24,8 @@
#include <string>
#include <vector>
+#include <boost/format.hpp>
+
#include "base/i18n.h"
#include "editor/editorinteractive.h"
#include "graphic/graphic.h"
@@ -45,7 +47,6 @@
(parent.get_w() - 140) / 2, (parent.get_h() - 150) / 2, 140, 150,
_("New Map"))
{
- char buffer[250];
int32_t const offsx = 5;
int32_t const offsy = 30;
int32_t const spacing = 5;
@@ -59,9 +60,10 @@
for (m_w = 0; Widelands::MAP_DIMENSIONS[m_w] < map_extent.w; ++m_w) {}
for (m_h = 0; Widelands::MAP_DIMENSIONS[m_h] < map_extent.h; ++m_h) {}
}
- snprintf
- (buffer, sizeof(buffer), _("Width: %u"), Widelands::MAP_DIMENSIONS[m_w]);
- m_width = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+
+ m_width = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Width: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_w])).str().c_str());
UI::Button * widthupbtn = new UI::Button
(this, "width_up",
@@ -79,10 +81,9 @@
posy += 20 + spacing + spacing;
- snprintf
- (buffer, sizeof(buffer),
- _("Height: %u"), Widelands::MAP_DIMENSIONS[m_h]);
- m_height = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ m_height = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Height: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_h])).str().c_str());
UI::Button * heightupbtn = new UI::Button
(this, "height_up",
@@ -124,19 +125,14 @@
assert(false);
}
- char buffer[200];
if (m_w < 0) m_w = 0;
if (m_w >= NUMBER_OF_MAP_DIMENSIONS) m_w = NUMBER_OF_MAP_DIMENSIONS - 1;
if (m_h < 0) m_h = 0;
if (m_h >= NUMBER_OF_MAP_DIMENSIONS) m_h = NUMBER_OF_MAP_DIMENSIONS - 1;
- snprintf
- (buffer, sizeof(buffer),
- _("Width: %u"), Widelands::MAP_DIMENSIONS[m_w]);
- m_width ->set_text(buffer);
- snprintf
- (buffer, sizeof(buffer),
- _("Height: %u"), Widelands::MAP_DIMENSIONS[m_h]);
- m_height->set_text(buffer);
+ m_width ->set_text((boost::format(_("Width: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_w])).str());
+ m_height->set_text((boost::format(_("Height: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_h])).str());
}
void Main_Menu_New_Map::clicked_create_map() {
=== modified file 'src/editor/ui_menus/editor_main_menu_random_map.cc'
--- src/editor/ui_menus/editor_main_menu_random_map.cc 2014-07-05 14:22:44 +0000
+++ src/editor/ui_menus/editor_main_menu_random_map.cc 2014-08-03 18:56:48 +0000
@@ -24,6 +24,8 @@
#include <string>
#include <vector>
+#include <boost/format.hpp>
+
#include "base/i18n.h"
#include "editor/editorinteractive.h"
#include "editor/map_generator.h"
@@ -58,7 +60,6 @@
{"blackland", _("Black")},
}),
m_current_world(0) {
- char buffer[250];
int32_t const offsx = 5;
int32_t const offsy = 5;
int32_t const spacing = 5;
@@ -88,9 +89,7 @@
rng.seed(clock());
rng.rand();
m_mapNumber = rng.rand();
- snprintf
- (buffer, sizeof(buffer), "%u", static_cast<unsigned int>(m_mapNumber));
- m_nrEditbox->setText(buffer);
+ m_nrEditbox->setText(std::to_string(static_cast<unsigned int>(m_mapNumber)));
posy += height + spacing + spacing + spacing;
@@ -121,19 +120,18 @@
widthdownbtn->sigclicked.connect
(boost::bind(&Main_Menu_New_Random_Map::button_clicked, this, MAP_W_MINUS));
- snprintf
- (buffer, sizeof(buffer), _("Width: %u"), Widelands::MAP_DIMENSIONS[m_w]);
m_width =
- new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Width: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_w])).str().c_str());
posy += 20 + spacing + spacing;
// ---------- Height ----------
- snprintf
- (buffer, sizeof(buffer),
- _("Height: %u"), Widelands::MAP_DIMENSIONS[m_h]);
- m_height = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ m_height = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Height: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_h])).str().c_str());
UI::Button * heightupbtn = new UI::Button
(this, "height_up",
@@ -172,8 +170,9 @@
waterdownbtn->sigclicked.connect
(boost::bind(&Main_Menu_New_Random_Map::button_clicked, this, WATER_MINUS));
- snprintf(buffer, sizeof(buffer), _("Water: %u %%"), m_waterval);
- m_water = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ m_water = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Water: %i %%"))
+ % static_cast<int>(m_waterval)).str().c_str());
posy += 20 + spacing + spacing;
@@ -197,9 +196,9 @@
landdownbtn->sigclicked.connect
(boost::bind(&Main_Menu_New_Random_Map::button_clicked, this, LAND_MINUS));
- snprintf
- (buffer, sizeof(buffer), _("Land: %u %%"), m_landval);
- m_land = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ m_land = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Land: %i %%"))
+ % static_cast<int>(m_landval)).str().c_str());
posy += 20 + spacing + spacing;
@@ -223,9 +222,9 @@
wastelanddownbtn->sigclicked.connect
(boost::bind(&Main_Menu_New_Random_Map::button_clicked, this, WASTE_MINUS));
- snprintf
- (buffer, sizeof(buffer), _("Wasteland: %u %%"), m_wastelandval);
- m_wasteland = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ m_wasteland = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Wasteland: %i %%"))
+ % static_cast<int>(m_wastelandval)).str().c_str());
posy += 20 + spacing + spacing;
@@ -233,10 +232,9 @@
// ---------- Mountains -----------
- snprintf
- (buffer, sizeof(buffer), _("Mountains: %u %%"),
- 100 - m_waterval - m_landval);
- m_mountains = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ m_mountains = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Mountains: %i %%"))
+ % static_cast<int>(100 - m_waterval - m_landval)).str().c_str());
posy += 20 + spacing + spacing;
@@ -322,8 +320,9 @@
playerdownbtn->sigclicked.connect
(boost::bind(&Main_Menu_New_Random_Map::button_clicked, this, PLAYER_MINUS));
- snprintf(buffer, sizeof(buffer), _("Players: %u"), m_pn);
- m_players = new UI::Textarea(this, posx + spacing + 20, posy, buffer);
+ m_players = new UI::Textarea(this, posx + spacing + 20, posy,
+ (boost::format(_("Players: %u"))
+ % static_cast<unsigned int>(m_pn)).str().c_str());
posy += 20 + spacing + spacing;
@@ -417,35 +416,31 @@
assert(false);
}
- char buffer[200];
if (m_w < 0) m_w = 0;
if (m_w >= NUMBER_OF_MAP_DIMENSIONS) m_w = NUMBER_OF_MAP_DIMENSIONS - 1;
if (m_h < 0) m_h = 0;
if (m_h >= NUMBER_OF_MAP_DIMENSIONS) m_h = NUMBER_OF_MAP_DIMENSIONS - 1;
- snprintf
- (buffer, sizeof(buffer),
- _("Width: %u"), Widelands::MAP_DIMENSIONS[m_w]);
- m_width ->set_text(buffer);
- snprintf
- (buffer, sizeof(buffer),
- _("Height: %u"), Widelands::MAP_DIMENSIONS[m_h]);
- m_height->set_text(buffer);
-
- snprintf
- (buffer, sizeof(buffer), _("Water: %u %%"), m_waterval);
- m_water->set_text(buffer);
- snprintf
- (buffer, sizeof(buffer), _("Land: %u %%"), m_landval);
- m_land->set_text(buffer);
- snprintf
- (buffer, sizeof(buffer), _("Wasteland: %u %%"), m_wastelandval);
- m_wasteland->set_text(buffer);
- snprintf
- (buffer, sizeof(buffer), _("Mountains: %u %%"),
- 100 - m_waterval - m_landval);
- m_mountains->set_text(buffer);
- snprintf(buffer, sizeof(buffer), _("Players: %u"), m_pn);
- m_players->set_text(buffer);
+
+ m_width ->set_text((boost::format(_("Width: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_w])).str().c_str());
+
+ m_height->set_text((boost::format(_("Height: %u"))
+ % static_cast<unsigned int>(Widelands::MAP_DIMENSIONS[m_h])).str().c_str());
+
+ m_water->set_text((boost::format(_("Water: %i %%"))
+ % static_cast<int>(m_waterval)).str().c_str());
+
+ m_land->set_text((boost::format(_("Land: %i %%"))
+ % static_cast<int>(m_landval)).str().c_str());
+
+ m_wasteland->set_text((boost::format(_("Wasteland: %i %%"))
+ % static_cast<int>(m_wastelandval)).str().c_str());
+
+ m_mountains->set_text((boost::format(_("Mountains: %i %%"))
+ % static_cast<int>(100 - m_waterval - m_landval)).str().c_str());
+
+ m_players->set_text((boost::format(_("Players: %u"))
+ % static_cast<unsigned int>(m_pn)).str().c_str());
nr_edit_box_changed(); // Update ID String
}
=== modified file 'src/editor/ui_menus/editor_main_menu_save_map.cc'
--- src/editor/ui_menus/editor_main_menu_save_map.cc 2014-07-20 07:43:07 +0000
+++ src/editor/ui_menus/editor_main_menu_save_map.cc 2014-08-03 18:56:48 +0000
@@ -230,12 +230,11 @@
m_author->set_text(map.get_author ());
m_descr ->set_text(map.get_description());
- char buf[200];
- sprintf(buf, "%i", map.get_nrplayers());
- m_nrplayers->set_text(buf);
+ m_nrplayers->set_text(std::to_string(static_cast<unsigned int>(map.get_nrplayers())));
- sprintf(buf, "%ix%i", map.get_width(), map.get_height());
- m_size->set_text(buf);
+ m_size->set_text((boost::format(_("%1$ix%2$i"))
+ % static_cast<int>(map.get_width())
+ % static_cast<int>(map.get_height())).str().c_str());
} else {
m_name ->set_text(FileSystem::FS_Filename(name));
m_author ->set_text("");
=== modified file 'src/editor/ui_menus/editor_tool_change_height_options_menu.cc'
--- src/editor/ui_menus/editor_tool_change_height_options_menu.cc 2014-07-26 16:37:37 +0000
+++ src/editor/ui_menus/editor_tool_change_height_options_menu.cc 2014-08-03 18:56:48 +0000
@@ -20,6 +20,7 @@
#include "editor/ui_menus/editor_tool_change_height_options_menu.h"
#include <cstdio>
+#include <string>
#include "base/i18n.h"
#include "editor/editorinteractive.h"
@@ -190,9 +191,8 @@
/// Update all the textareas, so that they represent the correct values.
void Editor_Tool_Change_Height_Options_Menu::update() {
- char buf[250];
- sprintf(buf, "%i", m_increase_tool.get_change_by());
- m_change_by_value.set_text(buf);
- sprintf(buf, "%i", m_increase_tool.set_tool().get_interval().min);
- m_set_to_value.set_text(buf);
+ m_change_by_value.set_text(std::to_string(m_increase_tool.get_change_by()));
+
+ m_set_to_value.set_text(std::to_string(
+ static_cast<unsigned int>(m_increase_tool.set_tool().get_interval().min)));
}
=== modified file 'src/editor/ui_menus/editor_tool_change_resources_options_menu.cc'
--- src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2014-07-14 10:45:44 +0000
+++ src/editor/ui_menus/editor_tool_change_resources_options_menu.cc 2014-08-03 18:56:48 +0000
@@ -20,6 +20,7 @@
#include "editor/ui_menus/editor_tool_change_resources_options_menu.h"
#include <cstdio>
+#include <string>
#include "base/i18n.h"
#include "editor/editorinteractive.h"
@@ -226,11 +227,11 @@
* Update all the textareas, so that they represent the correct values
*/
void Editor_Tool_Change_Resources_Options_Menu::update() {
- char buf[250];
- sprintf(buf, "%i", m_increase_tool.get_change_by());
- m_change_by_value.set_text(buf);
- sprintf(buf, "%i", m_increase_tool.set_tool().get_set_to());
- m_set_to_value.set_text(buf);
+
+ m_change_by_value.set_text(std::to_string(m_increase_tool.get_change_by()));
+
+ m_set_to_value.set_text(std::to_string(
+ static_cast<unsigned int>(m_increase_tool.set_tool().get_set_to())));
m_cur_selection.set_text
(ref_cast<Editor_Interactive, UI::Panel>(*get_parent()).egbase()
=== modified file 'src/editor/ui_menus/editor_tool_noise_height_options_menu.cc'
--- src/editor/ui_menus/editor_tool_noise_height_options_menu.cc 2014-07-26 16:37:37 +0000
+++ src/editor/ui_menus/editor_tool_noise_height_options_menu.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,8 @@
#include <cstdio>
+#include <boost/format.hpp>
+
#include "base/i18n.h"
#include "editor/editorinteractive.h"
#include "editor/tools/editor_decrease_height_tool.h"
@@ -141,17 +143,16 @@
* Update all textareas
*/
void Editor_Tool_Noise_Height_Options_Menu::update() {
- char buffer[200];
const Widelands::HeightInterval height_interval = m_noise_tool.get_interval();
- snprintf(buffer, sizeof(buffer), _("Minimum: %u"), height_interval.min);
- m_lower_label.set_text(buffer);
- snprintf(buffer, sizeof(buffer), _("Maximum: %u"), height_interval.max);
- m_upper_label.set_text(buffer);
-
- snprintf
- (buffer, sizeof(buffer),
- _("Set value: %u"), m_noise_tool.set_tool().get_interval().min);
- m_set_label.set_text(buffer);
+
+ m_lower_label.set_text((boost::format(_("Minimum: %u"))
+ % static_cast<unsigned int>(height_interval.min)).str());
+
+ m_upper_label.set_text((boost::format(_("Maximum: %u"))
+ % static_cast<unsigned int>(height_interval.max)).str());
+
+ m_set_label.set_text((boost::format(_("Set value: %u"))
+ % static_cast<unsigned int>(m_noise_tool.set_tool().get_interval().min)).str());
select_correct_tool();
}
=== modified file 'src/editor/ui_menus/editor_toolsize_menu.cc'
--- src/editor/ui_menus/editor_toolsize_menu.cc 2014-07-14 10:45:44 +0000
+++ src/editor/ui_menus/editor_toolsize_menu.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,8 @@
#include <cstdio>
+#include <boost/format.hpp>
+
#include "base/i18n.h"
#include "editor/editorinteractive.h"
#include "editor/tools/editor_tool.h"
@@ -71,9 +73,8 @@
eia().set_sel_radius(val);
m_decrease.set_enabled(0 < val);
m_increase.set_enabled (val < MAX_TOOL_AREA);
- char buffer[250];
- snprintf(buffer, sizeof(buffer), _("Current Size: %u"), val + 1);
- m_textarea.set_text(buffer);
+ m_textarea.set_text((boost::format(_("Current Size: %u"))
+ % static_cast<unsigned int>(val + 1)).str());
}
=== modified file 'src/io/dedicated_log.cc'
--- src/io/dedicated_log.cc 2014-06-08 21:47:45 +0000
+++ src/io/dedicated_log.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "io/dedicated_log.h"
+#include <string>
+
#include <boost/format.hpp>
#include "base/i18n.h"
@@ -165,13 +167,13 @@
temp += "<tr><td class=\"infoname\">Server MOTD</td><td class=\"info\">" + d_motd + "</td></tr>\n";
temp += "<tr><td class=\"infoname\">Started on</td><td class=\"info\">" + d_start + "</td></tr>\n";
temp += "<tr><td class=\"infoname\">Logins</td><td class=\"info\">";
- temp += (boost::format("%u") % d_logins).str() + "</td></tr>\n";
+ temp += std::to_string(d_logins) + "</td></tr>\n";
temp += "<tr><td class=\"infoname\">Logouts</td><td class=\"info\">";
- temp += (boost::format("%u") % d_logouts).str() + "</td></tr>\n";
+ temp += std::to_string(d_logouts) + "</td></tr>\n";
temp += "<tr><td class=\"infoname\">Chat messages</td><td class=\"info\">";
- temp += (boost::format("%u") % d_chatmessages).str() + "</td></tr>\n";
+ temp += std::to_string(d_chatmessages) + "</td></tr>\n";
temp += "<tr><td class=\"infoname\">Games started</td><td class=\"info\">";
- temp += (boost::format("%u") % d_games.size()).str() + "</td></tr>\n";
+ temp += std::to_string(d_games.size()) + "</td></tr>\n";
if (!d_games.empty()) {
// Games information
temp += "</table><br><table class=\"infogames\">\n";
=== modified file 'src/io/filesystem/zip_filesystem.cc'
--- src/io/filesystem/zip_filesystem.cc 2014-07-26 10:43:23 +0000
+++ src/io/filesystem/zip_filesystem.cc 2014-08-03 18:56:48 +0000
@@ -27,6 +27,8 @@
#include <cstring>
#include <string>
+#include <boost/format.hpp>
+
#include "base/wexception.h"
#include "io/filesystem/filesystem_exceptions.h"
#include "io/filesystem/zip_exceptions.h"
@@ -327,13 +329,11 @@
break;
if (len < 0) {
unzCloseCurrentFile(m_unzipfile);
- char buf[200];
- snprintf(buf, sizeof(buf), "read error %i", len);
throw ZipOperation_error
("ZipFilesystem::Load",
fname,
m_zipfilename,
- buf);
+ (boost::format("read error %i") % len).str().c_str());
}
totallen += len;
=== modified file 'src/logic/critter.cc'
--- src/logic/critter.cc 2014-07-28 17:12:07 +0000
+++ src/logic/critter.cc 2014-08-03 18:56:48 +0000
@@ -21,7 +21,9 @@
#include <cstdio>
#include <memory>
+#include <string>
+#include <boost/format.hpp>
#include <stdint.h>
#include "base/wexception.h"
@@ -48,9 +50,7 @@
std::vector<std::string> section_to_strings(Section* section) {
std::vector<std::string> return_value;
for (uint32_t idx = 0;; ++idx) {
- char buffer[32];
- snprintf(buffer, sizeof(buffer), "%i", idx);
- char const* const string = section->get_string(buffer, nullptr);
+ char const* const string = section->get_string(std::to_string(idx).c_str(), nullptr);
if (!string)
break;
return_value.emplace_back(string);
@@ -154,8 +154,7 @@
add_attributes(attributes, std::set<uint32_t>());
}
- char defaultpics[256];
- snprintf(defaultpics, sizeof(defaultpics), "%s_walk_!!_??.png", _name);
+ const std::string defaultpics = (boost::format("%s_walk_!!_??.png") % _name).str().c_str();
m_walk_anims.parse(*this, directory, prof, "walk", false, defaultpics);
while (Section::Value const * const v = global_s.get_next_val("program")) {
=== modified file 'src/logic/militarysite.cc'
--- src/logic/militarysite.cc 2014-08-02 10:14:12 +0000
+++ src/logic/militarysite.cc 2014-08-03 18:56:48 +0000
@@ -137,12 +137,12 @@
/** TRANSLATORS: %3% is the maximum number of soldier slots in the building */
*s =
(boost::format(ngettext("%1%(+%2%) soldier (+%3%)", "%1%(+%2%) soldiers (+%3%)", stationed))
- % stationed % present % (stationed - present) % (m_capacity - stationed)).str();
+ % present % (stationed - present) % (m_capacity - stationed)).str();
} else {
/** TRANSLATORS: %1% is the number of soldiers the plural refers to */
/** TRANSLATORS: %2% are currently open soldier slots in the building */
*s += (boost::format(ngettext("%1%(+%2%) soldier", "%1%(+%2%) soldiers", stationed))
- % stationed % present).str();
+ % present % (stationed - present)).str();
}
}
}
=== modified file 'src/logic/single_player_game_settings_provider.cc'
--- src/logic/single_player_game_settings_provider.cc 2014-07-20 07:45:17 +0000
+++ src/logic/single_player_game_settings_provider.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "logic/single_player_game_settings_provider.h"
+#include <boost/format.hpp>
+
#include "ai/computer_player.h"
#include "logic/tribe.h"
@@ -82,9 +84,8 @@
player.tribe = s.tribes.at(0).name;
player.random_tribe = false;
player.initialization_index = 0;
- char buf[200];
- snprintf(buf, sizeof(buf), "%s %u", _("Player"), oldplayers + 1);
- player.name = buf;
+ player.name = (boost::format(_("Player %u"))
+ % static_cast<unsigned int>(oldplayers + 1)).str();
player.team = 0;
// Set default computerplayer ai type
if (player.state == PlayerSettings::stateComputer) {
=== modified file 'src/logic/soldier.cc'
--- src/logic/soldier.cc 2014-07-28 16:59:54 +0000
+++ src/logic/soldier.cc 2014-08-03 18:56:48 +0000
@@ -22,6 +22,8 @@
#include <cstdio>
#include <list>
+#include <boost/format.hpp>
+
#include "base/macros.h"
#include "base/wexception.h"
#include "economy/economy.h"
@@ -129,28 +131,29 @@
m_attack_pics_fn .resize(m_max_attack_level + 1);
m_defense_pics_fn.resize(m_max_defense_level + 1);
m_evade_pics_fn .resize(m_max_evade_level + 1);
- char buffer[256];
+
std::string dir = directory;
dir += "/";
for (uint32_t i = 0; i <= m_max_hp_level; ++i) {
- snprintf(buffer, sizeof(buffer), "hp_level_%u_pic", i);
m_hp_pics_fn[i] = dir;
- m_hp_pics_fn[i] += global_s.get_safe_string(buffer);
+ m_hp_pics_fn[i] += global_s.get_safe_string((boost::format("hp_level_%u_pic")
+ % static_cast<unsigned int>(i)).str().c_str());
+
}
for (uint32_t i = 0; i <= m_max_attack_level; ++i) {
- snprintf(buffer, sizeof(buffer), "attack_level_%u_pic", i);
m_attack_pics_fn[i] = dir;
- m_attack_pics_fn[i] += global_s.get_safe_string(buffer);
+ m_attack_pics_fn[i] += global_s.get_safe_string((boost::format("attack_level_%u_pic")
+ % static_cast<unsigned int>(i)).str().c_str());
}
for (uint32_t i = 0; i <= m_max_defense_level; ++i) {
- snprintf(buffer, sizeof(buffer), "defense_level_%u_pic", i);
m_defense_pics_fn[i] = dir;
- m_defense_pics_fn[i] += global_s.get_safe_string(buffer);
+ m_defense_pics_fn[i] += global_s.get_safe_string((boost::format("defense_level_%u_pic")
+ % static_cast<unsigned int>(i)).str().c_str());
}
for (uint32_t i = 0; i <= m_max_evade_level; ++i) {
- snprintf(buffer, sizeof(buffer), "evade_level_%i_pic", i);
m_evade_pics_fn[i] = dir;
- m_evade_pics_fn[i] += global_s.get_safe_string(buffer);
+ m_evade_pics_fn[i] += global_s.get_safe_string((boost::format("evade_level_%u_pic")
+ % static_cast<unsigned int>(i)).str().c_str());
}
{ /// Battle animations
@@ -1546,34 +1549,34 @@
get_position().field->get_immovable();
BaseImmovable const * const immovable_dest =
map[dest] .get_immovable();
- char buffer[2048];
- snprintf
- (buffer, sizeof(buffer),
- "The game engine has encountered a logic error. The %s "
- "#%u of player %u could not find a way from (%i, %i) "
- "(with %s immovable) to the opponent (%s #%u of player "
- "%u) at (%i, %i) (with %s immovable). The %s will now "
- "desert (but will not be executed). Strange things may "
- "happen. No solution for this problem has been "
- "implemented yet. (bug #536066) (The game has been "
- "paused.)",
- descr().descname().c_str(), serial(), owner().player_number(),
- get_position().x, get_position().y,
- immovable_position ?
- immovable_position->descr().descname().c_str() : ("no"),
- opponent.descr().descname().c_str(), opponent.serial(),
- opponent.owner().player_number(),
- dest.x, dest.y,
- immovable_dest ?
- immovable_dest->descr().descname().c_str() : ("no"),
- descr().descname().c_str());
+
+ std::string messagetext =
+ (boost::format("The game engine has encountered a logic error. The %s "
+ "#%u of player %u could not find a way from (%i, %i) "
+ "(with %s immovable) to the opponent (%s #%u of player "
+ "%u) at (%i, %i) (with %s immovable). The %s will now "
+ "desert (but will not be executed). Strange things may "
+ "happen. No solution for this problem has been "
+ "implemented yet. (bug #536066) (The game has been "
+ "paused.)")
+ % descr().descname().c_str()
+ % static_cast<unsigned int>(serial())
+ % static_cast<unsigned int>(owner().player_number())
+ % static_cast<int>(get_position().x) % static_cast<int>(get_position().y)
+ % (immovable_position ? immovable_position->descr().descname().c_str() : ("no"))
+ % opponent.descr().descname().c_str()
+ % static_cast<unsigned int>(opponent.serial())
+ % static_cast<unsigned int>(opponent.owner().player_number())
+ % static_cast<int>(dest.x) % static_cast<int>(dest.y)
+ % (immovable_dest ? immovable_dest->descr().descname().c_str() : ("no"))
+ % descr().descname().c_str()).str();
owner().add_message
(game,
*new Message
("game engine",
game.get_gametime(), Forever(),
_("Logic error"),
- buffer,
+ messagetext,
get_position(),
m_serial));
opponent.owner().add_message
@@ -1582,7 +1585,7 @@
("game engine",
game.get_gametime(), Forever(),
_("Logic error"),
- buffer,
+ messagetext,
opponent.get_position(),
m_serial));
game.gameController()->setDesiredSpeed(0);
=== modified file 'src/logic/trainingsite.cc'
--- src/logic/trainingsite.cc 2014-07-30 08:42:52 +0000
+++ src/logic/trainingsite.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,8 @@
#include <cstdio>
+#include <boost/format.hpp>
+
#include "base/i18n.h"
#include "base/macros.h"
#include "economy/request.h"
@@ -655,9 +657,9 @@
upgrade.lastattempt = level;
upgrade.lastsuccess = false;
- char buf[200];
- sprintf(buf, "%s%d", upgrade.prefix.c_str(), level);
- return program_start(game, buf);
+ return program_start(game, (boost::format("%s%i")
+ % upgrade.prefix.c_str()
+ % static_cast<int>(level)).str().c_str());
}
TrainingSite::Upgrade * TrainingSite::get_upgrade(tAttribute const atr)
=== modified file 'src/logic/tribe.cc'
--- src/logic/tribe.cc 2014-07-28 18:03:51 +0000
+++ src/logic/tribe.cc 2014-08-03 18:56:48 +0000
@@ -23,6 +23,7 @@
#include <memory>
#include <boost/algorithm/string.hpp>
+#include <boost/format.hpp>
#include "base/i18n.h"
#include "base/macros.h"
@@ -400,13 +401,11 @@
return idx;
}
- char buffer[256];
-
int32_t i = 1;
int32_t num_indicators = 0;
for (;;) {
- snprintf(buffer, sizeof(buffer), "resi_%s%i", res->name().c_str(), i);
- if (get_immovable_index(buffer) == -1)
+ const std::string resi_filename = (boost::format("resi_%s%i") % res->name().c_str() % i).str();
+ if (get_immovable_index(resi_filename) == -1)
break;
++i;
++num_indicators;
@@ -432,15 +431,9 @@
if (static_cast<int32_t>(amount) < res->max_amount())
bestmatch += 1; // Resi start with 1, not 0
- snprintf
- (buffer, sizeof(buffer), "resi_%s%i", res->name().c_str(), bestmatch);
-
- // NoLog("Resource(%s): Indicator '%s' for amount = %u\n",
- //res->get_name(), buffer, amount);
-
-
-
- return get_immovable_index(buffer);
+ return get_immovable_index((boost::format("resi_%s%i")
+ % res->name().c_str()
+ % static_cast<int>(bestmatch)).str().c_str());
}
/*
=== modified file 'src/logic/warehouse.cc'
--- src/logic/warehouse.cc 2014-07-28 16:59:54 +0000
+++ src/logic/warehouse.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,8 @@
#include <algorithm>
+#include <boost/format.hpp>
+
#include "base/deprecated.h"
#include "base/log.h"
#include "base/macros.h"
@@ -451,16 +453,12 @@
(ref_cast<Game, Editor_Game_Base>(egbase), 4000);
log("Message: adding (wh) (%s) %i \n", to_string(descr().type()).c_str(), player.player_number());
- char message[2048];
- snprintf
- (message, sizeof(message),
- _("A new %s was added to your economy."),
- descr().descname().c_str());
send_message
(ref_cast<Game, Editor_Game_Base>(egbase),
"warehouse",
descr().descname(),
- message,
+ (boost::format(_("A new %s was added to your economy."))
+ % descr().descname().c_str()).str(),
true);
}
=== modified file 'src/logic/worker.cc'
--- src/logic/worker.cc 2014-08-01 12:57:17 +0000
+++ src/logic/worker.cc 2014-08-03 18:56:48 +0000
@@ -23,6 +23,8 @@
#include <memory>
#include <tuple>
+#include <boost/format.hpp>
+
#include "base/macros.h"
#include "base/wexception.h"
#include "economy/economy.h"
@@ -933,15 +935,13 @@
{
// Geologist also sends a message notifying the player
if (rdescr->detectable() && position.field->get_resources_amount()) {
- char message[1024];
// TODO(sirver): this is very wrong: It assumes a directory layout
// that might not be around forever.
- snprintf(message,
- sizeof(message),
- "<rt image=world/resources/pics/%s4.png>"
- "<p font-size=14 font-face=DejaVuSerif>%s</p></rt>",
- rdescr->name().c_str(),
- _("A geologist found resources."));
+ const std::string message =
+ (boost::format("<rt image=world/resources/pics/%s4.png>"
+ "<p font-size=14 font-face=DejaVuSerif>%s</p></rt>")
+ % rdescr->name().c_str()
+ % _("A geologist found resources.")).str().c_str();
// We should add a message to the player's message queue - but only,
// if there is not already a similar one in list.
@@ -1838,18 +1838,17 @@
descr().get_right_walk_anims(does_carry_ware())))
{
molog("[return]: Failed to return\n");
- char buffer[2048];
- snprintf
- (buffer, sizeof(buffer),
- _ ("Your %s can't find a way home and will likely die."),
- descr().descname().c_str());
+ const std::string message =
+ (boost::format(_("Your %s can't find a way home and will likely die."))
+ % descr().descname().c_str()).str().c_str();
+
owner().add_message
(game,
*new Message
("game engine",
game.get_gametime(), Forever(),
_("Worker got lost!"),
- buffer,
+ message,
get_position()),
m_serial);
set_location(nullptr);
=== modified file 'src/logic/worker_program.cc'
--- src/logic/worker_program.cc 2014-07-28 16:59:54 +0000
+++ src/logic/worker_program.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "logic/worker_program.h"
+#include <string>
+
#include "graphic/graphic.h"
#include "helper.h"
#include "logic/findnode.h"
@@ -65,10 +67,9 @@
for (uint32_t idx = 0;; ++idx) {
try
{
- char buf[32];
-
- snprintf(buf, sizeof(buf), "%i", idx);
- char const * const string = program_s.get_string(buf, nullptr);
+ char const * const string = program_s.get_string(
+ std::to_string(static_cast<unsigned int>(idx)).c_str(),
+ nullptr);
if (!string)
break;
=== modified file 'src/map_io/widelands_map_allowed_building_types_data_packet.cc'
--- src/map_io/widelands_map_allowed_building_types_data_packet.cc 2014-07-28 14:17:07 +0000
+++ src/map_io/widelands_map_allowed_building_types_data_packet.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "map_io/widelands_map_allowed_building_types_data_packet.h"
+#include <boost/format.hpp>
+
#include "base/macros.h"
#include "logic/game.h"
#include "logic/game_data_error.h"
@@ -68,10 +70,9 @@
(Building_Index i = tribe.get_nrbuildings();
0 < i;)
player->allow_building_type(--i, false);
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
try {
- Section & s = prof.get_safe_section(buffer);
+ Section & s = prof.get_safe_section((boost::format("player_%u")
+ % static_cast<unsigned int>(p)).str().c_str());
bool allowed;
while (const char * const name = s.get_next_bool(nullptr, &allowed)) {
@@ -107,9 +108,8 @@
Player_Number const nr_players = egbase.map().get_nrplayers();
iterate_players_existing_const(p, nr_players, egbase, player) {
const Tribe_Descr & tribe = player->tribe();
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
- Section & section = prof.create_section(buffer);
+ Section & section = prof.create_section((boost::format("player_%u")
+ % static_cast<unsigned int>(p)).str().c_str());
// Write for all buildings if it is enabled.
Building_Index const nr_buildings = tribe.get_nrbuildings();
=== modified file 'src/map_io/widelands_map_allowed_worker_types_data_packet.cc'
--- src/map_io/widelands_map_allowed_worker_types_data_packet.cc 2014-07-28 16:59:54 +0000
+++ src/map_io/widelands_map_allowed_worker_types_data_packet.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "map_io/widelands_map_allowed_worker_types_data_packet.h"
+#include <boost/format.hpp>
+
#include "base/macros.h"
#include "logic/game.h"
#include "logic/game_data_error.h"
@@ -55,10 +57,9 @@
if (packet_version == CURRENT_PACKET_VERSION) {
iterate_players_existing(p, egbase.map().get_nrplayers(), egbase, player) {
const Tribe_Descr & tribe = player->tribe();
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
try {
- Section* s = prof.get_section(buffer);
+ Section* s = prof.get_section((boost::format("player_%u")
+ % static_cast<unsigned int>(p)).str().c_str());
if (s == nullptr)
continue;
@@ -92,9 +93,8 @@
bool forbidden_worker_seen = false;
iterate_players_existing_const(p, egbase.map().get_nrplayers(), egbase, player) {
const Tribe_Descr & tribe = player->tribe();
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
- Section & section = prof.create_section(buffer);
+ Section & section = prof.create_section((boost::format("player_%u")
+ % static_cast<unsigned int>(p)).str().c_str());
// Only write the workers which are disabled.
for (Ware_Index b = 0; b < tribe.get_nrworkers(); ++b) {
=== modified file 'src/map_io/widelands_map_player_names_and_tribes_data_packet.cc'
--- src/map_io/widelands_map_player_names_and_tribes_data_packet.cc 2014-07-28 14:17:07 +0000
+++ src/map_io/widelands_map_player_names_and_tribes_data_packet.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "map_io/widelands_map_player_names_and_tribes_data_packet.h"
+#include <boost/format.hpp>
+
#include "logic/editor_game_base.h"
#include "logic/game_data_error.h"
#include "logic/map.h"
@@ -65,9 +67,8 @@
if (packet_version <= CURRENT_PACKET_VERSION) {
Player_Number const nr_players = map->get_nrplayers();
iterate_player_numbers(p, nr_players) {
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
- Section & s = prof.get_safe_section(buffer);
+ Section & s = prof.get_safe_section((boost::format("player_%u")
+ % static_cast<unsigned int>(p)).str().c_str());
map->set_scenario_player_name (p, s.get_string("name", ""));
map->set_scenario_player_tribe (p, s.get_string("tribe", ""));
map->set_scenario_player_ai (p, s.get_string("ai", ""));
@@ -93,9 +94,8 @@
const Map & map = egbase.map();
Player_Number const nr_players = map.get_nrplayers();
iterate_player_numbers(p, nr_players) {
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
- Section & s = prof.create_section(buffer);
+ Section & s = prof.create_section((boost::format("player_%u")
+ % static_cast<unsigned int>(p)).str().c_str());
s.set_string("name", map.get_scenario_player_name (p));
s.set_string("tribe", map.get_scenario_player_tribe (p));
s.set_string("ai", map.get_scenario_player_ai (p));
=== modified file 'src/map_io/widelands_map_player_position_data_packet.cc'
--- src/map_io/widelands_map_player_position_data_packet.cc 2014-07-28 14:17:07 +0000
+++ src/map_io/widelands_map_player_position_data_packet.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "map_io/widelands_map_player_position_data_packet.h"
+#include <boost/format.hpp>
+
#include "logic/editor_game_base.h"
#include "logic/game_data_error.h"
#include "logic/map.h"
@@ -48,9 +50,10 @@
Player_Number const nr_players = map.get_nrplayers();
iterate_player_numbers(p, nr_players) {
try {
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
- map.set_starting_pos(p, get_safe_coords(buffer, extent, &s));
+ map.set_starting_pos(p,
+ get_safe_coords((boost::format("player_%u")
+ % static_cast<unsigned int>(p)).str().c_str(),
+ extent, &s));
} catch (const _wexception & e) {
throw game_data_error("player %u: %s", p, e.what());
}
@@ -76,9 +79,8 @@
const Map & map = egbase.map();
const Player_Number nr_players = map.get_nrplayers();
iterate_player_numbers(p, nr_players) {
- char buffer[10];
- snprintf(buffer, sizeof(buffer), "player_%u", p);
- set_coords(buffer, map.get_starting_pos(p), &s);
+ set_coords((boost::format("player_%u") % static_cast<unsigned int>(p)).str().c_str(),
+ map.get_starting_pos(p), &s);
}
prof.write("player_position", false, fs);
=== modified file 'src/map_io/widelands_map_players_messages_data_packet.cc'
--- src/map_io/widelands_map_players_messages_data_packet.cc 2014-07-28 14:23:03 +0000
+++ src/map_io/widelands_map_players_messages_data_packet.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "map_io/widelands_map_players_messages_data_packet.h"
+#include <boost/format.hpp>
+
#include "logic/game_data_error.h"
#include "logic/player.h"
#include "map_io/coords_profile.h"
@@ -31,7 +33,6 @@
#define CURRENT_PACKET_VERSION 1
#define PLAYERDIRNAME_TEMPLATE "player/%u"
#define FILENAME_TEMPLATE PLAYERDIRNAME_TEMPLATE "/messages"
-#define FILENAME_SIZE 19
void Map_Players_Messages_Data_Packet::Read
(FileSystem & fs, Editor_Game_Base & egbase, bool, MapMapObjectLoader & mol)
@@ -43,10 +44,11 @@
Player_Number const nr_players = map .get_nrplayers();
iterate_players_existing(p, nr_players, egbase, player)
try {
- char filename[FILENAME_SIZE];
- snprintf(filename, sizeof(filename), FILENAME_TEMPLATE, p);
Profile prof;
- try {prof.read(filename, nullptr, fs);} catch (...) {continue;}
+ try {
+ prof.read((boost::format(FILENAME_TEMPLATE) % static_cast<unsigned int>(p)).str().c_str(),
+ nullptr, fs);
+ } catch (...) {continue;}
prof.get_safe_section("global").get_positive
("packet_version", CURRENT_PACKET_VERSION);
MessageQueue & messages = player->messages();
@@ -242,11 +244,10 @@
s.set_int ("serial", fileindex);
}
}
- char filename[FILENAME_SIZE];
- snprintf(filename, sizeof(filename), PLAYERDIRNAME_TEMPLATE, p);
- fs.EnsureDirectoryExists(filename);
- snprintf(filename, sizeof(filename), FILENAME_TEMPLATE, p);
- prof.write(filename, false, fs);
+ fs.EnsureDirectoryExists((boost::format(PLAYERDIRNAME_TEMPLATE)
+ % static_cast<unsigned int>(p)).str().c_str());
+ prof.write((boost::format(FILENAME_TEMPLATE)
+ % static_cast<unsigned int>(p)).str().c_str(), false, fs);
}
}
=== modified file 'src/map_io/widelands_map_players_view_data_packet.cc'
--- src/map_io/widelands_map_players_view_data_packet.cc 2014-07-28 16:59:54 +0000
+++ src/map_io/widelands_map_players_view_data_packet.cc 2014-08-03 18:56:48 +0000
@@ -22,6 +22,8 @@
#include <iostream>
#include <typeinfo>
+#include <boost/format.hpp>
+
#include "base/log.h"
#include "base/macros.h"
#include "economy/flag.h"
@@ -1176,10 +1178,10 @@
char filename[FILENAME_SIZE];
- snprintf(filename, sizeof(filename), PLAYERDIRNAME_TEMPLATE, plnum);
- fs.EnsureDirectoryExists(filename);
- snprintf(filename, sizeof(filename), DIRNAME_TEMPLATE, plnum);
- fs.EnsureDirectoryExists(filename);
+ fs.EnsureDirectoryExists((boost::format(PLAYERDIRNAME_TEMPLATE)
+ % static_cast<unsigned int>(plnum)).str().c_str());
+ fs.EnsureDirectoryExists((boost::format(DIRNAME_TEMPLATE)
+ % static_cast<unsigned int>(plnum)).str().c_str());
WRITE
(unseen_times_file,
=== modified file 'src/map_io/widelands_map_port_spaces_data_packet.cc'
--- src/map_io/widelands_map_port_spaces_data_packet.cc 2014-07-28 14:17:07 +0000
+++ src/map_io/widelands_map_port_spaces_data_packet.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "map_io/widelands_map_port_spaces_data_packet.h"
+#include <string>
+
#include <boost/algorithm/string.hpp>
#include "base/deprecated.h"
@@ -50,11 +52,9 @@
if (!num)
return;
- char buf[8]; // there won't be that many port spaces... definitely!
Section & s2 = prof.get_safe_section("port_spaces");
for (uint16_t i = 0; i < num; ++i) {
- snprintf(buf, sizeof(buf), "%u", i);
- map.set_port_space(get_safe_coords(buf, ext, &s2), true);
+ map.set_port_space(get_safe_coords(std::to_string(static_cast<unsigned int>(i)), ext, &s2), true);
}
} else
throw game_data_error
@@ -95,14 +95,12 @@
}
const uint16_t num = port_spaces.size();
- char buf[8]; // there won't be that many port spaces... Definitely!
s1.set_int("number_of_port_spaces", num);
Section & s2 = prof.create_section("port_spaces");
int i = 0;
for (const Coords& c : port_spaces) {
- snprintf(buf, sizeof(buf), "%u", i++);
- set_coords(buf, c, &s2);
+ set_coords(std::to_string(i++), c, &s2);
}
prof.write("port_spaces", false, fs);
}
=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc 2014-07-25 20:16:31 +0000
+++ src/network/netclient.cc 2014-08-03 18:56:48 +0000
@@ -22,6 +22,7 @@
#include <memory>
#include <boost/algorithm/string/predicate.hpp>
+#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include "base/i18n.h"
@@ -297,9 +298,8 @@
std::string NetClient::getGameDescription()
{
- char buf[200];
- snprintf(buf, sizeof(buf), "network player %i", d->settings.playernum);
- return buf;
+ return (boost::format("network player %u")
+ % static_cast<unsigned int>(d->settings.playernum)).str();
}
void NetClient::report_result
=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc 2014-07-26 10:43:23 +0000
+++ src/network/nethost.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,7 @@
#include <memory>
#include <sstream>
+#include <string>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/format.hpp>
@@ -1418,11 +1419,8 @@
std::string NetHost::getGameDescription()
{
- char buf[200];
- snprintf
- (buf, sizeof(buf),
- "network player %i (host)", d->settings.users.at(0).position);
- return buf;
+ return (boost::format("network player %u (host)")
+ % static_cast<unsigned int>(d->settings.users.at(0).position)).str();
}
const GameSettings& NetHost::settings()
@@ -2000,11 +1998,8 @@
std::string NetHost::getComputerPlayerName(uint8_t const playernum)
{
std::string name;
- uint32_t suffix = playernum;
do {
- char buf[200];
- snprintf(buf, sizeof(buf), _("Computer %u"), ++suffix);
- name = buf;
+ name = (boost::format(_("Computer %u")) % static_cast<unsigned int>(++playernum)).str();
} while (haveUserName(name, playernum));
return name;
}
@@ -2075,9 +2070,7 @@
if (haveUserName(effective_name, client.usernum)) {
uint32_t i = 2;
do {
- char buf[32];
- snprintf(buf, sizeof(buf), "%u", i++);
- effective_name = (boost::format(_("Player %s")) % buf).str();
+ effective_name = (boost::format(_("Player %u")) % i++).str();
} while (haveUserName(effective_name, client.usernum));
}
@@ -2264,16 +2257,20 @@
// inform the other clients about the problem regulary
if (deltanow - d->clients.at(i).lastdelta > 30) {
- char buf[5];
- //snprintf(buf, sizeof(buf), "%li", deltanow);
- snprintf(buf, sizeof(buf), ngettext("%li second", "%li seconds", deltanow), deltanow);
+ std::string seconds = (boost::format(ngettext("%li second", "%li seconds", deltanow))
+ % deltanow).str();
sendSystemMessageCode
- ("CLIENT_HUNG", d->settings.users.at(d->clients.at(i).usernum).name, buf);
+ ("CLIENT_HUNG",
+ d->settings.users.at(d->clients.at(i).usernum).name,
+ seconds.c_str());
+
d->clients.at(i).lastdelta = deltanow;
if (m_is_dedicated) {
- snprintf(buf, sizeof(buf), "%li", 300 - deltanow);
+ seconds = (boost::format("%li") % (300 - deltanow)).str();
sendSystemMessageCode
- ("CLIENT_HUNG_AUTOKICK", d->settings.users.at(d->clients.at(i).usernum).name, buf);
+ ("CLIENT_HUNG_AUTOKICK",
+ d->settings.users.at(d->clients.at(i).usernum).name,
+ seconds.c_str());
}
}
=== modified file 'src/profile/profile.cc'
--- src/profile/profile.cc 2014-07-25 20:40:51 +0000
+++ src/profile/profile.cc 2014-08-03 18:56:48 +0000
@@ -490,9 +490,7 @@
*/
void Section::set_int(char const * const name, int32_t const value)
{
- char buffer[sizeof("-2147483649")];
- sprintf(buffer, "%i", value);
- set_string(name, buffer);
+ set_string(name, std::to_string(value));
}
=== modified file 'src/scripting/lua_bases.cc'
--- src/scripting/lua_bases.cc 2014-07-28 16:59:54 +0000
+++ src/scripting/lua_bases.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "scripting/lua_bases.h"
+#include <boost/format.hpp>
+
#include "economy/economy.h"
#include "logic/checkstep.h"
#include "logic/constants.h"
@@ -315,10 +317,8 @@
}
int L_PlayerBase::__tostring(lua_State * L) {
- char rv[40];
- snprintf
- (rv, sizeof(rv), "Player(%i)", get(L, get_egbase(L)).player_number());
- lua_pushstring(L, rv);
+ lua_pushstring(L, (boost::format("Player(%i)")
+ % static_cast<unsigned int>(get(L, get_egbase(L)).player_number())).str().c_str());
return 1;
}
/* RST
=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc 2014-07-28 18:34:07 +0000
+++ src/scripting/lua_map.cc 2014-08-03 18:56:48 +0000
@@ -3522,9 +3522,9 @@
*/
// Hash is used to identify a class in a Set
int L_Field::get___hash(lua_State * L) {
- char buf[25];
- snprintf(buf, sizeof(buf), "%i_%i", m_c.x, m_c.y);
- lua_pushstring(L, buf);
+ lua_pushstring(L, (boost::format("%i_%i")
+ % static_cast<unsigned int>(m_c.x)
+ % static_cast<unsigned int>(m_c.y)).str().c_str());
return 1;
}
@@ -3852,9 +3852,9 @@
return 1;
}
int L_Field::__tostring(lua_State * L) {
- char buf[100];
- snprintf(buf, sizeof(buf), "Field(%i,%i)", m_c.x, m_c.y);
- lua_pushstring(L, buf);
+ lua_pushstring(L, (boost::format("Field(%i,%i)")
+ % static_cast<unsigned int>(m_c.x)
+ % static_cast<unsigned int>(m_c.y)).str().c_str());
return 1;
}
=== modified file 'src/ui_basic/helpwindow.cc'
--- src/ui_basic/helpwindow.cc 2014-07-28 16:59:54 +0000
+++ src/ui_basic/helpwindow.cc 2014-08-03 18:56:48 +0000
@@ -20,6 +20,7 @@
#include "ui_basic/helpwindow.h"
#include <memory>
+#include <string>
#include <boost/format.hpp>
@@ -49,9 +50,9 @@
:
Window(parent, "help_window", 0, 0, 20, 20, (boost::format(_("Help: %s")) % caption).str().c_str()),
textarea(new Multiline_Textarea(this, 5, 5, 30, 30, std::string(), Align_Left)),
- m_h1((format("%u") % (fontsize < 12 ? 18 : fontsize * 3 / 2)).str()),
- m_h2((format("%u") % (fontsize < 12 ? 12 : fontsize)).str()),
- m_p ((format("%u") % (fontsize < 12 ? 10 : fontsize * 5 / 6)).str()),
+ m_h1(std::to_string(fontsize < 12 ? 18 : fontsize * 3 / 2)),
+ m_h2(std::to_string(fontsize < 12 ? 12 : fontsize)),
+ m_p (std::to_string(fontsize < 12 ? 10 : fontsize * 5 / 6)),
m_fn(ui_fn().substr(0, ui_fn().size() - 4)) // Font file - .ttf
{
// Begin the text with the caption
=== modified file 'src/ui_basic/spinbox.cc'
--- src/ui_basic/spinbox.cc 2014-07-25 19:15:23 +0000
+++ src/ui_basic/spinbox.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,8 @@
#include <vector>
+#include <boost/format.hpp>
+
#include "base/deprecated.h"
#include "base/i18n.h"
#include "base/wexception.h"
@@ -103,11 +105,10 @@
textw = w - butw * 32 / 5;
}
- char buf[64];
- snprintf(buf, sizeof(buf), "%i %s", sbi->value, sbi->unit.c_str());
-
sbi->text = new UI::Textarea
- (this, butw * 16 / 5, 0, textw, h, buf, Align_Center);
+ (this, butw * 16 / 5, 0, textw, h,
+ (boost::format("%i %s") % sbi->value % sbi->unit.c_str()).str(),
+ Align_Center);
sbi->butPlus =
new Button
(this, "+",
@@ -170,9 +171,7 @@
}
}
if (!was_in_list) {
- char buf[64];
- snprintf(buf, sizeof(buf), "%i %s", sbi->value, sbi->unit.c_str());
- sbi->text->set_text(buf);
+ sbi->text->set_text((boost::format("%i %s") % sbi->value % sbi->unit.c_str()).str());
}
sbi->butMinus->set_enabled(sbi->min < sbi->value);
@@ -333,9 +332,7 @@
void SpinBox::remove_replacement(int32_t value)
{
if (int32_t i = findReplacement(value) >= 0) {
- char buf[64];
- snprintf(buf, sizeof(buf), "%i %s", value, sbi->unit.c_str());
- sbi->valrep[i].text = buf;
+ sbi->valrep[i].text = (boost::format("%i %s") % value % sbi->unit.c_str()).str();
}
}
=== modified file 'src/ui_fsmenu/base.cc'
--- src/ui_fsmenu/base.cc 2014-07-05 14:22:44 +0000
+++ src/ui_fsmenu/base.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,8 @@
#include <cstdio>
+#include <boost/format.hpp>
+
#include "base/log.h"
#include "base/wexception.h"
#include "graphic/font.h"
@@ -56,9 +58,8 @@
d(new Data)
{
// Load background graphics
- char buffer[256];
- snprintf(buffer, sizeof(buffer), "pics/%s", bgpic);
- d->res_background = ImageTransformations::resize(g_gr->images().get(buffer), get_w(), get_h());
+ const std::string bgpicpath = (boost::format("pics/%s") % bgpic).str();
+ d->res_background = ImageTransformations::resize(g_gr->images().get(bgpicpath), get_w(), get_h());
d->textstyle_small = UI::TextStyle::ui_small();
d->textstyle_small.font = UI::Font::get(ui_fn(), fs_small());
=== modified file 'src/ui_fsmenu/editor_mapselect.cc'
--- src/ui_fsmenu/editor_mapselect.cc 2014-07-20 07:46:24 +0000
+++ src/ui_fsmenu/editor_mapselect.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,7 @@
#include <cstdio>
#include <memory>
+#include <string>
#include <boost/format.hpp>
@@ -175,12 +176,10 @@
m_descr .set_text
(_(map.get_description()) + (map.get_hint().empty() ? "" : (std::string("\n") + _(map.get_hint()))));
- char buf[200];
- sprintf(buf, "%i", map.get_nrplayers());
- m_nr_players.set_text(buf);
+ m_nr_players.set_text(std::to_string(static_cast<unsigned int>(map.get_nrplayers())));
- sprintf(buf, "%ix%i", map.get_width(), map.get_height());
- m_size .set_text(buf);
+ /** TRANSLATORS: These are map coordinates */
+ m_size .set_text((boost::format(_("%1$ix%2$i")) % map.get_width() % map.get_height()).str());
} else {
m_name .set_text(std::string());
m_author .set_text(std::string());
=== modified file 'src/ui_fsmenu/launch_mpg.cc'
--- src/ui_fsmenu/launch_mpg.cc 2014-07-14 10:45:44 +0000
+++ src/ui_fsmenu/launch_mpg.cc 2014-08-03 18:56:48 +0000
@@ -548,25 +548,21 @@
std::unique_ptr<FileSystem> l_fs(g_fs->MakeSubFileSystem(m_settings->settings().mapfilename.c_str()));
Profile prof;
prof.read("map/player_names", nullptr, *l_fs);
- std::string strbuf;
std::string infotext = _("Saved players are:");
std::string player_save_name [MAX_PLAYERS];
std::string player_save_tribe[MAX_PLAYERS];
std::string player_save_ai [MAX_PLAYERS];
- char buf[32];
uint8_t i = 1;
for (; i <= m_nr_players; ++i) {
infotext += "\n* ";
- strbuf = std::string();
- snprintf(buf, sizeof(buf), "player_%u", i);
- Section & s = prof.get_safe_section(buf);
+ Section & s = prof.get_safe_section((boost::format("player_%u")
+ % static_cast<unsigned int>(i)).str().c_str());
player_save_name [i - 1] = s.get_string("name");
player_save_tribe[i - 1] = s.get_string("tribe");
player_save_ai [i - 1] = s.get_string("ai");
- snprintf(buf, sizeof(buf), _("Player %u"), i);
- infotext += buf;
+ infotext += (boost::format(_("Player %u")) % static_cast<unsigned int>(i)).str();
if (player_save_tribe[i - 1].empty()) {
std::string closed_string =
(boost::format("\\<%s\\>") % _("closed")).str();
@@ -594,9 +590,8 @@
m_settings->setPlayerTribe(i - 1, player_save_tribe[i - 1]);
// get translated tribename
- strbuf = "tribes/" + player_save_tribe[i - 1];
- strbuf += "/conf";
- Profile tribe(strbuf.c_str(), nullptr, "tribe_" + player_save_tribe[i - 1]);
+ Profile tribe((new std::string("tribes/" + player_save_tribe[i - 1] + "/conf"))->c_str(),
+ nullptr, "tribe_" + player_save_tribe[i - 1]);
Section & global = tribe.get_safe_section("tribe");
player_save_tribe[i - 1] = global.get_safe_string("name");
infotext += " (";
=== modified file 'src/ui_fsmenu/loadgame.cc'
--- src/ui_fsmenu/loadgame.cc 2014-07-14 10:45:44 +0000
+++ src/ui_fsmenu/loadgame.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,7 @@
#include <cstdio>
#include <memory>
+#include <string>
#include <boost/format.hpp>
@@ -234,16 +235,14 @@
m_tamapname.set_text(_(gpdp.get_mapname()));
}
- char buf[20];
uint32_t gametime = gpdp.get_gametime();
m_tagametime.set_text(gametimestring(gametime));
if (gpdp.get_number_of_players() > 0) {
- sprintf(buf, "%i", gpdp.get_number_of_players());
+ m_ta_players.set_text(std::to_string(static_cast<unsigned int>(gpdp.get_number_of_players())));
} else {
- sprintf(buf, "%s", _("Unknown"));
+ m_ta_players.set_text(_("Unknown"));
}
- m_ta_players.set_text(buf);
m_ta_win_condition.set_text(gpdp.get_win_condition());
std::string minimap_path = gpdp.get_minimap_path();
=== modified file 'src/ui_fsmenu/loadreplay.cc'
--- src/ui_fsmenu/loadreplay.cc 2014-07-05 14:22:44 +0000
+++ src/ui_fsmenu/loadreplay.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "ui_fsmenu/loadreplay.h"
+#include <string>
+
#include <boost/algorithm/string/predicate.hpp>
#include <boost/format.hpp>
@@ -192,16 +194,14 @@
m_delete.set_enabled(true);
m_tamapname.set_text(gpdp.get_mapname());
- char buf[20];
uint32_t gametime = gpdp.get_gametime();
m_tagametime.set_text(gametimestring(gametime));
if (gpdp.get_number_of_players() > 0) {
- sprintf(buf, "%i", gpdp.get_number_of_players());
+ m_ta_players.set_text(std::to_string(static_cast<unsigned int>(gpdp.get_number_of_players())));
} else {
- sprintf(buf, "%s", _("Unknown"));
+ m_ta_players.set_text(_("Unknown"));
}
- m_ta_players.set_text(buf);
m_ta_win_condition.set_text(gpdp.get_win_condition());
} else {
=== modified file 'src/ui_fsmenu/mapselect.cc'
--- src/ui_fsmenu/mapselect.cc 2014-07-25 20:40:51 +0000
+++ src/ui_fsmenu/mapselect.cc 2014-08-03 18:56:48 +0000
@@ -20,6 +20,7 @@
#include <cstdio>
#include <memory>
+#include <string>
#include <boost/format.hpp>
@@ -250,16 +251,12 @@
const MapData & map = m_maps_data[m_table.get_selected()];
if (map.width) {
- char buf[256];
-
// Translate the map data
i18n::Textdomain td("maps");
m_name .set_text(_(map.name));
m_author .set_text(map.author);
- sprintf(buf, "%-4ux%4u", map.width, map.height);
- m_size .set_text(buf);
- sprintf(buf, "%i", map.nrplayers);
- m_nr_players.set_text(buf);
+ m_size .set_text((boost::format("%-4ux%4u") % map.width % map.height).str());
+ m_nr_players.set_text(std::to_string(static_cast<unsigned int>(map.nrplayers)));
m_descr .set_text(_(map.description) + (map.hint.empty() ? "" : (std::string("\n") + _(map.hint))));
m_load_map_as_scenario.set_enabled(map.scenario);
} else {
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2014-07-25 22:17:48 +0000
+++ src/wlapplication.cc 2014-08-03 18:56:48 +0000
@@ -560,11 +560,11 @@
}
g_fs->EnsureDirectoryExists(SCREENSHOT_DIR);
for (uint32_t nr = 0; nr < 10000; ++nr) {
- char buffer[256];
- snprintf(buffer, sizeof(buffer), SCREENSHOT_DIR "/shot%04u.png", nr);
- if (g_fs->FileExists(buffer))
+ const std::string filename = (boost::format(SCREENSHOT_DIR "/shot%04u.png")
+ % static_cast<unsigned int>(nr)).str().c_str();
+ if (g_fs->FileExists(filename))
continue;
- g_gr->screenshot(buffer);
+ g_gr->screenshot(filename);
break;
}
}
=== modified file 'src/wui/attack_box.cc'
--- src/wui/attack_box.cc 2014-07-05 14:22:44 +0000
+++ src/wui/attack_box.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,10 @@
#include "wui/attack_box.h"
+#include <string>
+
+#include <boost/format.hpp>
+
#include "base/macros.h"
#include "graphic/graphic.h"
#include "logic/soldier.h"
@@ -119,7 +123,6 @@
assert(m_less_soldiers);
assert(m_add_soldiers);
- char buf[20];
int32_t max_attackers = get_max_attackers();
if (m_slider_soldiers->get_max_value() != max_attackers)
@@ -129,11 +132,12 @@
m_add_soldiers->set_enabled(max_attackers > m_slider_soldiers->get_value());
m_less_soldiers ->set_enabled(m_slider_soldiers->get_value() > 0);
- sprintf(buf, "%u / %u", m_slider_soldiers->get_value(), max_attackers);
- m_text_soldiers->set_text(buf);
+ /** TRANSLATORS: %1% of %2% soldiers. Used in Attack box. */
+ m_text_soldiers->set_text((boost::format(_("%1% / %2%"))
+ % m_slider_soldiers->get_value()
+ % max_attackers).str());
- sprintf(buf, "%u", max_attackers);
- m_add_soldiers->set_title(buf);
+ m_add_soldiers->set_title(std::to_string(max_attackers));
}
void AttackBox::init() {
=== modified file 'src/wui/building_statistics_menu.cc'
--- src/wui/building_statistics_menu.cc 2014-07-28 18:03:51 +0000
+++ src/wui/building_statistics_menu.cc 2014-08-03 18:56:48 +0000
@@ -22,6 +22,7 @@
#include <vector>
#include <boost/bind.hpp>
+#include <boost/format.hpp>
#include "base/i18n.h"
#include "base/macros.h"
@@ -468,30 +469,27 @@
uint32_t const percent =
static_cast<uint32_t>
(static_cast<float>(total_prod) / static_cast<float>(nr_owned));
- snprintf(buffer, sizeof(buffer), "%3u", percent);
+ te->set_string(Columns::Prod, (boost::format("%3u") % percent).str()); // space-pad for sort
if (is_selected) {
m_progbar.set_state(percent);
m_btn[Prev_Unproductive]->set_enabled(true);
m_btn[Next_Unproductive]->set_enabled(true);
}
} else {
- snprintf(buffer, sizeof(buffer), " ");
+ te->set_string(Columns::Prod, " ");
if (is_selected) {
m_btn[Prev_Unproductive]->set_enabled(false);
m_btn[Next_Unproductive]->set_enabled(false);
}
}
- te->set_string(Columns::Prod, buffer);
// number of this buildings
- snprintf(buffer, sizeof(buffer), "%3u", nr_owned); // space-pad for sort
- te->set_string(Columns::Owned, buffer);
+ te->set_string(Columns::Owned, (boost::format("%3u") % nr_owned).str()); // space-pad for sort
if (is_selected)
m_owned.set_text(buffer);
// number of currently builds
- snprintf(buffer, sizeof(buffer), "%3u", nr_build); // space-pad for sort
- te->set_string(Columns::Build, buffer);
+ te->set_string(Columns::Build, (boost::format("%3u") % nr_build).str()); // space-pad for sort
if (is_selected)
m_in_build.set_text(buffer);
}
=== modified file 'src/wui/buildingwindow.cc'
--- src/wui/buildingwindow.cc 2014-07-28 16:59:54 +0000
+++ src/wui/buildingwindow.cc 2014-08-03 18:56:48 +0000
@@ -228,17 +228,19 @@
if (owner.is_building_type_allowed(enhancement)) {
const Widelands::BuildingDescr & building_descr =
*tribe.get_building_descr(enhancement);
- char buffer[128];
- snprintf
- (buffer, sizeof(buffer),
- _("Enhance to %s"), building_descr.descname().c_str());
+
+ std::string tooltip = (boost::format(_("Enhance to %s"))
+ % building_descr.descname().c_str()).str()
+ + "<br><font size=11>" + _("Construction costs:") + "</font><br>"
+ + waremap_to_richtext(tribe, building_descr.enhancement_cost());
+
UI::Button * enhancebtn =
new UI::Button
(capsbuttons, "enhance", 0, 0, 34, 34,
g_gr->images().get("pics/but4.png"),
building_descr.get_icon(),
- std::string(buffer) + "<br><font size=11>" + _("Construction costs:") + "</font><br>" +
- waremap_to_richtext(tribe, building_descr.enhancement_cost()));
+ tooltip);
+
// button id = building id
enhancebtn->sigclicked.connect([this, enhancement] {act_enhance(enhancement);});
capsbuttons->add
=== modified file 'src/wui/encyclopedia_window.cc'
--- src/wui/encyclopedia_window.cc 2014-08-01 12:57:17 +0000
+++ src/wui/encyclopedia_window.cc 2014-08-03 18:56:48 +0000
@@ -191,15 +191,13 @@
// Make sure to detect if someone changes the type so that it
// needs more than 3 decimal digits to represent.
static_assert(sizeof(temp_group.second) == 1, "Number is too big for 3 char string.");
- char amount_string[4]; // Space for 3 digits + terminator.
- sprintf(amount_string, "%u", temp_group.second);
// picture only of first ware type in group
UI::Table<uintptr_t>::Entry_Record & tableEntry =
condTable.add(0);
tableEntry.set_picture
(0, tribe.get_ware_descr(*ware_types.begin())->icon(), ware_type_names);
- tableEntry.set_string (1, amount_string);
+ tableEntry.set_string(1, std::to_string(static_cast<unsigned int>(temp_group.second)));
condTable.set_sort_column(0);
condTable.sort();
}
=== modified file 'src/wui/game_debug_ui.cc'
--- src/wui/game_debug_ui.cc 2014-07-28 14:23:03 +0000
+++ src/wui/game_debug_ui.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,7 @@
#include "wui/game_debug_ui.h"
#include <cstdio>
+#include <string>
#include <boost/format.hpp>
@@ -155,11 +156,8 @@
(this, 0, 0,
g_gr->images().get("pics/but1.png"))
{
- char buffer[128];
-
m_serial = obj.serial();
- snprintf(buffer, sizeof(buffer), "%u", m_serial);
- set_title(buffer);
+ set_title(std::to_string(m_serial));
obj.create_debug_panels(parent.egbase(), m_tabs);
@@ -182,10 +180,7 @@
}
UI::Window::think();
} else {
- char buffer[128];
-
- snprintf(buffer, sizeof(buffer), "DEAD: %u", m_serial);
- set_title(buffer);
+ set_title((boost::format("DEAD: %u") % m_serial).str().c_str());
}
}
@@ -274,7 +269,6 @@
void FieldDebugWindow::think()
{
std::string str;
- char buffer[512];
UI::Window::think();
@@ -284,10 +278,11 @@
.egbase();
{
Widelands::Player_Number const owner = m_coords.field->get_owned_by();
- snprintf
- (buffer, sizeof(buffer), "(%i, %i)\nheight: %u\nowner: %u\n",
- m_coords.x, m_coords.y, m_coords.field->get_height(), owner);
- str += buffer;
+ str += (boost::format("(%i, %i)\nheight: %u\nowner: %u\n")
+ % m_coords.x % m_coords.y
+ % static_cast<unsigned int>(m_coords.field->get_height())
+ % static_cast<unsigned int>(owner)).str();
+
if (owner) {
Widelands::NodeCaps const buildcaps =
egbase.player(owner).get_buildcaps(m_coords);
@@ -313,35 +308,30 @@
Widelands::Player_Number const nr_players = m_map.get_nrplayers();
iterate_players_existing_const(plnum, nr_players, egbase, player) {
const Widelands::Player::Field & player_field = player->fields()[i];
- snprintf(buffer, sizeof(buffer), "Player %u:\n", plnum);
- str += buffer;
- snprintf
- (buffer, sizeof(buffer),
- " military influence: %u\n", player_field.military_influence);
- str += buffer;
+ str += (boost::format("Player %u:\n") % static_cast<unsigned int>(plnum)).str();
+ str += (boost::format(" military influence: %u\n")
+ % static_cast<unsigned int>(player_field.military_influence)).str();
+
Widelands::Vision const vision = player_field.vision;
- snprintf(buffer, sizeof(buffer), " vision: %u\n", vision);
- str += buffer;
+ str += (boost::format(" vision: %u\n") % static_cast<unsigned int>(vision)).str();
{
Widelands::Time const time_last_surveyed =
player_field.time_triangle_last_surveyed[Widelands::TCoords<>::D];
if (time_last_surveyed != Widelands::Never()) {
- snprintf
- (buffer, sizeof(buffer),
- " D triangle last surveyed at %u: amount %u\n",
- time_last_surveyed, player_field.resource_amounts.d);
- str += buffer;
+ str += (boost::format(" D triangle last surveyed at %u: amount %u\n")
+ % time_last_surveyed
+ % static_cast<unsigned int>(player_field.resource_amounts.d)).str();
+
} else str += " D triangle never surveyed\n";
}
{
Widelands::Time const time_last_surveyed =
player_field.time_triangle_last_surveyed[Widelands::TCoords<>::R];
if (time_last_surveyed != Widelands::Never()) {
- snprintf
- (buffer, sizeof(buffer),
- " R triangle last surveyed at %u: amount %u\n",
- time_last_surveyed, player_field.resource_amounts.r);
- str += buffer;
+ str += (boost::format(" R triangle last surveyed at %u: amount %u\n")
+ % time_last_surveyed
+ % static_cast<unsigned int>(player_field.resource_amounts.r)).str();
+
} else str += " R triangle never surveyed\n";
}
switch (vision) {
@@ -352,21 +342,17 @@
animation_name = "(seen an animation)";
}
- snprintf
- (buffer, sizeof(buffer),
- " last seen at %u:\n"
- " owner: %u\n"
- " immovable animation:\n%s\n"
- " ",
- player_field.time_node_last_unseen,
- player_field.owner,
- animation_name.c_str());
- str += buffer;
+ str += (boost::format(" last seen at %u:\n"
+ " owner: %u\n"
+ " immovable animation:\n%s\n"
+ " ")
+ % player_field.time_node_last_unseen
+ % static_cast<unsigned int>(player_field.owner)
+ % animation_name.c_str()).str();
break;
}
default:
- snprintf(buffer, sizeof(buffer), " seen %u times\n", vision - 1);
- str += buffer;
+ str += (boost::format(" seen %u times\n") % static_cast<unsigned int>(vision - 1)).str();
break;
}
}
@@ -374,16 +360,11 @@
Widelands::Resource_Index ridx = m_coords.field->get_resources();
int ramount = m_coords.field->get_resources_amount();
int startingAmount = m_coords.field->get_starting_res_amount();
- snprintf(buffer,
- sizeof(buffer),
- "Resource: %s\n",
- ibase().egbase().world().get_resource(ridx)->name().c_str());
-
- str += buffer;
-
- snprintf
- (buffer, sizeof(buffer), " Amount: %i/%i\n", ramount, startingAmount);
- str += buffer;
+
+ str += (boost::format("Resource: %s\n")
+ % ibase().egbase().world().get_resource(ridx)->name().c_str()).str();
+
+ str += (boost::format(" Amount: %i/%i\n") % ramount % startingAmount).str();
}
m_ui_field.set_text(str.c_str());
@@ -391,10 +372,9 @@
// Immovable information
if (Widelands::BaseImmovable * const imm = m_coords.field->get_immovable())
{
- snprintf
- (buffer, sizeof(buffer),
- "%s (%u)", imm->descr().name().c_str(), imm->serial());
- m_ui_immovable.set_title(buffer);
+ m_ui_immovable.set_title((boost::format("%s (%u)")
+ % imm->descr().name().c_str()
+ % static_cast<unsigned int>(imm->serial())).str().c_str());
m_ui_immovable.set_enabled(true);
} else {
m_ui_immovable.set_title("no immovable");
@@ -439,7 +419,7 @@
m_ui_bobs.add(
(boost::format("%s (%u)")
% temp_bob->descr().name()
- % temp_bob->serial()).str().c_str(),
+ % static_cast<unsigned int>(temp_bob->serial())).str().c_str(),
temp_bob->serial());
}
}
=== modified file 'src/wui/game_summary.cc'
--- src/wui/game_summary.cc 2014-07-14 10:45:44 +0000
+++ src/wui/game_summary.cc 2014-08-03 18:56:48 +0000
@@ -138,16 +138,15 @@
UI::Table<uintptr_t const>::Entry_Record & te
= m_players_table->add(i);
// Player name & pic
- // Boost doesn't handle uint8_t as integers
- uint16_t player_number = pes.player;
std::string pic_path =
- (boost::format("pics/genstats_enable_plr_0%|1$u|.png") % player_number).str();
+ (boost::format("pics/genstats_enable_plr_0%|1$u|.png")
+ % static_cast<unsigned int>(pes.player)).str();
const Image* pic = g_gr->images().get(pic_path);
te.set_picture(0, pic, p->get_name());
// Team
- uint16_t team_number = p->team_number();
std::string team_str =
- (boost::format("%|1$u|") % team_number).str();
+ (boost::format("%|1$u|")
+ % static_cast<unsigned int>(p->team_number())).str();
te.set_string(1, team_str);
// Status
std::string stat_str;
@@ -186,9 +185,9 @@
m_title_area->set_text
((boost::format(_("%s won!")) % single_won->get_name()).str());
} else {
- uint16_t team_number = team_won;
m_title_area->set_text
- ((boost::format(_("Team %|1$u| won!")) % team_number).str());
+ ((boost::format(_("Team %|1$u| won!"))
+ % static_cast<unsigned int>(team_won)).str());
}
}
m_players_table->update();
=== modified file 'src/wui/general_statistics_menu.cc'
--- src/wui/general_statistics_menu.cc 2014-07-25 13:45:18 +0000
+++ src/wui/general_statistics_menu.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,8 @@
#include <memory>
+#include <boost/format.hpp>
+
#include "base/i18n.h"
#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
@@ -145,14 +147,14 @@
iterate_players_existing_novar(p, nr_players, game) ++plr_in_game;
iterate_players_existing_const(p, nr_players, game, player) {
- char buffer[36];
- snprintf(buffer, sizeof(buffer), "pics/genstats_enable_plr_%02u.png", p);
+ const std::string pic = (boost::format("pics/genstats_enable_plr_%02u.png")
+ % static_cast<unsigned int>(p)).str().c_str();
UI::Button & cb =
*new UI::Button
(hbox1, "playerbutton",
0, 0, 25, 25,
g_gr->images().get("pics/but4.png"),
- g_gr->images().get(buffer),
+ g_gr->images().get(pic),
player->get_name().c_str());
cb.sigclicked.connect
(boost::bind(&General_Statistics_Menu::cb_changed_to, this, p));
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2014-07-28 14:23:03 +0000
+++ src/wui/interactive_base.cc 2014-08-03 18:56:48 +0000
@@ -307,9 +307,9 @@
static std::string speedString(uint32_t const speed)
{
if (speed) {
- char buffer[32];
- snprintf(buffer, sizeof(buffer), ("%u.%ux"), speed / 1000, speed / 100 % 10);
- return buffer;
+ return (boost::format("%u.%ux")
+ % (speed / 1000)
+ % (speed / 100 % 10)).str();
}
return _("PAUSE");
}
=== modified file 'src/wui/multiplayersetupgroup.cc'
--- src/wui/multiplayersetupgroup.cc 2014-07-24 18:22:30 +0000
+++ src/wui/multiplayersetupgroup.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "wui/multiplayersetupgroup.h"
+#include <string>
+
#include <boost/format.hpp>
#include "base/i18n.h"
@@ -113,24 +115,26 @@
} else {
name->set_text(us.name);
if (m_save != us.position) {
- char buf[42] = "pics/menu_tab_watch.png";
- char buf2[128];
+ const char* pic;
+ const char* temp_tooltip;
if (us.position < UserSettings::highestPlayernum()) {
- snprintf
- (buf, sizeof(buf),
- "pics/genstats_enable_plr_0%i.png", us.position + 1);
- snprintf(buf2, sizeof(buf2), _("Player %i"), us.position + 1);
- } else
- snprintf(buf2, sizeof(buf2), _("Spectator"));
+ pic = (boost::format("pics/genstats_enable_plr_0%u.png")
+ % static_cast<unsigned int>(us.position + 1)).str().c_str();
+ temp_tooltip = (boost::format(_("Player %u"))
+ % static_cast<unsigned int>(us.position + 1)).str().c_str();
+ } else {
+ pic = "pics/menu_tab_watch.png";
+ temp_tooltip = _("Spectator");
+ }
// Either Button if changeable OR text if not
if (m_id == s->settings().usernum) {
- type->set_pic(g_gr->images().get(buf));
- type->set_tooltip(buf2);
+ type->set_pic(g_gr->images().get(pic));
+ type->set_tooltip(temp_tooltip);
type->set_visible(true);
} else {
- type_icon->setIcon(g_gr->images().get(buf));
- type_icon->set_tooltip(buf2);
+ type_icon->setIcon(g_gr->images().get(pic));
+ type_icon->set_tooltip(temp_tooltip);
type_icon->set_visible(true);
}
m_save = us.position;
@@ -168,11 +172,11 @@
m_tribenames(tn)
{
set_size(w, h);
- char buf[42];
- snprintf
- (buf, sizeof(buf), "pics/fsel_editor_set_player_0%i_pos.png", id + 1);
+
+ const std::string pic = (boost::format("pics/fsel_editor_set_player_0%i_pos.png")
+ % static_cast<unsigned int>(id + 1)).str().c_str();
player =
- new UI::Icon(this, 0, 0, h, h, g_gr->images().get(buf));
+ new UI::Icon(this, 0, 0, h, h, g_gr->images().get(pic));
add(player, UI::Box::AlignCenter);
type = new UI::Button
(this, "player_type",
@@ -283,12 +287,12 @@
type ->set_tooltip(_("Shared in"));
type ->set_pic(g_gr->images().get("pics/shared_in.png"));
- char pic[42], hover[128];
- snprintf(pic, sizeof(pic), "pics/fsel_editor_set_player_0%i_pos.png", player_setting.shared_in);
- snprintf(hover, sizeof(hover), _("Player %i"), player_setting.shared_in);
+ const std::string pic = (boost::format("pics/fsel_editor_set_player_0%u_pos.png")
+ % static_cast<unsigned int>(player_setting.shared_in)).str().c_str();
tribe->set_pic(g_gr->images().get(pic));
- tribe->set_tooltip(hover);
+ tribe->set_tooltip((boost::format(_("Player %u"))
+ % static_cast<unsigned int>(player_setting.shared_in)).str().c_str());
team ->set_visible(false);
team ->set_enabled(false);
@@ -339,9 +343,7 @@
tribe->set_flat(false);
if (player_setting.team) {
- char buf[64];
- snprintf(buf, sizeof(buf), "%i", player_setting.team);
- team->set_title(buf);
+ team->set_title(std::to_string(static_cast<unsigned int>(player_setting.team)));
} else {
team->set_title("--");
}
=== modified file 'src/wui/playerdescrgroup.cc'
--- src/wui/playerdescrgroup.cc 2014-07-24 18:22:30 +0000
+++ src/wui/playerdescrgroup.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "wui/playerdescrgroup.h"
+#include <string>
+
#include <boost/format.hpp>
#include "base/i18n.h"
@@ -212,9 +214,7 @@
d->plr_name->set_text(player.name);
if (player.team) {
- char buf[64];
- snprintf(buf, sizeof(buf), "%i", player.team);
- d->btnPlayerTeam->set_title(buf);
+ d->btnPlayerTeam->set_title(std::to_string(static_cast<unsigned int>(player.team)));
} else {
d->btnPlayerTeam->set_title("--");
}
=== modified file 'src/wui/plot_area.cc'
--- src/wui/plot_area.cc 2014-07-20 07:46:50 +0000
+++ src/wui/plot_area.cc 2014-08-03 18:56:48 +0000
@@ -21,6 +21,7 @@
#include "wui/plot_area.h"
#include <cstdio>
+#include <string>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
@@ -367,7 +368,7 @@
// print the maximal value into the top right corner
draw_value
- ((format("%u") % max).str(), RGBColor(60, 125, 0),
+ (std::to_string(max), RGBColor(60, 125, 0),
Point(get_inner_w() - space_at_right - 2, spacing + 2), dst);
// plot the pixels
@@ -570,7 +571,7 @@
}
//print the min and max values
draw_value
- ((boost::format("%u") % highest_scale).str(), RGBColor(60, 125, 0),
+ (std::to_string(highest_scale), RGBColor(60, 125, 0),
Point(get_inner_w() - space_at_right - 2, spacing + 2), dst);
draw_value
=== modified file 'src/wui/productionsitewindow.cc'
--- src/wui/productionsitewindow.cc 2014-07-28 16:59:54 +0000
+++ src/wui/productionsitewindow.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,8 @@
#include "wui/productionsitewindow.h"
+#include <boost/format.hpp>
+
#include "economy/request.h"
#include "graphic/graphic.h"
#include "logic/constructionsite.h"
@@ -173,14 +175,11 @@
assert(worker->descr().becomes() != Widelands::INVALID_INDEX);
// Fill upgrade status
- char buffer[7];
- snprintf
- (buffer, sizeof(buffer),
- "%i/%i",
- worker->get_current_experience(),
- worker->descr().get_needed_experience());
-
- er.set_string(1, buffer);
+ /** TRANSLATORS: %1% = the experience a worker has */
+ /** TRANSLATORS: %2% = the experience a worker needs to reach the next level */
+ er.set_string(1, (boost::format(_("%1%/%2%"))
+ % worker->get_current_experience()
+ % worker->descr().get_needed_experience()).str());
er.set_string
(2, worker->descr().tribe().get_worker_descr
(worker->descr().becomes())->descname());
=== modified file 'src/wui/watchwindow.cc'
--- src/wui/watchwindow.cc 2014-07-26 10:43:23 +0000
+++ src/wui/watchwindow.cc 2014-08-03 18:56:48 +0000
@@ -19,6 +19,7 @@
#include "wui/watchwindow.h"
+#include <string>
#include <vector>
#include "base/i18n.h"
@@ -203,9 +204,8 @@
void WatchWindow::toggle_buttons() {
for (uint32_t i = 0; i < NUM_VIEWS; ++i) {
if (i < views.size()) {
- char buffer[32];
- snprintf(buffer, sizeof(buffer), "%i", i + 1);
- view_btns[i]->set_title(buffer);
+ //(boost::format("%u soldier") % stationed).str()
+ view_btns[i]->set_title(std::to_string(i + 1));
view_btns[i]->set_enabled(true);
} else {
view_btns[i]->set_title("-");
=== modified file 'txts/README.lua'
--- txts/README.lua 2014-03-25 06:18:48 +0000
+++ txts/README.lua 2014-08-03 18:56:48 +0000
@@ -1,5 +1,4 @@
include "scripting/formatting.lua"
-include "scripting/format_help.lua"
set_textdomain("texts")
Follow ups