2006-04-02 14:20:45 +00:00
|
|
|
/* Residual - Virtual machine to run LucasArts' 3D adventure games
|
2008-06-13 14:57:47 +00:00
|
|
|
*
|
|
|
|
* Residual is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
2006-04-02 14:20:45 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-01-26 11:47:23 +00:00
|
|
|
#include "common/sys.h"
|
|
|
|
#include "common/debug.h"
|
2008-07-30 09:54:22 +00:00
|
|
|
#include "common/str.h"
|
2005-01-01 12:27:57 +00:00
|
|
|
|
2008-07-30 10:40:44 +00:00
|
|
|
#include "engine/backend/platform/driver.h"
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-08-17 07:08:50 +00:00
|
|
|
#ifdef __PLAYSTATION2__
|
|
|
|
// for those replaced fopen/fread/etc functions
|
|
|
|
typedef unsigned long uint64;
|
|
|
|
typedef signed long int64;
|
|
|
|
#include "engine/backend/platform/ps2/fileio.h"
|
2004-02-01 12:38:33 +00:00
|
|
|
|
2008-08-17 07:08:50 +00:00
|
|
|
#define fprintf ps2_fprintf
|
|
|
|
#define fflush(a) ps2_fflush(a)
|
|
|
|
#endif
|
2004-12-09 23:55:43 +00:00
|
|
|
|
2008-08-17 07:08:50 +00:00
|
|
|
#ifdef __DS__
|
|
|
|
#include "engine/backend/fs/ds/ds-fs.h"
|
2004-02-01 12:38:33 +00:00
|
|
|
|
2008-08-17 07:08:50 +00:00
|
|
|
#undef stderr
|
|
|
|
#undef stdout
|
|
|
|
#undef stdin
|
2004-02-01 12:38:33 +00:00
|
|
|
|
2008-08-17 07:08:50 +00:00
|
|
|
#define stdout ((DS::fileHandle*) -1)
|
|
|
|
#define stderr ((DS::fileHandle*) -2)
|
|
|
|
#define stdin ((DS::fileHandle*) -3)
|
|
|
|
|
|
|
|
void std_fprintf(FILE* handle, const char* fmt, ...);
|
|
|
|
void std_fflush(FILE* handle);
|
|
|
|
|
|
|
|
#define fprintf(file, fmt, ...) { char str[128]; sprintf(str, fmt, ##__VA_ARGS__); DS::std_fwrite(str, strlen(str), 1, file); }
|
|
|
|
#define fflush(file) DS::std_fflush(file)
|
|
|
|
#endif
|
2004-02-01 12:38:33 +00:00
|
|
|
|
2008-07-30 09:54:22 +00:00
|
|
|
static void debugHelper(const char *in_buf, bool caret = true) {
|
|
|
|
char buf[STRINGBUFLEN];
|
|
|
|
|
|
|
|
strcpy(buf, in_buf);
|
|
|
|
|
|
|
|
if (caret)
|
|
|
|
printf("%s\n", buf);
|
|
|
|
else
|
|
|
|
printf("%s", buf);
|
|
|
|
|
|
|
|
#if defined(USE_WINDBG)
|
|
|
|
if (caret)
|
|
|
|
strcat(buf, "\n");
|
|
|
|
#if defined(_WIN32_WCE)
|
|
|
|
TCHAR buf_unicode[1024];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
|
|
|
|
OutputDebugString(buf_unicode);
|
|
|
|
#else
|
|
|
|
OutputDebugString(buf);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-07-30 09:54:22 +00:00
|
|
|
void CDECL debug(const char *s, ...) {
|
|
|
|
char buf[STRINGBUFLEN];
|
|
|
|
va_list va;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-07-30 09:54:22 +00:00
|
|
|
va_start(va, s);
|
|
|
|
vsnprintf(buf, STRINGBUFLEN, s, va);
|
2004-02-24 21:09:53 +00:00
|
|
|
va_end(va);
|
2008-07-30 09:54:22 +00:00
|
|
|
|
|
|
|
debugHelper(buf);
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|
|
|
|
|
2008-07-30 09:54:22 +00:00
|
|
|
void CDECL debug(int level, const char *s, ...) {
|
|
|
|
char buf[STRINGBUFLEN];
|
|
|
|
va_list va;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-07-30 09:54:22 +00:00
|
|
|
if (level > debugLevel)
|
|
|
|
return;
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2008-07-30 09:54:22 +00:00
|
|
|
va_start(va, s);
|
|
|
|
vsnprintf(buf, STRINGBUFLEN, s, va);
|
2004-02-24 21:09:53 +00:00
|
|
|
va_end(va);
|
2008-07-30 09:54:22 +00:00
|
|
|
|
|
|
|
debugHelper(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NORETURN CDECL error(const char *s, ...) {
|
|
|
|
char buf_input[STRINGBUFLEN];
|
|
|
|
char buf_output[STRINGBUFLEN];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
// Generate the full error message
|
|
|
|
va_start(va, s);
|
|
|
|
vsnprintf(buf_input, STRINGBUFLEN, s, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
strcpy(buf_output, buf_input);
|
|
|
|
|
|
|
|
// Print the error message to stderr
|
|
|
|
fprintf(stderr, "%s!\n", buf_output);
|
|
|
|
|
|
|
|
#if defined(USE_WINDBG)
|
|
|
|
#if defined(_WIN32_WCE)
|
|
|
|
TCHAR buf_output_unicode[1024];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buf_output, strlen(buf_output) + 1, buf_output_unicode, sizeof(buf_output_unicode));
|
|
|
|
OutputDebugString(buf_output_unicode);
|
|
|
|
#ifndef DEBUG
|
|
|
|
drawError(buf_output);
|
|
|
|
#else
|
|
|
|
int cmon_break_into_the_debugger_if_you_please = *(int *)(buf_output + 1); // bus error
|
|
|
|
printf("%d", cmon_break_into_the_debugger_if_you_please); // don't optimize the int out
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
OutputDebugString(buf_output);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PALMOS_MODE
|
|
|
|
extern void PalmFatalError(const char *err);
|
|
|
|
PalmFatalError(buf_output);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __SYMBIAN32__
|
|
|
|
Symbian::FatalError(buf_output);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (g_driver)
|
|
|
|
g_driver->quit();
|
2003-08-15 18:00:22 +00:00
|
|
|
|
2004-02-24 21:09:53 +00:00
|
|
|
exit(1);
|
2003-08-15 18:00:22 +00:00
|
|
|
}
|
2005-08-10 08:33:45 +00:00
|
|
|
|
2008-07-30 09:54:22 +00:00
|
|
|
void CDECL warning(const char *fmt, ...) {
|
|
|
|
char buf[STRINGBUFLEN];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
vsnprintf(buf, STRINGBUFLEN, fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
#if !defined (__SYMBIAN32__)
|
|
|
|
fprintf(stderr, "WARNING: %s!\n", buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_WINDBG)
|
|
|
|
strcat(buf, "\n");
|
|
|
|
#if defined(_WIN32_WCE)
|
|
|
|
TCHAR buf_unicode[1024];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, buf, strlen(buf) + 1, buf_unicode, sizeof(buf_unicode));
|
|
|
|
OutputDebugString(buf_unicode);
|
|
|
|
#else
|
|
|
|
OutputDebugString(buf);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-08-10 08:33:45 +00:00
|
|
|
const char *debug_levels[] = {
|
2005-08-12 12:05:18 +00:00
|
|
|
"NONE",
|
|
|
|
"NORMAL",
|
|
|
|
"WARN",
|
|
|
|
"ERROR",
|
|
|
|
"FUNC",
|
|
|
|
"BITMAP",
|
|
|
|
"MODEL",
|
|
|
|
"STUB",
|
|
|
|
"SMUSH",
|
|
|
|
"IMUSE",
|
|
|
|
"CHORE",
|
|
|
|
"ALL"
|
2005-08-10 08:33:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *debug_descriptions[] = {
|
2005-08-12 12:05:18 +00:00
|
|
|
"No debug messages will be printed (default)",
|
|
|
|
"\"Normal\" debug messages will be printed",
|
|
|
|
"Warning debug messages will be printed",
|
|
|
|
"Error debug messages will be printed",
|
|
|
|
"Function (normal and stub) debug messages will be printed",
|
|
|
|
"Bitmap debug messages will be printed",
|
|
|
|
"Model debug messages will be printed",
|
|
|
|
"Stub (missing function) debug messages will be printed",
|
|
|
|
"SMUSH (video) debug messages will be printed",
|
|
|
|
"IMUSE (audio) debug messages will be printed",
|
|
|
|
"Chore debug messages will be printed",
|
|
|
|
"All debug messages will be printed",
|
2005-08-10 08:33:45 +00:00
|
|
|
};
|
|
|
|
|