2004-05-08 03:11:51 +02:00
|
|
|
#include "precompiled.h"
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
#include "sysdep.h"
|
2004-07-15 21:59:27 +02:00
|
|
|
#include <memory.h>
|
2004-07-25 13:30:05 +02:00
|
|
|
#include <stdarg.h>
|
2004-03-03 00:56:51 +01:00
|
|
|
|
|
|
|
// portable debug output routines. Win32 offers better versions, which
|
|
|
|
// override these.
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
2004-06-18 20:56:10 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
// portable output routines (win.cpp overrides these)
|
2004-05-06 19:14:30 +02:00
|
|
|
|
|
|
|
void display_msg(const char* caption, const char* msg)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: %s\n", caption, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wdisplay_msg(const wchar_t* caption, const wchar_t* msg)
|
2004-03-03 00:56:51 +01:00
|
|
|
{
|
2004-06-02 17:12:48 +02:00
|
|
|
fwprintf(stderr, L"%ls: %ls\n", caption, msg);
|
2004-03-03 00:56:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-06 19:14:30 +02:00
|
|
|
|
2004-03-03 00:56:51 +01:00
|
|
|
void debug_out(const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
vprintf(fmt, args);
|
|
|
|
va_end(args);
|
2004-05-06 19:14:30 +02:00
|
|
|
fflush(stdout);
|
2004-03-03 00:56:51 +01:00
|
|
|
}
|
|
|
|
|
2004-03-03 01:37:41 +01:00
|
|
|
|
2004-08-02 15:47:38 +02:00
|
|
|
inline void check_heap()
|
2004-03-03 01:37:41 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2004-07-23 21:07:18 +02:00
|
|
|
|
2004-08-05 21:21:35 +02:00
|
|
|
inline int get_executable_name(char* /*n_path*/, size_t /*buf_size*/)
|
|
|
|
{
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2004-03-04 21:36:31 +01:00
|
|
|
#endif // #ifndef _WIN32
|
2004-06-02 17:12:48 +02:00
|
|
|
|
2004-07-12 18:48:10 +02:00
|
|
|
void debug_break()
|
|
|
|
{
|
|
|
|
#ifndef NDEBUG
|
|
|
|
# if defined(_WIN32)
|
|
|
|
win_debug_break();
|
|
|
|
# elif defined(_M_IX86)
|
|
|
|
ia32_debug_break();
|
2004-07-13 00:05:49 +02:00
|
|
|
# elif defined(OS_UNIX)
|
|
|
|
unix_debug_break();
|
2004-07-12 18:48:10 +02:00
|
|
|
# else
|
|
|
|
# error "port"
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-02 15:47:38 +02:00
|
|
|
const int MICROLOG_SIZE = 16384;
|
2004-07-15 21:29:56 +02:00
|
|
|
wchar_t MicroBuffer[MICROLOG_SIZE];
|
|
|
|
int MicroBuffer_off = 0;
|
|
|
|
|
|
|
|
void debug_microlog(const wchar_t *fmt, ...)
|
|
|
|
{
|
2004-08-02 15:47:38 +02:00
|
|
|
#ifndef NDEBUG
|
2004-07-15 21:29:56 +02:00
|
|
|
va_list argp;
|
|
|
|
wchar_t buffer[512];
|
|
|
|
|
|
|
|
va_start(argp, fmt);
|
2004-07-15 21:59:27 +02:00
|
|
|
vswprintf(buffer, sizeof(buffer), fmt, argp);
|
2004-07-15 21:29:56 +02:00
|
|
|
va_end(argp);
|
|
|
|
|
|
|
|
wcscat(buffer, L"\r\n");
|
|
|
|
|
|
|
|
int len = (int)wcslen(buffer);
|
|
|
|
|
|
|
|
// Lose half of the old data if the log's too big
|
|
|
|
if (MicroBuffer_off + len >= MICROLOG_SIZE)
|
|
|
|
{
|
|
|
|
memcpy(&MicroBuffer, (void*)&MicroBuffer[MICROLOG_SIZE/2], sizeof(wchar_t)*MICROLOG_SIZE/2);
|
|
|
|
memset(&MicroBuffer[MICROLOG_SIZE/2], 0, sizeof(wchar_t)*MICROLOG_SIZE/2);
|
|
|
|
MicroBuffer_off -= MICROLOG_SIZE/2;
|
|
|
|
}
|
|
|
|
memcpy(&MicroBuffer[MicroBuffer_off], buffer, sizeof(wchar_t)*len);
|
|
|
|
MicroBuffer_off += len;
|
2004-08-02 15:47:38 +02:00
|
|
|
#endif
|
2004-07-15 21:29:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 23:17:26 +02:00
|
|
|
|
2004-06-02 17:12:48 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
|
|
|
double round(double x)
|
|
|
|
{
|
|
|
|
return (long)(x + 0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2004-06-03 03:43:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_C99
|
|
|
|
|
|
|
|
float fminf(float a, float b)
|
|
|
|
{
|
|
|
|
return (a < b)? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
float fmaxf(float a, float b)
|
|
|
|
{
|
|
|
|
return (a > b)? a : b;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|