Beispiel #1
0
// 
// warning -- this function is implemented twice for ansi applications
// linking to the unicode library
// 
void WINAPI DbgLogInfo(DWORD Type,DWORD Level,const CHAR *pFormat,...)
{
    /* Check the current level for this type combination */

    BOOL bAccept = DbgCheckModuleLevel(Type,Level);
    if (bAccept == FALSE) {
        return;
    }

    TCHAR szInfo[2000];

    /* Format the variable length parameter list */

    va_list va;
    va_start(va, pFormat);

    lstrcpy(szInfo,m_ModuleName);
    wsprintf(szInfo + lstrlen(szInfo),
             TEXT("(tid %x) %8d : "),
             GetCurrentThreadId(), timeGetTime() - dwTimeOffset);

    CHAR szInfoA[2000];
    WideCharToMultiByte(CP_ACP, 0, szInfo, -1, szInfoA, NUMELMS(szInfoA), 0, 0);

    wvsprintfA(szInfoA + lstrlenA(szInfoA), pFormat, va);
    lstrcatA(szInfoA, "\r\n");

    WCHAR wszOutString[2000];
    MultiByteToWideChar(CP_ACP, 0, szInfoA, -1, wszOutString, NUMELMS(wszOutString));
    DbgOutString(wszOutString);

    va_end(va);
}
Beispiel #2
0
void trace(const char* fmt, ...){
	char buf [256];
	va_list va;
	va_start(va,fmt);
	int n = wvsprintfA(buf,fmt,va);
	va_end(va);
	if(n>0)WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),buf,n,(DWORD*)&n,0);
}
Beispiel #3
0
int
apxDisplayError(
    BOOL    bDisplay,
    LPCSTR  szFile,
    DWORD   dwLine,
    LPCSTR  szFormat,
    ...)
{
    va_list args;
    CHAR    buffer[1024+16];
    CHAR    sysbuf[2048];
    int     len = 0, nRet;
    LPCSTR  f = szFile;
    DWORD   err = GetLastError(); /* save the last Error code */
    if (f) {
        f = (szFile + lstrlenA(szFile) - 1);    
        while(f != szFile && '\\' != *f && '/' != *f)
            f--;
        if(f != szFile)
            f++;
    }
    sysbuf[0] = '\0';
    if (err != ERROR_SUCCESS) {
        len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | 
                             FORMAT_MESSAGE_IGNORE_INSERTS,
                             NULL,
                             err,
                             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                             sysbuf,
                             1000,
                             NULL);
        sysbuf[len] = 0;
    }
    if (szFormat) {
        va_start(args, szFormat);
        wvsprintfA(buffer, szFormat, args);
        va_end(args);
        if (f) {
            CHAR sb[MAX_PATH+1];
            wsprintfA(sb, "\n%s (%d)", f, dwLine);
            lstrcatA(sysbuf, sb);
        }
        lstrcatA(sysbuf, "\n");
        lstrcatA(sysbuf, buffer);
    }
    len = lstrlenA(sysbuf);
#ifdef _DEBUG_FULL
    OutputDebugStringA(sysbuf);
