summaryrefslogtreecommitdiff
path: root/plugins/ConnectionNotify/src/debug.cpp
blob: 0400b3a67373455428430e90aa0c6c1446c69545 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "ConnectionNotify.h"

void _OutputDebugString(TCHAR* lpOutputString, ... )
{
    TCHAR OutMsg[MAX_LENGTH];
    TCHAR format[MAX_LENGTH];
	int i,j;
    va_list argptr;    
    
    va_start( argptr, lpOutputString );            
    

    
    for(i=0,j=0;lpOutputString[i] != '\0';i++) 
    {
        format[j++] = lpOutputString[i];
		format[j] = '\0';
        // If escape character
        //if(lpOutputString[i] == '\\')
        //{
        //    i++;
        //    continue;
        //}
        // if not a substitutal character
        if(lpOutputString[i] != '%')
            continue;
        
        format[j++] = lpOutputString[++i];
        format[j] = '\0';
        switch(lpOutputString[i])
        {
            // string
        case 's':
            {
                TCHAR* s = va_arg( argptr, TCHAR * );
                mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, s);
                _tcsncpy(format,OutMsg,_countof(OutMsg));
                j = _tcslen(format);
                _tcscat(format,_T(" "));
                break;
            }
            // character
        case 'c':
            {
                char c = (char) va_arg( argptr, int );
                mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, c);
                _tcsncpy(format,OutMsg,_countof(OutMsg));
                j = _tcslen(format);
                _tcscat(format,_T(" "));
                break;
            }
            // integer
        case 'd':
            {
                int d = va_arg( argptr, int );
                mir_sntprintf(OutMsg, SIZEOF(OutMsg), format, d);
                _tcsncpy(format,OutMsg,_countof(OutMsg));
                j = _tcslen(format);
                _tcscat(format,_T(" "));
                break;
            }
        }
		format[j+1] = '\0';
    }
	_tcscat(format,_T("\n"));
    OutputDebugString(format);

    va_end( argptr );

}