From 9036c0fee0887f2567a3c04a2f29c95fc46d049d Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sat, 21 Feb 2009 18:46:03 +0000 Subject: Renamed SCI's console to sciconsole (MSVC has problems with files with the same name under different directories). ScummVM's console can be enabled correctly under MSVC now svn-id: r38722 --- engines/sci/engine/grammar.cpp | 2 +- engines/sci/engine/heap.cpp | 2 +- engines/sci/engine/scriptdebug.cpp | 2 +- engines/sci/include/console.h | 230 ------------------------------------- engines/sci/include/engine.h | 2 +- engines/sci/include/kernel.h | 2 +- engines/sci/include/sciconsole.h | 230 +++++++++++++++++++++++++++++++++++++ engines/sci/module.mk | 2 +- engines/sci/sci.cpp | 3 +- engines/sci/scicore/console.cpp | 128 --------------------- engines/sci/scicore/sciconsole.cpp | 128 +++++++++++++++++++++ 11 files changed, 365 insertions(+), 366 deletions(-) delete mode 100644 engines/sci/include/console.h create mode 100644 engines/sci/include/sciconsole.h delete mode 100644 engines/sci/scicore/console.cpp create mode 100644 engines/sci/scicore/sciconsole.cpp diff --git a/engines/sci/engine/grammar.cpp b/engines/sci/engine/grammar.cpp index a06464a0b4..5d72dcd8ad 100644 --- a/engines/sci/engine/grammar.cpp +++ b/engines/sci/engine/grammar.cpp @@ -30,7 +30,7 @@ #include "sci/tools.h" #include "sci/include/vocabulary.h" -#include "sci/include/console.h" +#include "sci/include/sciconsole.h" namespace Sci { diff --git a/engines/sci/engine/heap.cpp b/engines/sci/engine/heap.cpp index 925cbb8905..159d003c56 100644 --- a/engines/sci/engine/heap.cpp +++ b/engines/sci/engine/heap.cpp @@ -24,7 +24,7 @@ */ #include "sci/include/engine.h" -#include "sci/include/console.h" +#include "sci/include/sciconsole.h" #include "sci/engine/heap.h" namespace Sci { diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp index f67b513764..e23463ec19 100644 --- a/engines/sci/engine/scriptdebug.cpp +++ b/engines/sci/engine/scriptdebug.cpp @@ -49,7 +49,7 @@ #include "sci/engine/gc.h" #include "sci/include/sciresource.h" #include "sci/include/engine.h" -#include "sci/include/console.h" +#include "sci/include/sciconsole.h" #include "sci/include/kdebug.h" #include "sci/include/vocabulary.h" #include "sci/engine/kernel_types.h" diff --git a/engines/sci/include/console.h b/engines/sci/include/console.h deleted file mode 100644 index 7e0ad876c4..0000000000 --- a/engines/sci/include/console.h +++ /dev/null @@ -1,230 +0,0 @@ -/* 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. - * - * $URL$ - * $Id$ - * - */ - -/* Header file for the SCI console. -** Please note that the console does not use the priority field; the console -** should therefore be drawn after everything else has been drawn (with the -** possible exception of the mouse pointer). -*/ - -#ifndef _SCI_CONSOLE_H_ -#define _SCI_CONSOLE_H_ - -#include "common/scummsys.h" - -#include "sci/include/sci_memory.h" -#include "sci/tools.h" -#include "sci/include/vm_types.h" - -#define SCI_CONSOLE -#include "sci/include/gfx_operations.h" - -namespace Sci { - -extern int con_passthrough; -/* Echo all sciprintf() stuff to the text console */ -extern FILE *con_file; -/* Echo all sciprintf() output to a text file. Note: clients of freesci.dll -** should use open_console_file and close_console_file, rather than refer -** directly to the con_file variable. -*/ - -typedef union { - int32 val; - char *str; - reg_t reg; -} cmd_param_t; - -extern unsigned int cmd_paramlength; -/* The number of parameters passed to a function called from the parser */ - -extern cmd_param_t *cmd_params; -/* The parameters passed to a function called by the parser */ - -extern struct EngineState *con_gamestate; -/* The game state as used by some of the console commands */ - - -/*** 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 -** a pixmap has been provided to be -** published in the on-screen console -** This sets a single callback function to be used after sciprintf() -** is used. -*/ - -void con_init(); -/* Initializes the command parser -** Parameters: (void) -** Returns : (void) -** This function will initialize hook up a few commands to the parser. -** It must be called before cmdParse() is used. -*/ - - -void con_parse(EngineState *s, const char *command); -/* Parses a command and summons appropriate facilities to handle it -** Parameters: (EngineState *) s: The EngineState to use -** command: The command to execute -** Returns : (void) -*/ - - -int con_hook_command(int command(EngineState *s), const char *name, const char *param, const char *description); -/* Adds a command to the parser's command list -** Parameters: command: The command to add -** name: The command's name -** param: A description of the parameters it takes -** description: A short description of what it does -** Returns : 0 if successful, 1 if appending failed because -** of an incorrect *param string, 'command'==0, or -** 'name' already being in use. -** A valid param string is either empty (no parameters allowed) -** or contains one of the following tokens: -** ! Special token: EngineState* must be set for this function to be called -** i (an int) -** s (a 'string' (char *)) -** h (a byte, described in hexadecimal digits) -** a (a heap address, register or object name) -** r (any register value) -** x* (an arbitrary (possibly 0) number of 'x' tokens) -** The '*' token may only be used as the last token of the list. -** Another way to specify optional parameters is by means of the -** '-opt:t' notation, which allows an optional parameter of type 't' -** to be specified as 'opt:' when calling. See also the -** con_hasopt() and con_getopt() calls. -** -** Please note that the 'h' type does accept hexadecimal numbers greater -** than 0xff and less than 0x00, but clips them to this range. -** -** Example: "isi*" would define the function to take an int, a -** string, and an arbitrary number of ints as parameters (in that sequence). -** -** When the function is called, it can retrieve its parameters from cmd_params; -** the actual number of parameters is stored in cmd_paramlength. -** It is allowed to modify the char*s from a cmd_params[] element, as long -** as no element beyond strlen(cmd_params[x].str)+1 is accessed. -*/ - -cmd_param_t con_getopt(char *opt); -/* Retreives the specified optional parameter -** -- for use within console functions only -- -** Parameters: (char *) opt: The optional parameter to retrieve -** Returns : (cmd_param_t) The corresponding parameter -** Should only be used if con_hasopt() reports its presence. -*/ - -int con_hasopt(char *opt); -/* Checks whether an optional parameter was specified -** -- for use within console functions only -- -** Parameters: (char *) opt: The optional parameter to check for -** Returns : (int) non-zero iff the parameter was specified -*/ - -int con_can_handle_pixmaps(); -/* Determines whether the console supports pixmap inserts -** Returns : (int) non-zero iff pixmap inserts are supported -*/ - -int con_insert_pixmap(gfx_pixmap_t *pixmap); -/* Inserts a pixmap into the console history buffer -** Parameters: (gfx_pixmap_t *) pixmap: The pixmap to insert -** Returns : (int) 0 on success, non-zero if no receiver for -** the pixmap could not be found -** The pixmap must be unique; it is freed by the console on demand. -** Use gfx_clone_pixmap() if neccessary. -** If the pixmap could not be inserted, the called must destroy it -*/ - -int con_hook_page(const char *topic, const char *body); -/* Hooks a general information page to the manual page system -** Parameters: (const char *) topic: The topic name -** (const char *) body: The text body to assign to the topic -** Returns : (int) 0 on success -*/ - -int con_hook_int(int *pointer, const char *name, const char *description); -/* Adds an int to the list of modifyable ints. -** Parameters: pointer: Pointer to the int to add to the list -** name: Name for this value -** description: A short description for the value -** Returns : 0 on success, 1 if either value has already been added -** or if name is already being used for a different value. -** The internal list of int references is used by some of the basic commands. -*/ - - -void con_gfx_init(); -/* Initializes the gfx console -*/ - -void con_gfx_show(gfx_state_t *state); -/* Enters on-screen console mode -** Parameters: (gfx_state_t *state): The graphics state to use for interaction -** Returns : (void) -*/ - -char *con_gfx_read(gfx_state_t *state); -/* Reads a single line from the on-screen console, if it is open -** Parameters: (gfx_state_t *state): The graphics state to use for interaction -** Returns : (char *) The input, in a static buffer -*/ - -void con_gfx_hide(gfx_state_t *stae); -/* Closes the on-screen console -** Parameters: (gfx_state_t *state): The graphics state to use for interaction -** Returns : (void) -*/ - - -int sci_hexdump(byte *data, int length, int offsetplus); - -void open_console_file(char *filename); -/* Opens the file to which the console output is echoed. If a file was opened -** before, closes it. -** Parameters: filename - name of the file -** Returns : (void) -*/ - -void close_console_file(); -/* Closes the console output file. -** Parameters: (void) -** Returns : (void) -*/ - -} // End of namespace Sci - -#endif /* _SCI_CONSOLE_H_ */ diff --git a/engines/sci/include/engine.h b/engines/sci/include/engine.h index 2abcf2f4da..d6e54460a8 100644 --- a/engines/sci/include/engine.h +++ b/engines/sci/include/engine.h @@ -37,7 +37,7 @@ namespace Common { #include "sci/include/sciresource.h" #include "sci/include/script.h" #include "sci/include/vocabulary.h" -#include "sci/include/console.h" +#include "sci/include/sciconsole.h" #include "sci/include/vm.h" #include "sci/include/menubar.h" #include "sci/include/versions.h" diff --git a/engines/sci/include/kernel.h b/engines/sci/include/kernel.h index d28fe62250..e8b7c39ca4 100644 --- a/engines/sci/include/kernel.h +++ b/engines/sci/include/kernel.h @@ -33,7 +33,7 @@ #include "sci/include/uinput.h" #include "sci/include/event.h" #include "sci/include/vm.h" -#include "sci/include/console.h" /* sciprintf() */ +#include "sci/include/sciconsole.h" /* sciprintf() */ namespace Sci { diff --git a/engines/sci/include/sciconsole.h b/engines/sci/include/sciconsole.h new file mode 100644 index 0000000000..7e0ad876c4 --- /dev/null +++ b/engines/sci/include/sciconsole.h @@ -0,0 +1,230 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +/* Header file for the SCI console. +** Please note that the console does not use the priority field; the console +** should therefore be drawn after everything else has been drawn (with the +** possible exception of the mouse pointer). +*/ + +#ifndef _SCI_CONSOLE_H_ +#define _SCI_CONSOLE_H_ + +#include "common/scummsys.h" + +#include "sci/include/sci_memory.h" +#include "sci/tools.h" +#include "sci/include/vm_types.h" + +#define SCI_CONSOLE +#include "sci/include/gfx_operations.h" + +namespace Sci { + +extern int con_passthrough; +/* Echo all sciprintf() stuff to the text console */ +extern FILE *con_file; +/* Echo all sciprintf() output to a text file. Note: clients of freesci.dll +** should use open_console_file and close_console_file, rather than refer +** directly to the con_file variable. +*/ + +typedef union { + int32 val; + char *str; + reg_t reg; +} cmd_param_t; + +extern unsigned int cmd_paramlength; +/* The number of parameters passed to a function called from the parser */ + +extern cmd_param_t *cmd_params; +/* The parameters passed to a function called by the parser */ + +extern struct EngineState *con_gamestate; +/* The game state as used by some of the console commands */ + + +/*** 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 +** a pixmap has been provided to be +** published in the on-screen console +** This sets a single callback function to be used after sciprintf() +** is used. +*/ + +void con_init(); +/* Initializes the command parser +** Parameters: (void) +** Returns : (void) +** This function will initialize hook up a few commands to the parser. +** It must be called before cmdParse() is used. +*/ + + +void con_parse(EngineState *s, const char *command); +/* Parses a command and summons appropriate facilities to handle it +** Parameters: (EngineState *) s: The EngineState to use +** command: The command to execute +** Returns : (void) +*/ + + +int con_hook_command(int command(EngineState *s), const char *name, const char *param, const char *description); +/* Adds a command to the parser's command list +** Parameters: command: The command to add +** name: The command's name +** param: A description of the parameters it takes +** description: A short description of what it does +** Returns : 0 if successful, 1 if appending failed because +** of an incorrect *param string, 'command'==0, or +** 'name' already being in use. +** A valid param string is either empty (no parameters allowed) +** or contains one of the following tokens: +** ! Special token: EngineState* must be set for this function to be called +** i (an int) +** s (a 'string' (char *)) +** h (a byte, described in hexadecimal digits) +** a (a heap address, register or object name) +** r (any register value) +** x* (an arbitrary (possibly 0) number of 'x' tokens) +** The '*' token may only be used as the last token of the list. +** Another way to specify optional parameters is by means of the +** '-opt:t' notation, which allows an optional parameter of type 't' +** to be specified as 'opt:' when calling. See also the +** con_hasopt() and con_getopt() calls. +** +** Please note that the 'h' type does accept hexadecimal numbers greater +** than 0xff and less than 0x00, but clips them to this range. +** +** Example: "isi*" would define the function to take an int, a +** string, and an arbitrary number of ints as parameters (in that sequence). +** +** When the function is called, it can retrieve its parameters from cmd_params; +** the actual number of parameters is stored in cmd_paramlength. +** It is allowed to modify the char*s from a cmd_params[] element, as long +** as no element beyond strlen(cmd_params[x].str)+1 is accessed. +*/ + +cmd_param_t con_getopt(char *opt); +/* Retreives the specified optional parameter +** -- for use within console functions only -- +** Parameters: (char *) opt: The optional parameter to retrieve +** Returns : (cmd_param_t) The corresponding parameter +** Should only be used if con_hasopt() reports its presence. +*/ + +int con_hasopt(char *opt); +/* Checks whether an optional parameter was specified +** -- for use within console functions only -- +** Parameters: (char *) opt: The optional parameter to check for +** Returns : (int) non-zero iff the parameter was specified +*/ + +int con_can_handle_pixmaps(); +/* Determines whether the console supports pixmap inserts +** Returns : (int) non-zero iff pixmap inserts are supported +*/ + +int con_insert_pixmap(gfx_pixmap_t *pixmap); +/* Inserts a pixmap into the console history buffer +** Parameters: (gfx_pixmap_t *) pixmap: The pixmap to insert +** Returns : (int) 0 on success, non-zero if no receiver for +** the pixmap could not be found +** The pixmap must be unique; it is freed by the console on demand. +** Use gfx_clone_pixmap() if neccessary. +** If the pixmap could not be inserted, the called must destroy it +*/ + +int con_hook_page(const char *topic, const char *body); +/* Hooks a general information page to the manual page system +** Parameters: (const char *) topic: The topic name +** (const char *) body: The text body to assign to the topic +** Returns : (int) 0 on success +*/ + +int con_hook_int(int *pointer, const char *name, const char *description); +/* Adds an int to the list of modifyable ints. +** Parameters: pointer: Pointer to the int to add to the list +** name: Name for this value +** description: A short description for the value +** Returns : 0 on success, 1 if either value has already been added +** or if name is already being used for a different value. +** The internal list of int references is used by some of the basic commands. +*/ + + +void con_gfx_init(); +/* Initializes the gfx console +*/ + +void con_gfx_show(gfx_state_t *state); +/* Enters on-screen console mode +** Parameters: (gfx_state_t *state): The graphics state to use for interaction +** Returns : (void) +*/ + +char *con_gfx_read(gfx_state_t *state); +/* Reads a single line from the on-screen console, if it is open +** Parameters: (gfx_state_t *state): The graphics state to use for interaction +** Returns : (char *) The input, in a static buffer +*/ + +void con_gfx_hide(gfx_state_t *stae); +/* Closes the on-screen console +** Parameters: (gfx_state_t *state): The graphics state to use for interaction +** Returns : (void) +*/ + + +int sci_hexdump(byte *data, int length, int offsetplus); + +void open_console_file(char *filename); +/* Opens the file to which the console output is echoed. If a file was opened +** before, closes it. +** Parameters: filename - name of the file +** Returns : (void) +*/ + +void close_console_file(); +/* Closes the console output file. +** Parameters: (void) +** Returns : (void) +*/ + +} // End of namespace Sci + +#endif /* _SCI_CONSOLE_H_ */ diff --git a/engines/sci/module.mk b/engines/sci/module.mk index be8d7374a4..6e6c73716f 100644 --- a/engines/sci/module.mk +++ b/engines/sci/module.mk @@ -53,7 +53,7 @@ MODULE_OBJS = \ gfx/resource/sci_view_0.o \ gfx/resource/sci_view_1.o \ scicore/aatree.o \ - scicore/console.o \ + scicore/sciconsole.o \ scicore/decompress0.o \ scicore/decompress01.o \ scicore/decompress1.o \ diff --git a/engines/sci/sci.cpp b/engines/sci/sci.cpp index ff1a51f22a..17a9f5114a 100644 --- a/engines/sci/sci.cpp +++ b/engines/sci/sci.cpp @@ -173,8 +173,7 @@ Common::Error SciEngine::init() { initGraphics(320, 200, false); // Create debugger console. It requires GFX to be initialized - // FIXME: Enabling this leads to an unresolved external symbol during linking... - //_console = new Console(this); + _console = new Console(this); // Additional setup. printf("SciEngine::init\n"); diff --git a/engines/sci/scicore/console.cpp b/engines/sci/scicore/console.cpp deleted file mode 100644 index 8db1b930fb..0000000000 --- a/engines/sci/scicore/console.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* 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. - * - * $URL$ - * $Id$ - * - */ - -/* First part of the console implmentation: VM independent stuff */ -/* Remember, it doesn't have to be fast. */ - -#include "sci/include/sci_memory.h" -#include "sci/include/engine.h" - -namespace Sci { - -#ifdef SCI_CONSOLE - -int con_passthrough = 0; -FILE *con_file = NULL; - -static void(*_con_string_callback)(char*) = NULL; -static void (*_con_pixmap_callback)(gfx_pixmap_t *) = NULL; - -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; - } - - 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); - } - va_end(argp); - - if (con_passthrough) - printf("%s", buf); - if (con_file) - fprintf(con_file, "%s", buf); - - if (_con_string_callback) - _con_string_callback(buf); - else - free(buf); - - return 1; -} - -void con_set_string_callback(void(*callback)(char *)) { - _con_string_callback = callback; -} - -void con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)) { - _con_pixmap_callback = callback; -} - -int con_can_handle_pixmaps() { - return _con_pixmap_callback != NULL; -} - -int con_insert_pixmap(gfx_pixmap_t *pixmap) { - if (_con_pixmap_callback) - _con_pixmap_callback(pixmap); - else - return 1; - return 0; -} - -void open_console_file(char *filename) { - if (con_file != NULL) - fclose(con_file); - - if (NULL == filename) { - fprintf(stderr, "console.c: open_console_file(): NULL passed for parameter filename\r\n"); - } -#ifdef WIN32 - con_file = fopen(filename, "wt"); -#else - con_file = fopen(filename, "w"); -#endif - - if (NULL == con_file) - fprintf(stderr, "console.c: open_console_file(): Could not open output file %s\n", filename); -} - -void close_console_file() { - if (con_file != NULL) { - fclose(con_file); - con_file = NULL; - } -} - -#endif // SCI_CONSOLE - -} // End of namespace Sci diff --git a/engines/sci/scicore/sciconsole.cpp b/engines/sci/scicore/sciconsole.cpp new file mode 100644 index 0000000000..8db1b930fb --- /dev/null +++ b/engines/sci/scicore/sciconsole.cpp @@ -0,0 +1,128 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +/* First part of the console implmentation: VM independent stuff */ +/* Remember, it doesn't have to be fast. */ + +#include "sci/include/sci_memory.h" +#include "sci/include/engine.h" + +namespace Sci { + +#ifdef SCI_CONSOLE + +int con_passthrough = 0; +FILE *con_file = NULL; + +static void(*_con_string_callback)(char*) = NULL; +static void (*_con_pixmap_callback)(gfx_pixmap_t *) = NULL; + +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; + } + + 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); + } + va_end(argp); + + if (con_passthrough) + printf("%s", buf); + if (con_file) + fprintf(con_file, "%s", buf); + + if (_con_string_callback) + _con_string_callback(buf); + else + free(buf); + + return 1; +} + +void con_set_string_callback(void(*callback)(char *)) { + _con_string_callback = callback; +} + +void con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)) { + _con_pixmap_callback = callback; +} + +int con_can_handle_pixmaps() { + return _con_pixmap_callback != NULL; +} + +int con_insert_pixmap(gfx_pixmap_t *pixmap) { + if (_con_pixmap_callback) + _con_pixmap_callback(pixmap); + else + return 1; + return 0; +} + +void open_console_file(char *filename) { + if (con_file != NULL) + fclose(con_file); + + if (NULL == filename) { + fprintf(stderr, "console.c: open_console_file(): NULL passed for parameter filename\r\n"); + } +#ifdef WIN32 + con_file = fopen(filename, "wt"); +#else + con_file = fopen(filename, "w"); +#endif + + if (NULL == con_file) + fprintf(stderr, "console.c: open_console_file(): Could not open output file %s\n", filename); +} + +void close_console_file() { + if (con_file != NULL) { + fclose(con_file); + con_file = NULL; + } +} + +#endif // SCI_CONSOLE + +} // End of namespace Sci -- cgit v1.2.3