#endif
    if (len > 0 && bDisplay) {
        nRet = MessageBoxA(NULL, sysbuf, 
                           "Application System Error",
                           MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
    }
    /* Restore the last Error code */
    SetLastError(err);
    return len;
}
/* a hook for a function that redirects all VM messages. */
static jint JNICALL __apxJniVfprintf(FILE *fp, const char *format, va_list args)
{
    jint rv;
    CHAR sBuf[1024+16];
    rv = wvsprintfA(sBuf, format, args);
    if (apxLogWrite(APXLOG_MARK_INFO "%s", sBuf) == 0)
        fputs(sBuf, stdout);
    return rv;
}
Beispiel #5
0
int vprintf(const char *format, va_list args)
{
	char szBuff[1024];

	int retValue = wvsprintfA(szBuff, format, args);

	fwrite(szBuff, retValue, 1, stdout);

	return retValue;
}
Beispiel #6
0
void Parse_Print(LPCSTR   lpFmt,...)
{	
	CHAR  szBuf[1024];
	va_list  argList;
	memset(szBuf,0,1024);
	va_start(argList,  lpFmt); 
	wvsprintfA(szBuf,lpFmt,  argList);
	va_end(argList); 
	
	printf(szBuf);
}
Beispiel #7
0
static UINT SIOFmtPut(LPCSTR Fmt, ...)
{
	UINT cch;
	char buf[150]; // Plenty for our simple strings
	va_list val;
	va_start(val, Fmt);
	cch = wvsprintfA(buf, Fmt, val);
	cch = SIOPut(buf, cch);
	va_end(val);
	return cch;
}
Beispiel #8
0
static void DbgPrint_s(const char* format, ...)
{       
	static char dbg_msg_buff[0x1000]; 
        if (format)
        {
                va_list args;
                va_start(args, format);
                int len = wvsprintfA(dbg_msg_buff, format, args);
                va_end(args);
		OutputDebugStringA(dbg_msg_buff);
        }
}
Beispiel #9
0
void DebugOut(const CHAR* str, ...) {
	CHAR buff[1024];
	va_list parameters;
	va_start(parameters, str);
	wvsprintfA(buff, str, parameters);
	va_end(parameters);

	CHAR buff2[1024];
	strcpy_s(buff2, DEBUG_PREFIX);
	strcat_s(buff2, buff);

	OutputDebugStringA(buff2);
}
Beispiel #10
0
VOID DbgMsg( CHAR *MsgFormat, ... )
{
    CHAR   MsgText[256];
    va_list vargs;

    va_start( vargs, MsgFormat );
    wvsprintfA( MsgText, MsgFormat, vargs );
    va_end( vargs );

    if( *MsgText )
        OutputDebugStringA( "PRINTMAN: " );
    OutputDebugStringA( MsgText );
}
Beispiel #11
0
void win_traceA(const char *pszFmt, ...){
	CHAR tchbuf[1024] = {'$',0};
	va_list argList = NULL;
	va_start(argList, pszFmt);
	wvsprintfA(&tchbuf[1], pszFmt, argList);
	va_end(argList);
	lstrcatA(tchbuf, "\r\n");
	if(IsDebuggerPresent()){
		OutputDebugStringA(tchbuf);
	}else{
		DWORD dwWrt;
		WriteConsoleA(GetStdHandle(STD_ERROR_HANDLE), tchbuf, lstrlenA(tchbuf), &dwWrt, NULL);
	}
}
Beispiel #12
0
int WINAPIV wsprintfWInternal(LPWSTR wszOut, LPCWSTR pszFmt, ...) {
    char fmt[256]; // !!!
    char ach[256]; // !!!
    int i;

    va_list va;
    va_start(va, pszFmt);
    WideCharToMultiByte(GetACP(), 0, pszFmt, -1, fmt, 256, NULL, NULL);
    i = wvsprintfA(ach, fmt, va);
    va_end(va);

    MultiByteToWideChar(CP_ACP, 0, ach, -1, wszOut, i+1);

    return i;
}
Beispiel #13
0
static void vprintlog(HANDLE h, const char *format, va_list ap)
{
    char buf[1024];
        /* wvsprintf is only safe with a 1024 byte buffer */
    size_t len;
    DWORD BytesTransferred;

    wvsprintfA(buf, format, ap);
    buf[sizeof buf - 1] = '\0';

    len = lstrlenA(buf);
    buf[len++] = '\n';

    WriteFile(h, buf, (DWORD)len, &BytesTransferred, 0);
}
Beispiel #14
0
void log_line(char *format, ...)
{
#ifdef DEBUG
	char tmp[10240];
	va_list valist;
	va_start(valist, format);
	wvsprintfA(tmp, format, valist);
	va_end(valist);
	static FILE * f = fopen("F:\\e3d.log", "wb");
	if (f)
	{
		fprintf(f, "%s(%d)\r\n", tmp, GetCurrentThreadId());
		fflush(f);
	}
#endif
}
Beispiel #15
0
void _cdecl _DebugWriteA( LPCSTR szFormat, ... )
{
	if( szFormat != NULL )
	{
		char szBuffer[4096];

		va_list val;

		va_start( val,szFormat );
		wvsprintfA( szBuffer, szFormat, val );
		va_end( val );
		szBuffer[sizeof(szBuffer)-1] = '\0';

		_DebugAnsiFileWrite( szBuffer );
	}
	else
        _DebugAnsiFileWrite( NULL );
}
Beispiel #16
0
ErrRet NotifyAssert(const char* condition, const char* fileName, int lineNumber, const char* formats, ...)
{
    char szBuffer[4096];

    va_list args;
    va_start(args, formats);
//		wvsprintf(szBuffer, formats, args);
    wvsprintfA(szBuffer, formats, args);
    va_end(args);

    std::string filenameStr = fileName;

    // pass the data on to the message box
    ErrRet result = DisplayError("Assert Failed!",
                                 condition,
                                 szBuffer,
                                 filenameStr.c_str(),
                                 lineNumber);
    return result;
}
Beispiel #17
0
int lsh_com_err_proc (LPSTR whoami, long code,
                              LPSTR fmt, va_list args)
{
    int retval;
    HWND hOldFocus;
    char buf[1024], *cp;
    WORD mbformat = MB_OK | MB_ICONEXCLAMATION;

    cp = buf;
    memset(buf, '\0', sizeof(buf));
    cp[0] = '\0';

    if (code)
    {
        err_describe(buf, code);
        while (*cp)
            cp++;
    }

    if (fmt)
    {
        if (fmt[0] == '%' && fmt[1] == 'b')
	{
            fmt += 2;
            mbformat = va_arg(args, WORD);
            /* if the first arg is a %b, we use it for the message
               box MB_??? flags. */
	}
        if (code)
	{
            *cp++ = '\n';
            *cp++ = '\n';
	}
        wvsprintfA((LPSTR)cp, fmt, args);
    }
    hOldFocus = GetFocus();
    retval = MessageBoxA(/*GetRootParent(hOldFocus)*/NULL, buf, whoami,
                        mbformat | MB_ICONHAND | MB_TASKMODAL);
    SetFocus(hOldFocus);
    return retval;
}
Beispiel #18
0
void logPrint(const char * format, ...)
{
	HANDLE file = CreateFileA(LogFile, FILE_APPEND_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,  FILE_ATTRIBUTE_NORMAL, NULL);

	if (file && file != INVALID_HANDLE_VALUE)
	{
		va_list arg;
		va_start(arg, format);

		char str[1024] = {0};

        int shift = wsprintfA(str, "[%i.%03i]  ", GetTickCount() / 1000, GetTickCount() % 1000);

		wvsprintfA(str + shift - 1, format, arg);

		va_end(arg);

		DWORD resultLen = strlen(str);

        WriteFile(file, str, resultLen, &resultLen, NULL);

		CloseHandle(file);
	}
}
Beispiel #19
0
int
apxLogWrite(
    HANDLE  hFile,
    DWORD   dwLevel,
    BOOL    bTimeStamp,
    LPCSTR  szFile,
    DWORD   dwLine,
    LPCSTR  szFormat,
    ...)
{
    va_list args;
    CHAR    buffer[1024+32] = "";
    LPSTR   szBp;
    int     len = 0;
    LPCSTR  f = szFile;
    CHAR    sb[SIZ_PATHLEN];
    DWORD   wr;
    DWORD   err;
    BOOL    dolock = TRUE;
    apx_logfile_st *lf = (apx_logfile_st *)hFile;

    err = GetLastError(); /* save the last Error code */
    if (IS_INVALID_HANDLE(lf))
        lf = _st_sys_loghandle;
    if (IS_INVALID_HANDLE(lf)) {
        lf = &_st_sys_errhandle;
        lf->hFile = GetStdHandle(STD_ERROR_HANDLE);
        dolock = FALSE;
    }
    if (dwLevel < lf->dwLogLevel)
        return 0;
    if (f && (lf->dwLogLevel == APXLOG_LEVEL_DEBUG || dwLevel == APXLOG_LEVEL_ERROR)) {
        f = (szFile + lstrlenA(szFile) - 1);
        while(f != szFile && '\\' != *f && '/' != *f)
            f--;
        if(f != szFile)
            f++;
    }
    else
        f = NULL;
    szBp = buffer;
    if (!szFormat) {
        if (err == 0) {
            lstrcpyA(szBp, "Unknown error code");
            if (dwLevel == APXLOG_LEVEL_ERROR) {
                szBp += 18;
                wsprintfA(szBp, " occured in (%s:%d) ", f, dwLine);
            }
        }
        else
            FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
                           FORMAT_MESSAGE_IGNORE_INSERTS,
                           NULL,
                           err,
                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                           szBp,
                           1000,
                           NULL);
    }
    else {
        va_start(args, szFormat);
        wvsprintfA(szBp, szFormat, args);
        va_end(args);
    }
    len = lstrlenA(buffer);
    if (len > 0) {
        /* Remove trailing line separator */
        if (buffer[len - 1] == '\n')
            buffer[--len] = '\0';
        if (len > 0 && buffer[len - 1] == '\r')
            buffer[--len] = '\0';
        if (!IS_INVALID_HANDLE(lf->hFile)) {
            SYSTEMTIME t;
            GetLocalTime(&t);
            if (dolock) {
                APX_LOGLOCK(lf->hFile);
                logRotate(lf, &t);
            }
            if (bTimeStamp) {
                wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
                          t.wYear, t.wMonth, t.wDay,
                          t.wHour, t.wMinute, t.wSecond);
                WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
            }
            WriteFile(lf->hFile, _log_level[dwLevel],
                      lstrlenA(_log_level[dwLevel]), &wr, NULL);
            if (f && lf->dwLogLevel == APXLOG_LEVEL_DEBUG) {
                wsprintfA(sb, "(%10s:%-4d) ", f, dwLine);
                WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
            }
            if (len)
                WriteFile(lf->hFile, buffer, len, &wr, NULL);

            /* Terminate the line */
            WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
#ifdef _DEBUG_FULL
            FlushFileBuffers(lf->hFile);
#endif
            if (dolock) {
                APX_LOGUNLOCK(lf->hFile);
            }
        }
