aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/scicore
diff options
context:
space:
mode:
authorMax Horn2009-05-11 18:18:43 +0000
committerMax Horn2009-05-11 18:18:43 +0000
commitd09037fa6cc19e8f1bd3dac5b14369a8811726e8 (patch)
treef81a24b6915386b9d7d9b9260a09fc2081010c4f /engines/sci/scicore
parent548180663546d6ce2d29436fe2d54d8fe2170a18 (diff)
downloadscummvm-rg350-d09037fa6cc19e8f1bd3dac5b14369a8811726e8.tar.gz
scummvm-rg350-d09037fa6cc19e8f1bd3dac5b14369a8811726e8.tar.bz2
scummvm-rg350-d09037fa6cc19e8f1bd3dac5b14369a8811726e8.zip
SCI: Hacked stuff up so that debugger commands also print on the GUI console
svn-id: r40460
Diffstat (limited to 'engines/sci/scicore')
-rw-r--r--engines/sci/scicore/sciconsole.cpp57
-rw-r--r--engines/sci/scicore/sciconsole.h11
2 files changed, 24 insertions, 44 deletions
diff --git a/engines/sci/scicore/sciconsole.cpp b/engines/sci/scicore/sciconsole.cpp
index 0f5ea18017..863bf990b1 100644
--- a/engines/sci/scicore/sciconsole.cpp
+++ b/engines/sci/scicore/sciconsole.cpp
@@ -30,55 +30,46 @@
#include "sci/engine/state.h"
#include "sci/scicore/sciconsole.h"
+#include "sci/sci.h" // For _console only
+#include "sci/console.h" // For _console only
+
namespace Sci {
#ifdef SCI_CONSOLE
-int con_passthrough = false;
-
-static void (*_con_string_callback)(char*) = NULL;
static void (*_con_pixmap_callback)(gfx_pixmap_t *) = NULL;
+bool g_redirect_sciprintf_to_gui = false;
+
int sciprintf(const char *fmt, ...) {
va_list argp;
- int bufsize = 256;
- int i;
- char *buf = (char *)sci_malloc(bufsize);
- if (NULL == fmt) {
- fprintf(stderr, "console.c: sciprintf(): NULL passed for parameter fmt\n");
- return -1;
- }
-
- if (NULL == buf) {
- fprintf(stderr, "console.c: sciprintf(): malloc failed for buf\n");
- return -1;
- }
+ assert(fmt);
+ // First determine how big a buffer we need
va_start(argp, fmt);
- while ((i = vsnprintf(buf, bufsize - 1, fmt, argp)) == -1 || (i >= bufsize - 2)) {
- // while we're out of space...
- va_end(argp);
- va_start(argp, fmt); // reset argp
-
- free(buf);
- buf = (char *)sci_malloc(bufsize <<= 1);
- }
+ int bufsize = vsnprintf(0, 0, fmt, argp);
+ assert(bufsize >= 0);
va_end(argp);
- if (con_passthrough)
- printf("%s", buf);
+ // Allocate buffer for the full printed string
+ char *buf = (char *)sci_malloc(bufsize + 1);
+ assert(buf);
- if (_con_string_callback)
- _con_string_callback(buf);
- else
- free(buf);
+ // Print everything according to fmt into buf
+ va_start(argp, fmt); // reset argp
+ int bufsize2 = vsnprintf(buf, bufsize + 1, fmt, argp);
+ assert(bufsize == bufsize2);
+ va_end(argp);
- return 1;
-}
+ // Display the result suitably
+ if (g_redirect_sciprintf_to_gui)
+ ((SciEngine *)g_engine)->_console->DebugPrintf("%s", buf);
+ printf("%s", buf);
-void con_set_string_callback(void(*callback)(char *)) {
- _con_string_callback = callback;
+ free(buf);
+
+ return 1;
}
void con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)) {
diff --git a/engines/sci/scicore/sciconsole.h b/engines/sci/scicore/sciconsole.h
index b483dfb8a4..e4fc867e10 100644
--- a/engines/sci/scicore/sciconsole.h
+++ b/engines/sci/scicore/sciconsole.h
@@ -43,9 +43,6 @@ namespace Sci {
struct gfx_pixmap_t;
-/** If this flag is set, we echo all sciprintf() stuff to the text console. */
-extern int con_passthrough;
-
union cmd_param_t {
int32 val;
const char *str;
@@ -57,14 +54,6 @@ typedef int (*ConCommand)(EngineState *s, const Common::Array<cmd_param_t> &cmdP
/*** FUNCTION DEFINITIONS ***/
-void con_set_string_callback(void(*callback)(char *));
-/* Sets the console string callback
-** Parameters: (void -> char *) callback: The closure to invoke after
-** a string for sciprintf() has been generated
-** This sets a single callback function to be used after sciprintf()
-** is used.
-*/
-
void con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *));
/* Sets the console pixmap callback
** Parameters: (void -> gfx_pixmap_t *) callback: The closure to invoke after