1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #ifndef COMMON_CONSOLE_H
24 #define COMMON_CONSOLE_H
25
26 #include "common/scummsys.h"
27
28 namespace Common {
29
30 /**
31 * @defgroup common_text_console Text console
32 * @ingroup common
33 *
34 * @brief Output formatter, typically used for debugging.
35 *
36 * @{
37 */
38
39 /**
40 * An output formatter takes a source string and 'decorates' it with
41 * extra information, storing the result in a destination buffer.
42 *
43 * A typical use is to (optionally) enhance the output given by
44 * the error() and debug() functions with extra information on
45 * the state of the active engine.
46 */
47 typedef void (*OutputFormatter)(char *dst, const char *src, size_t dstSize);
48
49 /**
50 * Set the output formatter used by error().
51 */
52 void setErrorOutputFormatter(OutputFormatter f);
53
54
55 /**
56 * A callback that is invoked by error() just before aborting.
57 *
58 * A typical example would be a function that shows a debug
59 * console and displays the given message in it.
60 */
61 typedef bool (*ErrorHandler)(const char *msg);
62
63 /**
64 * Set a callback that is invoked by error() after the error
65 * message has been printed, but before the application is
66 * terminated.
67 *
68 * This can be used to e.g. show a debugger console.
69 */
70 void setErrorHandler(ErrorHandler handler);
71
72 /** @} */
73
74 } // End of namespace Common
75
76 /**
77 * @addtogroup common_text_console
78 * @{
79 */
80
81 /**
82 * Print an error message to the text console and then terminate the process.
83 */
84 void NORETURN_PRE error(MSVC_PRINTF const char *s, ...) GCC_PRINTF(1, 2) NORETURN_POST;
85
86 #ifdef DISABLE_TEXT_CONSOLE
87
warning(MSVC_PRINTF const char * s,...)88 inline void GCC_PRINTF(1, 2) warning(MSVC_PRINTF const char *s, ...) {}
89
90 #else
91
92 /**
93 * Print a warning message to the text console (stderr).
94 *
95 * Automatically prepends the text "WARNING: " and appends
96 * an exclamation mark and a newline.
97 */
98 void warning(MSVC_PRINTF const char *s, ...) GCC_PRINTF(1, 2);
99
100 #endif
101 /** @} */
102
103 #endif
104