#ifdef _DEBUG_FULL
        {
            char tid[1024 + 16];
            wsprintfA(tid, "[%04d] %s", GetCurrentThreadId(), buffer);
            OutputDebugStringA(tid);
        }
#endif
    }
    /* Restore the last Error code */
    SetLastError(err);
    if (szFormat && err != 0 && dwLevel == APXLOG_LEVEL_ERROR) {
        /* Print the System error description
         */
        apxLogWrite(hFile, dwLevel, bTimeStamp, szFile, dwLine, NULL);
    }
    return len;
}
Beispiel #20
0
int
apxDisplayError(
    BOOL    bDisplay,
    LPCSTR  szFile,
    DWORD   dwLine,
    LPCSTR  szFormat,
    ...)
{
    va_list args;
    CHAR    buffer[SIZ_HUGLEN];
    CHAR    sysbuf[SIZ_HUGLEN];
    int     len = 0, nRet;
    LPCSTR  f = szFile;
    DWORD   err = GetLastError(); /* save the last Error code */
    if (f) {
        f = (szFile + lstrlenA(szFile) - 1);
        while(f != szFile && '\\' != *f && '/' != *f)
            f--;
        if(f != szFile)
            f++;
    }
    else
        f = "";
    sysbuf[0] = '\0';
    if (err != ERROR_SUCCESS) {
        len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
                             FORMAT_MESSAGE_IGNORE_INSERTS,
                             NULL,
                             err,
                             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                             sysbuf,
                             SIZ_DESLEN,
                             NULL);
        sysbuf[len] = '\0';
        if (len > 0) {
            if (sysbuf[len - 1] == '\n')
                sysbuf[--len] = '\0';
            if (len > 0 && sysbuf[len - 1] == '\r')
                sysbuf[--len] = '\0';
        }
    }
    if (szFormat) {
        va_start(args, szFormat);
        wvsprintfA(buffer, szFormat, args);
        va_end(args);
        if (f && *f) {
            CHAR sb[SIZ_PATHLEN];
            wsprintfA(sb, "%s (%d)", f, dwLine);
            lstrcatA(sysbuf, sb);
        }
        lstrlcatA(sysbuf, SIZ_HUGLEN, LINE_SEP);
        lstrlcatA(sysbuf, SIZ_HUGLEN, buffer);
    }
    len = lstrlenA(sysbuf);
