6 #include "debugtools.h"
9 /* ---------------------------------------------------------------------- */
11 #define SAVE_STRING_COUNT 50
12 static void *strings
[SAVE_STRING_COUNT
];
13 static int nextstring
;
15 /* ---------------------------------------------------------------------- */
21 if (strings
[nextstring
]) free (strings
[nextstring
]);
22 res
= strings
[nextstring
] = xmalloc (n
);
23 if (++nextstring
== SAVE_STRING_COUNT
) nextstring
= 0;
27 /* ---------------------------------------------------------------------- */
30 debugstr_an (LPCSTR src
, int n
)
34 if (!src
) return "(null)";
36 dst
= res
= gimme1 (n
* 4 + 10);
38 while (n
-- > 0 && *src
)
43 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
44 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
45 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
46 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
47 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
49 if (c
>= ' ' && c
<= 126)
54 *dst
++ = '0' + ((c
>> 6) & 7);
55 *dst
++ = '0' + ((c
>> 3) & 7);
56 *dst
++ = '0' + ((c
>> 0) & 7);
71 /* ---------------------------------------------------------------------- */
76 return debugstr_an (s
, 80);
79 /* ---------------------------------------------------------------------- */
82 debugstr_wn (LPCWSTR src
, int n
)
86 if (!src
) return "(null)";
88 dst
= res
= gimme1 (n
* 4 + 10);
90 while (n
-- > 0 && *src
)
95 case '\n': *dst
++ = '\\'; *dst
++ = 'n'; break;
96 case '\r': *dst
++ = '\\'; *dst
++ = 'r'; break;
97 case '\t': *dst
++ = '\\'; *dst
++ = 't'; break;
98 case '"': *dst
++ = '\\'; *dst
++ = '"'; break;
99 case '\\': *dst
++ = '\\'; *dst
++ = '\\'; break;
101 if (c
>= ' ' && c
<= 126)
106 *dst
++ = '0' + ((c
>> 6) & 7);
107 *dst
++ = '0' + ((c
>> 3) & 7);
108 *dst
++ = '0' + ((c
>> 0) & 7);
123 /* ---------------------------------------------------------------------- */
126 debugstr_w (LPCWSTR s
)
128 return debugstr_wn (s
, 80);
131 /* ---------------------------------------------------------------------- */
132 /* This routine returns a nicely formated name of the resource res
133 If the resource name is a string, it will return '<res-name>'
134 If it is a number, it will return #<4-digit-hex-number> */
135 LPSTR
debugres_a( LPCSTR res
)
138 if (HIWORD(res
)) return debugstr_a(res
);
139 sprintf(resname
, "#%04x", LOWORD(res
));
140 return debugstr_a (resname
);
143 LPSTR
debugres_w( LPCWSTR res
)
146 if (HIWORD(res
)) return debugstr_w(res
);
147 sprintf(resname
, "#%04x", LOWORD(res
));
148 return debugstr_a (resname
);
151 /* ---------------------------------------------------------------------- */
153 void debug_dumpstr (LPCSTR s
)
162 fputc ('\\', stderr
);
166 fputc ('\\', stderr
);
170 fputc ('\\', stderr
);
174 fputc ('\\', stderr
);
179 fprintf (stderr
, "\\0x%02x", *s
);
188 /* ---------------------------------------------------------------------- */
190 int dbg_printf(const char *format
, ...)
195 va_start(valist
, format
);
196 ret
= vfprintf(stderr
, format
, valist
);