本文整理汇总了C++中UTIL_Format函数的典型用法代码示例。如果您正苦于以下问题:C++ UTIL_Format函数的具体用法?C++ UTIL_Format怎么用?C++ UTIL_Format使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UTIL_Format函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MapChangeData
void NextMapManager::OnSourceModLevelChange( const char *mapName )
{
/* Skip the first 'mapchange' when the server starts up */
if (m_tempChangeInfo.startTime != 0)
{
if (strcmp(mapName, m_tempChangeInfo.m_mapName) == 0)
{
/* The map change was as we expected */
m_mapHistory.push_back(new MapChangeData(lastMap, m_tempChangeInfo.m_changeReason, m_tempChangeInfo.startTime));
}
else
{
/* Something intercepted the mapchange */
char newReason[255];
UTIL_Format(newReason, sizeof(newReason), "%s (Map overridden)", m_tempChangeInfo.m_changeReason);
m_mapHistory.push_back(new MapChangeData(lastMap, newReason, m_tempChangeInfo.startTime));
}
/* TODO: Should this be customizable? */
if (m_mapHistory.size() > 20)
{
SourceHook::List<MapChangeData *>::iterator iter;
iter = m_mapHistory.begin();
delete (MapChangeData *)*iter;
m_mapHistory.erase(iter);
}
}
m_tempChangeInfo.m_mapName[0] ='\0';
m_tempChangeInfo.m_changeReason[0] = '\0';
m_tempChangeInfo.startTime = time(NULL);
UTIL_Format(lastMap, sizeof(lastMap), mapName);
}
示例2: MAKELANGID
void LibrarySystem::GetPlatformErrorEx(int code, char *error, size_t maxlength)
{
if (error && maxlength)
{
#if defined PLATFORM_WINDOWS
if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
(DWORD)code,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)error,
maxlength,
NULL) == 0)
{
UTIL_Format(error, maxlength, "error code %08x", code);
}
#elif defined PLATFORM_LINUX
const char *ae = strerror_r(code, error, maxlength);
if (ae != error)
{
UTIL_Format(error, maxlength, "%s", ae);
}
#elif defined PLATFORM_POSIX
strerror_r(code, error, maxlength);
#endif
}
}
示例3: strlen
void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLength)
{
const char *filename = "";
char native[sNAMEMAX+1];
CList<CScript,AMX*>::iterator a = g_loadedscripts.find(amx);
if (a)
filename = (*a).getName();
size_t len = strlen(filename);
for (size_t i=len-1; i<len; i--)
{
if ((filename[i] == '/' || filename[i] == '\\') && i != len - 1)
{
filename = &(filename[i+1]);
break;
}
}
if (error == AMX_ERR_EXIT)
{
UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - %s", error, filename, GenericError(AMX_ERR_EXIT));
} else if (error == AMX_ERR_NATIVE) {
amx_GetNative(amx, reinterpret_cast<long>(amx->usertags[UT_NATIVE]), native);
UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") (native \"%s\") - debug not enabled!", error, filename, native);
} else {
UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - debug not enabled!", error, filename);
}
}
示例4: UTIL_Format
CDirectory::CDirectory(const char *path)
{
#if defined PLATFORM_WINDOWS
char newpath[PLATFORM_MAX_PATH];
UTIL_Format(newpath, sizeof(newpath) - 1, "%s\\*.*", path);
m_dir = FindFirstFile(newpath, &m_fd);
if (!IsValid())
{
m_fd.cFileName[0] = '\0';
}
#elif defined PLATFORM_POSIX
m_dir = opendir(path);
if (IsValid())
{
m_ep = readdir(m_dir); // TODO: we need to read past "." and ".."!
UTIL_Format(m_origpath, sizeof(m_origpath) - 1, "%s", path);
}
else
{
m_ep = nullptr;
}
#endif
}
示例5: fopen
SMCError TextParsers::ParseSMCFile(const char *file,
ITextListener_SMC *smc_listener,
SMCStates *states,
char *buffer,
size_t maxsize)
{
const char *errstr;
FILE *fp = fopen(file, "rt");
if (fp == NULL)
{
char error[256] = "unknown";
if (states != NULL)
{
states->line = 0;
states->col = 0;
}
/*libsys->GetPlatformError(error, sizeof(error));*/
UTIL_Format(buffer, maxsize, "File could not be opened: %s", error);
return SMCError_StreamOpen;
}
SMCError result = ParseStream_SMC(fp, FileStreamReader, smc_listener, states);
fclose(fp);
errstr = GetSMCErrorString(result);
UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
return result;
}
示例6: RETURN_META
void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const char *video, bool bLongLoading)
#endif
{
if (g_forcedChange)
{
g_Logger.LogMessage("[SM] Changed map to \"%s\"", map);
RETURN_META(MRES_IGNORED);
}
const char *newmap = sm_nextmap.GetString();
if (newmap[0] == 0 || !engine->IsMapValid(newmap))
{
RETURN_META(MRES_IGNORED);
}
g_Logger.LogMessage("[SM] Changed map to \"%s\"", newmap);
UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), newmap);
UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change");
#if SOURCE_ENGINE != SE_DARKMESSIAH
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown));
#else
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown, video, bLongLoading));
#endif
}
示例7: UTIL_Format
METAMOD_PLUGIN *_GetPluginPtr(const char *path, int fail_api)
{
METAMOD_FN_ORIG_LOAD fn;
METAMOD_PLUGIN *pl;
int ret;
if (!(g_hCore=openlib(path)))
{
#if defined __linux__ || defined __APPLE__
UTIL_Format(s_FailPlugin.error_buffer,
sizeof(s_FailPlugin.error_buffer),
"%s",
dlerror());
#else
DWORD err = GetLastError();
if (FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
s_FailPlugin.error_buffer,
sizeof(s_FailPlugin.error_buffer),
NULL)
== 0)
{
UTIL_Format(s_FailPlugin.error_buffer,
sizeof(s_FailPlugin.error_buffer),
"unknown error %x",
err);
}
#endif
s_FailPlugin.fail_version = fail_api;
return (METAMOD_PLUGIN *)&s_FailPlugin;
}
if (!(fn=(METAMOD_FN_ORIG_LOAD)findsym(g_hCore, "CreateInterface")))
{
goto error;
}
pl = (METAMOD_PLUGIN *)fn(METAMOD_PLAPI_NAME, &ret);
if (!pl)
{
goto error;
}
return pl;
error:
closelib(g_hCore);
g_hCore = NULL;
return NULL;
}
示例8: UTIL_Format
void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeReason )
{
/* Store the mapname and reason */
UTIL_Format(m_tempChangeInfo.m_mapName, sizeof(m_tempChangeInfo.m_mapName), mapName);
UTIL_Format(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), changeReason);
/* Change level and skip our hook */
g_forcedChange = true;
engine->ChangeLevel(mapName, NULL);
g_forcedChange = false;
}
示例9: PSKeyValueF
cell PSKeyValueF(const char *name, AMX *amx, cell *params)
{
if (params[1]==0)
{
MF_LogError(amx,AMX_ERR_NATIVE,"Invalid particle system handle provided!");
return 0;
}
KeyValueData kvd;
char StrData[1024];
UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2]));
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
kvd.szValue=&StrData[0];
kvd.fHandled=0;
//printf("\"%s\" \"%s\"\n",kvd.szKeyName,kvd.szValue);
MDLL_KeyValue(reinterpret_cast<edict_t *>(params[1]),&kvd);
return 1;
}
示例10: UTIL_Format
unsigned int CValveMenuDisplay::DrawItem(const ItemDrawInfo &item)
{
if (m_NextPos > 9 || !CanDrawItem(item.style))
{
return 0;
}
/**
* For these cases we can't draw anything at all, but
* we can at least bump the position since we were explicitly asked to.
*/
if ((item.style & ITEMDRAW_NOTEXT)
|| (item.style & ITEMDRAW_SPACER))
{
return m_NextPos++;
}
char buffer[255];
UTIL_Format(buffer, sizeof(buffer), "%d. %s", m_NextPos, item.display);
KeyValues *ki = m_pKv->FindKey(g_OptionNumTable[m_NextPos], true);
ki->SetString("command", g_OptionCmdTable[m_NextPos]);
ki->SetString("msg", buffer);
return m_NextPos++;
}
示例11: amx_geoip_region_code
// native geoip_region_code(const ip[], result[], len);
static cell AMX_NATIVE_CALL amx_geoip_region_code(AMX *amx, cell *params)
{
int length;
int finalLength = 0;
char code[12]; // This should be largely enough to hold xx-yyyy and more if needed.
char *ip = stripPort(MF_GetAmxString(amx, params[1], 0, &length));
const char *pathCountry[] = { "country", "iso_code", NULL };
const char *countryCode = lookupString(ip, pathCountry, &length);
if (countryCode)
{
finalLength = length + 1; // + 1 for dash.
UTIL_Format(code, finalLength + 1, "%s-", countryCode); // + EOS.
const char *pathRegion[] = { "subdivisions", "0", "iso_code", NULL }; // First result.
const char *regionCode = lookupString(ip, pathRegion, &length);
if (regionCode)
{
finalLength += length;
strncat(code, regionCode, length);
}
else
{
finalLength = 0;
}
}
return MF_SetAmxString(amx, params[2], finalLength ? code : "", ke::Min(finalLength, params[3]));
}
示例12: strlen
EXPORT void *CreateInterface(const char *pName, int *pReturnCode)
{
if (strcmp(pName, METAMOD_PLAPI_NAME) == 0)
{
char our_file[256];
if (!GetFileOfAddress((void *)CreateInterface_MMS, our_file, sizeof(our_file)))
{
return NULL;
}
/* Go backwards and get the first token */
size_t len = strlen(our_file);
for (size_t i = len; i-- > 0;)
{
if (IsPathSepChar(our_file[i]))
{
our_file[i] = '\0';
break;
}
}
char new_file[256];
UTIL_Format(new_file, sizeof(new_file), "%s" PATH_SEP_CHAR MMS_1_4_EP1_FILE, our_file);
return TryAndLoadLibrary(new_file);
}
return NULL;
}
示例13: UTIL_Format
ConfigResult Translator::OnSourceModConfigChanged(const char *key,
const char *value,
ConfigSource source,
char *error,
size_t maxlength)
{
if (strcasecmp(key, "ServerLang") == 0)
{
if (source == ConfigSource_Console)
{
unsigned int index;
if (!GetLanguageByCode(value, &index))
{
UTIL_Format(error, maxlength, "Language code \"%s\" is not registered", value);
return ConfigResult_Reject;
}
m_ServerLang = index;
} else {
strncopy(m_InitialLang, value, sizeof(m_InitialLang));
}
return ConfigResult_Accept;
}
return ConfigResult_Ignore;
}
示例14: BuildPath
void SourceModBase::DoGlobalPluginLoads()
{
char config_path[PLATFORM_MAX_PATH];
char plugins_path[PLATFORM_MAX_PATH];
BuildPath(Path_SM, config_path,
sizeof(config_path),
"configs/plugin_settings.cfg");
BuildPath(Path_SM, plugins_path,
sizeof(plugins_path),
"plugins");
/* Load any auto extensions */
extsys->TryAutoload();
/* Fire the extensions ready message */
g_SMAPI->MetaFactory(SOURCEMOD_NOTICE_EXTENSIONS, NULL, NULL);
/* Load any game extension */
const char *game_ext;
if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL)
{
char path[PLATFORM_MAX_PATH];
UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext);
extsys->LoadAutoExtension(path);
}
scripts->LoadAll(config_path, plugins_path);
}
示例15: UTIL_Format
IPhraseFile *CPhraseCollection::AddPhraseFile(const char *filename)
{
size_t i;
unsigned int fid;
IPhraseFile *pFile;
char full_name[PLATFORM_MAX_PATH];
/* No compat shim here. The user should have read the doc. */
UTIL_Format(full_name, sizeof(full_name), "%s.txt", filename);
fid = g_Translator.FindOrAddPhraseFile(full_name);
pFile = g_Translator.GetFileByIndex(fid);
for (i = 0; i < m_Files.size(); i++)
{
if (m_Files[i] == pFile)
{
return pFile;
}
}
m_Files.push_back(pFile);
return pFile;
}