All pastes #435242 Raw Edit

Debug functions

public text v1 · immutable
·published 2007-04-11 21:03 UTC
rendered paste body

/*----------------------------------------------------------------------------*-
Function:
	Text_GetLinear
Params:
	identifier[] - The string to find the text for.
	Language:languageID - The language to get the text for.
Return:
	text[]
Notes:
	Mainly a debug function.  Searches through the entire array using normal
	strcmp and one by one searching methods.  Can be around 10x slower than
	using the hashed binary search methods.  Note: if the required string is
	the first in the array in which case this is marginally faster, but so
	fractionally faster and so rarely that it shouldn't be used at all.
-*----------------------------------------------------------------------------*/

#if defined _DEBUG

stock Text_GetTextLinear(identifier[], Language:languageID)
{
	new
		ret[MAX_TEXT_ENTRY] = "*** Internal Error! No text or errors found";
	for (new i = 0; i < MAX_TEXT; i++)
	{
		if (!strcmp(g_sNameTable[i][E_TEXT_POINTERS_NAME], identifier))
		{
			new
				index = g_sNameTable[i][E_TEXT_POINTERS_POINTER][languageID];
			if (index != TEXT_NO_TEXT) return g_sTextTable[languageID][index];
		}
	}
	return ret;
}

#endif


/*----------------------------------------------------------------------------*-
Function:
	Text_PrintAll
Params:
	-
Return:
	-
Notes:
	Debug function.
-*----------------------------------------------------------------------------*/

#if defined _DEBUG

Text_PrintAll()
{
	for (new i = 0; i < MAX_TEXT; i++)
	{
		new
			yes = g_sNameTable[i][E_TEXT_POINTERS_NAME][0];
		if (!yes) continue;
		new
			str[MAX_STRING];
		format(str, sizeof (str), "%s (%d): ", g_sNameTable[i][E_TEXT_POINTERS_NAME], bernstein(g_sNameTable[i][E_TEXT_POINTERS_NAME]));
		for (new Language:j; j < MAX_LANGUAGES; j++)
		{
			format(str, sizeof (str), "%s%s, ", str, g_sNameTable[i][E_TEXT_POINTERS_POINTER][j] == TEXT_NO_POINTERS ? "NONE" : g_sTextTable[j][g_sNameTable[i][E_TEXT_POINTERS_POINTER][j]]);
		}
		print(str);
	}
}

#endif