Changeset - r12499:2e177e6e0453
[Not reviewed]
master
0 2 0
alberth - 15 years ago 2009-07-25 07:49:49
alberth@openttd.org
(svn r16946) -Doc: Adding docs for some string parameter manipulation functions.
2 files changed with 41 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/strings.cpp
Show inline comments
 
@@ -26,26 +26,26 @@
 
#include "core/endian_func.hpp"
 
#include "date_func.h"
 
#include "vehicle_base.h"
 
#include "company_func.h"
 
#include "video/video_driver.hpp"
 
#include "engine_base.h"
 
#include "strgen/strgen.h"
 
#include "gfx_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/control_codes.h"
 

	
 
DynamicLanguages _dynlang;
 
uint64 _decode_parameters[20];
 
DynamicLanguages _dynlang;     ///< Language information of the program.
 
uint64 _decode_parameters[20]; ///< Global array of string parameters. To access, use #SetDParam.
 

	
 
static char *StationGetSpecialString(char *buff, int x, const char *last);
 
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last);
 
static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const char *last);
 

	
 
static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last);
 

	
 
struct LanguagePack : public LanguagePackHeader {
 
	char data[]; // list of strings
 
};
 

	
 
static char **_langpack_offs;
 
@@ -162,24 +162,28 @@ char *InlineString(char *buf, StringID s
 
}
 

	
 

	
 
/** This function is used to "bind" a C string to a OpenTTD dparam slot.
 
 * @param n slot of the string
 
 * @param str string to bind
 
 */
 
void SetDParamStr(uint n, const char *str)
 
{
 
	SetDParam(n, (uint64)(size_t)str);
 
}
 

	
 
/**
 
 * Shift the string parameters in the global string parameter array by \a amount positions, making room at the beginning.
 
 * @param amount Number of positions to shift.
 
 */
 
void InjectDParam(uint amount)
 
{
 
	assert((uint)amount < lengthof(_decode_parameters));
 
	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint64));
 
}
 

	
 
static char *FormatNumber(char *buff, int64 number, const char *last, const char *separator)
 
{
 
	uint64 divisor = 10000000000000000000ULL;
 
	uint64 quot;
 
	int i;
 
	uint64 tot;
src/strings_func.h
Show inline comments
 
@@ -4,58 +4,93 @@
 

	
 
#ifndef STRINGS_FUNC_H
 
#define STRINGS_FUNC_H
 

	
 
#include "strings_type.h"
 

	
 
char *InlineString(char *buf, StringID string);
 
char *GetString(char *buffr, StringID string, const char *last);
 
const char *GetStringPtr(StringID string);
 

	
 
void InjectDParam(uint amount);
 

	
 
/**
 
 * Set a string parameter \a v at index \a n in a given array \a s.
 
 * @param s Array of string parameters.
 
 * @param n Index of the string parameter.
 
 * @param v Value of the string parameter.
 
 */
 
static inline void SetDParamX(uint64 *s, uint n, uint64 v)
 
{
 
	s[n] = v;
 
}
 

	
 
/**
 
 * Set a string parameter \a v at index \a n in the global string parameter array.
 
 * @param n Index of the string parameter.
 
 * @param v Value of the string parameter.
 
 */
 
static inline void SetDParam(uint n, uint64 v)
 
{
 
	extern uint64 _decode_parameters[20];
 

	
 
	assert(n < lengthof(_decode_parameters));
 
	_decode_parameters[n] = v;
 
}
 

	
 
void SetDParamStr(uint n, const char *str);
 

	
 
/**
 
 * Get the current string parameter at index \a n from parameter array \a s.
 
 * @param s Array of string parameters.
 
 * @param n Index of the string parameter.
 
 * @return Value of the requested string parameter.
 
 */
 
static inline uint64 GetDParamX(const uint64 *s, uint n)
 
{
 
	return s[n];
 
}
 

	
 
/**
 
 * Get the current string parameter at index \a n from the global string parameter array.
 
 * @param s Array of string parameters.
 
 * @param n Index of the string parameter.
 
 * @return Value of the requested string parameter.
 
 */
 
static inline uint64 GetDParam(uint n)
 
{
 
	extern uint64 _decode_parameters[20];
 

	
 
	assert(n < lengthof(_decode_parameters));
 
	return _decode_parameters[n];
 
}
 

	
 
/**
 
 * Copy \a num string parameters from array \a src into the global string parameter array.
 
 * @param offs Index in the global array to copy the first string parameter to.
 
 * @param src  Source array of string parameters.
 
 * @param num  Number of string parameters to copy.
 
 */
 
static inline void CopyInDParam(int offs, const uint64 *src, int num)
 
{
 
	extern uint64 _decode_parameters[20];
 
	memcpy(_decode_parameters + offs, src, sizeof(uint64) * (num));
 
}
 

	
 
/**
 
 * Copy \a num string parameters from the global string parameter array to the \a dst array.
 
 * @param dst  Destination array of string parameters.
 
 * @param offs Index in the global array to copy the first string parameter from.
 
 * @param num  Number of string parameters to copy.
 
 */
 
static inline void CopyOutDParam(uint64 *dst, int offs, int num)
 
{
 
	extern uint64 _decode_parameters[20];
 
	memcpy(dst, _decode_parameters + offs, sizeof(uint64) * (num));
 
}
 

	
 
extern DynamicLanguages _dynlang; // defined in strings.cpp
 

	
 
bool ReadLanguagePack(int index);
 
void InitializeLanguagePacks();
 

	
 
int CDECL StringIDSorter(const void *a, const void *b);
0 comments (0 inline, 0 general)