Beispiel #1
0
void ProfileEngine::WriteReport(FILE *fp, ProfileReport *report, const char *name)
{
	size_t i, num;
	prof_atom_report_t *ar;
	char new_name[512];

	fprintf(fp, " <report name=\"%s\">\n", name);
	
	num = report->GetNumReports();
	for (i = 0; i < num; i++)
	{
		ar = report->GetReport(i);

		strncopy(new_name, ar->atom_name, sizeof(new_name));
		UTIL_ReplaceAll(new_name, sizeof(new_name), "<", "&lt;", true);
		UTIL_ReplaceAll(new_name, sizeof(new_name), ">", "&gt;", true);

		fprintf(fp, "  <item name=\"%s\" numcalls=\"%d\" mintime=\"%f\" maxtime=\"%f\" totaltime=\"%f\"/>\n", 
			new_name,
			ar->num_calls,
			ar->min_time,
			ar->max_time,
			ar->total_time);
	}

	fprintf(fp, " </report>\n");
}
Beispiel #2
0
static cell AMX_NATIVE_CALL replace_string(AMX *amx, cell *params)
{
	int len;
	size_t maxlength = (size_t)params[2];

	char *text = get_amxstring(amx, params[1], 0, len);
	const char *search = get_amxstring(amx, params[3], 1, len);
	const char *replace = get_amxstring(amx, params[4], 2, len);

	bool caseSensitive = params[5] ? true : false;

	if (search[0] == '\0')
	{
		LogError(amx, AMX_ERR_NATIVE, "Cannot replace searches of empty strings.");
		return -1;
	}

	int count = UTIL_ReplaceAll(text, maxlength + 1, search, replace, caseSensitive); // + EOS

	set_amxstring(amx, params[1], text, maxlength);

	return count;
}
Beispiel #3
0
void CPhraseFile::ReparseFile()
{
	if (m_pPhraseLookup)
	{
		sm_trie_destroy(m_pPhraseLookup);
	}
	m_pPhraseLookup = sm_trie_create();

	m_LangCount = m_pTranslator->GetLanguageCount();

	if (!m_LangCount)
	{
		return;
	}

	SMCError err;
	char path[PLATFORM_MAX_PATH];
	g_SourceMod.BuildPath(Path_SM, path, PLATFORM_MAX_PATH, "translations/%s", m_File.c_str());

	//backwards compatibility shim
	/* :HACKHACK: Change .cfg/.txt and vice versa for compatibility */
	if (!g_LibSys.PathExists(path))
	{
		if (m_File.compare("common.cfg") == 0)
		{
			UTIL_ReplaceAll(path, sizeof(path), "common.cfg", "common.phrases.txt");
		} else if (strstr(path, ".cfg")) {
			UTIL_ReplaceAll(path, sizeof(path), ".cfg", ".txt");
		} else if (strstr(path, ".txt")) {
			UTIL_ReplaceAll(path, sizeof(path), ".txt", ".cfg");
		}
	}

	SMCStates states;

	if ((err=textparsers->ParseFile_SMC(path, this, &states)) != SMCError_Okay)
	{
		const char *msg = textparsers->GetSMCErrorString(err);
		if (!msg)
		{
			msg = m_ParseError.c_str();
		}

		g_Logger.LogError("[SM] Fatal error encountered parsing translation file \"%s\"", m_File.c_str());
		g_Logger.LogError("[SM] Error (line %d, column %d): %s", states.line, states.col, msg);
	}

	const char *code;
	for (unsigned int i = 1; i < m_LangCount; i++)
	{
		if (!m_pTranslator->GetLanguageInfo(i, &code, NULL))
		{
			continue;
		}

		g_SourceMod.BuildPath(Path_SM, 
			path,
			PLATFORM_MAX_PATH,
			"translations/%s/%s",
			code,
			m_File.c_str());

		/* Speculatively load these. */
		if (!g_LibSys.PathExists(path))
		{
			continue;
		}

		if ((err=textparsers->ParseFile_SMC(path, this, &states)) != SMCError_Okay)
		{
			const char *msg = textparsers->GetSMCErrorString(err);
			if (!msg)
			{
				msg = m_ParseError.c_str();
			}

			g_Logger.LogError("[SM] Fatal error encountered parsing translation file \"%s/%s\"", 
				code, 
				m_File.c_str());
			g_Logger.LogError("[SM] Error (line %d, column %d): %s",
				states.line,
				states.col,
				msg);
		}
	}
}