Changeset - r21395:222aeff2f57d
[Not reviewed]
master
0 3 0
rubidium - 10 years ago 2014-04-24 17:40:43
rubidium@openttd.org
(svn r26494) -Codechange: replace some further usages of s(n)printf with seprintf
3 files changed with 20 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/script/squirrel.cpp
Show inline comments
 
@@ -10,25 +10,30 @@
 
/** @file squirrel.cpp the implementation of the Squirrel class. It handles all Squirrel-stuff and gives a nice API back to work with. */
 

	
 
#include <stdarg.h>
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "squirrel_std.hpp"
 
#include "../fileio_func.h"
 
#include "../string_func.h"
 
#include <sqstdaux.h>
 
#include <../squirrel/sqpcheader.h>
 
#include <../squirrel/sqvm.h>
 

	
 
/* Due to the different characters for Squirrel, the scsnprintf might be a simple
 
 * snprint which triggers the safeguard. But it isn't always a simple snprintf.
 
 * Likewise for scstrcat. */
 
#include "../safeguards.h"
 
#undef snprintf
 
#undef strcat
 

	
 
void Squirrel::CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
 
{
 
	SQChar buf[1024];
 

	
 
#ifdef _SQ64
 
	scsnprintf(buf, lengthof(buf), _SC("Error %s:%ld/%ld: %s"), source, line, column, desc);
 
#else
 
	scsnprintf(buf, lengthof(buf), _SC("Error %s:%d/%d: %s"), source, line, column, desc);
 
#endif
 

	
 
	/* Check if we have a custom print function */
 
@@ -278,26 +283,27 @@ bool Squirrel::CallBoolMethod(HSQOBJECT 
 
}
 

	
 
/* static */ bool Squirrel::CreateClassInstanceVM(HSQUIRRELVM vm, const char *class_name, void *real_instance, HSQOBJECT *instance, SQRELEASEHOOK release_hook, bool prepend_API_name)
 
{
 
	Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);
 

	
 
	int oldtop = sq_gettop(vm);
 

	
 
	/* First, find the class */
 
	sq_pushroottable(vm);
 

	
 
	if (prepend_API_name) {
 
		char *class_name2 = (char *)alloca(strlen(class_name) + strlen(engine->GetAPIName()) + 1);
 
		sprintf(class_name2, "%s%s", engine->GetAPIName(), class_name);
 
		size_t len = strlen(class_name) + strlen(engine->GetAPIName()) + 1;
 
		char *class_name2 = (char *)alloca(len);
 
		seprintf(class_name2, class_name2 + len - 1, "%s%s", engine->GetAPIName(), class_name);
 

	
 
		sq_pushstring(vm, OTTD2SQ(class_name2), -1);
 
	} else {
 
		sq_pushstring(vm, OTTD2SQ(class_name), -1);
 
	}
 

	
 
	if (SQ_FAILED(sq_get(vm, -2))) {
 
		DEBUG(misc, 0, "[squirrel] Failed to find class by the name '%s%s'", prepend_API_name ? engine->GetAPIName() : "", class_name);
 
		sq_settop(vm, oldtop);
 
		return false;
 
	}
 

	
src/script/squirrel_std.cpp
Show inline comments
 
@@ -8,25 +8,28 @@
 
 */
 

	
 
/** @file squirrel_std.cpp Implements the Squirrel Standard Function class */
 

	
 
#include <squirrel.h>
 
#include <sqstdmath.h>
 
#include "../stdafx.h"
 
#include "../debug.h"
 
#include "squirrel_std.hpp"
 
#include "../core/alloc_func.hpp"
 
#include "../core/math_func.hpp"
 

	
 
/* Due to the different characters for Squirrel, the scstrcat might be a simple
 
 * strcat which triggers the safeguard. But it isn't always a simple strcat. */
 
#include "../safeguards.h"
 
#undef strcat
 

	
 

	
 
SQInteger SquirrelStd::min(HSQUIRRELVM vm)
 
{
 
	SQInteger tmp1, tmp2;
 

	
 
	sq_getinteger(vm, 2, &tmp1);
 
	sq_getinteger(vm, 3, &tmp2);
 
	sq_pushinteger(vm, ::min(tmp1, tmp2));
 
	return 1;
 
}
 

	
src/settings.cpp
Show inline comments
 
@@ -1665,59 +1665,62 @@ void GetGRFPresetList(GRFPresetList *lis
 

	
 
	delete ini;
 
}
 

	
 
/**
 
 * Load a NewGRF configuration by preset-name.
 
 * @param config_name Name of the preset.
 
 * @return NewGRF configuration.
 
 * @see GetGRFPresetList
 
 */
 
GRFConfig *LoadGRFPresetFromConfig(const char *config_name)
 
{
 
	char *section = (char*)alloca(strlen(config_name) + 8);
 
	sprintf(section, "preset-%s", config_name);
 
	size_t len = strlen(config_name) + 8;
 
	char *section = (char*)alloca(len);
 
	seprintf(section, section + len - 1, "preset-%s", config_name);
 

	
 
	IniFile *ini = IniLoadConfig();
 
	GRFConfig *config = GRFLoadConfig(ini, section, false);
 
	delete ini;
 

	
 
	return config;
 
}
 

	
 
/**
 
 * Save a NewGRF configuration with a preset name.
 
 * @param config_name Name of the preset.
 
 * @param config      NewGRF configuration to save.
 
 * @see GetGRFPresetList
 
 */
 
void SaveGRFPresetToConfig(const char *config_name, GRFConfig *config)
 
{
 
	char *section = (char*)alloca(strlen(config_name) + 8);
 
	sprintf(section, "preset-%s", config_name);
 
	size_t len = strlen(config_name) + 8;
 
	char *section = (char*)alloca(len);
 
	seprintf(section, section + len - 1, "preset-%s", config_name);
 

	
 
	IniFile *ini = IniLoadConfig();
 
	GRFSaveConfig(ini, section, config);
 
	ini->SaveToDisk(_config_file);
 
	delete ini;
 
}
 

	
 
/**
 
 * Delete a NewGRF configuration by preset name.
 
 * @param config_name Name of the preset.
 
 */
 
void DeleteGRFPresetFromConfig(const char *config_name)
 
{
 
	char *section = (char*)alloca(strlen(config_name) + 8);
 
	sprintf(section, "preset-%s", config_name);
 
	size_t len = strlen(config_name) + 8;
 
	char *section = (char*)alloca(len);
 
	seprintf(section, section + len - 1, "preset-%s", config_name);
 

	
 
	IniFile *ini = IniLoadConfig();
 
	ini->RemoveGroup(section);
 
	ini->SaveToDisk(_config_file);
 
	delete ini;
 
}
 

	
 
const SettingDesc *GetSettingDescription(uint index)
 
{
 
	if (index >= lengthof(_settings)) return NULL;
 
	return &_settings[index];
 
}
0 comments (0 inline, 0 general)