Removed all snprintf statements and constants for maximum

message sizes.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3065 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-01-28 21:49:28 +00:00
parent 6ac57f3c1f
commit 43e7b4bd45
11 changed files with 70 additions and 100 deletions

View File

@ -26,10 +26,8 @@
#include "tracks/track.hpp" #include "tracks/track.hpp"
#include "tracks/track_manager.hpp" #include "tracks/track_manager.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Challenge::addUnlockTrackReward(const std::string &track_name) void Challenge::addUnlockTrackReward(const std::string &track_name)
@ -93,7 +91,7 @@ const std::string Challenge::getUnlockedMessage() const
// add line break if we are showing multiple messages // add line break if we are showing multiple messages
if(n>0) unlocked_message+='\n'; if(n>0) unlocked_message+='\n';
char message[128]; std::string message;
// write message depending on feature type // write message depending on feature type
switch(m_feature[n].type) switch(m_feature[n].type)
@ -101,24 +99,34 @@ const std::string Challenge::getUnlockedMessage() const
case UNLOCK_TRACK: case UNLOCK_TRACK:
{ // {} avoids compiler warning { // {} avoids compiler warning
Track* track = track_manager->getTrack( m_feature[n].name ); Track* track = track_manager->getTrack( m_feature[n].name );
snprintf(message, 127, _("New track '%s'\nnow available"), _(track->getName()) ); message = StringUtils::insert_values(
_("New track '%s'\nnow available"),
_(track->getName()) );
break; break;
} }
case UNLOCK_MODE: case UNLOCK_MODE:
snprintf(message, 127, _("New game mode\n'%s'\nnow available"), m_feature[n].user_name.c_str() ); message = StringUtils::insert_values(
_("New game mode\n'%s'\nnow available"),
m_feature[n].user_name);
break; break;
case UNLOCK_GP: case UNLOCK_GP:
{ {
std::string gp_user_name = grand_prix_manager->getGrandPrix(m_feature[n].name)->getName(); std::string gp_user_name = grand_prix_manager->getGrandPrix(m_feature[n].name)->getName();
snprintf(message, 127, _("New Grand Prix '%s'\nnow available"), gp_user_name.c_str() ); message = StringUtils::insert_values(
_("New Grand Prix '%s'\nnow available"),
gp_user_name);
break; break;
} }
case UNLOCK_DIFFICULTY: case UNLOCK_DIFFICULTY:
snprintf(message, 127, _("New difficulty\n'%s'\nnow available"), m_feature[n].user_name.c_str() ); message = StringUtils::insert_values(
_("New difficulty\n'%s'\nnow available"),
m_feature[n].user_name);
break; break;
case UNLOCK_KART: case UNLOCK_KART:
const KartProperties *kp=kart_properties_manager->getKart(m_feature[n].name ); const KartProperties *kp=kart_properties_manager->getKart(m_feature[n].name );
snprintf(message, 127, _("New kart\n'%s'\nnow available"), kp->getName().c_str()); message = StringUtils::insert_values(
_("New kart\n'%s'\nnow available"),
kp->getName());
break; break;
} // switch } // switch
unlocked_message += message; unlocked_message += message;

View File

@ -30,7 +30,6 @@
# ifndef __CYGWIN__ # ifndef __CYGWIN__
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
// Some portabilty defines // Some portabilty defines
# define snprintf _snprintf
# define access _access # define access _access
# define F_OK 04 # define F_OK 04
# endif # endif

View File

