ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

textconsole.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #define FORBIDDEN_SYMBOL_EXCEPTION_exit
00024 
00025 #include "common/textconsole.h"
00026 #include "common/system.h"
00027 #include "common/str.h"
00028 
00029 namespace Common {
00030 
00031 static OutputFormatter s_errorOutputFormatter = nullptr;
00032 
00033 void setErrorOutputFormatter(OutputFormatter f) {
00034     s_errorOutputFormatter = f;
00035 }
00036 
00037 static ErrorHandler s_errorHandler = nullptr;
00038 
00039 void setErrorHandler(ErrorHandler handler) {
00040     s_errorHandler = handler;
00041 }
00042 
00043 
00044 } // End of namespace Common
00045 
00046 
00047 #ifndef DISABLE_TEXT_CONSOLE
00048 
00049 void warning(const char *s, ...) {
00050     Common::String output;
00051     va_list va;
00052 
00053     va_start(va, s);
00054     output = Common::String::vformat(s, va);
00055     va_end(va);
00056 
00057     output = "WARNING: " + output + "!\n";
00058 
00059     if (g_system)
00060         g_system->logMessage(LogMessageType::kWarning, output.c_str());
00061     // TODO: Think of a good fallback in case we do not have
00062     // any OSystem yet.
00063 }
00064 
00065 #endif
00066 
00067 void NORETURN_PRE error(const char *s, ...) {
00068     // We don't use String::vformat here, as that require
00069     // using the heap, and that might be impossible at this
00070     // point, e.g. if the error was an "out-of-memory" error.
00071     char buf_input[STRINGBUFLEN];
00072     char buf_output[STRINGBUFLEN];
00073     va_list va;
00074 
00075     // Generate the full error message
00076     va_start(va, s);
00077     vsnprintf(buf_input, STRINGBUFLEN, s, va);
00078     va_end(va);
00079 
00080 
00081     // Next, give the active engine (if any) a chance to augment the message
00082     if (Common::s_errorOutputFormatter) {
00083         (*Common::s_errorOutputFormatter)(buf_output, buf_input, STRINGBUFLEN);
00084     } else {
00085         strncpy(buf_output, buf_input, STRINGBUFLEN);
00086     }
00087 
00088     buf_output[STRINGBUFLEN - 3] = '\0';
00089     buf_output[STRINGBUFLEN - 2] = '\0';
00090     buf_output[STRINGBUFLEN - 1] = '\0';
00091     strcat(buf_output, "!\n");
00092 
00093     if (g_system)
00094         g_system->logMessage(LogMessageType::kError, buf_output);
00095     // TODO: Think of a good fallback in case we do not have
00096     // any OSystem yet.
00097 
00098     // If there is an error handler, invoke it now
00099     if (Common::s_errorHandler)
00100         (*Common::s_errorHandler)(buf_output);
00101 
00102     if (g_system)
00103         g_system->fatalError();
00104 
00105 #if defined(SAMSUNGTV)
00106     // FIXME
00107     for (;;) {}
00108 #else
00109     exit(1);
00110 #endif
00111 }


Generated on Sat Mar 23 2019 05:02:16 for ResidualVM by doxygen 1.7.1
curved edge   curved edge