示例#1
0
void plResponderModifier::ILog(uint32_t color, const char* format, ...)
{
#ifdef STATUS_LOG
    if (!gLog)
        gLog = plStatusLogMgr::GetInstance().CreateStatusLog(15, "Responder", plStatusLog::kFilledBackground | plStatusLog::kDeleteForMe | plStatusLog::kDontWriteFile | plStatusLog::kAlignToTop);

    if (!format || *format == '\0')
        return;

    ST::string keyName = GetKeyName();

    // Make sure this key isn't in our list of keys to deny
    for (const auto& it : gNoLogStrings) {
        if (keyName.starts_with(it))
            return;
    }

    // Format the log text
    char buf[256];
    va_list args;
    va_start(args, format);
    int numWritten = hsVsnprintf(buf, sizeof(buf), format, args);
    hsAssert(numWritten > 0, "Buffer too small");
    va_end(args);

    // Strip the redundant part off the key name
    ST_ssize_t modPos = keyName.find("_ResponderModifier");
    if (modPos != -1)
        keyName = keyName.left(modPos);

    ST::string logLine = ST::format("{}: {}", keyName, buf);
    gLog->AddLine(logLine.c_str(), color);
#endif // STATUS_LOG
}
示例#2
0
//===========================================================================
unsigned StrPrintf (char * dest, unsigned count, const char format[], ...) {
    va_list argList;
    va_start(argList, format);
    int result = hsVsnprintf((char *)dest, count, (const char *)format, argList);
    va_end(argList);
    return IStrPrintfValidate(dest, count, result);
}
示例#3
0
bool formatv(std::string & out, const char * fmt, va_list args)
{
#define kBufSz 2048

    char buf[kBufSz];
    char * pbuf = buf;
    int len = 0;
    int attempts = 0;
    bool success = false;
    const int kMaxAttempts = 40;

    do
    {
        int maxlen = kBufSz*attempts+kBufSz-1;
        len = hsVsnprintf(pbuf,maxlen,fmt,args);
        attempts++;
        success = (len>=0 && len<maxlen);
        if (!success)
        {
            if (pbuf!=buf)
                delete [] pbuf;
            pbuf = new char[kBufSz+kBufSz*attempts];
        }
    }
    while (!success && attempts<kMaxAttempts);

    if (success)
    {
        pbuf[len] = '\0';
        out = pbuf;
    }

    if (success)
    {
        pbuf[len] = '\0';
        out = pbuf;
    }
    else
    {
        out = "";
        if ( attempts==kMaxAttempts )
        {
            hsDebugMessage( "xtl::formatv - Max reallocs occurred while formatting string. Result is likely truncated!", 0 );
        }
    }

    if (pbuf!=buf)
        delete [] pbuf;

    return success;
}
示例#4
0
//===========================================================================
unsigned StrPrintfV (char * dest, unsigned count, const char format[], va_list args) {
    int result = hsVsnprintf(dest, count, format, args);
    return IStrPrintfValidate(dest, count, result);
}