Partially handle EAX buffer properties
[dsound-openal.git] / debug.c
blob2e91ff37792443b1d38d4091d89606ea84cd024f
1 #ifdef __WINESRC__
2 #error This file should not be compiled with Wine.
3 #endif
5 #include <stdarg.h>
6 #include <stdio.h>
7 #include <stdlib.h>
9 #include <windows.h>
10 #include "dsound.h"
12 /* allocate some tmp string space */
13 /* FIXME: this is not 100% thread-safe */
14 static char *get_temp_buffer( size_t size )
16 static char *list[32];
17 static LONG pos;
18 char *ret;
19 int idx;
21 idx = InterlockedExchangeAdd( &pos, 1 ) % (sizeof(list)/sizeof(list[0]));
22 if ((ret = realloc( list[idx], size ))) list[idx] = ret;
23 return ret;
27 /* release unused part of the buffer */
28 static void release_temp_buffer( char *buffer, size_t size )
30 /* don't bother doing anything */
31 (void)buffer;
32 (void)size;
35 /* printf with temp buffer allocation */
36 const char *wine_dbg_sprintf( const char *format, ... )
38 static const int max_size = 200;
39 char *ret;
40 int len;
41 va_list valist;
43 va_start(valist, format);
44 ret = get_temp_buffer( max_size );
45 len = vsnprintf( ret, max_size, format, valist );
46 if (len == -1 || len >= max_size) ret[max_size-1] = 0;
47 else release_temp_buffer( ret, len + 1 );
48 va_end(valist);
49 return ret;
52 /* default implementation of wine_dbgstr_wn */
53 const char *wine_dbgstr_wn( const WCHAR *str, int n )
55 char *dst, *res;
56 size_t size;
58 if (!((ULONG_PTR)str >> 16))
60 if (!str) return "(null)";
61 res = get_temp_buffer( 6 );
62 sprintf( res, "#%04x", LOWORD(str) );
63 return res;
65 if (n == -1)
67 const WCHAR *end = str;
68 while (*end) end++;
69 n = end - str;
71 if (n < 0) n = 0;
72 size = 12 + min( 300, n * 5 );
73 dst = res = get_temp_buffer( size );
74 *dst++ = 'L';
75 *dst++ = '"';
76 while (n-- > 0 && dst <= res + size - 10)
78 WCHAR c = *str++;
79 switch (c)
81 case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
82 case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
83 case '\t': *dst++ = '\\'; *dst++ = 't'; break;
84 case '"': *dst++ = '\\'; *dst++ = '"'; break;
85 case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
86 default:
87 if (c >= ' ' && c <= 126)
88 *dst++ = (char)c;
89 else
91 *dst++ = '\\';
92 sprintf(dst,"%04x",c);
93 dst+=4;
97 *dst++ = '"';
98 if (n > 0)
100 *dst++ = '.';
101 *dst++ = '.';
102 *dst++ = '.';
104 *dst++ = 0;
105 release_temp_buffer( res, dst - res );
106 return res;
109 const char *debugstr_guid( const GUID *id )
111 if (!id) return "(null)";
112 if (!((ULONG_PTR)id >> 16)) return wine_dbg_sprintf( "<guid-0x%04hx>", (WORD)(ULONG_PTR)id );
113 return wine_dbg_sprintf( "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
114 id->Data1, id->Data2, id->Data3,
115 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
116 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7] );