@ -33,10 +33,7 @@
#include "karts/kart_properties_manager.hpp" #include "karts/kart_properties_manager.hpp"
#include "network/network_manager.hpp" #include "network/network_manager.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
enum WidgetTokens enum WidgetTokens
{ {
@ -108,9 +105,8 @@ CharSel::CharSel(int whichPlayer)
if (m_player_index < (int)kart_properties_manager->getNumSelectedKarts()) if (m_player_index < (int)kart_properties_manager->getNumSelectedKarts())
kart_properties_manager->removeLastSelectedKart(); kart_properties_manager->removeLastSelectedKart();
char heading[MAX_MESSAGE_LENGTH]; std::string heading = StringUtils::insert_values( _("Player %d, choose a driver"),
snprintf(heading, sizeof(heading), _("Player %d, choose a driver"), m_player_index + 1);
m_player_index + 1);
widget_manager->addTitleWgt( WTOK_TITLE, 100, 10, heading ); widget_manager->addTitleWgt( WTOK_TITLE, 100, 10, heading );
widget_manager->hideWgtRect(WTOK_TITLE); widget_manager->hideWgtRect(WTOK_TITLE);
widget_manager->breakLine(); widget_manager->breakLine();

View File

@ -19,10 +19,6 @@
#include "config_controls.hpp" #include "config_controls.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
#include "gui/menu_manager.hpp" #include "gui/menu_manager.hpp"
#include "gui/widget_manager.hpp" #include "gui/widget_manager.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"

View File

@ -18,11 +18,8 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config_display.hpp" #include "config_display.hpp"
#include <algorithm>
#if defined(WIN32) && !defined(__CYGWIN__) #include <algorithm>
# define snprintf _snprintf
#endif
#include "main_loop.hpp" #include "main_loop.hpp"
#include "widget_manager.hpp" #include "widget_manager.hpp"
@ -30,7 +27,7 @@
#include "menu_manager.hpp" #include "menu_manager.hpp"
#include "sdldrv.hpp" #include "sdldrv.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "utils/string_utils.hpp"
enum WidgetTokens enum WidgetTokens
{ {
@ -84,9 +81,9 @@ ConfigDisplay::ConfigDisplay()
widget_manager->addTextButtonWgt(WTOK_NEXT_BACKGROUND, 60, 7, _("Next background")); widget_manager->addTextButtonWgt(WTOK_NEXT_BACKGROUND, 60, 7, _("Next background"));
widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 60, 2 ); widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 60, 2 );
char msg [MAX_MESSAGE_LENGTH];
//I18N: displays current resolution //I18N: displays current resolution
snprintf( msg, MAX_MESSAGE_LENGTH, _("Current: %dx%d"), m_curr_width, m_curr_height ); std::string msg = StringUtils::insert_values(_("Current: %dx%d"),
m_curr_width, m_curr_height);
widget_manager->addTextWgt( WTOK_CURRENT_RES, 60, 7, msg); widget_manager->addTextWgt( WTOK_CURRENT_RES, 60, 7, msg);
widget_manager->hideWgtRect(WTOK_CURRENT_RES); widget_manager->hideWgtRect(WTOK_CURRENT_RES);
@ -176,10 +173,11 @@ void ConfigDisplay::select()
} }
else else
{ {
char msg [MAX_MESSAGE_LENGTH]; //I18N: displays current resolution
snprintf (msg, MAX_MESSAGE_LENGTH, "Current: %dx%d", std::string s = StringUtils::insert_values(_("Current: %dx%d"),
user_config->m_width, user_config->m_height); user_config->m_width,
widget_manager->setWgtText(WTOK_CURRENT_RES, msg); user_config->m_height);
widget_manager->setWgtText(WTOK_CURRENT_RES, s);
if ( isBlacklisted( user_config->m_width, if ( isBlacklisted( user_config->m_width,
user_config->m_height )) user_config->m_height ))
@ -357,9 +355,9 @@ void ConfigDisplay::getScreenModes()
void ConfigDisplay::changeApplyButton() void ConfigDisplay::changeApplyButton()
{ {
// change Apply button text // change Apply button text
char msg [MAX_MESSAGE_LENGTH]; std::string msg = StringUtils::insert_values(_("Apply %dx%d"),
snprintf(msg, MAX_MESSAGE_LENGTH, _("Apply %dx%d"), m_sizes[m_curr_res].first,
m_sizes[m_curr_res].first,m_sizes[m_curr_res].second); m_sizes[m_curr_res].second);
widget_manager->setWgtText(WTOK_APPLY_RES, msg); widget_manager->setWgtText(WTOK_APPLY_RES, msg);
widget_manager->activateWgt(WTOK_APPLY_RES); widget_manager->activateWgt(WTOK_APPLY_RES);
@ -391,9 +389,9 @@ bool ConfigDisplay::isBlacklisted(int width, int height)
void ConfigDisplay::showBlacklistButtons() void ConfigDisplay::showBlacklistButtons()
{ {
//change Apply button to Blacklisted button //change Apply button to Blacklisted button
char msg [MAX_MESSAGE_LENGTH]; std::string msg = StringUtils::insert_values(_("%dx%d Blacklisted"),
snprintf(msg, MAX_MESSAGE_LENGTH, _("%dx%d Blacklisted"), m_sizes[m_curr_res].first,
m_sizes[m_curr_res].first,m_sizes[m_curr_res].second); m_sizes[m_curr_res].second);
widget_manager->setWgtText(WTOK_APPLY_RES, msg); widget_manager->setWgtText(WTOK_APPLY_RES, msg);
widget_manager->deactivateWgt(WTOK_APPLY_RES); widget_manager->deactivateWgt(WTOK_APPLY_RES);

View File

@ -26,11 +26,7 @@
#include "gui/menu_manager.hpp" #include "gui/menu_manager.hpp"
#include "gui/widget_manager.hpp" #include "gui/widget_manager.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
enum WidgetTokens enum WidgetTokens
{ {
@ -107,7 +103,8 @@ void DisplayResConfirm::countdown()
if (m_counter > 1) if (m_counter > 1)
{ {
m_counter--; m_counter--;
snprintf(m_count, MAX_MESSAGE_LENGTH, _("Confirm Resolution Within %d Seconds"), m_counter); m_count = StringUtils::insert_values(_("Confirm Resolution Within %d Seconds"),
m_counter);
widget_manager->setWgtText( WTOK_TITLE, m_count ); widget_manager->setWgtText( WTOK_TITLE, m_count );
} }
else else

View File

@ -17,8 +17,8 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_DISPLAY_RES_CONFIRM_H #ifndef HEADER_DISPLAY_RES_CONFIRM_HPP
#define HEADER_DISPLAY_RES_CONFIRM_H #define HEADER_DISPLAY_RES_CONFIRM_HPP
#include "base_gui.hpp" #include "base_gui.hpp"
@ -35,9 +35,9 @@ public:
void handle(GameAction ga, int value); void handle(GameAction ga, int value);
private: private:
char m_count[60]; std::string m_count;
int m_counter; int m_counter;
const bool FROM_WINDOW; const bool FROM_WINDOW;
SDL_TimerID m_timer; SDL_TimerID m_timer;
}; };

View File

@ -21,9 +21,6 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
#include <SDL/SDL.h> #include <SDL/SDL.h>
@ -41,7 +38,7 @@
#include "karts/kart_properties.hpp" #include "karts/kart_properties.hpp"
#include "karts/kart_properties_manager.hpp" #include "karts/kart_properties_manager.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "graphics/scene.hpp" #include "utils/string_utils.hpp"
enum WidgetTokens enum WidgetTokens
{ {
@ -80,9 +77,8 @@ GrandPrixEnd::GrandPrixEnd()
} }
} }
static char output[MAX_MESSAGE_LENGTH]; std::string output = StringUtils::insert_values(_("The winner is %s!"),
snprintf(output, sizeof(output), race_manager->getKartName(winner_kart_id));
_("The winner is %s!"),race_manager->getKartName(winner_kart_id).c_str()); // FIXME - uses inner-name and not user name
widget_manager->addWgt( WTOK_TITLE, 60, 10); widget_manager->addWgt( WTOK_TITLE, 60, 10);
widget_manager->showWgtRect(WTOK_TITLE); widget_manager->showWgtRect(WTOK_TITLE);
widget_manager->showWgtText(WTOK_TITLE); widget_manager->showWgtText(WTOK_TITLE);

View File

@ -20,15 +20,13 @@
#include "gui/player_controls.hpp" #include "gui/player_controls.hpp"
#include <SDL/SDL.h> #include <SDL/SDL.h>
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
#include "sdldrv.hpp" #include "sdldrv.hpp"
#include "user_config.hpp" #include "user_config.hpp"
#include "gui/menu_manager.hpp" #include "gui/menu_manager.hpp"
#include "gui/widget_manager.hpp" #include "gui/widget_manager.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#include "utils/string_utils.hpp"
enum WidgetTokens enum WidgetTokens
{ {
@ -81,14 +79,11 @@ const char *sKartAction2String[KA_LAST+1] =
PlayerControls::PlayerControls(int whichPlayer): PlayerControls::PlayerControls(int whichPlayer):
m_player_index(whichPlayer), m_player_index(whichPlayer),
m_grab_input(false) m_grab_input(false)
{ {
// This is quite difficult to convert to using ustringstream, since the std::string s = StringUtils::insert_values( _("Choose your controls, %s"),
// position of %s in the string might vary from language to language. user_config->m_player[m_player_index].getName());
char heading[MAX_MESSAGE_LENGTH];
snprintf(heading, sizeof(heading), _("Choose your controls, %s"),
user_config->m_player[m_player_index].getName().c_str() );
widget_manager->addTitleWgt( WTOK_TITLE, 60, 7, heading ); widget_manager->addTitleWgt( WTOK_TITLE, 60, 7, s);
widget_manager->hideWgtRect(WTOK_TITLE); widget_manager->hideWgtRect(WTOK_TITLE);
widget_manager->breakLine(); widget_manager->breakLine();

View File

@ -25,10 +25,6 @@
#include "lisp/lisp.hpp" #include "lisp/lisp.hpp"
#include "utils/translation.hpp" #include "utils/translation.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define snprintf _snprintf
#endif
namespace lisp namespace lisp
{ {
@ -51,11 +47,9 @@ namespace lisp
std::ifstream in(filename.c_str()); std::ifstream in(filename.c_str());
if(!in.good()) if(!in.good())
{ {
char msg[MAX_ERROR_MESSAGE_LENGTH]; std::ostringstream msg;
snprintf(msg, sizeof(msg), msg << "Couldn't open file '" << filename << "'.";
"Couldn't open file '%s'.", throw std::runtime_error(msg.str());
filename.c_str());
throw std::runtime_error(msg);
} }
return parse(in); return parse(in);
} }
@ -89,19 +83,17 @@ namespace lisp
{ {
case Lexer::TOKEN_EOF: case Lexer::TOKEN_EOF:
{ {
char msg[MAX_ERROR_MESSAGE_LENGTH]; std::ostringstream msg;
snprintf(msg, sizeof(msg), msg << "Parse Error at line " << m_lexer->getLineNumber()
"Parse Error at line %d: Unexpected EOF.", << ": Unexpected EOF.";
m_lexer->getLineNumber()); throw std::runtime_error(msg.str());
throw std::runtime_error(msg);
} }
case Lexer::TOKEN_CLOSE_PAREN: case Lexer::TOKEN_CLOSE_PAREN:
{ {
char msg[MAX_ERROR_MESSAGE_LENGTH]; std::ostringstream msg;
snprintf(msg, sizeof(msg), msg << "Parse Error at line " << m_lexer->getLineNumber()
"Parse Error at line %d: Unexpected ')'.", << ": Unexpected ')'.";
m_lexer->getLineNumber()); throw std::runtime_error(msg.str());
throw std::runtime_error(msg);
} }
case Lexer::TOKEN_TRANSLATION: case Lexer::TOKEN_TRANSLATION:
{ {
@ -110,11 +102,10 @@ namespace lisp
Lisp* next=read(); Lisp* next=read();
if(next->getType()!=Lisp::TYPE_STRING) if(next->getType()!=Lisp::TYPE_STRING)
{ {
char msg[MAX_ERROR_MESSAGE_LENGTH]; std::ostringstream msg;
snprintf(msg, sizeof(msg), msg << "Parse Error at line " << m_lexer->getLineNumber()
"Parse Error at line %d: No string inside translation.", << ": No string inside translation.";
m_lexer->getLineNumber()); throw std::runtime_error(msg.str());
throw std::runtime_error(msg);
} }
const char* trans=_(next->m_v.m_string); const char* trans=_(next->m_v.m_string);
const size_t LEN = strlen(trans) + 1; const size_t LEN = strlen(trans) + 1;
@ -133,11 +124,10 @@ namespace lisp
if(m_token != Lexer::TOKEN_CLOSE_PAREN) if(m_token != Lexer::TOKEN_CLOSE_PAREN)
{ {
char msg[MAX_ERROR_MESSAGE_LENGTH]; std::ostringstream msg;
snprintf(msg, sizeof(msg), msg << "Parse Error at line " << m_lexer->getLineNumber()
"Parse Error at line %d: Expected ')'.", << ": Expected ')'.";
m_lexer->getLineNumber()); throw std::runtime_error(msg.str());
throw std::runtime_error(msg);
} }
break; break;
case Lexer::TOKEN_SYMBOL: case Lexer::TOKEN_SYMBOL:

View File

@ -35,11 +35,6 @@
# define N_(String) String # define N_(String) String
#endif #endif
// This length is used for all translated error messages.
#define MAX_ERROR_MESSAGE_LENGTH 160
// This length is used for all normal messages
#define MAX_MESSAGE_LENGTH 80
class Translations class Translations
{ {
public: public: