2009-11-24 22:11:07 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2011-05-23 17:36:45 +00:00
|
|
|
#define FORBIDDEN_SYMBOL_EXCEPTION_exit
|
|
|
|
|
2009-11-26 10:59:46 +00:00
|
|
|
#include "common/textconsole.h"
|
2009-11-24 22:11:07 +00:00
|
|
|
#include "common/system.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/str.h"
|
2009-11-24 22:11:07 +00:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
static OutputFormatter s_errorOutputFormatter = 0;
|
|
|
|
|
|
|
|
void setErrorOutputFormatter(OutputFormatter f) {
|
|
|
|
s_errorOutputFormatter = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ErrorHandler s_errorHandler = 0;
|
|
|
|
|
|
|
|
void setErrorHandler(ErrorHandler handler) {
|
|
|
|
s_errorHandler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-26 18:33:27 +00:00
|
|
|
} // End of namespace Common
|
2009-11-24 22:11:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef DISABLE_TEXT_CONSOLE
|
|
|
|
|
|
|
|
void warning(const char *s, ...) {
|
2011-03-18 13:42:51 +00:00
|
|
|
Common::String output;
|
2009-11-24 22:11:07 +00:00
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, s);
|
2011-03-18 13:42:51 +00:00
|
|
|
output = Common::String::vformat(s, va);
|
2009-11-24 22:11:07 +00:00
|
|
|
va_end(va);
|
|
|
|
|
2011-03-18 13:42:51 +00:00
|
|
|
output = "WARNING: " + output + "!\n";
|
2009-11-24 22:11:07 +00:00
|
|
|
|
2010-11-18 19:12:14 +00:00
|
|
|
if (g_system)
|
|
|
|
g_system->logMessage(LogMessageType::kWarning, output.c_str());
|
|
|
|
// TODO: Think of a good fallback in case we do not have
|
|
|
|
// any OSystem yet.
|
2009-11-24 22:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 21:56:10 +00:00
|
|
|
void NORETURN_PRE error(const char *s, ...) {
|
2011-03-18 13:42:51 +00:00
|
|
|
// We don't use String::vformat here, as that require
|
|
|
|
// using the heap, and that might be impossible at this
|
|
|
|
// point, e.g. if the error was an "out-of-memory" error.
|
2009-11-24 22:11:07 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
// Next, give the active engine (if any) a chance to augment the message
|
|
|
|
if (Common::s_errorOutputFormatter) {
|
|
|
|
(*Common::s_errorOutputFormatter)(buf_output, buf_input, STRINGBUFLEN);
|
|
|
|
} else {
|
|
|
|
strncpy(buf_output, buf_input, STRINGBUFLEN);
|
|
|
|
}
|
|
|
|
|
2011-01-11 03:03:40 +00:00
|
|
|
buf_output[STRINGBUFLEN - 3] = '\0';
|
|
|
|
buf_output[STRINGBUFLEN - 2] = '\0';
|
|
|
|
buf_output[STRINGBUFLEN - 1] = '\0';
|
2009-11-24 22:11:07 +00:00
|
|
|
strcat(buf_output, "!\n");
|
|
|
|
|
2010-11-18 19:12:14 +00:00
|
|
|
if (g_system)
|
|
|
|
g_system->logMessage(LogMessageType::kError, buf_output);
|
|
|
|
// TODO: Think of a good fallback in case we do not have
|
|
|
|
// any OSystem yet.
|
2009-11-24 22:11:07 +00:00
|
|
|
|
|
|
|
// If there is an error handler, invoke it now
|
|
|
|
if (Common::s_errorHandler)
|
|
|
|
(*Common::s_errorHandler)(buf_output);
|
|
|
|
|
|
|
|
if (g_system)
|
2010-11-18 19:12:14 +00:00
|
|
|
g_system->fatalError();
|
2009-11-24 22:11:07 +00:00
|
|
|
|
|
|
|
#if defined(SAMSUNGTV)
|
|
|
|
// FIXME
|
|
|
|
for (;;) {}
|
|
|
|
#else
|
|
|
|
exit(1);
|
|
|
|
#endif
|
|
|
|
}
|