#ifdef _DEBUG_FULL
    OutputDebugStringA(sysbuf);
#endif
    if (len > 0) {
        if (bDisplay) {
            nRet = MessageBoxA(NULL, sysbuf,
                               "Application System Error",
                               MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
        }
        else {
            fputs(sysbuf, stderr);
            if (!szFormat)
                fputs(LINE_SEP, stderr);
            fflush(stderr);
        }
    }
    /* Restore the last Error code */
    SetLastError(err);
    return len;
}
Beispiel #21
0
/*
    010510 Carl Corcoran
*/
void CCString::FormatvA(PCSTR szFormat, va_list arg)
{
    CHAR sz[1024];
    wvsprintfA(sz, szFormat, arg);
    this->cpy(CCString(sz));
}
Beispiel #22
0
int
apxLogWrite(
    HANDLE  hFile,
    DWORD   dwLevel,
    BOOL    bTimeStamp,
    LPCSTR  szFile,
    DWORD   dwLine,
    LPCSTR  szFormat,
    ...)
{
    va_list args;
    CHAR    buffer[1024+32];
    LPSTR   szBp;
    int     len = 0;
    LPCSTR  f = szFile;
    CHAR    sb[MAX_PATH+1];
    DWORD   wr;
    DWORD   err;
    BOOL    dolock = TRUE;
    apx_logfile_st *lf = (apx_logfile_st *)hFile;

    err = GetLastError(); /* save the last Error code */
    if (IS_INVALID_HANDLE(lf))
        lf = _st_sys_loghandle;
    if (IS_INVALID_HANDLE(lf)) {
        lf = &_st_sys_errhandle;
        lf->hFile = GetStdHandle(STD_ERROR_HANDLE);
        dolock = FALSE;
    }
    if (dwLevel < lf->dwLogLevel)
        return 0;
    if (f) {
        f = (szFile + lstrlenA(szFile) - 1);    
        while(f != szFile && '\\' != *f && '/' != *f)
            f--;
        if(f != szFile)
            f++;
    }
    lstrcpyA(buffer, _log_level[dwLevel]);
    if (!dolock)
        lstrcatA(buffer, "\n");
    szBp = &buffer[lstrlenA(buffer)];
    if (!szFormat) {
        FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | 
                       FORMAT_MESSAGE_IGNORE_INSERTS,
                       NULL,
                       err,
                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                       szBp,
                       1000,
                       NULL);
    }
    else {
        va_start(args, szFormat);
        wvsprintfA(szBp, szFormat, args);
        va_end(args);
    }
    len = lstrlenA(buffer);
    if (len > 0) {
        /* Remove trailing line separator */
        if (buffer[len - 1] == '\n') {
            buffer[len - 1] = '\0';
            --len;
        }
        if (!IS_INVALID_HANDLE(lf->hFile)) {
            SYSTEMTIME t;
            GetLocalTime(&t);
            if (lf->bRotate) {
                if (!apx_log_rotate(lf, &t))
                    return 0;
            }
            if (dolock) {
                APX_LOGLOCK(lf->hFile);
            }
            if (bTimeStamp) {
                wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ", 
                          t.wYear, t.wMonth, t.wDay,
                          t.wHour, t.wMinute, t.wSecond);
                WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
            }
            if (f) {
                wsprintfA(sb, "[%-4d %s] ", dwLine, f);
                WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
            }

            WriteFile(lf->hFile, buffer, len, &wr, NULL);
            /* Terminate the line */            
            WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
#ifdef _DEBUG_FULL
            FlushFileBuffers(lf->hFile);
#endif
            if (dolock) {
                APX_LOGUNLOCK(lf->hFile);
            }
        }
#ifdef _DEBUG_FULL
        {
            char tid[1024 + 16];
            wsprintfA(tid, "[%04X] %s", GetCurrentThreadId(), buffer);
            OutputDebugStringA(tid);
        }
#endif
    }
    /* Restore the last Error code */
    SetLastError(err);
    return len;
}