aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/scicore
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/scicore')
-rw-r--r--engines/sci/scicore/console.cpp8
-rw-r--r--engines/sci/scicore/decompress0.cpp22
-rw-r--r--engines/sci/scicore/decompress01.cpp20
-rw-r--r--engines/sci/scicore/decompress1.cpp54
-rw-r--r--engines/sci/scicore/decompress11.cpp20
-rw-r--r--engines/sci/scicore/resource.cpp24
-rw-r--r--engines/sci/scicore/resource_map.cpp18
-rw-r--r--engines/sci/scicore/sci_memory.cpp24
-rw-r--r--engines/sci/scicore/script.cpp8
-rw-r--r--engines/sci/scicore/tools.cpp34
-rw-r--r--engines/sci/scicore/vocab.cpp8
-rw-r--r--engines/sci/scicore/vocab_debug.cpp2
12 files changed, 145 insertions, 97 deletions
diff --git a/engines/sci/scicore/console.cpp b/engines/sci/scicore/console.cpp
index a276875bc2..8db1b930fb 100644
--- a/engines/sci/scicore/console.cpp
+++ b/engines/sci/scicore/console.cpp
@@ -46,12 +46,12 @@ int sciprintf(const char *fmt, ...) {
char *buf = (char *)sci_malloc(bufsize);
if (NULL == fmt) {
- error("console.c: sciprintf(): NULL passed for parameter fmt\n");
+ fprintf(stderr, "console.c: sciprintf(): NULL passed for parameter fmt\n");
return -1;
}
if (NULL == buf) {
- error("console.c: sciprintf(): malloc failed for buf\n");
+ fprintf(stderr, "console.c: sciprintf(): malloc failed for buf\n");
return -1;
}
@@ -104,7 +104,7 @@ void open_console_file(char *filename) {
fclose(con_file);
if (NULL == filename) {
- error("console.c: open_console_file(): NULL passed for parameter filename\r\n");
+ fprintf(stderr, "console.c: open_console_file(): NULL passed for parameter filename\r\n");
}
#ifdef WIN32
con_file = fopen(filename, "wt");
@@ -113,7 +113,7 @@ void open_console_file(char *filename) {
#endif
if (NULL == con_file)
- error("console.c: open_console_file(): Could not open output file %s\n", filename);
+ fprintf(stderr, "console.c: open_console_file(): Could not open output file %s\n", filename);
}
void close_console_file() {
diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp
index 0f6411b6a7..4cf476713a 100644
--- a/engines/sci/scicore/decompress0.cpp
+++ b/engines/sci/scicore/decompress0.cpp
@@ -27,7 +27,6 @@
** This is for SCI version 0 style compression.
*/
-#include "common/util.h"
#include "sci/include/sci_memory.h"
#include "sci/include/sciresource.h"
@@ -100,7 +99,7 @@ int decrypt1(guint8 *dest, guint8 *src, int length, int complength) {
if (token > 0xff) {
if (token >= tokenctr) {
#ifdef _SCI_DECOMPRESS_DEBUG
- error("decrypt1: Bad token %x", token);
+ fprintf(stderr, "decrypt1: Bad token %x!\n", token);
#endif
// Well this is really bad
// May be it should throw something like SCI_ERROR_DECOMPRESSION_INSANE
@@ -109,7 +108,7 @@ int decrypt1(guint8 *dest, guint8 *src, int length, int complength) {
if (destctr + tokenlastlength > length) {
#ifdef _SCI_DECOMPRESS_DEBUG
// For me this seems a normal situation, It's necessary to handle it
- printf("decrypt1: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)",
+ printf("decrypt1: Trying to write beyond the end of array(len=%d, destctr=%d, tok_len=%d)!\n",
length, destctr, tokenlastlength);
#endif
i = 0;
@@ -126,7 +125,7 @@ int decrypt1(guint8 *dest, guint8 *src, int length, int complength) {
tokenlastlength = 1;
if (destctr >= length) {
#ifdef _SCI_DECOMPRESS_DEBUG
- printf("decrypt1: Try to write single byte beyond end of array");
+ printf("decrypt1: Try to write single byte beyond end of array!\n");
#endif
} else
dest[destctr++] = (byte)token;
@@ -289,9 +288,13 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
- error("Resource %s.%03hi encrypted with method %hi at %.2f%% ratio\n", sci_resource_types[result->type],
- result->number, compressionMethod, (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size));
- error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size);
+ fprintf(stderr, "Resource %s.%03hi encrypted with method %hi at %.2f%%"
+ " ratio\n",
+ sci_resource_types[result->type], result->number, compressionMethod,
+ (result->size == 0) ? -1.0 :
+ (100.0 * compressedLength / result->size));
+ fprintf(stderr, " compressedLength = 0x%hx, actualLength=0x%hx\n",
+ compressedLength, result->size);
#endif
switch (compressionMethod) {
@@ -330,8 +333,9 @@ int decompress0(resource_t *result, Common::ReadStream &stream, int sci_version)
break;
default:
- error("Resource %s.%03hi: Compression method %hi not supported", sci_resource_types[result->type],
- result->number, compressionMethod);
+ fprintf(stderr, "Resource %s.%03hi: Compression method %hi not "
+ "supported!\n", sci_resource_types[result->type], result->number,
+ compressionMethod);
free(result->data);
result->data = 0; // So that we know that it didn't work
result->status = SCI_STATUS_NOMALLOC;
diff --git a/engines/sci/scicore/decompress01.cpp b/engines/sci/scicore/decompress01.cpp
index 59afdb6b56..7b3a1d004c 100644
--- a/engines/sci/scicore/decompress01.cpp
+++ b/engines/sci/scicore/decompress01.cpp
@@ -25,7 +25,6 @@
// Reads data from a resource file and stores the result in memory
-#include "common/util.h"
#include "sci/include/sci_memory.h"
#include "sci/include/sciresource.h"
@@ -425,7 +424,7 @@ byte *view_reorder(byte *inbuffer, int dsize) {
for (l = 0;l < loopheaders;l++) {
if (lh_mask & lb) { // The loop is _not_ present
if (lh_last == -1) {
- error("Error: While reordering view: Loop not present, but can't re-use last loop");
+ fprintf(stderr, "Error: While reordering view: Loop not present, but can't re-use last loop!\n");
lh_last = 0;
}
putInt16(lh_ptr, lh_last);
@@ -459,7 +458,7 @@ byte *view_reorder(byte *inbuffer, int dsize) {
}
if (celindex < cel_total) {
- error("View decompression generated too few (%d / %d) headers", celindex, cel_total);
+ fprintf(stderr, "View decompression generated too few (%d / %d) headers!\n", celindex, cel_total);
return NULL;
}
@@ -542,9 +541,13 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version
#ifdef _SCI_DECOMPRESS_DEBUG
- error("Resource %s.%03hi encrypted with method SCI01/%hi at %.2f%% ratio\n", sci_resource_types[result->type],
- result->number, compressionMethod, (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size));
- error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size);
+ fprintf(stderr, "Resource %s.%03hi encrypted with method SCI01/%hi at %.2f%%"
+ " ratio\n",
+ sci_resource_types[result->type], result->number, compressionMethod,
+ (result->size == 0) ? -1.0 :
+ (100.0 * compressedLength / result->size));
+ fprintf(stderr, " compressedLength = 0x%hx, actualLength=0x%hx\n",
+ compressedLength, result->size);
#endif
switch (compressionMethod) {
@@ -611,8 +614,9 @@ int decompress01(resource_t *result, Common::ReadStream &stream, int sci_version
break;
default:
- error("Resource %s.%03hi: Compression method SCI1/%hi not supported", sci_resource_types[result->type],
- result->number, compressionMethod);
+ fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not "
+ "supported!\n", sci_resource_types[result->type], result->number,
+ compressionMethod);
free(result->data);
result->data = 0; // So that we know that it didn't work
result->status = SCI_STATUS_NOMALLOC;
diff --git a/engines/sci/scicore/decompress1.cpp b/engines/sci/scicore/decompress1.cpp
index 6a49ceb740..7ee7715870 100644
--- a/engines/sci/scicore/decompress1.cpp
+++ b/engines/sci/scicore/decompress1.cpp
@@ -71,7 +71,8 @@ static inline int getbits_msb_first(struct bit_read_struct *inp, int bits) {
int i;
if (inp->bytepos + morebytes >= inp->length) {
- error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n", inp->bytepos, morebytes, inp->length);
+ fprintf(stderr, "read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
+ inp->bytepos, morebytes, inp->length);
return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
}
@@ -95,7 +96,8 @@ static inline int getbits(struct bit_read_struct *inp, int bits) {
int i;
if (inp->bytepos + morebytes >= inp->length) {
- error("read out-of-bounds with bytepos %d + morebytes %d >= length %d\n", inp->bytepos, morebytes, inp->length);
+ fprintf(stderr, "read out-of-bounds with bytepos %d + morebytes %d >= length %d\n",
+ inp->bytepos, morebytes, inp->length);
return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
}
@@ -109,7 +111,7 @@ static inline int getbits(struct bit_read_struct *inp, int bits) {
inp->bytepos += morebytes;
if (DEBUG_DCL_INFLATE)
- error("(%d:%04x)", bits, result);
+ fprintf(stderr, "(%d:%04x)", bits, result);
return result;
}
@@ -121,14 +123,14 @@ static int huffman_lookup(struct bit_read_struct *inp, int *tree) {
while (!(tree[pos] & HUFFMAN_LEAF)) {
CALLC(bit = getbits(inp, 1));
if (DEBUG_DCL_INFLATE)
- error("[%d]:%d->", pos, bit);
+ fprintf(stderr, "[%d]:%d->", pos, bit);
if (bit)
pos = tree[pos] & ~(~0 << BRANCH_SHIFT);
else
pos = tree[pos] >> BRANCH_SHIFT;
}
if (DEBUG_DCL_INFLATE)
- error("=%02x\n", tree[pos] & 0xffff);
+ fprintf(stderr, "=%02x\n", tree[pos] & 0xffff);
return tree[pos] & 0xffff;
}
@@ -147,7 +149,7 @@ static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
warning("DCL-INFLATE: Warning: Decompressing ASCII mode (untested)");
//DEBUG_DCL_INFLATE = 1;
} else if (mode) {
- error("DCL-INFLATE: Error: Encountered mode %02x, expected 00 or 01\n", mode);
+ fprintf(stderr, "DCL-INFLATE: Error: Encountered mode %02x, expected 00 or 01\n", mode);
return 1;
}
@@ -155,18 +157,18 @@ static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
int i;
for (i = 0; i < reader->length; i++) {
- error("%02x ", reader->data[i]);
+ fprintf(stderr, "%02x ", reader->data[i]);
if (!((i + 1) & 0x1f))
- error("\n");
+ fprintf(stderr, "\n");
}
- error("\n---\n");
+ fprintf(stderr, "\n---\n");
}
if (length_param < 3 || length_param > 6)
- error("Warning: Unexpected length_param value %d (expected in [3,6])\n", length_param);
+ fprintf(stderr, "Warning: Unexpected length_param value %d (expected in [3,6])\n", length_param);
while (write_pos < length) {
CALLC(value = getbits(reader, 1));
@@ -185,7 +187,7 @@ static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
}
if (DEBUG_DCL_INFLATE)
- error(" | ");
+ fprintf(stderr, " | ");
CALLC(value = huffman_lookup(reader, distance_tree));
@@ -203,15 +205,15 @@ static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
++val_distance;
if (DEBUG_DCL_INFLATE)
- error("\nCOPY(%d from %d)\n", val_length, val_distance);
+ fprintf(stderr, "\nCOPY(%d from %d)\n", val_length, val_distance);
if (val_length + write_pos > length) {
- error("DCL-INFLATE Error: Write out of bounds while copying %d bytes\n", val_length);
+ fprintf(stderr, "DCL-INFLATE Error: Write out of bounds while copying %d bytes\n", val_length);
return -SCI_ERROR_DECOMPRESSION_OVERFLOW;
}
if (write_pos < val_distance) {
- error("DCL-INFLATE Error: Attempt to copy from before beginning of input stream\n");
+ fprintf(stderr, "DCL-INFLATE Error: Attempt to copy from before beginning of input stream\n");
return -SCI_ERROR_DECOMPRESSION_INSANE;
}
@@ -223,8 +225,8 @@ static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
if (DEBUG_DCL_INFLATE) {
int i;
for (i = 0; i < copy_length; i++)
- error("\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
- error("\n");
+ fprintf(stderr, "\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
+ fprintf(stderr, "\n");
}
val_length -= copy_length;
@@ -242,7 +244,7 @@ static int decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
dest[write_pos++] = value;
if (DEBUG_DCL_INFLATE)
- error("\33[32;31m%02x \33[37;37m", value);
+ fprintf(stderr, "\33[32;31m%02x \33[37;37m", value);
}
}
@@ -331,10 +333,15 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
- error("Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%% ratio\n", result->number,
- sci_resource_type_suffixes[result->type], early ? 'e' : 'l', compressionMethod,
- (result->size == 0) ? -1.0 : (100.0 * compressedLength / result->size));
- error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size);
+ fprintf(stderr, "Resource %i.%s encrypted with method SCI1%c/%hi at %.2f%%"
+ " ratio\n",
+ result->number, sci_resource_type_suffixes[result->type],
+ early ? 'e' : 'l',
+ compressionMethod,
+ (result->size == 0) ? -1.0 :
+ (100.0 * compressedLength / result->size));
+ fprintf(stderr, " compressedLength = 0x%hx, actualLength=0x%hx\n",
+ compressedLength, result->size);
#endif
switch (compressionMethod) {
@@ -400,8 +407,9 @@ int decompress1(resource_t *result, Common::ReadStream &stream, int sci_version)
break;
default:
- error("Resource %s.%03hi: Compression method SCI1/%hi not supported", sci_resource_types[result->type],
- result->number, compressionMethod);
+ fprintf(stderr, "Resource %s.%03hi: Compression method SCI1/%hi not "
+ "supported!\n", sci_resource_types[result->type], result->number,
+ compressionMethod);
free(result->data);
result->data = 0; // So that we know that it didn't work
result->status = SCI_STATUS_NOMALLOC;
diff --git a/engines/sci/scicore/decompress11.cpp b/engines/sci/scicore/decompress11.cpp
index 722f51dd6f..d2600b46e8 100644
--- a/engines/sci/scicore/decompress11.cpp
+++ b/engines/sci/scicore/decompress11.cpp
@@ -25,7 +25,6 @@
// Reads data from a resource file and stores the result in memory
-#include "common/util.h"
#include "sci/include/sci_memory.h"
#include "sci/include/sciresource.h"
@@ -99,10 +98,14 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version
}
#ifdef _SCI_DECOMPRESS_DEBUG
- error("Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%% ratio\n", result->number,
- sci_resource_type_suffixes[result->type], compressionMethod, (result->size == 0) ? -1.0 :
- (100.0 * compressedLength / result->size));
- error(" compressedLength = 0x%hx, actualLength=0x%hx\n", compressedLength, result->size);
+ fprintf(stderr, "Resource %i.%s encrypted with method SCI1.1/%hi at %.2f%%"
+ " ratio\n",
+ result->number, sci_resource_type_suffixes[result->type],
+ compressionMethod,
+ (result->size == 0) ? -1.0 :
+ (100.0 * compressedLength / result->size));
+ fprintf(stderr, " compressedLength = 0x%hx, actualLength=0x%hx\n",
+ compressedLength, result->size);
#endif
DDEBUG("/%d[%d]", compressionMethod, result->size);
@@ -135,7 +138,7 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version
case 3:
case 4: // NYI
- error("Resource %d.%s: Warning: compression type #%d not yet implemented\n",
+ fprintf(stderr, "Resource %d.%s: Warning: compression type #%d not yet implemented\n",
result->number, sci_resource_type_suffixes[result->type], compressionMethod);
free(result->data);
result->data = NULL;
@@ -143,8 +146,9 @@ int decompress11(resource_t *result, Common::ReadStream &stream, int sci_version
break;
default:
- error("Resource %d.%s: Compression method SCI1/%hi not supported", result->number,
- sci_resource_type_suffixes[result->type], compressionMethod);
+ fprintf(stderr, "Resource %d.%s: Compression method SCI1/%hi not "
+ "supported!\n", result->number, sci_resource_type_suffixes[result->type],
+ compressionMethod);
free(result->data);
result->data = NULL; // So that we know that it didn't work
result->status = SCI_STATUS_NOMALLOC;
diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp
index 0a40d0f6a0..705546f6a4 100644
--- a/engines/sci/scicore/resource.cpp
+++ b/engines/sci/scicore/resource.cpp
@@ -481,7 +481,7 @@ ResourceManager::ResourceManager(int version, int maxMemory) {
free(_resources);
_resources = NULL;
}
- sciprintf("Resmgr: Could not retrieve a resource list");
+ sciprintf("Resmgr: Could not retrieve a resource list!\n");
_scir_free_resource_sources(mgr->_sources);
error("FIXME: Move this code to an init() method so that we can perform error handling");
// return NULL;
@@ -623,8 +623,9 @@ static void _scir_add_to_lru(ResourceManager *mgr, resource_t *res) {
mgr->memory_lru += res->size;
#if (SCI_VERBOSE_RESMGR > 1)
- error("Adding %s.%03d (%d bytes) to lru control: %d bytes total\n", sci_resource_types[res->type],
- res->number, res->size, mgr->memory_lru);
+ fprintf(stderr, "Adding %s.%03d (%d bytes) to lru control: %d bytes total\n",
+ sci_resource_types[res->type], res->number, res->size,
+ mgr->memory_lru);
#endif
@@ -637,22 +638,25 @@ static void _scir_print_lru_list(ResourceManager *mgr) {
resource_t *res = mgr->lru_first;
while (res) {
- error("\t%s.%03d: %d bytes\n", sci_resource_types[res->type], res->number, res->size);
+ fprintf(stderr, "\t%s.%03d: %d bytes\n",
+ sci_resource_types[res->type], res->number,
+ res->size);
mem += res->size;
++entries;
res = res->next;
}
- error("Total: %d entries, %d bytes (mgr says %d)\n", entries, mem, mgr->memory_lru);
+ fprintf(stderr, "Total: %d entries, %d bytes (mgr says %d)\n",
+ entries, mem, mgr->memory_lru);
}
static void _scir_free_old_resources(ResourceManager *mgr, int last_invulnerable) {
while (mgr->_maxMemory < mgr->memory_lru && (!last_invulnerable || mgr->lru_first != mgr->lru_last)) {
resource_t *goner = mgr->lru_last;
if (!goner) {
- error("Internal error: mgr->lru_last is NULL");
- error("LRU-mem= %d\n", mgr->memory_lru);
- error("lru_first = %p\n", (void *)mgr->lru_first);
+ fprintf(stderr, "Internal error: mgr->lru_last is NULL!\n");
+ fprintf(stderr, "LRU-mem= %d\n", mgr->memory_lru);
+ fprintf(stderr, "lru_first = %p\n", (void *)mgr->lru_first);
_scir_print_lru_list(mgr);
}
@@ -714,9 +718,9 @@ resource_t * scir_find_resource(ResourceManager *mgr, int type, int number, int
void scir_unlock_resource(ResourceManager *mgr, resource_t *res, int resnum, int restype) {
if (!res) {
if (restype >= ARRAYSIZE(sci_resource_types))
- sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %03d.%03d", restype, resnum);
+ sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %03d.%03d!\n", restype, resnum);
else
- sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %s.%03d", sci_resource_types[restype], resnum);
+ sciprintf("Resmgr: Warning: Attempt to unlock non-existant resource %s.%03d!\n", sci_resource_types[restype], resnum);
return;
}
diff --git a/engines/sci/scicore/resource_map.cpp b/engines/sci/scicore/resource_map.cpp
index f0e418facd..dd44dabfcb 100644
--- a/engines/sci/scicore/resource_map.cpp
+++ b/engines/sci/scicore/resource_map.cpp
@@ -147,8 +147,10 @@ static int sci_res_read_entry(ResourceManager *mgr, ResourceSource *map,
}
#if 0
- error("Read [%04x] %6d.%s\tresource.%03d, %08x\n", res->id, res->number,
- sci_resource_type_suffixes[res->type], res->file, res->file_offset);
+ fprintf(stderr, "Read [%04x] %6d.%s\tresource.%03d, %08x\n",
+ res->id, res->number,
+ sci_resource_type_suffixes[res->type],
+ res->file, res->file_offset);
#endif
if (res->source == NULL)
@@ -307,7 +309,7 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
file.close();
if (!resource_index) {
- sciprintf("resource.map was empty");
+ sciprintf("resource.map was empty!\n");
_scir_free_resources(resources, resource_nr);
return SCI_ERROR_RESMAP_NOT_FOUND;
}
@@ -339,7 +341,7 @@ int sci0_read_resource_map(ResourceManager *mgr, ResourceSource *map, resource_t
return 0;
}
-#define TEST error("OK in line %d\n", __LINE__);
+#define TEST fprintf(stderr, "OK in line %d\n", __LINE__);
static int sci10_or_11(int *types) {
int this_restype = 0;
@@ -464,7 +466,9 @@ int sci1_read_resource_map(ResourceManager *mgr, ResourceSource *map, ResourceSo
}
#if 0
- error("Read [%04x] %6d.%s\tresource.%03d, %08x ==> %d\n", res->id, res->number, sci_resource_type_suffixes[res->type],
+ fprintf(stderr, "Read [%04x] %6d.%s\tresource.%03d, %08x ==> %d\n",
+ res->id, res->number,
+ sci_resource_type_suffixes[res->type],
res->file, res->file_offset, addto);
#endif
@@ -491,7 +495,7 @@ int main(int argc, char **argv) {
int notok = sci0_read_resource_map(".", &resources, &resource_nr);
if (notok) {
- error("Failed: Error code %d\n", notok);
+ fprintf(stderr, "Failed: Error code %d\n", notok);
return 1;
}
@@ -507,7 +511,7 @@ int main(int argc, char **argv) {
sci_resource_types[res->type], res->number);
}
} else
- error("Found no resources.\n");
+ fprintf(stderr, "Found no resources.\n");
return 0;
}
diff --git a/engines/sci/scicore/sci_memory.cpp b/engines/sci/scicore/sci_memory.cpp
index 4b2b56d696..693f90848f 100644
--- a/engines/sci/scicore/sci_memory.cpp
+++ b/engines/sci/scicore/sci_memory.cpp
@@ -54,8 +54,9 @@ char *sci_strdup(const char *src) {
void *res;
if (!src) {
- error("_SCI_STRDUP() [%s (%s) : %u]\n", __FILE__, "", __LINE__);
- error(" attempt to strdup NULL pointer\n");
+ fprintf(stderr, "_SCI_STRDUP() [%s (%s) : %u]\n",
+ __FILE__, "", __LINE__);
+ fprintf(stderr, " attempt to strdup NULL pointer\n");
BREAKPOINT();
}
ALLOC_MEM((res = strdup(src)), strlen(src), __FILE__, __LINE__, "")
@@ -69,8 +70,9 @@ char *sci_strndup(const char *src, size_t length) {
size_t rlen = (int)MIN(strlen(src), length) + 1;
if (!src) {
- error("_SCI_STRNDUP() [%s (%s) : %u]\n", __FILE__, "", __LINE__);
- error(" attempt to strndup NULL pointer\n");
+ fprintf(stderr, "_SCI_STRNDUP() [%s (%s) : %u]\n",
+ __FILE__, "", __LINE__);
+ fprintf(stderr, " attempt to strndup NULL pointer\n");
BREAKPOINT();
}
ALLOC_MEM((res = malloc(rlen)), rlen, __FILE__, __LINE__, "")
@@ -99,7 +101,7 @@ char *sci_strndup(const char *src, size_t length) {
extern void *sci_refcount_alloc(size_t length) {
guint32 *data = (guint32 *)sci_malloc(REFCOUNT_OVERHEAD + length);
#ifdef TRACE_REFCOUNT
- error("[] REF: Real-alloc at %p\n", data);
+ fprintf(stderr, "[] REF: Real-alloc at %p\n", data);
#endif
data += 3;
@@ -107,7 +109,8 @@ extern void *sci_refcount_alloc(size_t length) {
data[-3] = REFCOUNT_MAGIC_LIVE_2;
REFCOUNT(data) = 1;
#ifdef TRACE_REFCOUNT
- error("[] REF: Alloc'd %p (ref=%d) OK=%d\n", data, REFCOUNT(data), REFCOUNT_CHECK(data));
+ fprintf(stderr, "[] REF: Alloc'd %p (ref=%d) OK=%d\n", data, REFCOUNT(data),
+ REFCOUNT_CHECK(data));
#endif
return data;
}
@@ -119,14 +122,15 @@ extern void *sci_refcount_incref(void *data) {
REFCOUNT(data)++;
#ifdef TRACE_REFCOUNT
- error("[] REF: Inc'ing %p (now ref=%d)\n", data, REFCOUNT(data));
+ fprintf(stderr, "[] REF: Inc'ing %p (now ref=%d)\n", data, REFCOUNT(data));
#endif
return data;
}
extern void sci_refcount_decref(void *data) {
#ifdef TRACE_REFCOUNT
- error("[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data), REFCOUNT_CHECK(data));
+ fprintf(stderr, "[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data),
+ REFCOUNT_CHECK(data));
#endif
if (!REFCOUNT_CHECK(data)) {
BREAKPOINT();
@@ -137,11 +141,11 @@ extern void sci_refcount_decref(void *data) {
fdata[-3] = REFCOUNT_MAGIC_DEAD_2;
#ifdef TRACE_REFCOUNT
- error("[] REF: Freeing (%p)...\n", fdata - 3);
+ fprintf(stderr, "[] REF: Freeing (%p)...\n", fdata - 3);
#endif
free(fdata - 3);
#ifdef TRACE_REFCOUNT
- error("[] REF: Done.\n");
+ fprintf(stderr, "[] REF: Done.\n");
#endif
}
}
diff --git a/engines/sci/scicore/script.cpp b/engines/sci/scicore/script.cpp
index 6116a12a47..1675768cda 100644
--- a/engines/sci/scicore/script.cpp
+++ b/engines/sci/scicore/script.cpp
@@ -114,7 +114,7 @@ int script_find_selector(EngineState *s, const char *selectorname) {
if (strcmp(selectorname, s->selector_names[i]) == 0)
return i;
- sciprintf("Warning: Could not map '%s' to any selector", selectorname);
+ sciprintf("Warning: Could not map '%s' to any selector!\n", selectorname);
return -1;
}
@@ -317,7 +317,7 @@ static void script_dump_class(char *data, int seeker, int objsize, char **snames
while (overloads--) {
int selector = getInt16((unsigned char *)data + (seeker));
- error("selector=%d; snames_nr =%d\n", selector, snames_nr);
+ fprintf(stderr, "selector=%d; snames_nr =%d\n", selector, snames_nr);
sciprintf(" [%03x] %s: @", selector & 0xffff, (snames && selector >= 0 && selector < snames_nr) ?
snames[selector] : "<?>");
sciprintf("%04x\n", getInt16((unsigned char *)data + seeker + selectors * 2 + 2) & 0xffff);
@@ -334,7 +334,7 @@ void script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snam
int word_count;
if (!script) {
- sciprintf("Script not found");
+ sciprintf("Script not found!\n");
return;
}
@@ -471,7 +471,7 @@ void script_dissect(ResourceManager *resmgr, int res_no, char **snames, int snam
break;
default:
- sciprintf("Unsupported");
+ sciprintf("Unsupported!\n");
return;
}
diff --git a/engines/sci/scicore/tools.cpp b/engines/sci/scicore/tools.cpp
index 784f52bcc3..66ad33a8e2 100644
--- a/engines/sci/scicore/tools.cpp
+++ b/engines/sci/scicore/tools.cpp
@@ -50,10 +50,10 @@
Sleep(0); \
} else { \
if (timeBeginPeriod(1) != TIMERR_NOERROR) \
- error("timeBeginPeriod(1) failed\n"); \
+ fprintf(stderr, "timeBeginPeriod(1) failed\n"); \
Sleep(x); \
if (timeEndPeriod(1) != TIMERR_NOERROR) \
- error("timeEndPeriod(1) failed\n"); \
+ fprintf(stderr, "timeEndPeriod(1) failed\n"); \
} \
} while (0);
#endif
@@ -112,13 +112,29 @@ int sci_ffs(int _mask) {
// Functions for internal macro use
void _SCIkvprintf(FILE *file, const char *format, va_list args);
-void _SCIkprintf(FILE *file, const char *format, ...) GCC_PRINTF(2, 3);
void _SCIkvprintf(FILE *file, const char *format, va_list args) {
vfprintf(file, format, args);
if (con_file) vfprintf(con_file, format, args);
}
+
+void _SCIkwarn(EngineState *s, const char *file, int line, int area, const char *format, ...) {
+ va_list args;
+
+ if (area == SCIkERROR_NR)
+ fprintf(stderr, "ERROR: ");
+ else
+ fprintf(stderr, "Warning: ");
+
+ va_start(args, format);
+ _SCIkvprintf(stderr, format, args);
+ va_end(args);
+ fflush(NULL);
+
+ if (sci_debug_flags & _DEBUG_FLAG_BREAK_ON_WARNINGS) script_debug_flag = 1;
+}
+
void _SCIkdebug(EngineState *s, const char *file, int line, int area, const char *format, ...) {
va_list args;
@@ -174,13 +190,13 @@ void sci_gettime(long *seconds, long *useconds) {
DWORD tm;
if (TIMERR_NOERROR != timeBeginPeriod(1)) {
- error("timeBeginPeriod(1) failed in sci_gettime\n");
+ fprintf(stderr, "timeBeginPeriod(1) failed in sci_gettime\n");
}
tm = timeGetTime();
if (TIMERR_NOERROR != timeEndPeriod(1)) {
- error("timeEndPeriod(1) failed in sci_gettime\n");
+ fprintf(stderr, "timeEndPeriod(1) failed in sci_gettime\n");
}
*seconds = tm / 1000;
@@ -283,7 +299,7 @@ char *sci_find_first(sci_dir_t *dir, const char *mask) {
closedir(dir->dir);
if (!(dir->dir = opendir("."))) {
- sciprintf("%s, L%d: opendir(\".\") failed", __FILE__, __LINE__);
+ sciprintf("%s, L%d: opendir(\".\") failed!\n", __FILE__, __LINE__);
return NULL;
}
@@ -347,7 +363,7 @@ int sci_mkpath(const char *path) {
sciprintf("Error: Could not create subdirectory '%s' in", path_position);
if (next_separator)
*next_separator = G_DIR_SEPARATOR_S[0];
- sciprintf(" '%s'", path);
+ sciprintf(" '%s'!\n", path);
return -2;
}
}
@@ -399,7 +415,7 @@ Common::String _fcaseseek(const char *fname) {
// free it afterwards */
if (strchr(fname, G_DIR_SEPARATOR)) {
- error("_fcaseseek() does not support subdirs\n");
+ fprintf(stderr, "_fcaseseek() does not support subdirs\n");
BREAKPOINT();
}
@@ -450,7 +466,7 @@ char *sci_getcwd() {
free(cwd);
}
- error("Could not determine current working directory");
+ fprintf(stderr, "Could not determine current working directory!\n");
return NULL;
}
diff --git a/engines/sci/scicore/vocab.cpp b/engines/sci/scicore/vocab.cpp
index 83ab4a4a2d..527928b6db 100644
--- a/engines/sci/scicore/vocab.cpp
+++ b/engines/sci/scicore/vocab.cpp
@@ -101,7 +101,7 @@ vocab_get_words(ResourceManager *resmgr, int *word_counter) {
seeker = 26 * 2; /* vocab.000 starts with 26 16-bit pointers which we don't use */
if (resource->size < seeker) {
- error("Invalid main vocabulary encountered: Too small\n");
+ fprintf(stderr, "Invalid main vocabulary encountered: Too small\n");
return NULL;
/* Now this ought to be critical, but it'll just cause parse() and said() not to work */
}
@@ -199,7 +199,7 @@ vocab_get_suffices(ResourceManager *resmgr, int *suffices_nr) {
unsigned int seeker = 1;
if (!resource) {
- error("Could not find suffix vocabulary");
+ fprintf(stderr, "Could not find suffix vocabulary!\n");
return NULL; /* Not critical */
}
@@ -271,14 +271,14 @@ vocab_get_branches(ResourceManager * resmgr, int *branches_nr) {
int i;
if (!resource) {
- error("No parser tree data found");
+ fprintf(stderr, "No parser tree data found!\n");
return NULL;
}
*branches_nr = resource->size / 20;
if (*branches_nr == 0) {
- error("Parser tree data is empty");
+ fprintf(stderr, "Parser tree data is empty!\n");
return NULL;
}
diff --git a/engines/sci/scicore/vocab_debug.cpp b/engines/sci/scicore/vocab_debug.cpp
index bd3eb2e312..28073e91a3 100644
--- a/engines/sci/scicore/vocab_debug.cpp
+++ b/engines/sci/scicore/vocab_debug.cpp
@@ -246,7 +246,7 @@ opcode* vocabulary_get_opcodes(ResourceManager *resmgr) {
/* if the resource couldn't be loaded, leave */
if (r == NULL) {
- error("unable to load vocab.%03d\n", VOCAB_RESOURCE_OPCODES);
+ fprintf(stderr, "unable to load vocab.%03d\n", VOCAB_RESOURCE_OPCODES);
return NULL;
}