aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorMax Horn2009-02-15 22:28:50 +0000
committerMax Horn2009-02-15 22:28:50 +0000
commit5ecfecd3bc795446581186eb7f0e04b1c0caa0e3 (patch)
treec69aa304b273dd26c3226c7d25be9890c163b886 /engines/sci
parent57434d955fc6eaa77ab1ef5c408f733a59dabbcf (diff)
downloadscummvm-rg350-5ecfecd3bc795446581186eb7f0e04b1c0caa0e3.tar.gz
scummvm-rg350-5ecfecd3bc795446581186eb7f0e04b1c0caa0e3.tar.bz2
scummvm-rg350-5ecfecd3bc795446581186eb7f0e04b1c0caa0e3.zip
SCI: Run astyle to make the code be more compliant with our Code Formatting Guidelines: scicore dir
svn-id: r38318
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/scicore/aatree.cpp33
-rw-r--r--engines/sci/scicore/console.cpp75
-rw-r--r--engines/sci/scicore/decompress0.cpp114
-rw-r--r--engines/sci/scicore/decompress01.cpp241
-rw-r--r--engines/sci/scicore/decompress1.cpp90
-rw-r--r--engines/sci/scicore/decompress11.cpp45
-rw-r--r--engines/sci/scicore/exe.cpp14
-rw-r--r--engines/sci/scicore/exe_dec.h6
-rw-r--r--engines/sci/scicore/exe_lzexe.cpp39
-rw-r--r--engines/sci/scicore/exe_raw.cpp12
-rw-r--r--engines/sci/scicore/games.h154
-rw-r--r--engines/sci/scicore/hashmap.cpp2
-rw-r--r--engines/sci/scicore/modules.cpp43
-rw-r--r--engines/sci/scicore/old_objects.cpp804
-rw-r--r--engines/sci/scicore/reg_t_hashmap.cpp3
-rw-r--r--engines/sci/scicore/resource.cpp330
-rw-r--r--engines/sci/scicore/resource_map.cpp236
-rw-r--r--engines/sci/scicore/resource_patch.cpp57
-rw-r--r--engines/sci/scicore/resourcecheck.cpp7
-rw-r--r--engines/sci/scicore/sci_memory.cpp98
-rw-r--r--engines/sci/scicore/script.cpp809
-rw-r--r--engines/sci/scicore/tools.cpp267
-rw-r--r--engines/sci/scicore/versions.cpp71
-rw-r--r--engines/sci/scicore/vocab.cpp602
-rw-r--r--engines/sci/scicore/vocab_debug.cpp555
25 files changed, 2202 insertions, 2505 deletions
diff --git a/engines/sci/scicore/aatree.cpp b/engines/sci/scicore/aatree.cpp
index 7bbef8c43b..7f2829686e 100644
--- a/engines/sci/scicore/aatree.cpp
+++ b/engines/sci/scicore/aatree.cpp
@@ -30,8 +30,7 @@
#include "sci/include/sci_memory.h"
-struct aatree
-{
+struct aatree {
struct aatree *left, *right;
int level;
void *key;
@@ -41,8 +40,7 @@ struct aatree
static aatree_t bottom = {&bottom, &bottom, 0, NULL};
static void
-skew(aatree_t **t)
-{
+skew(aatree_t **t) {
if ((*t)->left->level == (*t)->level) {
/* Rotate right */
aatree_t *temp = *t;
@@ -53,8 +51,7 @@ skew(aatree_t **t)
}
static void
-split(aatree_t **t)
-{
+split(aatree_t **t) {
if ((*t)->right->right->level == (*t)->level) {
/* Rotate left */
aatree_t *temp = *t;
@@ -66,8 +63,7 @@ split(aatree_t **t)
}
static int
-delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void *, const void *))
-{
+delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void *, const void *)) {
int retval = -1;
if (*t != &bottom) {
@@ -91,8 +87,7 @@ delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void *
*t = (*t)->right;
sci_free(temp);
retval = 0;
- }
- else if (((*t)->left->level < (*t)->level - 1) || ((*t)->right->level < (*t)->level - 1)) {
+ } else if (((*t)->left->level < (*t)->level - 1) || ((*t)->right->level < (*t)->level - 1)) {
(*t)->level--;
if ((*t)->right->level > (*t)->level)
(*t)->right->level = (*t)->level;
@@ -108,14 +103,12 @@ delete_node(void *x, aatree_t **t, aatree_t *deleted, int (*compar)(const void *
}
aatree_t *
-aatree_new()
-{
+aatree_new() {
return &bottom;
}
int
-aatree_insert(void *x, aatree_t **t, int (*compar)(const void *, const void *))
-{
+aatree_insert(void *x, aatree_t **t, int (*compar)(const void *, const void *)) {
int retval = -1;
int c;
@@ -145,14 +138,12 @@ aatree_insert(void *x, aatree_t **t, int (*compar)(const void *, const void *))
}
int
-aatree_delete(void *x, aatree_t **t, int (*compar)(const void *, const void *))
-{
+aatree_delete(void *x, aatree_t **t, int (*compar)(const void *, const void *)) {
return delete_node(x, t, &bottom, compar);
}
aatree_t *
-aatree_walk(aatree_t *t, int direction)
-{
+aatree_walk(aatree_t *t, int direction) {
if ((direction == AATREE_WALK_LEFT) && (t->left != &bottom))
return t->left;
@@ -163,14 +154,12 @@ aatree_walk(aatree_t *t, int direction)
}
void *
-aatree_get_data(aatree_t *t)
-{
+aatree_get_data(aatree_t *t) {
return t->key;
}
void
-aatree_free(aatree_t *t)
-{
+aatree_free(aatree_t *t) {
if (t == &bottom)
return;
diff --git a/engines/sci/scicore/console.cpp b/engines/sci/scicore/console.cpp
index 4bb45160b5..ab53240634 100644
--- a/engines/sci/scicore/console.cpp
+++ b/engines/sci/scicore/console.cpp
@@ -44,12 +44,11 @@ static void (*_con_pixmap_callback)(gfx_pixmap_t *) = NULL;
int
-sciprintf (const char *fmt, ...)
-{
+sciprintf(const char *fmt, ...) {
va_list argp;
size_t bufsize = 256;
unsigned int i;
- char *buf = (char *) sci_malloc (bufsize);
+ char *buf = (char *) sci_malloc(bufsize);
if (NULL == fmt) {
fprintf(stderr, "console.c: sciprintf(): NULL passed for parameter fmt\n");
@@ -61,24 +60,24 @@ sciprintf (const char *fmt, ...)
return -1;
}
- va_start (argp, fmt);
- while ((i = vsnprintf (buf, bufsize - 1, fmt, argp)) == -1
- || (i >= bufsize - 2)) {
+ 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 */
+ va_end(argp);
+ va_start(argp, fmt); /* reset argp */
- free (buf);
- buf = (char *) sci_malloc (bufsize <<= 1);
+ free(buf);
+ buf = (char *) sci_malloc(bufsize <<= 1);
}
- va_end (argp);
+ va_end(argp);
if (con_passthrough)
- printf ("%s", buf);
+ printf("%s", buf);
if (con_file)
- fprintf (con_file, "%s", buf);
+ fprintf(con_file, "%s", buf);
+
-
if (_con_string_callback)
_con_string_callback(buf);
else
@@ -88,26 +87,22 @@ sciprintf (const char *fmt, ...)
}
void
-con_set_string_callback(void(*callback)(char *))
-{
+con_set_string_callback(void(*callback)(char *)) {
_con_string_callback = callback;
}
void
-con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *))
-{
+con_set_pixmap_callback(void(*callback)(gfx_pixmap_t *)) {
_con_pixmap_callback = callback;
}
int
-con_can_handle_pixmaps(void)
-{
+con_can_handle_pixmaps(void) {
return _con_pixmap_callback != NULL;
}
int
-con_insert_pixmap(gfx_pixmap_t *pixmap)
-{
+con_insert_pixmap(gfx_pixmap_t *pixmap) {
if (_con_pixmap_callback)
_con_pixmap_callback(pixmap);
else
@@ -117,34 +112,30 @@ con_insert_pixmap(gfx_pixmap_t *pixmap)
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");
- }
+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");
+ con_file = fopen(filename, "wt");
#else
- con_file = fopen (filename, "w");
+ 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);
+ if (NULL == con_file)
+ fprintf(stderr, "console.c: open_console_file(): Could not open output file %s\n", filename);
}
void
-close_console_file (void)
-{
- if (con_file != NULL)
- {
- fclose (con_file);
- con_file = NULL;
- }
+close_console_file(void) {
+ if (con_file != NULL) {
+ fclose(con_file);
+ con_file = NULL;
+ }
}
diff --git a/engines/sci/scicore/decompress0.cpp b/engines/sci/scicore/decompress0.cpp
index 6dba2d5299..3c92a454c4 100644
--- a/engines/sci/scicore/decompress0.cpp
+++ b/engines/sci/scicore/decompress0.cpp
@@ -36,7 +36,7 @@
/* 9-12 bit LZW encoding */
int
decrypt1(guint8 *dest, guint8 *src, int length, int complength)
- /* Doesn't do length checking yet */
+/* Doesn't do length checking yet */
{
/* Theory: Considering the input as a bit stream, we get a series of
** 9 bit elements in the beginning. Every one of them is a 'token'
@@ -73,9 +73,9 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength)
guint32 tokenmaker = src[bytectr++] >> bitctr;
if (bytectr < complength)
- tokenmaker |= (src[bytectr] << (8-bitctr));
- if (bytectr+1 < complength)
- tokenmaker |= (src[bytectr+1] << (16-bitctr));
+ tokenmaker |= (src[bytectr] << (8 - bitctr));
+ if (bytectr + 1 < complength)
+ tokenmaker |= (src[bytectr+1] << (16 - bitctr));
token = tokenmaker & bitmask;
@@ -98,44 +98,40 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength)
int i;
if (token > 0xff) {
- if (token >= tokenctr)
- {
+ if (token >= tokenctr) {
#ifdef _SCI_DECOMPRESS_DEBUG
- fprintf(stderr, "decrypt1: Bad token %x!\n", 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 */
- } else
- {
- tokenlastlength = tokenlengthlist[token]+1;
- if (destctr+tokenlastlength>length)
- {
+ /* Well this is really bad */
+ /* May be it should throw something like SCI_ERROR_DECOMPRESSION_INSANE */
+ } else {
+ tokenlastlength = tokenlengthlist[token] + 1;
+ 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)!\n",
- length, destctr, tokenlastlength);
+ /* 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)!\n",
+ length, destctr, tokenlastlength);
#endif
- i = 0;
- for (; destctr<length; destctr++) {
- dest[destctr++] = dest [tokenlist[token]+i];
- i++;
- }
- } else
- for (i=0; i< tokenlastlength; i++) {
- dest[destctr++] = dest[tokenlist[token]+i];
+ i = 0;
+ for (; destctr < length; destctr++) {
+ dest[destctr++] = dest [tokenlist[token] + i];
+ i++;
+ }
+ } else
+ for (i = 0; i < tokenlastlength; i++) {
+ dest[destctr++] = dest[tokenlist[token] + i];
+ }
}
- }
} else {
tokenlastlength = 1;
- if (destctr >= length)
- {
+ if (destctr >= length) {
#ifdef _SCI_DECOMPRESS_DEBUG
- printf ("decrypt1: Try to write single byte beyond end of array!\n");
+ printf("decrypt1: Try to write single byte beyond end of array!\n");
#endif
- } else
- dest[destctr++] = (byte)token;
+ } else
+ dest[destctr++] = (byte)token;
}
}
@@ -149,7 +145,7 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength)
} else continue; /* no further tokens allowed */
}
- tokenlist[tokenctr] = destctr-tokenlastlength;
+ tokenlist[tokenctr] = destctr - tokenlastlength;
tokenlengthlist[tokenctr++] = tokenlastlength;
}
@@ -169,8 +165,7 @@ decrypt1(guint8 *dest, guint8 *src, int length, int complength)
/* decrypt2 helper function */
gint16 getc2(guint8 *node, guint8 *src,
- guint16 *bytectr, guint16 *bitctr, int complength)
-{
+ guint16 *bytectr, guint16 *bitctr, int complength) {
guint16 next;
while (node[1] != 0) {
@@ -189,23 +184,22 @@ gint16 getc2(guint8 *node, guint8 *src,
if (++(*bytectr) > complength)
return -1;
else if (*bytectr < complength)
- result |= src[*bytectr] >> (8-(*bitctr));
+ result |= src[*bytectr] >> (8 - (*bitctr));
result &= 0x0ff;
return (result | 0x100);
}
- }
- else {
+ } else {
next = node[1] >> 4; /* high 4 bits */
}
- node += next<<1;
+ node += next << 1;
}
return getInt16(node);
}
/* Huffman token decryptor */
int decrypt2(guint8* dest, guint8* src, int length, int complength)
- /* no complength checking atm */
+/* no complength checking atm */
{
guint8 numnodes, terminator;
guint8 *nodes;
@@ -214,11 +208,11 @@ int decrypt2(guint8* dest, guint8* src, int length, int complength)
numnodes = src[0];
terminator = src[1];
- bytectr = 2+ (numnodes << 1);
- nodes = src+2;
+ bytectr = 2 + (numnodes << 1);
+ nodes = src + 2;
while (((c = getc2(nodes, src, &bytectr, &bitctr, complength))
- != (0x0100 | terminator)) && (c >= 0)) {
+ != (0x0100 | terminator)) && (c >= 0)) {
if (length-- == 0) return SCI_ERROR_DECOMPRESSION_OVERFLOW;
*dest = (guint8)c;
@@ -232,8 +226,7 @@ int decrypt2(guint8* dest, guint8* src, int length, int complength)
/* Carl Muckenhoupt's decompression code ends here */
/***************************************************************************/
-int sci0_get_compression_method(int resh)
-{
+int sci0_get_compression_method(int resh) {
guint16 compressedLength;
guint16 compressionMethod;
guint16 result_size;
@@ -243,8 +236,8 @@ int sci0_get_compression_method(int resh)
return SCI_ERROR_IO_ERROR;
if ((read(resh, &compressedLength, 2) != 2) ||
- (read(resh, &result_size, 2) != 2) ||
- (read(resh, &compressionMethod, 2) != 2))
+ (read(resh, &result_size, 2) != 2) ||
+ (read(resh, &compressionMethod, 2) != 2))
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -255,14 +248,13 @@ int sci0_get_compression_method(int resh)
}
-int decompress0(resource_t *result, int resh, int sci_version)
-{
+int decompress0(resource_t *result, int resh, int sci_version) {
guint16 compressedLength;
guint16 compressionMethod;
guint16 result_size;
guint8 *buffer;
- if (read(resh, &(result->id),2) != 2)
+ if (read(resh, &(result->id), 2) != 2)
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -275,8 +267,8 @@ int decompress0(resource_t *result, int resh, int sci_version)
return SCI_ERROR_DECOMPRESSION_INSANE;
if ((read(resh, &compressedLength, 2) != 2) ||
- (read(resh, &result_size, 2) != 2) ||
- (read(resh, &compressionMethod, 2) != 2))
+ (read(resh, &result_size, 2) != 2) ||
+ (read(resh, &compressionMethod, 2) != 2))
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -287,7 +279,7 @@ int decompress0(resource_t *result, int resh, int sci_version)
result->size = result_size;
if ((result->size > SCI_MAX_RESOURCE_SIZE) ||
- (compressedLength > SCI_MAX_RESOURCE_SIZE))
+ (compressedLength > SCI_MAX_RESOURCE_SIZE))
return SCI_ERROR_RESOURCE_TOO_BIG;
/* With SCI0, this simply cannot happen. */
@@ -311,15 +303,15 @@ int decompress0(resource_t *result, int resh, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
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));
+ " 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);
+ compressedLength, result->size);
#endif
- switch(compressionMethod) {
+ switch (compressionMethod) {
case 0: /* no compression */
if (result->size != compressedLength) {
@@ -356,9 +348,9 @@ int decompress0(resource_t *result, int resh, int sci_version)
break;
default:
- fprintf(stderr,"Resource %s.%03hi: Compression method %hi not "
- "supported!\n", 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 1f9d429b90..138ec8df33 100644
--- a/engines/sci/scicore/decompress01.cpp
+++ b/engines/sci/scicore/decompress01.cpp
@@ -50,25 +50,23 @@ static gint16 curtoken, endtoken;
guint32 gbits(int numbits, guint8 * data, int dlen);
-void decryptinit3(void)
-{
+void decryptinit3(void) {
int i;
lastchar = lastbits = s_bitstring = stakptr = 0;
numbits = 9;
curtoken = 0x102;
endtoken = 0x1ff;
decryptstart = 0;
- gbits(0,0,0);
- for(i=0;i<0x1004;i++) {
- tokens[i].next=0;
- tokens[i].data=0;
+ gbits(0, 0, 0);
+ for (i = 0;i < 0x1004;i++) {
+ tokens[i].next = 0;
+ tokens[i].data = 0;
}
}
-int decrypt3(guint8 *dest, guint8 *src, int length, int complength)
-{
+int decrypt3(guint8 *dest, guint8 *src, int length, int complength) {
static gint16 token;
- while(length != 0) {
+ while (length != 0) {
switch (decryptstart) {
case 0:
@@ -97,7 +95,7 @@ int decrypt3(guint8 *dest, guint8 *src, int length, int complength)
token = lastbits;
stak[stakptr++] = lastchar;
}
- while ((token > 0xff)&&(token < 0x1004)) { /* follow links back in data */
+ while ((token > 0xff) && (token < 0x1004)) { /* follow links back in data */
stak[stakptr++] = tokens[token].data;
token = tokens[token].next;
}
@@ -131,26 +129,24 @@ int decrypt3(guint8 *dest, guint8 *src, int length, int complength)
return 0; /* [DJ] shut up compiler warning */
}
-guint32 gbits(int numbits, guint8 * data, int dlen)
-{
+guint32 gbits(int numbits, guint8 * data, int dlen) {
int place; /* indicates location within byte */
guint32 bitstring;
- static guint32 whichbit=0;
+ static guint32 whichbit = 0;
int i;
- if(numbits==0) {whichbit=0; return 0;}
+ if (numbits == 0) {whichbit = 0; return 0;}
place = whichbit >> 3;
- bitstring=0;
- for(i=(numbits>>3)+1;i>=0;i--)
- {
- if (i+place < dlen)
- bitstring |=data[place+i] << (8*(2-i));
- }
+ bitstring = 0;
+ for (i = (numbits >> 3) + 1;i >= 0;i--) {
+ if (i + place < dlen)
+ bitstring |= data[place+i] << (8 * (2 - i));
+ }
/* bitstring = data[place+2] | (long)(data[place+1])<<8
| (long)(data[place])<<16;*/
- bitstring >>= 24-(whichbit & 7)-numbits;
- bitstring &= (0xffffffff >> (32-numbits));
+ bitstring >>= 24 - (whichbit & 7) - numbits;
+ bitstring &= (0xffffffff >> (32 - numbits));
/* Okay, so this could be made faster with a table lookup.
It doesn't matter. It's fast enough as it is. */
whichbit += numbits;
@@ -193,25 +189,22 @@ enum {
#define EXTRA_MAGIC_SIZE 15
static
-void decode_rle(byte **rledata, byte **pixeldata, byte *outbuffer, int size)
-{
+void decode_rle(byte **rledata, byte **pixeldata, byte *outbuffer, int size) {
int pos = 0;
char nextbyte;
byte *rd = *rledata;
byte *ob = outbuffer;
byte *pd = *pixeldata;
- while (pos < size)
- {
+ while (pos < size) {
nextbyte = *(rd++);
*(ob++) = nextbyte;
pos ++;
- switch (nextbyte&0xC0)
- {
+ switch (nextbyte&0xC0) {
case 0x40 :
case 0x00 :
memcpy(ob, pd, nextbyte);
- pd +=nextbyte;
+ pd += nextbyte;
ob += nextbyte;
pos += nextbyte;
break;
@@ -236,20 +229,17 @@ void decode_rle(byte **rledata, byte **pixeldata, byte *outbuffer, int size)
* Yes, this is inefficient.
*/
static
-int rle_size(byte *rledata, int dsize)
-{
+int rle_size(byte *rledata, int dsize) {
int pos = 0;
char nextbyte;
int size = 0;
-
- while (pos < dsize)
- {
+
+ while (pos < dsize) {
nextbyte = *(rledata++);
pos ++;
size ++;
-
- switch (nextbyte&0xC0)
- {
+
+ switch (nextbyte&0xC0) {
case 0x40 :
case 0x00 :
pos += nextbyte;
@@ -265,8 +255,7 @@ int rle_size(byte *rledata, int dsize)
return size;
}
-byte *pic_reorder(byte *inbuffer, int dsize)
-{
+byte *pic_reorder(byte *inbuffer, int dsize) {
byte *reorderBuffer;
int view_size;
int view_start;
@@ -276,13 +265,13 @@ byte *pic_reorder(byte *inbuffer, int dsize)
byte *writer;
char viewdata[CEL_HEADER_SIZE];
byte *cdata, *cdata_start;
-
- writer = reorderBuffer=(byte *) malloc(dsize);
+
+ writer = reorderBuffer = (byte *) malloc(dsize);
*(writer++) = PIC_OP_OPX;
*(writer++) = PIC_OPX_SET_PALETTE;
- for (i=0;i<256;i++) /* Palette translation map */
+ for (i = 0;i < 256;i++) /* Palette translation map */
*(writer++) = i;
putInt16(writer, 0); /* Palette stamp */
@@ -299,29 +288,27 @@ byte *pic_reorder(byte *inbuffer, int dsize)
memcpy(viewdata, seeker, sizeof(viewdata));
seeker += sizeof(viewdata);
-
+
memcpy(writer, seeker, 4*256); /* Palette */
- seeker += 4*256;
- writer += 4*256;
+ seeker += 4 * 256;
+ writer += 4 * 256;
- if (view_start != PAL_SIZE + 2) /* +2 for the opcode */
- {
- memcpy(writer, seeker, view_start-PAL_SIZE-2);
+ if (view_start != PAL_SIZE + 2) { /* +2 for the opcode */
+ memcpy(writer, seeker, view_start - PAL_SIZE - 2);
seeker += view_start - PAL_SIZE - 2;
writer += view_start - PAL_SIZE - 2;
}
- if (dsize != view_start+EXTRA_MAGIC_SIZE+view_size)
- {
- memcpy(reorderBuffer+view_size+view_start+EXTRA_MAGIC_SIZE, seeker,
- dsize-view_size-view_start-EXTRA_MAGIC_SIZE);
- seeker += dsize-view_size-view_start-EXTRA_MAGIC_SIZE;
+ if (dsize != view_start + EXTRA_MAGIC_SIZE + view_size) {
+ memcpy(reorderBuffer + view_size + view_start + EXTRA_MAGIC_SIZE, seeker,
+ dsize - view_size - view_start - EXTRA_MAGIC_SIZE);
+ seeker += dsize - view_size - view_start - EXTRA_MAGIC_SIZE;
}
- cdata_start=cdata=(byte *) malloc(cdata_size);
+ cdata_start = cdata = (byte *) malloc(cdata_size);
memcpy(cdata, seeker, cdata_size);
seeker += cdata_size;
-
+
writer = reorderBuffer + view_start;
*(writer++) = PIC_OP_OPX;
*(writer++) = PIC_OPX_EMBEDDED_VIEW;
@@ -335,9 +322,9 @@ byte *pic_reorder(byte *inbuffer, int dsize)
writer += sizeof(viewdata);
*(writer++) = 0;
-
+
decode_rle(&seeker, &cdata, writer, view_size);
-
+
free(cdata_start);
free(inbuffer);
return reorderBuffer;
@@ -346,22 +333,23 @@ byte *pic_reorder(byte *inbuffer, int dsize)
#define VIEW_HEADER_COLORS_8BIT 0x80
static
-void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengths, int max)
-{
+void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengths, int max) {
int c, w;
-
- for (c=0;c<max;c++)
- {
- w=getUInt16(*seeker);
- putInt16(*writer, w);
- *seeker += 2; *writer += 2;
- w=getUInt16(*seeker);
- putInt16(*writer, w);
- *seeker += 2; *writer += 2;
- w=getUInt16(*seeker);
- putInt16(*writer, w);
- *seeker += 2; *writer += 2;
- w=*((*seeker)++);
+
+ for (c = 0;c < max;c++) {
+ w = getUInt16(*seeker);
+ putInt16(*writer, w);
+ *seeker += 2;
+ *writer += 2;
+ w = getUInt16(*seeker);
+ putInt16(*writer, w);
+ *seeker += 2;
+ *writer += 2;
+ w = getUInt16(*seeker);
+ putInt16(*writer, w);
+ *seeker += 2;
+ *writer += 2;
+ w = *((*seeker)++);
putInt16(*writer, w); /* Zero extension */
*writer += 2;
@@ -372,8 +360,7 @@ void build_cel_headers(byte **seeker, byte **writer, int celindex, int *cc_lengt
-byte *view_reorder(byte *inbuffer, int dsize)
-{
+byte *view_reorder(byte *inbuffer, int dsize) {
byte *cellengths;
int loopheaders;
int lh_present;
@@ -386,15 +373,15 @@ byte *view_reorder(byte *inbuffer, int dsize)
byte *outbuffer = (byte *) malloc(dsize);
byte *writer = outbuffer;
byte *lh_ptr;
- byte *rle_ptr,*pix_ptr;
+ byte *rle_ptr, *pix_ptr;
int l, lb, c, celindex, lh_last = -1;
int chptr;
int w;
int *cc_lengths;
byte **cc_pos;
-
+
/* Parse the main header */
- cellengths = inbuffer+getUInt16(seeker)+2;
+ cellengths = inbuffer + getUInt16(seeker) + 2;
seeker += 2;
loopheaders = *(seeker++);
lh_present = *(seeker++);
@@ -407,12 +394,12 @@ byte *view_reorder(byte *inbuffer, int dsize)
cel_total = getUInt16(seeker);
seeker += 2;
- cc_pos = (byte **) malloc(sizeof(byte *)*cel_total);
- cc_lengths = (int *) malloc(sizeof(int)*cel_total);
-
- for (c=0;c<cel_total;c++)
- cc_lengths[c] = getUInt16(cellengths+2*c);
-
+ cc_pos = (byte **) malloc(sizeof(byte *) * cel_total);
+ cc_lengths = (int *) malloc(sizeof(int) * cel_total);
+
+ for (c = 0;c < cel_total;c++)
+ cc_lengths[c] = getUInt16(cellengths + 2 * c);
+
*(writer++) = loopheaders;
*(writer++) = VIEW_HEADER_COLORS_8BIT;
putInt16(writer, lh_mask);
@@ -423,32 +410,29 @@ byte *view_reorder(byte *inbuffer, int dsize)
writer += 2;
lh_ptr = writer;
- writer += 2*loopheaders; /* Make room for the loop offset table */
+ writer += 2 * loopheaders; /* Make room for the loop offset table */
pix_ptr = writer;
-
+
memcpy(celcounts, seeker, lh_present);
seeker += lh_present;
lb = 1;
celindex = 0;
- rle_ptr = pix_ptr = cellengths + (2*cel_total);
+ rle_ptr = pix_ptr = cellengths + (2 * cel_total);
w = 0;
-
- for (l=0;l<loopheaders;l++)
- {
- if (lh_mask & lb) /* The loop is _not_ present */
- {
+
+ for (l = 0;l < loopheaders;l++) {
+ if (lh_mask & lb) { /* The loop is _not_ present */
if (lh_last == -1) {
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);
lh_ptr += 2;
- } else
- {
- lh_last = writer-outbuffer;
+ } else {
+ lh_last = writer - outbuffer;
putInt16(lh_ptr, lh_last);
lh_ptr += 2;
putInt16(writer, celcounts[w]);
@@ -457,64 +441,61 @@ byte *view_reorder(byte *inbuffer, int dsize)
writer += 2;
/* Now, build the cel offset table */
- chptr = (writer - outbuffer)+(2*celcounts[w]);
+ chptr = (writer - outbuffer) + (2 * celcounts[w]);
- for (c=0;c<celcounts[w];c++)
- {
+ for (c = 0;c < celcounts[w];c++) {
putInt16(writer, chptr);
writer += 2;
cc_pos[celindex+c] = outbuffer + chptr;
- chptr += 8 + getUInt16(cellengths+2*(celindex+c));
+ chptr += 8 + getUInt16(cellengths + 2 * (celindex + c));
}
build_cel_headers(&seeker, &writer, celindex, cc_lengths, celcounts[w]);
-
+
celindex += celcounts[w];
w++;
}
- lb = lb << 1;
- }
+ lb = lb << 1;
+ }
- if (celindex < cel_total)
- {
+ if (celindex < cel_total) {
fprintf(stderr, "View decompression generated too few (%d / %d) headers!\n", celindex, cel_total);
return NULL;
}
-
+
/* Figure out where the pixel data begins. */
- for (c=0;c<cel_total;c++)
+ for (c = 0;c < cel_total;c++)
pix_ptr += rle_size(pix_ptr, cc_lengths[c]);
- rle_ptr = cellengths + (2*cel_total);
- for (c=0;c<cel_total;c++)
- decode_rle(&rle_ptr, &pix_ptr, cc_pos[c]+8, cc_lengths[c]);
+ rle_ptr = cellengths + (2 * cel_total);
+ for (c = 0;c < cel_total;c++)
+ decode_rle(&rle_ptr, &pix_ptr, cc_pos[c] + 8, cc_lengths[c]);
*(writer++) = 'P';
*(writer++) = 'A';
*(writer++) = 'L';
-
- for (c=0;c<256;c++)
+
+ for (c = 0;c < 256;c++)
*(writer++) = c;
seeker -= 4; /* The missing four. Don't ask why. */
- memcpy(writer, seeker, 4*256+4);
-
+ memcpy(writer, seeker, 4*256 + 4);
+
free(cc_pos);
free(cc_lengths);
free(inbuffer);
- return outbuffer;
+ return outbuffer;
}
-int decompress01(resource_t *result, int resh, int sci_version)
-{
+int decompress01(resource_t *result, int resh, int sci_version) {
guint16 compressedLength, result_size;
guint16 compressionMethod;
guint8 *buffer;
- if (read(resh, &(result->id),2) != 2)
+ if (read(resh, &(result->id), 2) != 2)
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -528,8 +509,8 @@ int decompress01(resource_t *result, int resh, int sci_version)
return SCI_ERROR_DECOMPRESSION_INSANE;
if ((read(resh, &compressedLength, 2) != 2) ||
- (read(resh, &result_size, 2) != 2) ||
- (read(resh, &compressionMethod, 2) != 2))
+ (read(resh, &result_size, 2) != 2) ||
+ (read(resh, &compressionMethod, 2) != 2))
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -544,7 +525,7 @@ int decompress01(resource_t *result, int resh, int sci_version)
/* This return will never happen in SCI0 or SCI1 (does it have any use?) */
if ((result->size > SCI_MAX_RESOURCE_SIZE) ||
- (compressedLength > SCI_MAX_RESOURCE_SIZE))
+ (compressedLength > SCI_MAX_RESOURCE_SIZE))
return SCI_ERROR_RESOURCE_TOO_BIG;
if (compressedLength > 4)
@@ -567,15 +548,15 @@ int decompress01(resource_t *result, int resh, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
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));
+ " 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);
+ compressedLength, result->size);
#endif
- switch(compressionMethod) {
+ switch (compressionMethod) {
case 0: /* no compression */
if (result->size != compressedLength) {
@@ -612,7 +593,7 @@ int decompress01(resource_t *result, int resh, int sci_version)
result->status = SCI_STATUS_ALLOCATED;
break;
- case 3:
+ case 3:
decryptinit3();
if (decrypt3(result->data, buffer, result->size, compressedLength)) {
free(result->data);
@@ -637,11 +618,11 @@ int decompress01(resource_t *result, int resh, int sci_version)
result->data = pic_reorder(result->data, result->size);
result->status = SCI_STATUS_ALLOCATED;
break;
-
+
default:
- fprintf(stderr,"Resource %s.%03hi: Compression method SCI1/%hi not "
- "supported!\n", 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 be88d775aa..3e0ec5fcf8 100644
--- a/engines/sci/scicore/decompress1.cpp
+++ b/engines/sci/scicore/decompress1.cpp
@@ -67,15 +67,14 @@ static int ascii_tree[] = {
#define CALLC(x) { if ((x) == -SCI_ERROR_DECOMPRESSION_OVERFLOW) return -SCI_ERROR_DECOMPRESSION_OVERFLOW; }
static inline int
-getbits_msb_first(struct bit_read_struct *inp, int bits)
-{
+getbits_msb_first(struct bit_read_struct *inp, int bits) {
int morebytes = (bits + inp->bitpos - 1) >> 3;
int result = 0;
int i;
if (inp->bytepos + morebytes >= inp->length) {
- fprintf(stderr,"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;
}
@@ -94,15 +93,14 @@ getbits_msb_first(struct bit_read_struct *inp, int bits)
static int DEBUG_DCL_INFLATE = 0; /* FIXME: Make this a define eventually */
static inline int
-getbits(struct bit_read_struct *inp, int bits)
-{
+getbits(struct bit_read_struct *inp, int bits) {
int morebytes = (bits + inp->bitpos - 1) >> 3;
int result = 0;
int i;
if (inp->bytepos + morebytes >= inp->length) {
- fprintf(stderr,"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;
}
@@ -116,28 +114,27 @@ getbits(struct bit_read_struct *inp, int bits)
inp->bytepos += morebytes;
if (DEBUG_DCL_INFLATE)
- fprintf(stderr,"(%d:%04x)", bits, result);
+ fprintf(stderr, "(%d:%04x)", bits, result);
return result;
}
static int
-huffman_lookup(struct bit_read_struct *inp, int *tree)
-{
+huffman_lookup(struct bit_read_struct *inp, int *tree) {
int pos = 0;
int bit;
while (!(tree[pos] & HUFFMAN_LEAF)) {
CALLC(bit = getbits(inp, 1));
if (DEBUG_DCL_INFLATE)
- fprintf(stderr,"[%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)
- fprintf(stderr,"=%02x\n", tree[pos] & 0xffff);
+ fprintf(stderr, "=%02x\n", tree[pos] & 0xffff);
return tree[pos] & 0xffff;
}
@@ -146,8 +143,7 @@ huffman_lookup(struct bit_read_struct *inp, int *tree)
#define DCL_ASCII_MODE 1
static int
-decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
-{
+decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader) {
int mode, length_param, value, val_length, val_distance;
int write_pos = 0;
int M[] = {0x07, 0x08, 0x0A, 0x0E, 0x16, 0x26, 0x46, 0x86, 0x106};
@@ -156,28 +152,28 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
CALLC(length_param = getbits(reader, 8));
if (mode == DCL_ASCII_MODE) {
- fprintf(stderr,"DCL-INFLATE: Warning: Decompressing ASCII mode (untested)\n");
+ fprintf(stderr, "DCL-INFLATE: Warning: Decompressing ASCII mode (untested)\n");
/* DEBUG_DCL_INFLATE = 1; */
} else if (mode) {
- fprintf(stderr,"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;
}
if (DEBUG_DCL_INFLATE) {
int i;
for (i = 0; i < reader->length; i++) {
- fprintf(stderr,"%02x ", reader->data[i]);
- if (!((i+1) & 0x1f))
- fprintf(stderr,"\n");
+ fprintf(stderr, "%02x ", reader->data[i]);
+ if (!((i + 1) & 0x1f))
+ fprintf(stderr, "\n");
}
- fprintf(stderr,"\n---\n");
+ fprintf(stderr, "\n---\n");
}
if (length_param < 3 || length_param > 6)
- fprintf(stderr,"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));
@@ -196,7 +192,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
}
if (DEBUG_DCL_INFLATE)
- fprintf(stderr," | ");
+ fprintf(stderr, " | ");
CALLC(value = huffman_lookup(reader, distance_tree));
@@ -214,7 +210,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
++val_distance;
if (DEBUG_DCL_INFLATE)
- fprintf(stderr,"\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) {
fprintf(stderr, "DCL-INFLATE Error: Write out of bounds while copying %d bytes\n", val_length);
@@ -227,14 +223,14 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
}
while (val_length) {
- int copy_length = (val_length > val_distance)? val_distance : val_length;
+ int copy_length = (val_length > val_distance) ? val_distance : val_length;
memcpy(dest + write_pos, dest + write_pos - val_distance, copy_length);
if (DEBUG_DCL_INFLATE) {
int i;
for (i = 0; i < copy_length; i++)
- fprintf(stderr,"\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
+ fprintf(stderr, "\33[32;31m%02x\33[37;37m ", dest[write_pos + i]);
fprintf(stderr, "\n");
}
@@ -261,8 +257,7 @@ decrypt4_hdyn(byte *dest, int length, struct bit_read_struct *reader)
}
int
-decrypt4(guint8* dest, guint8* src, int length, int complength)
-{
+decrypt4(guint8* dest, guint8* src, int length, int complength) {
struct bit_read_struct reader;
reader.length = complength;
@@ -280,15 +275,14 @@ void decryptinit3(void);
int decrypt3(guint8* dest, guint8* src, int length, int complength);
int decompress1(resource_t *result, int resh, int early);
-int decompress1(resource_t *result, int resh, int sci_version)
-{
+int decompress1(resource_t *result, int resh, int sci_version) {
guint16 compressedLength;
guint16 compressionMethod, result_size;
guint8 *buffer;
guint8 tempid;
if (sci_version == SCI_VERSION_1_EARLY) {
- if (read(resh, &(result->id),2) != 2)
+ if (read(resh, &(result->id), 2) != 2)
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -306,7 +300,7 @@ int decompress1(resource_t *result, int resh, int sci_version)
result->id = tempid;
- result->type = result->id &0x7f;
+ result->type = result->id & 0x7f;
if (read(resh, &(result->number), 2) != 2)
return SCI_ERROR_IO_ERROR;
@@ -318,8 +312,8 @@ int decompress1(resource_t *result, int resh, int sci_version)
}
if ((read(resh, &compressedLength, 2) != 2) ||
- (read(resh, &result_size, 2) != 2) ||
- (read(resh, &compressionMethod, 2) != 2))
+ (read(resh, &result_size, 2) != 2) ||
+ (read(resh, &compressionMethod, 2) != 2))
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -330,7 +324,7 @@ int decompress1(resource_t *result, int resh, int sci_version)
result->size = result_size;
if ((result->size > SCI_MAX_RESOURCE_SIZE) ||
- (compressedLength > SCI_MAX_RESOURCE_SIZE))
+ (compressedLength > SCI_MAX_RESOURCE_SIZE))
return SCI_ERROR_RESOURCE_TOO_BIG;
if (compressedLength > 4)
@@ -353,17 +347,17 @@ int decompress1(resource_t *result, int resh, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
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));
+ " 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);
+ compressedLength, result->size);
#endif
- switch(compressionMethod) {
+ switch (compressionMethod) {
case 0: /* no compression */
if (result->size != compressedLength) {
@@ -400,7 +394,7 @@ int decompress1(resource_t *result, int resh, int sci_version)
result->status = SCI_STATUS_ALLOCATED;
break;
- case 3:
+ case 3:
decryptinit3();
if (decrypt3(result->data, buffer, result->size, compressedLength)) {
free(result->data);
@@ -425,11 +419,11 @@ int decompress1(resource_t *result, int resh, int sci_version)
result->data = pic_reorder(result->data, result->size);
result->status = SCI_STATUS_ALLOCATED;
break;
-
+
default:
- fprintf(stderr,"Resource %s.%03hi: Compression method SCI1/%hi not "
- "supported!\n", 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 88f3a2795a..0e27b1e464 100644
--- a/engines/sci/scicore/decompress11.cpp
+++ b/engines/sci/scicore/decompress11.cpp
@@ -35,8 +35,7 @@ void decryptinit3(void);
int decrypt3(guint8* dest, guint8* src, int length, int complength);
int decrypt4(guint8* dest, guint8* src, int length, int complength);
-int decompress11(resource_t *result, int resh, int sci_version)
-{
+int decompress11(resource_t *result, int resh, int sci_version) {
guint16 compressedLength;
guint16 compressionMethod, result_size;
guint8 *buffer;
@@ -49,7 +48,7 @@ int decompress11(resource_t *result, int resh, int sci_version)
result->id = tempid;
- result->type = result->id &0x7f;
+ result->type = result->id & 0x7f;
if (read(resh, &(result->number), 2) != 2)
return SCI_ERROR_IO_ERROR;
@@ -60,8 +59,8 @@ int decompress11(resource_t *result, int resh, int sci_version)
return SCI_ERROR_DECOMPRESSION_INSANE;
if ((read(resh, &compressedLength, 2) != 2) ||
- (read(resh, &result_size, 2) != 2) ||
- (read(resh, &compressionMethod, 2) != 2))
+ (read(resh, &result_size, 2) != 2) ||
+ (read(resh, &compressionMethod, 2) != 2))
return SCI_ERROR_IO_ERROR;
#ifdef WORDS_BIGENDIAN
@@ -71,12 +70,12 @@ int decompress11(resource_t *result, int resh, int sci_version)
#endif
result->size = result_size;
- /* if ((result->size < 0) || (compressedLength < 0))
- return SCI_ERROR_DECOMPRESSION_INSANE; */
- /* This return will never happen in SCI0 or SCI1 (does it have any use?) */
+ /* if ((result->size < 0) || (compressedLength < 0))
+ return SCI_ERROR_DECOMPRESSION_INSANE; */
+ /* This return will never happen in SCI0 or SCI1 (does it have any use?) */
if ((result->size > SCI_MAX_RESOURCE_SIZE) ||
- (compressedLength > SCI_MAX_RESOURCE_SIZE))
+ (compressedLength > SCI_MAX_RESOURCE_SIZE))
return SCI_ERROR_RESOURCE_TOO_BIG;
if (compressedLength > 0)
@@ -103,18 +102,18 @@ int decompress11(resource_t *result, int resh, int sci_version)
#ifdef _SCI_DECOMPRESS_DEBUG
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));
+ " 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);
+ compressedLength, result->size);
#endif
DDEBUG("/%d[%d]", compressionMethod, result->size);
- switch(compressionMethod) {
+ switch (compressionMethod) {
case 0: /* no compression */
if (result->size != compressedLength) {
@@ -143,17 +142,17 @@ int decompress11(resource_t *result, int resh, int sci_version)
case 3:
case 4: /* NYI */
- fprintf(stderr,"Resource %d.%s: Warning: compression type #%d not yet implemented\n",
- result->number, sci_resource_type_suffixes[result->type], compressionMethod);
+ 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;
result->status = SCI_STATUS_NOMALLOC;
break;
default:
- fprintf(stderr,"Resource %d.%s: Compression method SCI1/%hi not "
- "supported!\n", 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;
@@ -161,7 +160,7 @@ int decompress11(resource_t *result, int resh, int sci_version)
return SCI_ERROR_UNKNOWN_COMPRESSION;
}
- free(buffer);
- return 0;
+ free(buffer);
+ return 0;
}
diff --git a/engines/sci/scicore/exe.cpp b/engines/sci/scicore/exe.cpp
index 4e97f80ed5..e266fd9665 100644
--- a/engines/sci/scicore/exe.cpp
+++ b/engines/sci/scicore/exe.cpp
@@ -39,15 +39,13 @@ exe_decompressor_t *exe_decompressors[] = {
NULL
};
-struct _exe_file
-{
+struct _exe_file {
struct _exe_decompressor *decompressor;
struct _exe_handle *handle;
};
exe_file_t *
-exe_open(const char *filename)
-{
+exe_open(const char *filename) {
int i = 0;
exe_decompressor_t *dec;
@@ -58,7 +56,7 @@ exe_open(const char *filename)
exe_file_t *file = (exe_file_t*)sci_malloc(sizeof(exe_file_t));
sciprintf("Scanning '%s' with decompressor '%s'\n",
- filename, dec->name);
+ filename, dec->name);
file->handle = handle;
file->decompressor = dec;
@@ -72,14 +70,12 @@ exe_open(const char *filename)
}
int
-exe_read(exe_file_t *file, void *buf, int count)
-{
+exe_read(exe_file_t *file, void *buf, int count) {
return file->decompressor->read(file->handle, buf, count);
}
void
-exe_close(exe_file_t *file)
-{
+exe_close(exe_file_t *file) {
file->decompressor->close(file->handle);
sci_free(file);
diff --git a/engines/sci/scicore/exe_dec.h b/engines/sci/scicore/exe_dec.h
index 9b30da0772..32695a615d 100644
--- a/engines/sci/scicore/exe_dec.h
+++ b/engines/sci/scicore/exe_dec.h
@@ -35,7 +35,7 @@ typedef struct _exe_decompressor {
** of lower-case (where applicable) alphanumerics
*/
- exe_handle_t * (*open) (const char *filename);
+ exe_handle_t * (*open)(const char *filename);
/* Opens an executable file
** Parameters: (const char *) filename: Filename of executable to open.
** Returns : (exe_handle_t *) Decompressor file handle, or NULL on
@@ -44,7 +44,7 @@ typedef struct _exe_decompressor {
** decompressor. If this is not the case the function will fail.
*/
- int (*read) (exe_handle_t *handle, void *buf, int count);
+ int (*read)(exe_handle_t *handle, void *buf, int count);
/* Reads from executable file
** Parameters: (exe_handle_t *) handle: Decompressor file handle.
** (void *) buf: Buffer to store decompressed data.
@@ -56,7 +56,7 @@ typedef struct _exe_decompressor {
** reached.
*/
- void (*close) (exe_handle_t *handle);
+ void (*close)(exe_handle_t *handle);
/* Closes a decompressor file handle.
** Parameters: (exe_handle_t *) handle: Decompressor file handle.
** Returns : (void)
diff --git a/engines/sci/scicore/exe_lzexe.cpp b/engines/sci/scicore/exe_lzexe.cpp
index 4445ed8df9..30b0671f5e 100644
--- a/engines/sci/scicore/exe_lzexe.cpp
+++ b/engines/sci/scicore/exe_lzexe.cpp
@@ -49,8 +49,7 @@
*/
#define LZEXE_BUFFER_MAX (LZEXE_BUFFER_SIZE - 256)
-struct _exe_handle
-{
+struct _exe_handle {
FILE *f;
/* Output buffer. */
@@ -66,8 +65,7 @@ struct _exe_handle
};
static int
-lzexe_read_uint16(FILE *f, int *value)
-{
+lzexe_read_uint16(FILE *f, int *value) {
int data;
if ((*value = fgetc(f)) == EOF)
@@ -81,8 +79,7 @@ lzexe_read_uint16(FILE *f, int *value)
}
static int
-lzexe_read_uint8(FILE *f, int *value)
-{
+lzexe_read_uint8(FILE *f, int *value) {
if ((*value = fgetc(f)) == EOF)
return 0;
@@ -90,8 +87,7 @@ lzexe_read_uint8(FILE *f, int *value)
}
static int
-lzexe_init(exe_handle_t *handle, FILE *f)
-{
+lzexe_init(exe_handle_t *handle, FILE *f) {
handle->f = f;
handle->bufptr = handle->buffer;
handle->eod = 0;
@@ -104,27 +100,23 @@ lzexe_init(exe_handle_t *handle, FILE *f)
}
static int
-lzexe_get_bit(exe_handle_t *handle, int *bit)
-{
+lzexe_get_bit(exe_handle_t *handle, int *bit) {
*bit = handle->buf & 1;
- if (--handle->count == 0)
- {
+ if (--handle->count == 0) {
if (!lzexe_read_uint16(handle->f, &handle->buf))
return 0;
handle->count = 16;
- }
- else
+ } else
handle->buf >>= 1;
return 1;
}
static int
-lzexe_decompress(exe_handle_t *handle)
-{
+lzexe_decompress(exe_handle_t *handle) {
while (!handle->eod
- && handle->bufptr - handle->buffer <= LZEXE_BUFFER_MAX) {
+ && handle->bufptr - handle->buffer <= LZEXE_BUFFER_MAX) {
int bit;
int len, span;
@@ -222,8 +214,7 @@ lzexe_decompress(exe_handle_t *handle)
}
static exe_handle_t *
-lzexe_open(const char *filename)
-{
+lzexe_open(const char *filename) {
exe_handle_t *handle;
guint8 head[0x20];
guint8 size[2];
@@ -242,7 +233,7 @@ lzexe_open(const char *filename)
** overlays == 0.
*/
if (UINT16(head) != 0x5a4d || UINT16(head + 8) != 2
- || UINT16(head + 0x1a) != 0)
+ || UINT16(head + 0x1a) != 0)
return NULL;
/* Verify that first relocation item offset is 0x1c. */
@@ -251,7 +242,7 @@ lzexe_open(const char *filename)
/* Look for lzexe signature. */
if (memcmp(head + 0x1c, "LZ09", 4)
- && memcmp(head + 0x1c, "LZ91", 4)) {
+ && memcmp(head + 0x1c, "LZ91", 4)) {
return NULL;
}
@@ -281,8 +272,7 @@ lzexe_open(const char *filename)
}
static int
-lzexe_read(exe_handle_t *handle, void *buf, int count)
-{
+lzexe_read(exe_handle_t *handle, void *buf, int count) {
int done = 0;
while (done != count) {
@@ -326,8 +316,7 @@ lzexe_read(exe_handle_t *handle, void *buf, int count)
}
static void
-lzexe_close(exe_handle_t *handle)
-{
+lzexe_close(exe_handle_t *handle) {
fclose(handle->f);
sci_free(handle);
diff --git a/engines/sci/scicore/exe_raw.cpp b/engines/sci/scicore/exe_raw.cpp
index 9a0dc5f742..e2fbfb328f 100644
--- a/engines/sci/scicore/exe_raw.cpp
+++ b/engines/sci/scicore/exe_raw.cpp
@@ -28,16 +28,14 @@
#include <stdio.h>
#include "sci/include/sci_memory.h"
-struct _exe_handle
-{
+struct _exe_handle {
FILE *f;
};
#include "sci/scicore/exe_dec.h"
static exe_handle_t *
-raw_open(const char *filename)
-{
+raw_open(const char *filename) {
FILE *f = sci_fopen(filename, "rb");
exe_handle_t *handle;
@@ -51,14 +49,12 @@ raw_open(const char *filename)
}
static int
-raw_read(exe_handle_t *handle, void *buf, int count)
-{
+raw_read(exe_handle_t *handle, void *buf, int count) {
return fread(buf, 1, count, handle->f);
}
static void
-raw_close(exe_handle_t *handle)
-{
+raw_close(exe_handle_t *handle) {
fclose(handle->f);
sci_free(handle);
diff --git a/engines/sci/scicore/games.h b/engines/sci/scicore/games.h
index b5c4a02b29..b94140d200 100644
--- a/engines/sci/scicore/games.h
+++ b/engines/sci/scicore/games.h
@@ -35,89 +35,89 @@
#include "sci/include/versions.h"
typedef struct _sci_game {
- int id; /* currently CRC of resource.001 */
- int res_version;
- sci_version_t version;
- const char *name;
+ int id; /* currently CRC of resource.001 */
+ int res_version;
+ sci_version_t version;
+ const char *name;
} sci_game_t;
/* Interpreter versions for Amiga and Atari ST ports are tentative */
sci_game_t sci_games[] = {
- { 0x5D451535, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,510), "Leisure Suit Larry 1 v1.0-mac"}, /* x.yyy.zzz */ /* Launcher says v2.0, game crashes on DoAvoider */
- { 0x6C176EE0, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,577), "Leisure Suit Larry 1 v2.1"},
- { 0x1C36E076, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,510), "Leisure Suit Larry 1 v1.000-es"}, /* 1.SQ4.057 */ /* Crashes on function 0x7b */
-
- { 0xFEAB629D, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,343), "Leisure Suit Larry 2 v1.000.011-3.5"},
- { 0x13DD3CD2, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,343), "Leisure Suit Larry 2 v1.000.011-5.25" },
- { 0x1D0F3B31, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 2 v1.001.006-st"}, /* 1.000.159 */
- { 0x40BEC726, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,409), "Leisure Suit Larry 2 v1.002.000-3.5"},
- { 0x0C848403, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,409), "Leisure Suit Larry 2 v1.002.000-5.25" },
- { 0x7E9CF339, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 2 v1.003-ami"}, /* x.yyy.zzz */
-
- { 0x06D737B5, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 3 v1.003-3.5" },
- { 0xE0A1C352, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 3 v1.003-5.25" },
- { 0xC48FE83A, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 3 v1.021-3.5" },
- { 0x484587DD, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 3 v1.021-5.25"},
-/* { 0x????????, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 3 v1.021-st"},*/ /* 1.002.026 */
- { 0x6348030A, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 3 v1.039-ami"}, /* 1.002.032 */
-
- { 0x94EA377B, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,685), "CB1" },
- { 0xFD9EE7BD, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,685), "Camelot" },
- { 0x2829987F, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,685), "Camelot" },
- { 0x980CEAD3, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,629), "Demo Quest" },
- { 0x3DB972CA, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Hoyle 2" },
- { 0xC0B37651, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,685), "Iceman" },
- { 0xDABA6B8A, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,999), "KQ1 v1.000.051-3.5" }, /* S.old.010 */
- { 0x270E37F3, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,274), "KQ4" },
- { 0x685F1205, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,502), "KQ4" },
- { 0xC14E3A2A, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,395), "PQ2" },
- { 0x4BD66036, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,490), "PQ2" },
- { 0x7132D6D8, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,629), "QfG1" },
- { 0xF8F4913F, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,685), "SQ3" },
- { 0x34FBC324, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,999), "SQ3/DE" }, /* S.old.114 */
- { 0xE4A3234D, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,506), "Fun Seekers Guide v1.02"},
- { 0x85AFE241, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,519), "Hoyle 1 v1.000.104"},
- { 0xE0E070C3, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Hoyle 2 v1.000.011"},
- { 0xD0B8794E, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,668), "Iceman v1.023"},
- { 0x94EA377B, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,631), "The Colonel's Bequest v1.000.046"},
- { 0x28543FDF, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,453), "Astro Chicken"},
- { 0x31F46F7D, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,453), "Space Quest III v1.0V int"},
- { 0xAA2C94B9, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,685), "Mixed-Up Mother Goose v1.011 Int.#8.2.90"},
- { 0x3B15678B, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,631), "The Colonel's Bequest v1.000.046-3.5"},
- { 0x0E042F46, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,530), "Hoyle 1 v1.000.113-3.5"},
- { 0x1EACB959, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,566), "HQ v1.000-5.25"},
- { 0x2BEAF5E7, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,566), "HQ v1.001-5.25"},
- { 0x63626D3E, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,668), "Iceman v1.023-5.25"},
- { 0xDA5E7B7D, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,409), "KQ4 v1.003.006-3.5"},
- { 0x376A5472, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,502), "KQ4 v1.006.003-5.25"},
- { 0x364B40B2, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,395), "PQ2 v1.001.000-5.25"},
- { 0x664B4123, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,409), "PQ2 v1.001.006-3.5"},
- { 0x379F4582, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,453), "SQ3 v1.0V-5.25"},
- { 0x04B0B081, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,294), "xmascard v1.04"},
-
- { 0x4447B28D, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,72), "Trial v1.105"},
-
- { 0xB1C2CCAE, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,200), "SQ4 v1.052"}, /* 1.000.753 */
- { 0xAA6AF6A9, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,60), "KQ5 v0.000.062"},
- { 0x092C2C0D, 3, SCI_VERSION(1,000,172), "jones v1.000.060"}, /* x.yyy.zzz */
-
- { 0xC415A485, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,172), "jones v1.000.060-cd"}, /* x.yyy.zzz */
-
- { 0x89C595E3, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,510), "SQ1 v2.000"}, /* T.A00.081 */
- { 0x09D4FC54, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,510), "LSL5 v1.000"}, /* T.A00.169 */
- { 0xF3ED1D81, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,510), "PQ3 v1.00"}, /* T.A00.178 */
- { 0x501B5E6B, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,510), "Brain v1.000"}, /* 1.000.044 */
- { 0xB1B7279B, SCI_VERSION_AUTODETECT, SCI_VERSION(1,000,510), "Longbow v1.000"}, /* 1.000.168 */
-
- { 0x82595EBE, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,453), "SQ3 v1.0V-ami"}, /* x.yyy.zzz */
- { 0xF6080B61, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,530), "Hoyle 1 v1.000.139-ami"}, /* x.yyy.zzz */
-
- { 0x8AFEA2D0, 2, SCI_VERSION(1,000,000), "KQ1 v1.000.054-ami"}, /* 1.003.007 */
+ { 0x5D451535, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 510), "Leisure Suit Larry 1 v1.0-mac"}, /* x.yyy.zzz */ /* Launcher says v2.0, game crashes on DoAvoider */
+ { 0x6C176EE0, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 577), "Leisure Suit Larry 1 v2.1"},
+ { 0x1C36E076, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 510), "Leisure Suit Larry 1 v1.000-es"}, /* 1.SQ4.057 */ /* Crashes on function 0x7b */
+
+ { 0xFEAB629D, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 343), "Leisure Suit Larry 2 v1.000.011-3.5"},
+ { 0x13DD3CD2, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 343), "Leisure Suit Larry 2 v1.000.011-5.25" },
+ { 0x1D0F3B31, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Leisure Suit Larry 2 v1.001.006-st"}, /* 1.000.159 */
+ { 0x40BEC726, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 409), "Leisure Suit Larry 2 v1.002.000-3.5"},
+ { 0x0C848403, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 409), "Leisure Suit Larry 2 v1.002.000-5.25" },
+ { 0x7E9CF339, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Leisure Suit Larry 2 v1.003-ami"}, /* x.yyy.zzz */
+
+ { 0x06D737B5, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Leisure Suit Larry 3 v1.003-3.5" },
+ { 0xE0A1C352, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Leisure Suit Larry 3 v1.003-5.25" },
+ { 0xC48FE83A, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Leisure Suit Larry 3 v1.021-3.5" },
+ { 0x484587DD, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Leisure Suit Larry 3 v1.021-5.25"},
+ /* { 0x????????, SCI_VERSION_AUTODETECT, SCI_VERSION(0,000,572), "Leisure Suit Larry 3 v1.021-st"},*/ /* 1.002.026 */
+ { 0x6348030A, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Leisure Suit Larry 3 v1.039-ami"}, /* 1.002.032 */
+
+ { 0x94EA377B, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 685), "CB1" },
+ { 0xFD9EE7BD, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 685), "Camelot" },
+ { 0x2829987F, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 685), "Camelot" },
+ { 0x980CEAD3, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 629), "Demo Quest" },
+ { 0x3DB972CA, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Hoyle 2" },
+ { 0xC0B37651, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 685), "Iceman" },
+ { 0xDABA6B8A, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 999), "KQ1 v1.000.051-3.5" }, /* S.old.010 */
+ { 0x270E37F3, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 274), "KQ4" },
+ { 0x685F1205, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 502), "KQ4" },
+ { 0xC14E3A2A, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 395), "PQ2" },
+ { 0x4BD66036, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 490), "PQ2" },
+ { 0x7132D6D8, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 629), "QfG1" },
+ { 0xF8F4913F, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 685), "SQ3" },
+ { 0x34FBC324, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 999), "SQ3/DE" }, /* S.old.114 */
+ { 0xE4A3234D, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 506), "Fun Seekers Guide v1.02"},
+ { 0x85AFE241, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 519), "Hoyle 1 v1.000.104"},
+ { 0xE0E070C3, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 572), "Hoyle 2 v1.000.011"},
+ { 0xD0B8794E, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 668), "Iceman v1.023"},
+ { 0x94EA377B, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 631), "The Colonel's Bequest v1.000.046"},
+ { 0x28543FDF, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 453), "Astro Chicken"},
+ { 0x31F46F7D, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 453), "Space Quest III v1.0V int"},
+ { 0xAA2C94B9, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 685), "Mixed-Up Mother Goose v1.011 Int.#8.2.90"},
+ { 0x3B15678B, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 631), "The Colonel's Bequest v1.000.046-3.5"},
+ { 0x0E042F46, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 530), "Hoyle 1 v1.000.113-3.5"},
+ { 0x1EACB959, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 566), "HQ v1.000-5.25"},
+ { 0x2BEAF5E7, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 566), "HQ v1.001-5.25"},
+ { 0x63626D3E, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 668), "Iceman v1.023-5.25"},
+ { 0xDA5E7B7D, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 409), "KQ4 v1.003.006-3.5"},
+ { 0x376A5472, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 502), "KQ4 v1.006.003-5.25"},
+ { 0x364B40B2, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 395), "PQ2 v1.001.000-5.25"},
+ { 0x664B4123, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 409), "PQ2 v1.001.006-3.5"},
+ { 0x379F4582, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 453), "SQ3 v1.0V-5.25"},
+ { 0x04B0B081, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 294), "xmascard v1.04"},
+
+ { 0x4447B28D, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 72), "Trial v1.105"},
+
+ { 0xB1C2CCAE, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 200), "SQ4 v1.052"}, /* 1.000.753 */
+ { 0xAA6AF6A9, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 60), "KQ5 v0.000.062"},
+ { 0x092C2C0D, 3, SCI_VERSION(1, 000, 172), "jones v1.000.060"}, /* x.yyy.zzz */
+
+ { 0xC415A485, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 172), "jones v1.000.060-cd"}, /* x.yyy.zzz */
+
+ { 0x89C595E3, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 510), "SQ1 v2.000"}, /* T.A00.081 */
+ { 0x09D4FC54, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 510), "LSL5 v1.000"}, /* T.A00.169 */
+ { 0xF3ED1D81, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 510), "PQ3 v1.00"}, /* T.A00.178 */
+ { 0x501B5E6B, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 510), "Brain v1.000"}, /* 1.000.044 */
+ { 0xB1B7279B, SCI_VERSION_AUTODETECT, SCI_VERSION(1, 000, 510), "Longbow v1.000"}, /* 1.000.168 */
+
+ { 0x82595EBE, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 453), "SQ3 v1.0V-ami"}, /* x.yyy.zzz */
+ { 0xF6080B61, SCI_VERSION_AUTODETECT, SCI_VERSION(0, 000, 530), "Hoyle 1 v1.000.139-ami"}, /* x.yyy.zzz */
+
+ { 0x8AFEA2D0, 2, SCI_VERSION(1, 000, 000), "KQ1 v1.000.054-ami"}, /* 1.003.007 */
/* Undetermined Amiga versions: */
-/* { 0x8AE5F854, ?, SCI_VERSION(), "ARTHUR" }, */
-/* { 0x9FB7015B, ?, SCI_VERSION(), "CB1" }, */
-/* { 0x560CEDD5, ?, SCI_VERSION(), "iceMan" }, */
+ /* { 0x8AE5F854, ?, SCI_VERSION(), "ARTHUR" }, */
+ /* { 0x9FB7015B, ?, SCI_VERSION(), "CB1" }, */
+ /* { 0x560CEDD5, ?, SCI_VERSION(), "iceMan" }, */
{ 0, 0, 0, NULL } /* terminator */
};
diff --git a/engines/sci/scicore/hashmap.cpp b/engines/sci/scicore/hashmap.cpp
index 1b2b6af5c1..bb3bc7a670 100644
--- a/engines/sci/scicore/hashmap.cpp
+++ b/engines/sci/scicore/hashmap.cpp
@@ -183,4 +183,4 @@ TYPE##_hash_map_remove_value(TYPE##_hash_map_t *map, TYPE value) \
return oldnode->value; \
} else return -1; /* Not found */ \
} \
-
+
diff --git a/engines/sci/scicore/modules.cpp b/engines/sci/scicore/modules.cpp
index f63d4e4aa0..2b3cfabbaa 100644
--- a/engines/sci/scicore/modules.cpp
+++ b/engines/sci/scicore/modules.cpp
@@ -34,19 +34,18 @@
static sci_module_t *
-_sci_try_open_module(char *filename, char *path, char *struct_name, void **handle)
-{
+_sci_try_open_module(char *filename, char *path, char *struct_name, void **handle) {
char *fullname = sci_malloc(strlen(path) + strlen(DIR_SEPARATOR_STR)
- + strlen(filename));
+ + strlen(filename));
sci_module_t *module;
-fprintf(stderr,"Trying module %s at %s\n", filename, path);
+ fprintf(stderr, "Trying module %s at %s\n", filename, path);
strcpy(fullname, path);
strcat(fullname, DIR_SEPARATOR_STR);
strcat(fullname, filename);
-fprintf(stderr,"Total name is %s\n", fullname);
+ fprintf(stderr, "Total name is %s\n", fullname);
*handle = dlopen(fullname, RTLD_NOW);
-fprintf(stderr,"Could not open because: %s\n", dlerror());
+ fprintf(stderr, "Could not open because: %s\n", dlerror());
free(fullname);
if (!*handle)
@@ -54,19 +53,18 @@ fprintf(stderr,"Could not open because: %s\n", dlerror());
module = (sci_module_t *) dlsym(*handle, struct_name);
if (!module)
- fprintf(stderr,"%s: Failed to find symbol '%s'.\n",
- fullname, struct_name);
+ fprintf(stderr, "%s: Failed to find symbol '%s'.\n",
+ fullname, struct_name);
return module;
}
void *
sci_find_module(char *path, char *name, char *type, char *struct_prefix,
- char *file_suffix, int magic, int version, void **handle)
-{
+ char *file_suffix, int magic, int version, void **handle) {
char *module_name = sci_malloc(strlen(type) + strlen(DIR_SEPARATOR_STR)
- + strlen(name) + strlen(file_suffix)
- + strlen(MODULE_NAME_SUFFIX) + 1);
+ + strlen(name) + strlen(file_suffix)
+ + strlen(MODULE_NAME_SUFFIX) + 1);
char *struct_name = sci_malloc(strlen(struct_prefix) + strlen(name) + 1);
char *dir_end;
char *path_pos = path;
@@ -88,19 +86,19 @@ sci_find_module(char *path, char *name, char *type, char *struct_prefix,
*dir_end = 0;
module = _sci_try_open_module(module_name, path_pos,
- struct_name, handle);
+ struct_name, handle);
if (module) {
if (module->class_magic != magic) {
fprintf(stderr, "%s at %s is not a %s module, skipping...\n",
- module_name, path_pos, type);
+ module_name, path_pos, type);
dlclose(*handle);
module = NULL;
} else if (module->class_version != version) {
fprintf(stderr, "%s at %s has %s module version %d,"
- " expected %d- skipping...\n",
- module_name, path_pos, type, module->class_version,
- version);
+ " expected %d- skipping...\n",
+ module_name, path_pos, type, module->class_version,
+ version);
dlclose(*handle);
module = NULL;
}
@@ -115,8 +113,8 @@ sci_find_module(char *path, char *name, char *type, char *struct_prefix,
if (!module) {
*handle = NULL;
- fprintf(stderr,"%s module '%s' not found in path '%s'.\n",
- type, name, path);
+ fprintf(stderr, "%s module '%s' not found in path '%s'.\n",
+ type, name, path);
} else {
if (dir_end)
*dir_end = 0;
@@ -137,14 +135,13 @@ sci_find_module(char *path, char *name, char *type, char *struct_prefix,
void
-sci_close_module(void *module, char *type, char *name)
-{
+sci_close_module(void *module, char *type, char *name) {
if (!module)
return;
if (dlclose(module)) {
- fprintf(stderr,"Error while closing %s module '%s': %s\n",
- type, name, dlerror());
+ fprintf(stderr, "Error while closing %s module '%s': %s\n",
+ type, name, dlerror());
}
}
diff --git a/engines/sci/scicore/old_objects.cpp b/engines/sci/scicore/old_objects.cpp
index 8408373537..cd142bc90e 100644
--- a/engines/sci/scicore/old_objects.cpp
+++ b/engines/sci/scicore/old_objects.cpp
@@ -25,359 +25,328 @@ object **object_map, *object_root;
int max_object;
const char* globals[] = {
- /*00*/
- "ego",
- "GAMEID",
- "roomXX",
- "speed",
- /*04*/
- "quitFlag",
- "cast",
- "regions",
- "timer",
- /*08*/
- "sounds",
- "inv",
- "eventHandler",
- "roomNumberExit",
- /*0C*/
- "previousRoomNumber",
- "roomNumber",
- "enterDebugModeOnRoomExit",
- "score",
- /*10*/
- "maximumScore",
- "11",
- "speed",
- "13",
- /*14*/
- "14",
- "loadCursor",
- "normalFont",
- "restoreSaveFont", /*dialogFont*/
- /*18*/
- "18",
- "19",
- "defaultFont",
- "1B",
- /*1C*/
- "pointerToVersionNumber",
- "locales",
- "pointerToSaveGameDirectory",
- "1F"
+ /*00*/
+ "ego",
+ "GAMEID",
+ "roomXX",
+ "speed",
+ /*04*/
+ "quitFlag",
+ "cast",
+ "regions",
+ "timer",
+ /*08*/
+ "sounds",
+ "inv",
+ "eventHandler",
+ "roomNumberExit",
+ /*0C*/
+ "previousRoomNumber",
+ "roomNumber",
+ "enterDebugModeOnRoomExit",
+ "score",
+ /*10*/
+ "maximumScore",
+ "11",
+ "speed",
+ "13",
+ /*14*/
+ "14",
+ "loadCursor",
+ "normalFont",
+ "restoreSaveFont", /*dialogFont*/
+ /*18*/
+ "18",
+ "19",
+ "defaultFont",
+ "1B",
+ /*1C*/
+ "pointerToVersionNumber",
+ "locales",
+ "pointerToSaveGameDirectory",
+ "1F"
};
-static int add_object(object* obj)
-{
+static int add_object(object* obj) {
FLEXARRAY_APPEND(object*, fobjects, obj, return 1);
return 0;
}
-static void dump(byte* data, int len)
-{
- int i=0;
- while(i<len)
- {
+static void dump(byte* data, int len) {
+ int i = 0;
+ while (i < len) {
printf("%02X ", data[i++]);
- if(i%8==0) printf(" ");
- if(i%16==0) printf("\n");
+ if (i % 8 == 0) printf(" ");
+ if (i % 16 == 0) printf("\n");
}
- if(i%16) printf("\n");
+ if (i % 16) printf("\n");
}
-static void printMethod(object* obj, int meth, int indent)
-{
- script_method* m=obj->methods[meth];
+static void printMethod(object* obj, int meth, int indent) {
+ script_method* m = obj->methods[meth];
int i, j;
- for(j=0; j<indent*2-1; j++) printf(" ");
+ for (j = 0; j < indent*2 - 1; j++) printf(" ");
printf("Method %s\n", snames[m->number]);
- for(i=0; i<m->used; i++)
- {
- script_opcode op=m->data[i];
+ for (i = 0; i < m->used; i++) {
+ script_opcode op = m->data[i];
- for(j=0; j<indent; j++) printf(" ");
+ for (j = 0; j < indent; j++) printf(" ");
printf("%s ", opcodes[op.opcode].name);
- switch(op.opcode)
- {
- case 0x21: /*callk*/
- {
- if(op.arg1>knames_count) printf("<no such kernel function %02X> ", op.arg1);
- else printf("%s ", knames[op.arg1]);
- printf("%02X", op.arg2);
- } break;
- case 0x28: /*class*/
- {
- if(op.arg1>max_object) printf("<no such class %02X>", op.arg1);
- else
- {
- /* [DJ] op.arg1+1 adjusts for the <root> object */
- if(fobjects.data[op.arg1+1]==0) printf("<null object>");
- else printf("%s", fobjects.data[op.arg1+1]->name);
+ switch (op.opcode) {
+ case 0x21: { /*callk*/
+ if (op.arg1 > knames_count) printf("<no such kernel function %02X> ", op.arg1);
+ else printf("%s ", knames[op.arg1]);
+ printf("%02X", op.arg2);
+ }
+ break;
+ case 0x28: { /*class*/
+ if (op.arg1 > max_object) printf("<no such class %02X>", op.arg1);
+ else {
+ /* [DJ] op.arg1+1 adjusts for the <root> object */
+ if (fobjects.data[op.arg1+1] == 0) printf("<null object>");
+ else printf("%s", fobjects.data[op.arg1+1]->name);
+ }
+ }
+ break;
+ case 0x44: {
+ if (op.arg1 > 0x20) printf("<no such global %02X> ", op.arg1);
+ else printf("%s ", globals[op.arg1]);
+ }
+ break;
+ default: {
+ int args[3];
+ args[0] = op.arg1;
+ args[1] = op.arg2;
+ args[2] = op.arg3;
+ for (j = 0; j < 3; j++) {
+ switch (formats[op.opcode][j]) {
+ case Script_Invalid: {
+ printf("<invalid> ");
+ }
+ break;
+ case Script_None: {
+ j = 3;
+ }
+ break;
+ case Script_SByte:
+ case Script_Byte: {
+ printf("%02X ", args[j]);
+ }
+ break;
+ case Script_Word:
+ case Script_SVariable:
+ case Script_Variable:
+ case Script_SRelative:
+ case Script_Property:
+ case Script_Global:
+ case Script_Local:
+ case Script_Temp:
+ case Script_Param: {
+ printf("%04X ", args[j]);
+ }
+ break;
+ case Script_SWord: {
+ if (args[j] < 0) printf("-%04X", -args[j]);
+ else printf("%04X", args[j]);
+ }
+ break;
+ case Script_End: {
+ printf("\n");
+ return;
+ }
+ break;
+ default: {
+ printf("<unknown arg type %d> ", formats[op.opcode][j]);
}
- } break;
- case 0x44:
- {
- if(op.arg1>0x20) printf("<no such global %02X> ", op.arg1);
- else printf("%s ", globals[op.arg1]);
- } break;
- default:
- {
- int args[3];
- args[0]=op.arg1;
- args[1]=op.arg2;
- args[2]=op.arg3;
- for(j=0; j<3; j++)
- {
- switch(formats[op.opcode][j])
- {
- case Script_Invalid:
- {
- printf("<invalid> ");
- } break;
- case Script_None:
- {
- j=3;
- } break;
- case Script_SByte:
- case Script_Byte:
- {
- printf("%02X ", args[j]);
- } break;
- case Script_Word:
- case Script_SVariable:
- case Script_Variable:
- case Script_SRelative:
- case Script_Property:
- case Script_Global:
- case Script_Local:
- case Script_Temp:
- case Script_Param:
- {
- printf("%04X ", args[j]);
- } break;
- case Script_SWord:
- {
- if(args[j]<0) printf("-%04X", -args[j]);
- else printf("%04X", args[j]);
- } break;
- case Script_End:
- {
- printf("\n");
- return;
- } break;
- default:
- {
- printf("<unknown arg type %d> ", formats[op.opcode][j]);
- }
- }
}
- } break;
+ }
+ }
+ break;
}
printf("\n");
}
}
-static void printObject_r(object* obj, int flags, int level)
-{
+static void printObject_r(object* obj, int flags, int level) {
int i;
- for(i=0; i<level; i++) printf(" ");
- if(obj==0) printf("(null)\n");
- else
- {
+ for (i = 0; i < level; i++) printf(" ");
+ if (obj == 0) printf("(null)\n");
+ else {
printf("%s\n", obj->name);
- if(flags&SCRIPT_PRINT_METHODS)
- {
- for(i=0; i<obj->method_count; i++)
- {
- printMethod(obj, i, level+1);
+ if (flags&SCRIPT_PRINT_METHODS) {
+ for (i = 0; i < obj->method_count; i++) {
+ printMethod(obj, i, level + 1);
}
}
- if(flags&SCRIPT_PRINT_CHILDREN)
- {
- for(i=0; i<obj->children.used; i++)
- {
- printObject_r(obj->children.data[i], flags, level+1);
+ if (flags&SCRIPT_PRINT_CHILDREN) {
+ for (i = 0; i < obj->children.used; i++) {
+ printObject_r(obj->children.data[i], flags, level + 1);
}
}
}
}
-void printObject(object* obj, int flags)
-{
+void printObject(object* obj, int flags) {
printf("pO(%p, %d)\n", obj, flags);
printObject_r(obj, flags, 0);
}
-static object* object_new()
-{
- object* obj= (object*)sci_malloc(sizeof(object));
- if(obj==0) return 0;
+static object* object_new() {
+ object* obj = (object*)sci_malloc(sizeof(object));
+ if (obj == 0) return 0;
- obj->parent=0;
+ obj->parent = 0;
FLEXARRAY_INIT(object*, obj->children);
- obj->name=0;
- obj->selector_count=0;
- obj->selector_numbers=0;
- obj->methods=0;
- obj->method_count=0;
+ obj->name = 0;
+ obj->selector_count = 0;
+ obj->selector_numbers = 0;
+ obj->methods = 0;
+ obj->method_count = 0;
return obj;
}
-static int add_child(object* parent, object* child)
-{
+static int add_child(object* parent, object* child) {
FLEXARRAY_APPEND(object*, parent->children, child, return 1);
return 0;
}
-static object* fake_object(const char* reason)
-{
- object* obj=object_new();
- if(obj==0)
- {
- #ifdef SCRIPT_DEBUG
+static object* fake_object(const char* reason) {
+ object* obj = object_new();
+ if (obj == 0) {
+#ifdef SCRIPT_DEBUG
printf("object_new failed during fake for %s\n", reason);
- #endif
+#endif
free(obj);
return 0;
}
- if(add_child(object_root, obj))
- {
- #ifdef SCRIPT_DEBUG
+ if (add_child(object_root, obj)) {
+#ifdef SCRIPT_DEBUG
printf("add_child failed during fake for %s\n", reason);
- #endif
+#endif
free(obj);
return 0;
}
- obj->name=reason;
- if(add_object(obj))
- {
- #ifdef SCRIPT_DEBUG
+ obj->name = reason;
+ if (add_object(obj)) {
+#ifdef SCRIPT_DEBUG
printf("add_object failed during fake for %s\n", reason);
- #endif
+#endif
/*FIXME: clean up parent*/
return 0;
}
return obj;
}
-static script_method* decode_method(byte* data)
-{
- script_method* m;
- int done=0;
- int pos=0;
- static int count=0;
-
- count++;
-
- if((m= (script_method*)sci_malloc(sizeof(script_method)))==0) return 0;
- FLEXARRAY_INIT(script_opcode, *m);
-
- while(!done)
- {
- int op=data[pos]>>1;
- int size=2-(data[pos]&1);
- int* args[3];
- int arg;
- int old_pos;
-
- FLEXARRAY_ADD_SPACE(script_opcode, *m, 1, return 0);
- old_pos=pos;
- m->data[m->used-1].pos=pos;
- m->data[m->used-1].opcode=op;
-
- /*Copy the adresses of the args to an array for convenience*/
- args[0]=&m->data[m->used-1].arg1;
- args[1]=&m->data[m->used-1].arg2;
- args[2]=&m->data[m->used-1].arg3;
-
- /*Skip past the opcode*/
- pos++;
-
- for(arg=0; arg<4; arg++)
- {
- switch(formats[op][arg])
- {
- case Script_Invalid: /*Can't happen(tm)*/
- {
- int i;
- printf("Invalid opcode %02X at %04X in method %d\n", op, pos, count);
- for(i=m->used-9; i<m->used-1; i++)
- {
- printf("%s[%02X] ", opcodes[m->data[i].opcode].name, m->data[i].opcode);
- dump(data+m->data[i].pos, m->data[i].size);
- }
- printf("Dump from %04X-%04X\n", pos-16, pos+16);
- dump(data + pos - 16, 32);
- } break;
- case Script_None: /*No more args*/
- {
- arg=4;
- } break;
- case Script_Byte: /*Just a one byte arg*/
- case Script_SByte:
- {
- *args[arg]=data[pos++];
- } break;
- case Script_Word: /*A two byte arg*/
- {
- *args[arg]=getInt16(data+pos);
- pos+=2;
- } break;
- case Script_SWord: /*A signed two-byte arg*/
- {
- int t=getInt16(data+pos);
- if(t&0x8000) *args[arg]=-(t&0x7FFF);
- else *args[arg]=t;
- pos+=2;
- } break;
- case Script_Variable: /*Size of arg depends on LSB in opcode*/
- case Script_SVariable:
- case Script_SRelative:
- case Script_Property:
- case Script_Global:
- case Script_Local:
- case Script_Temp:
- case Script_Param:
- {
- if(size==1) *args[arg]=data[pos++];
- else
- {
- *args[arg]=getInt16(data+pos);
- pos+=2;
+static script_method* decode_method(byte* data) {
+ script_method* m;
+ int done = 0;
+ int pos = 0;
+ static int count = 0;
+
+ count++;
+
+ if ((m = (script_method*)sci_malloc(sizeof(script_method))) == 0) return 0;
+ FLEXARRAY_INIT(script_opcode, *m);
+
+ while (!done) {
+ int op = data[pos] >> 1;
+ int size = 2 - (data[pos] & 1);
+ int* args[3];
+ int arg;
+ int old_pos;
+
+ FLEXARRAY_ADD_SPACE(script_opcode, *m, 1, return 0);
+ old_pos = pos;
+ m->data[m->used-1].pos = pos;
+ m->data[m->used-1].opcode = op;
+
+ /*Copy the adresses of the args to an array for convenience*/
+ args[0] = &m->data[m->used-1].arg1;
+ args[1] = &m->data[m->used-1].arg2;
+ args[2] = &m->data[m->used-1].arg3;
+
+ /*Skip past the opcode*/
+ pos++;
+
+ for (arg = 0; arg < 4; arg++) {
+ switch (formats[op][arg]) {
+ case Script_Invalid: { /*Can't happen(tm)*/
+ int i;
+ printf("Invalid opcode %02X at %04X in method %d\n", op, pos, count);
+ for (i = m->used - 9; i < m->used - 1; i++) {
+ printf("%s[%02X] ", opcodes[m->data[i].opcode].name, m->data[i].opcode);
+ dump(data + m->data[i].pos, m->data[i].size);
+ }
+ printf("Dump from %04X-%04X\n", pos - 16, pos + 16);
+ dump(data + pos - 16, 32);
+ }
+ break;
+ case Script_None: { /*No more args*/
+ arg = 4;
+ }
+ break;
+ case Script_Byte: /*Just a one byte arg*/
+ case Script_SByte: {
+ *args[arg] = data[pos++];
+ }
+ break;
+ case Script_Word: { /*A two byte arg*/
+ *args[arg] = getInt16(data + pos);
+ pos += 2;
+ }
+ break;
+ case Script_SWord: { /*A signed two-byte arg*/
+ int t = getInt16(data + pos);
+ if (t&0x8000) *args[arg] = -(t & 0x7FFF);
+ else *args[arg] = t;
+ pos += 2;
+ }
+ break;
+ case Script_Variable: /*Size of arg depends on LSB in opcode*/
+ case Script_SVariable:
+ case Script_SRelative:
+ case Script_Property:
+ case Script_Global:
+ case Script_Local:
+ case Script_Temp:
+ case Script_Param: {
+ if (size == 1) *args[arg] = data[pos++];
+ else {
+ *args[arg] = getInt16(data + pos);
+ pos += 2;
+ }
+ }
+ break;
+ case Script_End: { /*Special tag for ret*/
+ done = 1;
+ arg = 4;
+ }
+ break;
+ default: { /*Can't happen(tm)*/
+ printf("Unknown argument format %d for op %02X\n", formats[op][arg], op);
+ }
+ break;
+ }
}
- } break;
- case Script_End: /*Special tag for ret*/
- {
- done=1;
- arg=4;
- } break;
- default: /*Can't happen(tm)*/
- {
- printf("Unknown argument format %d for op %02X\n", formats[op][arg], op);
- } break;
- }
+ fflush(stdout);
+ if (m->used) m->data[m->used-1].size = pos - old_pos;
}
- fflush(stdout);
- if (m->used) m->data[m->used-1].size=pos-old_pos;
- }
- return m;
+ return m;
}
#ifdef SCRIPT_DEBUG
-void list_code_blocks(resource_t* r)
-{
- int pos=getInt16(r->data+2);
- while(pos<r->size-2)
- {
- int type=getInt16(r->data+pos);
- int len=getInt16(r->data+pos+2);
- if(type==2) printf("%X-%X\n", pos, pos+len);
- pos+=len;
+void list_code_blocks(resource_t* r) {
+ int pos = getInt16(r->data + 2);
+ while (pos < r->size - 2) {
+ int type = getInt16(r->data + pos);
+ int len = getInt16(r->data + pos + 2);
+ if (type == 2) printf("%X-%X\n", pos, pos + len);
+ pos += len;
}
}
#endif
@@ -385,93 +354,83 @@ void list_code_blocks(resource_t* r)
/*These expect the frame, the whole frame, and, well, other stuff too,
*I guess, as long as it looks like a frame*/
-static int get_type(unsigned char* obj)
-{
+static int get_type(unsigned char* obj) {
return getInt16(obj);
}
-static int get_length(unsigned char* obj)
-{
- return getInt16(obj+2);
+static int get_length(unsigned char* obj) {
+ return getInt16(obj + 2);
}
-static int get_selector_count(unsigned char* obj)
-{
- return getInt16(obj+10);
+static int get_selector_count(unsigned char* obj) {
+ return getInt16(obj + 10);
}
-static int get_selector_value(unsigned char* obj, int sel)
-{
- assert(sel<get_selector_count(obj));
+static int get_selector_value(unsigned char* obj, int sel) {
+ assert(sel < get_selector_count(obj));
return getInt16(obj + 12 + sel*2);
}
/*Bas things happen if the method offset value is wrong*/
-static unsigned char* get_method_area(unsigned char* obj)
-{
- return obj+getInt16(obj+8)+10;
+static unsigned char* get_method_area(unsigned char* obj) {
+ return obj + getInt16(obj + 8) + 10;
}
-static int get_method_count(unsigned char* obj)
-{
+static int get_method_count(unsigned char* obj) {
return getInt16(get_method_area(obj));
}
-static int get_method_number(unsigned char* obj, int i)
-{
- assert(i<get_method_count(obj));
- return getInt16(get_method_area(obj)+2+2*i);
+static int get_method_number(unsigned char* obj, int i) {
+ assert(i < get_method_count(obj));
+ return getInt16(get_method_area(obj) + 2 + 2*i);
}
-static int get_method_location(unsigned char* obj, int i)
-{
- assert(i<get_method_count(obj));
- return getInt16(get_method_area(obj)+4+2*get_method_count(obj)+2*i);
+static int get_method_location(unsigned char* obj, int i) {
+ assert(i < get_method_count(obj));
+ return getInt16(get_method_area(obj) + 4 + 2*get_method_count(obj) + 2*i);
}
/*Returns the position of the first frame of type 'type' in resource 'r',
*starting from the frame starting at 'start', or -1 on failure.
*/
-static int find_frame(resource_t* r, int type, unsigned int start)
-{
- int t=-1;
+static int find_frame(resource_t* r, int type, unsigned int start) {
+ int t = -1;
unsigned int pos = start;
unsigned char* frame;
- assert(start<=r->size-4);
+ assert(start <= r->size - 4);
- #ifdef SCRIPT_DEBUG
+#ifdef SCRIPT_DEBUG
printf("Searching for frame of type %d in script %03d, starting at %#x\n", type, r->number, start);
- dump(r->data+start, 32);
- #endif
+ dump(r->data + start, 32);
+#endif
/*Some times there's an extra byte at the beginning. Christoph?*/
#if 1
- if(pos==0 && r->size>=6 && \
- !((0<getInt16(r->data)) && (10>getInt16(r->data)))) pos=2;
+ if (pos == 0 && r->size >= 6 && \
+ !((0 < getInt16(r->data)) && (10 > getInt16(r->data)))) pos = 2;
#else
- if(pos == 0)
+ if (pos == 0)
pos = 2;
#endif
frame = r->data + pos;
- while(1)
- {
+ while (1) {
#ifdef SCRIPT_DEBUG
printf("offset = %#x\n", pos);
dump(frame, 32);
#endif
t = get_type(frame);
- if(t == type)
+ if (t == type)
break;
- if(t == 0)
+ if (t == 0)
return -1;
- pos+=get_length(frame);
- if(pos > (r->size - 2))
+ pos += get_length(frame);
+ if (pos > (r->size - 2))
return -1;
- frame+=get_length(frame);
+ frame += get_length(frame);
}
return pos;
@@ -482,8 +441,7 @@ static int find_frame(resource_t* r, int type, unsigned int start)
/*FIXME: lots of things are identical to read_object and read_class. Some of
*these would benefit from being put in separate functions.*/
-static object* read_object(resource_mgr_t *resmgr, int script, int positions[1000])
-{
+static object* read_object(resource_mgr_t *resmgr, int script, int positions[1000]) {
resource_t* r = scir_find_resource(resmgr, sci_script, script, 0);
unsigned char* raw;
int pos;
@@ -491,94 +449,85 @@ static object* read_object(resource_mgr_t *resmgr, int script, int positions[100
printf("Searching for object in script %03d\n", script);
- if(r==0) return 0;
+ if (r == 0) return 0;
/*Skip to the next object*/
- #ifdef SCRIPT_DEBUG
+#ifdef SCRIPT_DEBUG
printf("pre skip: pos=%#x\n", positions[script]);
- #endif
- pos=find_frame(r, 1, positions[script]);
- #ifdef SCRIPT_DEBUG
+#endif
+ pos = find_frame(r, 1, positions[script]);
+#ifdef SCRIPT_DEBUG
printf("post skip: pos=%#x\n", pos);
- #endif
- if(pos==-1) return 0;
- else positions[script]=pos+get_length(r->data+pos);
- #ifdef SCRIPT_DEBUG
- printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data+pos));
- #endif
+#endif
+ if (pos == -1) return 0;
+ else positions[script] = pos + get_length(r->data + pos);
+#ifdef SCRIPT_DEBUG
+ printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data + pos));
+#endif
/*Construct the object*/
- obj=object_new();
- raw=r->data+pos;
+ obj = object_new();
+ raw = r->data + pos;
/*Fill in the name*/
- if(get_selector_count(raw)<4) obj->name="<anonymous>";
- else
- {
+ if (get_selector_count(raw) < 4) obj->name = "<anonymous>";
+ else {
if (get_selector_value(raw, 3))
obj->name = (char *) r->data + get_selector_value(raw, 3);
- else obj->name="<null>";
+ else obj->name = "<null>";
}
/*Fill in the class*/
- if(get_selector_count(raw)==0) obj->parent=object_root;
- else
- {
- int parent_id=get_selector_value(raw, 1);
- if(parent_id>=fobjects.used)
- {
+ if (get_selector_count(raw) == 0) obj->parent = object_root;
+ else {
+ int parent_id = get_selector_value(raw, 1);
+ if (parent_id >= fobjects.used) {
free(obj);
return 0;
}
- if(parent_id<1) obj->parent=object_root;
- else obj->parent=fobjects.data[parent_id];
+ if (parent_id < 1) obj->parent = object_root;
+ else obj->parent = fobjects.data[parent_id];
}
/*Add the object to the class*/
- if(!obj->parent)
- {
+ if (!obj->parent) {
free(obj);
return 0;
}
- if(add_child(obj->parent, obj)){
+ if (add_child(obj->parent, obj)) {
free(obj);
return 0;
}
- if(add_object(obj))
- {
+ if (add_object(obj)) {
free(obj);
return 0;
}
/*FIXME: decode selectors here*/
- obj->method_count=get_method_count(raw);
- obj->methods= (script_method**)sci_malloc(obj->method_count*sizeof(script_method));
- if(obj->methods==0)
- {
+ obj->method_count = get_method_count(raw);
+ obj->methods = (script_method**)sci_malloc(obj->method_count * sizeof(script_method));
+ if (obj->methods == 0) {
free(obj);
return 0;
} else {
int i;
- for(i=0; i<obj->method_count; i++)
- {
- int number=get_method_number(raw, i);
- int position=get_method_location(raw, i);
-
- if((obj->methods[i]=decode_method(r->data+position))==0)
- {
- obj->method_count=i-1;
+ for (i = 0; i < obj->method_count; i++) {
+ int number = get_method_number(raw, i);
+ int position = get_method_location(raw, i);
+
+ if ((obj->methods[i] = decode_method(r->data + position)) == 0) {
+ obj->method_count = i - 1;
break;
}
- obj->methods[i]->number=number;
+ obj->methods[i]->number = number;
}
}
return obj;
}
-static object* read_class(resource_mgr_t *resmgr, int script, int positions[1000])
-{
+static object* read_class(resource_mgr_t *resmgr, int script, int positions[1000]) {
resource_t* r = scir_find_resource(resmgr, sci_script, script, 0);
unsigned char* raw;
int pos;
@@ -586,62 +535,57 @@ static object* read_class(resource_mgr_t *resmgr, int script, int positions[1000
printf("Searching for class in script %03d\n", script);
- if(r==0) return fake_object("<resource not found>");
+ if (r == 0) return fake_object("<resource not found>");
/*Skip to the next class*/
- #ifdef SCRIPT_DEBUG
+#ifdef SCRIPT_DEBUG
printf("pre skip: pos=%#x\n", positions[script]);
- #endif
- pos=find_frame(r, 6, positions[script]);
- #ifdef SCRIPT_DEBUG
+#endif
+ pos = find_frame(r, 6, positions[script]);
+#ifdef SCRIPT_DEBUG
printf("post skip: pos=%#x\n", pos);
- #endif
- if(pos==-1) return fake_object("<no more classes in script>");
- else positions[script]=pos+get_length(r->data+pos);
- #ifdef SCRIPT_DEBUG
- printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data+pos));
- #endif
+#endif
+ if (pos == -1) return fake_object("<no more classes in script>");
+ else positions[script] = pos + get_length(r->data + pos);
+#ifdef SCRIPT_DEBUG
+ printf("post post: pos=%#x (len=%#x)\n", positions[script], get_length(r->data + pos));
+#endif
/*Construct the object*/
- obj=object_new();
- raw=r->data+pos;
+ obj = object_new();
+ raw = r->data + pos;
/*Fill in the name*/
- if(get_selector_count(raw)<4) obj->name="<anonymous>";
- else
- {
+ if (get_selector_count(raw) < 4) obj->name = "<anonymous>";
+ else {
if (get_selector_value(raw, 3))
obj->name = (char *) r->data + get_selector_value(raw, 3);
- else obj->name="<null>";
+ else obj->name = "<null>";
}
/*Fill in the parent*/
- if(get_selector_count(raw)==0) obj->parent=object_root;
- else
- {
- int superclass_id=get_selector_value(raw, 1);
+ if (get_selector_count(raw) == 0) obj->parent = object_root;
+ else {
+ int superclass_id = get_selector_value(raw, 1);
printf("superclass==%d\n", superclass_id);
- if(superclass_id>=fobjects.used)
- {
+ if (superclass_id >= fobjects.used) {
free(obj);
return fake_object("<no such superclass>");
}
- if(superclass_id<1) obj->parent=object_root;
- else obj->parent=fobjects.data[superclass_id];
+ if (superclass_id < 1) obj->parent = object_root;
+ else obj->parent = fobjects.data[superclass_id];
}
/*Add the class to the hierarchy*/
- if(!obj->parent)
- {
+ if (!obj->parent) {
free(obj);
return fake_object("<null parent>");
}
- if(add_child(obj->parent, obj)){
+ if (add_child(obj->parent, obj)) {
free(obj);
return fake_object("<add_child failed>");
}
- if(add_object(obj))
- {
+ if (add_object(obj)) {
free(obj);
return fake_object("<add_object failed>");
}
@@ -651,64 +595,58 @@ static object* read_class(resource_mgr_t *resmgr, int script, int positions[1000
return obj;
}
-void freeObject(object* obj)
-{
+void freeObject(object* obj) {
int i;
- for(i=0; i<obj->children.used; i++) freeObject(obj->children.data[i]);
+ for (i = 0; i < obj->children.used; i++) freeObject(obj->children.data[i]);
free(obj);
}
-static int objects_init(resource_mgr_t *resmgr)
-{
+static int objects_init(resource_mgr_t *resmgr) {
FLEXARRAY_INIT(object*, fobjects);
- max_object=0;
+ max_object = 0;
- if((object_root=object_new())==0) return 1;
- object_root->name="<root>";
+ if ((object_root = object_new()) == 0) return 1;
+ object_root->name = "<root>";
add_object(object_root);
- opcodes=vocabulary_get_opcodes(resmgr);
- knames=vocabulary_get_knames(resmgr, &knames_count);
- snames=vocabulary_get_snames(resmgr, NULL, 0);
+ opcodes = vocabulary_get_opcodes(resmgr);
+ knames = vocabulary_get_knames(resmgr, &knames_count);
+ snames = vocabulary_get_snames(resmgr, NULL, 0);
return 0;
}
-int loadObjects(resource_mgr_t *resmgr)
-{
+int loadObjects(resource_mgr_t *resmgr) {
int i;
int *classes, class_count;
int positions[1000];
- if(objects_init(resmgr))
- {
- #ifdef SCRIPT_DEBUG
+ if (objects_init(resmgr)) {
+#ifdef SCRIPT_DEBUG
perror("objects_init");
- #endif
+#endif
return 1;
}
- classes=vocabulary_get_classes(resmgr, &class_count);
+ classes = vocabulary_get_classes(resmgr, &class_count);
- for(i=0; i<1000; i++) positions[i]=0;
- for(i=0; i<class_count; i++)
- {
+ for (i = 0; i < 1000; i++) positions[i] = 0;
+ for (i = 0; i < class_count; i++) {
#ifdef SCRIPT_DEBUG
- printf ("\n\nReading class 0x%02X\n", i);
+ printf("\n\nReading class 0x%02X\n", i);
#endif
- if(read_class(resmgr, classes[i], positions)==0)
- {
- #ifdef SCRIPT_DEBUG
+ if (read_class(resmgr, classes[i], positions) == 0) {
+#ifdef SCRIPT_DEBUG
fprintf(stderr, "Failed to load class %d, which is a parent.\n", i);
- #endif
+#endif
return 1;
}
}
- for(i=0; i<1000; i++) positions[i]=0;
- for(i=0; i<1000; i++) while(read_object(resmgr, i, positions));
+ for (i = 0; i < 1000; i++) positions[i] = 0;
+ for (i = 0; i < 1000; i++) while (read_object(resmgr, i, positions));
- object_map=fobjects.data;
- max_object=fobjects.used;
+ object_map = fobjects.data;
+ max_object = fobjects.used;
return 0;
}
diff --git a/engines/sci/scicore/reg_t_hashmap.cpp b/engines/sci/scicore/reg_t_hashmap.cpp
index 5ab2395909..3d1e37e454 100644
--- a/engines/sci/scicore/reg_t_hashmap.cpp
+++ b/engines/sci/scicore/reg_t_hashmap.cpp
@@ -31,8 +31,7 @@
#include "sci/scicore/hashmap.cpp"
static inline int
-compare_reg_t (reg_t lhs, reg_t rhs)
-{
+compare_reg_t (reg_t lhs, reg_t rhs) {
if (lhs.segment == rhs.segment)
return lhs.offset - rhs.offset;
else
diff --git a/engines/sci/scicore/resource.cpp b/engines/sci/scicore/resource.cpp
index ea02a7e693..8f8fe52b4e 100644
--- a/engines/sci/scicore/resource.cpp
+++ b/engines/sci/scicore/resource.cpp
@@ -68,18 +68,21 @@ const char* sci_error_types[] = {
"Decompression failed: Decompression buffer overflow",
"Decompression failed: Sanity check failed",
"Decompression failed: Resource too big",
- "SCI version is unsupported"};
+ "SCI version is unsupported"
+};
-const char* sci_resource_types[] = {"view","pic","script","text","sound",
- "memory","vocab","font","cursor",
- "patch","bitmap","palette","cdaudio",
- "audio","sync","message","map","heap"};
+const char* sci_resource_types[] = {"view", "pic", "script", "text", "sound",
+ "memory", "vocab", "font", "cursor",
+ "patch", "bitmap", "palette", "cdaudio",
+ "audio", "sync", "message", "map", "heap"
+ };
/* These are the 18 resource types supported by SCI1 */
-const char *sci_resource_type_suffixes[] = {"v56","p56","scr","tex","snd",
- " ","voc","fon","cur","pat",
- "bit","pal","cda","aud","syn",
- "msg","map","hep"};
+const char *sci_resource_type_suffixes[] = {"v56", "p56", "scr", "tex", "snd",
+ " ", "voc", "fon", "cur", "pat",
+ "bit", "pal", "cda", "aud", "syn",
+ "msg", "map", "hep"
+ };
int resourcecmp(const void *first, const void *second);
@@ -113,17 +116,16 @@ static patch_sprintf_funct *patch_sprintfers[] = {
};
-int resourcecmp (const void *first, const void *second)
-{
+int resourcecmp(const void *first, const void *second) {
if (((resource_t *)first)->type ==
- ((resource_t *)second)->type)
+ ((resource_t *)second)->type)
return (((resource_t *)first)->number <
- ((resource_t *)second)->number)? -1 :
- !(((resource_t *)first)->number ==
- ((resource_t *)second)->number);
+ ((resource_t *)second)->number) ? -1 :
+ !(((resource_t *)first)->number ==
+ ((resource_t *)second)->number);
else
return (((resource_t *)first)->type <
- ((resource_t *)second)->type)? -1 : 1;
+ ((resource_t *)second)->type) ? -1 : 1;
}
@@ -135,8 +137,7 @@ int resourcecmp (const void *first, const void *second)
/*-----------------------------*/
void
-_scir_add_altsource(resource_t *res, resource_source_t *source, unsigned int file_offset)
-{
+_scir_add_altsource(resource_t *res, resource_source_t *source, unsigned int file_offset) {
resource_altsource_t *rsrc = (resource_altsource_t*)sci_malloc(sizeof(resource_altsource_t));
rsrc->next = res->alt_sources;
@@ -146,8 +147,7 @@ _scir_add_altsource(resource_t *res, resource_source_t *source, unsigned int fil
}
resource_t *
-_scir_find_resource_unsorted(resource_t *res, int res_nr, int type, int number)
-{
+_scir_find_resource_unsorted(resource_t *res, int res_nr, int type, int number) {
int i;
for (i = 0; i < res_nr; i++)
if (res[i].number == number && res[i].type == type)
@@ -160,10 +160,9 @@ _scir_find_resource_unsorted(resource_t *res, int res_nr, int type, int number)
/*-----------------------------------*/
resource_source_t *
-scir_add_external_map(resource_mgr_t *mgr, char *file_name)
-{
- resource_source_t *newsrc = (resource_source_t *)
- malloc(sizeof(resource_source_t));
+scir_add_external_map(resource_mgr_t *mgr, char *file_name) {
+ resource_source_t *newsrc = (resource_source_t *)
+ malloc(sizeof(resource_source_t));
/* Add the new source to the SLL of sources */
newsrc->next = mgr->sources;
@@ -179,10 +178,9 @@ scir_add_external_map(resource_mgr_t *mgr, char *file_name)
resource_source_t *
scir_add_volume(resource_mgr_t *mgr, resource_source_t *map, char *filename,
- int number, int extended_addressing)
-{
- resource_source_t *newsrc = (resource_source_t *)
- malloc(sizeof(resource_source_t));
+ int number, int extended_addressing) {
+ resource_source_t *newsrc = (resource_source_t *)
+ malloc(sizeof(resource_source_t));
/* Add the new source to the SLL of sources */
newsrc->next = mgr->sources;
@@ -197,10 +195,9 @@ scir_add_volume(resource_mgr_t *mgr, resource_source_t *map, char *filename,
}
resource_source_t *
-scir_add_patch_dir(resource_mgr_t *mgr, int type, char *dirname)
-{
- resource_source_t *newsrc = (resource_source_t *)
- malloc(sizeof(resource_source_t));
+scir_add_patch_dir(resource_mgr_t *mgr, int type, char *dirname) {
+ resource_source_t *newsrc = (resource_source_t *)
+ malloc(sizeof(resource_source_t));
/* Add the new source to the SLL of sources */
newsrc->next = mgr->sources;
@@ -213,15 +210,13 @@ scir_add_patch_dir(resource_mgr_t *mgr, int type, char *dirname)
}
resource_source_t *
-scir_get_volume(resource_mgr_t *mgr, resource_source_t *map, int volume_nr)
-{
+scir_get_volume(resource_mgr_t *mgr, resource_source_t *map, int volume_nr) {
resource_source_t *seeker = mgr->sources;
- while (seeker)
- {
+ while (seeker) {
if (seeker->source_type == RESSOURCE_TYPE_VOLUME &&
- seeker->associated_map == map &&
- seeker->location.file.volume_number == volume_nr)
+ seeker->associated_map == map &&
+ seeker->location.file.volume_number == volume_nr)
return seeker;
seeker = seeker->next;
}
@@ -234,16 +229,14 @@ scir_get_volume(resource_mgr_t *mgr, resource_source_t *map, int volume_nr)
/*------------------------------------------------*/
static void
-_scir_init_trivial(resource_mgr_t *mgr)
-{
+_scir_init_trivial(resource_mgr_t *mgr) {
mgr->resources_nr = 0;
mgr->resources = (resource_t*)sci_malloc(1);
}
static void
-_scir_load_from_patch_file(int fh, resource_t *res, char *filename)
-{
+_scir_load_from_patch_file(int fh, resource_t *res, char *filename) {
unsigned int really_read;
res->data = (unsigned char*)sci_malloc(res->size);
@@ -251,7 +244,7 @@ _scir_load_from_patch_file(int fh, resource_t *res, char *filename)
if (really_read < res->size) {
sciprintf("Error: Read %d bytes from %s but expected %d!\n",
- really_read, filename, res->size);
+ really_read, filename, res->size);
exit(1);
}
@@ -259,8 +252,7 @@ _scir_load_from_patch_file(int fh, resource_t *res, char *filename)
}
static void
-_scir_load_resource(resource_mgr_t *mgr, resource_t *res, int protect)
-{
+_scir_load_resource(resource_mgr_t *mgr, resource_t *res, int protect) {
char filename[MAXPATHLEN];
int fh;
resource_t backup;
@@ -273,7 +265,7 @@ _scir_load_resource(resource_mgr_t *mgr, resource_t *res, int protect)
if (!patch_sprintfers[mgr->sci_version]) {
sciprintf("Resource manager's SCI version (%d) has no patch file name printers -> internal error!\n",
- mgr->sci_version);
+ mgr->sci_version);
exit(1);
}
@@ -292,7 +284,7 @@ _scir_load_resource(resource_mgr_t *mgr, resource_t *res, int protect)
*raiser = toupper(*raiser); /* Uppercasify */
++raiser;
}
- fh = sci_open(filename, O_RDONLY|O_BINARY);
+ fh = sci_open(filename, O_RDONLY | O_BINARY);
} /* Try case-insensitively name */
if (!IS_VALID_FD(fh)) {
@@ -309,22 +301,22 @@ _scir_load_resource(resource_mgr_t *mgr, resource_t *res, int protect)
lseek(fh, res->file_offset, SEEK_SET);
if (res->source->source_type == RESSOURCE_TYPE_DIRECTORY ||
- res->source->source_type == RESSOURCE_TYPE_AUDIO_DIRECTORY)
+ res->source->source_type == RESSOURCE_TYPE_AUDIO_DIRECTORY)
_scir_load_from_patch_file(fh, res, filename);
else if (!decompressors[mgr->sci_version]) {
/* Check whether we support this at all */
sciprintf("Resource manager's SCI version (%d) is invalid!\n",
- mgr->sci_version);
+ mgr->sci_version);
exit(1);
} else {
int error = /* Decompress from regular resource file */
- decompressors[mgr->sci_version](res, fh, mgr->sci_version);
+ decompressors[mgr->sci_version](res, fh, mgr->sci_version);
if (error) {
sciprintf("Error %d occured while reading %s.%03d"
- " from resource file: %s\n",
- error, sci_resource_types[res->type], res->number,
- sci_error_types[error]);
+ " from resource file: %s\n",
+ error, sci_resource_types[res->type], res->number,
+ sci_error_types[error]);
if (protect)
memcpy(res, &backup, sizeof(resource_t));
@@ -342,21 +334,19 @@ _scir_load_resource(resource_mgr_t *mgr, resource_t *res, int protect)
}
resource_t *
-scir_test_resource(resource_mgr_t *mgr, int type, int number)
-{
+scir_test_resource(resource_mgr_t *mgr, int type, int number) {
resource_t binseeker;
binseeker.type = type;
binseeker.number = number;
return (resource_t *)
- bsearch(&binseeker, mgr->resources, mgr->resources_nr,
- sizeof(resource_t), resourcecmp);
+ bsearch(&binseeker, mgr->resources, mgr->resources_nr,
+ sizeof(resource_t), resourcecmp);
}
int sci0_get_compression_method(int resh);
int
-sci_test_view_type(resource_mgr_t *mgr)
-{
+sci_test_view_type(resource_mgr_t *mgr) {
int fh;
char filename[MAXPATHLEN];
int compression;
@@ -365,14 +355,13 @@ sci_test_view_type(resource_mgr_t *mgr)
mgr->sci_version = SCI_VERSION_AUTODETECT;
- for (i=0;i<1000;i++)
- {
+ for (i = 0;i < 1000;i++) {
res = scir_test_resource(mgr, sci_view, i);
if (!res) continue;
if (res->source->source_type == RESSOURCE_TYPE_DIRECTORY ||
- res->source->source_type == RESSOURCE_TYPE_AUDIO_DIRECTORY)
+ res->source->source_type == RESSOURCE_TYPE_AUDIO_DIRECTORY)
continue;
strcpy(filename, res->source->location.file.name);
@@ -384,9 +373,9 @@ sci_test_view_type(resource_mgr_t *mgr)
*raiser = toupper(*raiser); /* Uppercasify */
++raiser;
}
- fh = sci_open(filename, O_RDONLY|O_BINARY);
+ fh = sci_open(filename, O_RDONLY | O_BINARY);
} /* Try case-insensitively name */
-
+
if (!IS_VALID_FD(fh)) continue;
lseek(fh, res->file_offset, SEEK_SET);
@@ -398,14 +387,13 @@ sci_test_view_type(resource_mgr_t *mgr)
}
/* Try the same thing with pics */
- for (i=0;i<1000;i++)
- {
+ for (i = 0;i < 1000;i++) {
res = scir_test_resource(mgr, sci_pic, i);
if (!res) continue;
if (res->source->source_type == RESSOURCE_TYPE_DIRECTORY ||
- res->source->source_type == RESSOURCE_TYPE_AUDIO_DIRECTORY)
+ res->source->source_type == RESSOURCE_TYPE_AUDIO_DIRECTORY)
continue;
strcpy(filename, res->source->location.file.name);
@@ -418,9 +406,9 @@ sci_test_view_type(resource_mgr_t *mgr)
*raiser = toupper(*raiser); /* Uppercasify */
++raiser;
}
- fh = sci_open(filename, O_RDONLY|O_BINARY);
+ fh = sci_open(filename, O_RDONLY | O_BINARY);
} /* Try case-insensitively name */
-
+
if (!IS_VALID_FD(fh)) continue;
lseek(fh, res->file_offset, SEEK_SET);
@@ -433,14 +421,13 @@ sci_test_view_type(resource_mgr_t *mgr)
return mgr->sci_version;
}
-
-
+
+
int
scir_add_appropriate_sources(resource_mgr_t *mgr,
- int allow_patches,
- char *dir)
-{
+ int allow_patches,
+ char *dir) {
const char *trailing_slash = "";
//char path_separator;
sci_dir_t dirent;
@@ -449,14 +436,13 @@ scir_add_appropriate_sources(resource_mgr_t *mgr,
int fd;
char fullname[MAXPATHLEN];
- if (dir[strlen(dir)-1] != G_DIR_SEPARATOR)
- {
+ if (dir[strlen(dir)-1] != G_DIR_SEPARATOR) {
trailing_slash = G_DIR_SEPARATOR_S;
}
name = (char *)malloc(strlen(dir) + 1 +
- strlen("RESOURCE.MAP") + 1);
-
+ strlen("RESOURCE.MAP") + 1);
+
sprintf(fullname, "%s%s%s", dir, trailing_slash, "RESOURCE.MAP");
fd = sci_open("RESOURCE.MAP", O_RDONLY | O_BINARY);
if (!IS_VALID_FD(fd)) return 0;
@@ -465,8 +451,7 @@ scir_add_appropriate_sources(resource_mgr_t *mgr,
free(name);
sci_init_dir(&dirent);
name = sci_find_first(&dirent, "RESOURCE.0??");
- while (name != NULL)
- {
+ while (name != NULL) {
char *dot = strrchr(name, '.');
int number = atoi(dot + 1);
@@ -484,8 +469,7 @@ scir_add_appropriate_sources(resource_mgr_t *mgr,
}
static int
-_scir_scan_new_sources(resource_mgr_t *mgr, int *detected_version, resource_source_t *source)
-{
+_scir_scan_new_sources(resource_mgr_t *mgr, int *detected_version, resource_source_t *source) {
int preset_version = mgr->sci_version;
int resource_error = 0;
int dummy = mgr->sci_version;
@@ -498,35 +482,33 @@ _scir_scan_new_sources(resource_mgr_t *mgr, int *detected_version, resource_sour
if (source->next)
_scir_scan_new_sources(mgr, detected_version, source->next);
- if (!source->scanned)
- {
+ if (!source->scanned) {
source->scanned = 1;
- switch (source->source_type)
- {
+ switch (source->source_type) {
case RESSOURCE_TYPE_DIRECTORY:
if (mgr->sci_version <= SCI_VERSION_01)
sci0_read_resource_patches(source,
- &mgr->resources,
- &mgr->resources_nr);
+ &mgr->resources,
+ &mgr->resources_nr);
else
sci1_read_resource_patches(source,
- &mgr->resources,
- &mgr->resources_nr);
+ &mgr->resources,
+ &mgr->resources_nr);
break;
case RESSOURCE_TYPE_EXTERNAL_MAP:
if (preset_version <= SCI_VERSION_01_VGA_ODD
- /* || preset_version == SCI_VERSION_AUTODETECT -- subsumed by the above line */) {
+ /* || preset_version == SCI_VERSION_AUTODETECT -- subsumed by the above line */) {
resource_error =
- sci0_read_resource_map(mgr,
- source,
- &mgr->resources,
- &mgr->resources_nr,
- detected_version);
-
+ sci0_read_resource_map(mgr,
+ source,
+ &mgr->resources,
+ &mgr->resources_nr,
+ detected_version);
+
#if 0
if (resource_error >= SCI_ERROR_CRITICAL) {
sciprintf("Resmgr: Error while loading resource map: %s\n",
- sci_error_types[resource_error]);
+ sci_error_types[resource_error]);
if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND)
sciprintf("Running SCI games without a resource map is not supported ATM\n");
sci_free(mgr);
@@ -546,34 +528,33 @@ _scir_scan_new_sources(resource_mgr_t *mgr, int *detected_version, resource_sour
}
#endif
}
-
- if ((preset_version == SCI_VERSION_1_EARLY)||
- (preset_version == SCI_VERSION_1_LATE)||
- (preset_version == SCI_VERSION_1_1)||
- ((*detected_version == SCI_VERSION_AUTODETECT)&&(preset_version == SCI_VERSION_AUTODETECT)))
- {
+
+ if ((preset_version == SCI_VERSION_1_EARLY) ||
+ (preset_version == SCI_VERSION_1_LATE) ||
+ (preset_version == SCI_VERSION_1_1) ||
+ ((*detected_version == SCI_VERSION_AUTODETECT) && (preset_version == SCI_VERSION_AUTODETECT))) {
resource_error =
- sci1_read_resource_map(mgr,
- source,
- scir_get_volume(mgr, source, 0),
- &mgr->resources,
- &mgr->resources_nr,
- detected_version);
-
+ sci1_read_resource_map(mgr,
+ source,
+ scir_get_volume(mgr, source, 0),
+ &mgr->resources,
+ &mgr->resources_nr,
+ detected_version);
+
if (resource_error == SCI_ERROR_RESMAP_NOT_FOUND) {
/* fixme: Try reading w/o resource.map */
resource_error = SCI_ERROR_NO_RESOURCE_FILES_FOUND;
}
-
+
if (resource_error == SCI_ERROR_NO_RESOURCE_FILES_FOUND) {
/* Initialize empty resource manager */
_scir_init_trivial(mgr);
resource_error = 0;
}
-
+
*detected_version = SCI_VERSION_1;
}
-
+
mgr->sci_version = *detected_version;
break;
}
@@ -584,15 +565,13 @@ _scir_scan_new_sources(resource_mgr_t *mgr, int *detected_version, resource_sour
}
int
-scir_scan_new_sources(resource_mgr_t *mgr, int *detected_version)
-{
+scir_scan_new_sources(resource_mgr_t *mgr, int *detected_version) {
_scir_scan_new_sources(mgr, detected_version, mgr->sources);
return 0;
}
static void
-_scir_free_resource_sources(resource_source_t *rss)
-{
+_scir_free_resource_sources(resource_source_t *rss) {
if (rss) {
_scir_free_resource_sources(rss->next);
free(rss);
@@ -601,8 +580,7 @@ _scir_free_resource_sources(resource_source_t *rss)
resource_mgr_t *
scir_new_resource_manager(char *dir, int version,
- char allow_patches, int max_memory)
-{
+ char allow_patches, int max_memory) {
int resource_error = 0;
resource_mgr_t *mgr = (resource_mgr_t*)sci_malloc(sizeof(resource_mgr_t));
char *caller_cwd = sci_getcwd();
@@ -654,20 +632,18 @@ scir_new_resource_manager(char *dir, int version,
switch (resmap_version) {
case SCI_VERSION_0:
if (scir_test_resource(mgr, sci_vocab,
- VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) {
+ VOCAB_RESOURCE_SCI0_MAIN_VOCAB)) {
version = sci_test_view_type(mgr);
- if (version == SCI_VERSION_01_VGA)
- {
+ if (version == SCI_VERSION_01_VGA) {
sciprintf("Resmgr: Detected KQ5 or similar\n");
} else {
sciprintf("Resmgr: Detected SCI0\n");
version = SCI_VERSION_0;
}
} else if (scir_test_resource(mgr, sci_vocab,
- VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) {
+ VOCAB_RESOURCE_SCI1_MAIN_VOCAB)) {
version = sci_test_view_type(mgr);
- if (version == SCI_VERSION_01_VGA)
- {
+ if (version == SCI_VERSION_01_VGA) {
sciprintf("Resmgr: Detected KQ5 or similar\n");
} else {
if (scir_test_resource(mgr, sci_vocab, 912)) {
@@ -680,47 +656,45 @@ scir_new_resource_manager(char *dir, int version,
}
} else {
version = sci_test_view_type(mgr);
- if (version == SCI_VERSION_01_VGA)
- {
+ if (version == SCI_VERSION_01_VGA) {
sciprintf("Resmgr: Detected KQ5 or similar\n");
} else {
sciprintf("Resmgr: Warning: Could not find vocabulary; assuming SCI0 w/o parser\n");
version = SCI_VERSION_0;
}
- } break;
+ }
+ break;
case SCI_VERSION_01_VGA_ODD:
version = resmap_version;
sciprintf("Resmgr: Detected Jones/CD or similar\n");
break;
- case SCI_VERSION_1:
- {
+ case SCI_VERSION_1: {
resource_t *res = scir_test_resource(mgr, sci_script, 0);
-
+
mgr->sci_version = version = SCI_VERSION_1_EARLY;
_scir_load_resource(mgr, res, 1);
-
+
if (res->status == SCI_STATUS_NOMALLOC)
- mgr->sci_version = version = SCI_VERSION_1_LATE;
+ mgr->sci_version = version = SCI_VERSION_1_LATE;
/* No need to handle SCI 1.1 here - it was done in resource_map.c */
break;
}
default:
sciprintf("Resmgr: Warning: While autodetecting: Couldn't"
- " determine SCI version!\n");
+ " determine SCI version!\n");
}
- if (!resource_error)
- {
+ if (!resource_error) {
#if 0
if (version <= SCI_VERSION_01)
sci0_read_resource_patches(dir,
- &mgr->resources,
- &mgr->resources_nr);
+ &mgr->resources,
+ &mgr->resources_nr);
else
sci1_read_resource_patches(dir,
- &mgr->resources,
- &mgr->resources_nr);
+ &mgr->resources,
+ &mgr->resources_nr);
#endif
qsort(mgr->resources, mgr->resources_nr, sizeof(resource_t),
@@ -736,8 +710,7 @@ scir_new_resource_manager(char *dir, int version,
}
static void
-_scir_free_altsources(resource_altsource_t *dynressrc)
-{
+_scir_free_altsources(resource_altsource_t *dynressrc) {
if (dynressrc) {
_scir_free_altsources(dynressrc->next);
free(dynressrc);
@@ -745,8 +718,7 @@ _scir_free_altsources(resource_altsource_t *dynressrc)
}
void
-_scir_free_resources(resource_t *resources, int resources_nr)
-{
+_scir_free_resources(resource_t *resources, int resources_nr) {
int i;
for (i = 0; i < resources_nr; i++) {
@@ -762,8 +734,7 @@ _scir_free_resources(resource_t *resources, int resources_nr)
}
void
-scir_free_resource_manager(resource_mgr_t *mgr)
-{
+scir_free_resource_manager(resource_mgr_t *mgr) {
_scir_free_resources(mgr->resources, mgr->resources_nr);
_scir_free_resource_sources(mgr->sources);
mgr->resources = NULL;
@@ -773,8 +744,7 @@ scir_free_resource_manager(resource_mgr_t *mgr)
static void
-_scir_unalloc(resource_t *res)
-{
+_scir_unalloc(resource_t *res) {
sci_free(res->data);
res->data = NULL;
res->status = SCI_STATUS_NOMALLOC;
@@ -782,11 +752,10 @@ _scir_unalloc(resource_t *res)
static void
-_scir_remove_from_lru(resource_mgr_t *mgr, resource_t *res)
-{
+_scir_remove_from_lru(resource_mgr_t *mgr, resource_t *res) {
if (res->status != SCI_STATUS_ENQUEUED) {
sciprintf("Resmgr: Oops: trying to remove resource that isn't"
- " enqueued\n");
+ " enqueued\n");
return;
}
@@ -805,11 +774,10 @@ _scir_remove_from_lru(resource_mgr_t *mgr, resource_t *res)
}
static void
-_scir_add_to_lru(resource_mgr_t *mgr, resource_t *res)
-{
+_scir_add_to_lru(resource_mgr_t *mgr, resource_t *res) {
if (res->status != SCI_STATUS_ALLOCATED) {
sciprintf("Resmgr: Oops: trying to enqueue resource with state"
- " %d\n", res->status);
+ " %d\n", res->status);
return;
}
@@ -824,8 +792,8 @@ _scir_add_to_lru(resource_mgr_t *mgr, resource_t *res)
mgr->memory_lru += res->size;
#if (SCI_VERBOSE_RESMGR > 1)
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);
+ sci_resource_types[res->type], res->number, res->size,
+ mgr->memory_lru);
#endif
@@ -833,35 +801,33 @@ _scir_add_to_lru(resource_mgr_t *mgr, resource_t *res)
}
static void
-_scir_print_lru_list(resource_mgr_t *mgr)
-{
+_scir_print_lru_list(resource_mgr_t *mgr) {
int mem = 0;
int entries = 0;
resource_t *res = mgr->lru_first;
while (res) {
- fprintf(stderr,"\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;
}
- fprintf(stderr,"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(resource_mgr_t *mgr, int last_invulnerable)
-{
+_scir_free_old_resources(resource_mgr_t *mgr, int last_invulnerable) {
while (mgr->max_memory < mgr->memory_lru
- && (!last_invulnerable || mgr->lru_first != mgr->lru_last)) {
+ && (!last_invulnerable || mgr->lru_first != mgr->lru_last)) {
resource_t *goner = mgr->lru_last;
if (!goner) {
- 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);
+ 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);
}
@@ -869,22 +835,21 @@ _scir_free_old_resources(resource_mgr_t *mgr, int last_invulnerable)
_scir_unalloc(goner);
#ifdef SCI_VERBOSE_RESMGR
sciprintf("Resmgr-debug: LRU: Freeing %s.%03d (%d bytes)\n",
- sci_resource_types[goner->type], goner->number,
- goner->size);
+ sci_resource_types[goner->type], goner->number,
+ goner->size);
#endif
}
}
resource_t *
-scir_find_resource(resource_mgr_t *mgr, int type, int number, int lock)
-{
+scir_find_resource(resource_mgr_t *mgr, int type, int number, int lock) {
resource_t *retval;
if (number >= sci_max_resource_nr[mgr->sci_version]) {
int modded_number = number % sci_max_resource_nr[mgr->sci_version];
sciprintf("[resmgr] Requested invalid resource %s.%d, mapped to %s.%d\n",
- sci_resource_types[type], number,
- sci_resource_types[type], modded_number);
+ sci_resource_types[type], number,
+ sci_resource_types[type], modded_number);
number = modded_number;
}
@@ -921,25 +886,24 @@ scir_find_resource(resource_mgr_t *mgr, int type, int number, int lock)
return retval;
else {
sciprintf("Resmgr: Failed to read %s.%03d\n",
- sci_resource_types[retval->type], retval->number);
+ sci_resource_types[retval->type], retval->number);
return NULL;
}
}
void
-scir_unlock_resource(resource_mgr_t *mgr, resource_t *res, int resnum, int restype)
-{
+scir_unlock_resource(resource_mgr_t *mgr, resource_t *res, int resnum, int restype) {
if (!res) {
sciprintf("Resmgr: Warning: Attempt to unlock non-existant"
- " resource %s.%03d!\n",
- sci_resource_types[restype], resnum);
+ " resource %s.%03d!\n",
+ sci_resource_types[restype], resnum);
return;
}
if (res->status != SCI_STATUS_LOCKED) {
sciprintf("Resmgr: Warning: Attempt to unlock unlocked"
- " resource %s.%03d\n",
- sci_resource_types[res->type], res->number);
+ " resource %s.%03d\n",
+ sci_resource_types[res->type], res->number);
return;
}
diff --git a/engines/sci/scicore/resource_map.cpp b/engines/sci/scicore/resource_map.cpp
index 48ea54cb3a..984efa83ac 100644
--- a/engines/sci/scicore/resource_map.cpp
+++ b/engines/sci/scicore/resource_map.cpp
@@ -39,48 +39,44 @@
#define SCI11_RESMAP_ENTRIES_SIZE 5
static int
-detect_odd_sci01(int fh)
-{
- byte buf[6];
- int files_ok = 1;
- int fsize, resources_nr, tempfh, read_ok;
- char filename[14];
-
- fsize = sci_fd_size(fh);
- if (fsize < 0) {
- perror("Error occured while trying to get filesize of resource.map");
- return SCI_ERROR_RESMAP_NOT_FOUND;
- }
-
- resources_nr = fsize / SCI0_RESMAP_ENTRIES_SIZE;
-
- while (resources_nr-->1)
- {
- read_ok = read(fh, &buf, SCI0_RESMAP_ENTRIES_SIZE);
-
- if (read_ok)
- {
- sprintf(filename, "resource.%03i", SCI0_RESFILE_GET_FILE(buf+2));
- tempfh = sci_open(filename, O_RDONLY | O_BINARY);
-
- if (tempfh == SCI_INVALID_FD) {
- files_ok = 0;
- break;
- }
+detect_odd_sci01(int fh) {
+ byte buf[6];
+ int files_ok = 1;
+ int fsize, resources_nr, tempfh, read_ok;
+ char filename[14];
+
+ fsize = sci_fd_size(fh);
+ if (fsize < 0) {
+ perror("Error occured while trying to get filesize of resource.map");
+ return SCI_ERROR_RESMAP_NOT_FOUND;
+ }
+
+ resources_nr = fsize / SCI0_RESMAP_ENTRIES_SIZE;
- close(tempfh);
+ while (resources_nr-- > 1) {
+ read_ok = read(fh, &buf, SCI0_RESMAP_ENTRIES_SIZE);
+
+ if (read_ok) {
+ sprintf(filename, "resource.%03i", SCI0_RESFILE_GET_FILE(buf + 2));
+ tempfh = sci_open(filename, O_RDONLY | O_BINARY);
+
+ if (tempfh == SCI_INVALID_FD) {
+ files_ok = 0;
+ break;
+ }
+
+ close(tempfh);
+ }
}
- }
- lseek(fh, 0, SEEK_SET);
+ lseek(fh, 0, SEEK_SET);
- return files_ok;
+ return files_ok;
}
-
+
static int
-sci_res_read_entry(resource_mgr_t *mgr, resource_source_t *map,
- byte *buf, resource_t *res, int sci_version)
-{
+sci_res_read_entry(resource_mgr_t *mgr, resource_source_t *map,
+ byte *buf, resource_t *res, int sci_version) {
res->id = buf[0] | (buf[1] << 8);
res->type = SCI0_RESID_GET_TYPE(buf);
res->number = SCI0_RESID_GET_NUMBER(buf);
@@ -106,62 +102,56 @@ sci_res_read_entry(resource_mgr_t *mgr, resource_source_t *map,
#if 0
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);
+ res->id, res->number,
+ sci_resource_type_suffixes[res->type],
+ res->file, res->file_offset);
#endif
if (res->source == NULL) return 1;
return 0;
}
-inline int sci1_res_type(int ofs, int *types, int lastrt)
-{
+inline int sci1_res_type(int ofs, int *types, int lastrt) {
int i, last = -1;
- for (i=0;i<=sci1_last_resource;i++)
- if (types[i])
- {
- if (types[i]>ofs)
+ for (i = 0;i <= sci1_last_resource;i++)
+ if (types[i]) {
+ if (types[i] > ofs)
return last;
- last=i;
+ last = i;
}
return lastrt;
}
-int sci1_parse_header(int fd, int *types, int *lastrt)
-{
+int sci1_parse_header(int fd, int *types, int *lastrt) {
unsigned char rtype;
unsigned char offset[2];
int read_ok;
int size = 0;
- do
- {
+ do {
read_ok = read(fd, &rtype, 1);
if (!read_ok) break;
read_ok = read(fd, &offset, 2);
- if (read_ok<2)
- read_ok=0;
- if (rtype!=0xff)
- {
- types[rtype&0x7f]=(offset[1]<<8)|(offset[0]);
- *lastrt = rtype&0x7f;
+ if (read_ok < 2)
+ read_ok = 0;
+ if (rtype != 0xff) {
+ types[rtype&0x7f] = (offset[1] << 8) | (offset[0]);
+ *lastrt = rtype & 0x7f;
}
- size+=3;
+ size += 3;
} while (read_ok && (rtype != 0xFF));
if (!read_ok) return 0;
-
+
return size;
}
int
-sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t **resource_p, int *resource_nr_p, int *sci_version)
-{
+sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t **resource_p, int *resource_nr_p, int *sci_version) {
int fsize;
int fd;
resource_t *resources;
@@ -170,7 +160,7 @@ sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t *
int resources_total_read = 0;
int next_entry;
int max_resfile_nr = 0;
-
+
byte buf[SCI0_RESMAP_ENTRIES_SIZE];
fd = sci_open(map->location.file.name, O_RDONLY | O_BINARY);
@@ -181,44 +171,42 @@ sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t *
/* Theory: An SCI1 map file begins with an index that allows us to seek quickly
to a particular resource type. The entries are three bytes long; one byte
- resource type, two bytes start position and so on.
+ resource type, two bytes start position and so on.
The below code therefore tests for three things:
-
+
Is the first resource type 'view'?
Do those entries start at an offset that is an exact multiple of the
index entry size?
Is the second resource type 'pic'?
-
- This requires that a given game has both views and pics,
+
+ This requires that a given game has both views and pics,
a safe assumption usually, except in message.map and room-specific
(audio) map files, neither of which SCI0 has.
-
+
*/
-
+
if ((buf[0] == 0x80) &&
- (buf[1] % 3 == 0) &&
- (buf[3] == 0x81))
- {
+ (buf[1] % 3 == 0) &&
+ (buf[3] == 0x81)) {
close(fd);
return SCI_ERROR_INVALID_RESMAP_ENTRY;
}
lseek(fd, 0, SEEK_SET);
- switch (detect_odd_sci01(fd))
- {
- case 0 : /* Odd SCI01 */
+ switch (detect_odd_sci01(fd)) {
+ case 0 : /* Odd SCI01 */
if (*sci_version == SCI_VERSION_AUTODETECT)
- *sci_version = SCI_VERSION_01_VGA_ODD;
+ *sci_version = SCI_VERSION_01_VGA_ODD;
break;
- case 1 : /* SCI0 or normal SCI01 */
+ case 1 : /* SCI0 or normal SCI01 */
if (*sci_version == SCI_VERSION_AUTODETECT)
- *sci_version = SCI_VERSION_0;
+ *sci_version = SCI_VERSION_0;
break;
- default : /* Neither, or error occurred */
+ default : /* Neither, or error occurred */
return SCI_ERROR_RESMAP_NOT_FOUND;
}
-
+
if ((fsize = sci_fd_size(fd)) < 0) {
perror("Error occured while trying to get filesize of resource.map");
return SCI_ERROR_RESMAP_NOT_FOUND;
@@ -233,7 +221,7 @@ sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t *
int read_ok = read(fd, &buf, SCI0_RESMAP_ENTRIES_SIZE);
next_entry = 1;
- if (read_ok < 0 ) {
+ if (read_ok < 0) {
sciprintf("Error while reading %s: ", map->location.file.name);
perror("");
next_entry = 0;
@@ -255,21 +243,21 @@ sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t *
for (i = 0; i < resource_index; i++)
if (resources[resource_index].id ==
- resources[i].id) {
+ resources[i].id) {
addto = i;
fresh = 0;
}
_scir_add_altsource(resources + addto,
- resources[resource_index].source,
- resources[resource_index].file_offset);
+ resources[resource_index].source,
+ resources[resource_index].file_offset);
if (fresh)
++resource_index;
if (++resources_total_read >= resources_nr) {
sciprintf("Warning: After %d entries, resource.map"
- " is not terminated!\n", resource_index);
+ " is not terminated!\n", resource_index);
next_entry = 0;
}
@@ -290,7 +278,7 @@ sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t *
return SCI_ERROR_INVALID_RESMAP_ENTRY;
} else {
#if 0
-/* Check disabled, Mac SQ3 thinks it has resource.004 but doesn't need it -- CR */
+ /* Check disabled, Mac SQ3 thinks it has resource.004 but doesn't need it -- CR */
/* Check whether the highest resfile used exists */
char filename_buf[14];
sprintf(filename_buf, "resource.%03d", max_resfile_nr);
@@ -316,29 +304,26 @@ sci0_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_t *
#define TEST fprintf(stderr, "OK in line %d\n", __LINE__);
-static int sci10_or_11(int *types)
-{
+static int sci10_or_11(int *types) {
int this_restype = 0;
int next_restype = 1;
- while (next_restype <= sci_heap)
- {
+ while (next_restype <= sci_heap) {
int could_be_10 = 0;
int could_be_11 = 0;
- while (types[this_restype] == 0)
- {
+ while (types[this_restype] == 0) {
this_restype++;
next_restype++;
}
- while (types[next_restype] == 0)
+ while (types[next_restype] == 0)
next_restype++;
could_be_10 = ((types[next_restype] - types[this_restype])
- % SCI1_RESMAP_ENTRIES_SIZE) == 0;
+ % SCI1_RESMAP_ENTRIES_SIZE) == 0;
could_be_11 = ((types[next_restype] - types[this_restype])
- % SCI11_RESMAP_ENTRIES_SIZE) == 0;
+ % SCI11_RESMAP_ENTRIES_SIZE) == 0;
if (could_be_10 && !could_be_11) return SCI_VERSION_1;
if (could_be_11 && !could_be_10) return SCI_VERSION_1_1;
@@ -352,15 +337,14 @@ static int sci10_or_11(int *types)
int
sci1_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_source_t *vol,
- resource_t **resource_p, int *resource_nr_p, int *sci_version)
-{
+ resource_t **resource_p, int *resource_nr_p, int *sci_version) {
int fsize;
int fd;
resource_t *resources, *resource_start;
int resources_nr;
int resource_index = 0;
int ofs, header_size;
- int *types = (int*)sci_malloc(sizeof(int) * (sci1_last_resource+1));
+ int *types = (int*)sci_malloc(sizeof(int) * (sci1_last_resource + 1));
int i;
byte buf[SCI1_RESMAP_ENTRIES_SIZE];
int lastrt;
@@ -374,8 +358,7 @@ sci1_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_sou
memset(types, 0, sizeof(int) * (sci1_last_resource + 1));
- if (!(sci1_parse_header(fd, types, &lastrt)))
- {
+ if (!(sci1_parse_header(fd, types, &lastrt))) {
close(fd);
return SCI_ERROR_INVALID_RESMAP_ENTRY;
}
@@ -384,17 +367,16 @@ sci1_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_sou
if (*sci_version == SCI_VERSION_AUTODETECT)
*sci_version = entry_size_selector;
- if (*sci_version == SCI_VERSION_AUTODETECT) /* That didn't help */
- {
+ if (*sci_version == SCI_VERSION_AUTODETECT) { /* That didn't help */
sciprintf("Unable to detect resource map version\n");
close(fd);
return SCI_ERROR_NO_RESOURCE_FILES_FOUND;
}
- entrysize = entry_size_selector == SCI_VERSION_1_1
- ? SCI11_RESMAP_ENTRIES_SIZE
- : SCI1_RESMAP_ENTRIES_SIZE;
-
+ entrysize = entry_size_selector == SCI_VERSION_1_1
+ ? SCI11_RESMAP_ENTRIES_SIZE
+ : SCI1_RESMAP_ENTRIES_SIZE;
+
if ((fsize = sci_fd_size(fd)) < 0) {
perror("Error occured while trying to get filesize of resource.map");
close(fd);
@@ -402,7 +384,7 @@ sci1_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_sou
}
resources_nr = (fsize - types[0]) / entrysize;
- resource_start = resources = (resource_t*)sci_realloc(mgr->resources, (mgr->resources_nr + resources_nr)*sizeof(resource_t));
+ resource_start = resources = (resource_t*)sci_realloc(mgr->resources, (mgr->resources_nr + resources_nr) * sizeof(resource_t));
resources += mgr->resources_nr;
i = 0;
@@ -411,19 +393,16 @@ sci1_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_sou
lseek(fd, ofs, SEEK_SET);
- for (i=0; i<resources_nr; i++)
- {
- int read_ok = read(fd, &buf, entrysize);
+ for (i = 0; i < resources_nr; i++) {
+ int read_ok = read(fd, &buf, entrysize);
int j;
resource_t *res;
int addto = resource_index;
int fresh = 1;
- if (read_ok < entrysize)
- {
+ if (read_ok < entrysize) {
#if 0
- if (!eof(fd))
- {
+ if (!eof(fd)) {
sciprintf("Error while reading %s: ", map->location.file.name);
perror("");
} else read_ok = 1;
@@ -433,39 +412,37 @@ sci1_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_sou
res = &(resources[resource_index]);
res->type = sci1_res_type(ofs, types, lastrt);
- res->number= SCI1_RESFILE_GET_NUMBER(buf);
+ res->number = SCI1_RESFILE_GET_NUMBER(buf);
res->status = SCI_STATUS_NOMALLOC;
- if (entry_size_selector < SCI_VERSION_1_1)
- {
+ if (entry_size_selector < SCI_VERSION_1_1) {
res->source = scir_get_volume(mgr, map, SCI1_RESFILE_GET_FILE(buf));
res->file_offset = SCI1_RESFILE_GET_OFFSET(buf);
- } else
- {
- res->source = vol;
+ } else {
+ res->source = vol;
res->file_offset = SCI11_RESFILE_GET_OFFSET(buf);
};
-
+
res->id = res->number | (res->type << 16);
for (j = 0; i < resource_index; i++)
if (resources[resource_index].id ==
- resources[i].id) {
+ resources[i].id) {
addto = i;
fresh = 0;
}
#if 0
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);
+ res->id, res->number,
+ sci_resource_type_suffixes[res->type],
+ res->file, res->file_offset, addto);
#endif
_scir_add_altsource(resources + addto,
- resources[resource_index].source,
- resources[resource_index].file_offset);
-
+ resources[resource_index].source,
+ resources[resource_index].file_offset);
+
if (fresh)
++resource_index;
@@ -478,19 +455,18 @@ sci1_read_resource_map(resource_mgr_t *mgr, resource_source_t *map, resource_sou
*resource_p = resource_start;
*resource_nr_p += resource_index;
return 0;
-
+
}
#ifdef TEST_RESOURCE_MAP
int
-main(int argc, char **argv)
-{
+main(int argc, char **argv) {
int resources_nr;
resource_t *resources;
int notok = sci0_read_resource_map(".", &resources, &resources_nr);
if (notok) {
- fprintf(stderr,"Failed: Error code %d\n",notok);
+ fprintf(stderr, "Failed: Error code %d\n", notok);
return 1;
}
diff --git a/engines/sci/scicore/resource_patch.cpp b/engines/sci/scicore/resource_patch.cpp
index 6702bd5d0d..a663735443 100644
--- a/engines/sci/scicore/resource_patch.cpp
+++ b/engines/sci/scicore/resource_patch.cpp
@@ -34,22 +34,19 @@
#endif
void
-sci0_sprintf_patch_file_name(char *string, resource_t *res)
-{
+sci0_sprintf_patch_file_name(char *string, resource_t *res) {
sprintf(string, "%s.%03i", sci_resource_types[res->type], res->number);
}
void
-sci1_sprintf_patch_file_name(char *string, resource_t *res)
-{
+sci1_sprintf_patch_file_name(char *string, resource_t *res) {
sprintf(string, "%d.%s", res->number, sci_resource_type_suffixes[res->type]);
}
/* version-agnostic patch application */
static void
process_patch(resource_source_t *source,
- char *entry, int restype, int resnumber, resource_t **resource_p, int *resource_nr_p)
-{
+ char *entry, int restype, int resnumber, resource_t **resource_p, int *resource_nr_p) {
int fsize;
char filename[MAXPATHLEN];
@@ -66,9 +63,9 @@ process_patch(resource_source_t *source,
int file;
guint8 filehdr[2];
resource_t *newrsc = _scir_find_resource_unsorted(*resource_p,
- *resource_nr_p,
- restype,
- resnumber);
+ *resource_nr_p,
+ restype,
+ resnumber);
if (fsize < 3) {
printf("File too small\n");
@@ -100,9 +97,9 @@ process_patch(resource_source_t *source,
/* Completely new resource! */
++(*resource_nr_p);
*resource_p = (resource_t*)sci_realloc(*resource_p,
- *resource_nr_p
- * sizeof(resource_t));
- newrsc = (*resource_p-1) + *resource_nr_p;
+ *resource_nr_p
+ * sizeof(resource_t));
+ newrsc = (*resource_p - 1) + *resource_nr_p;
newrsc->alt_sources = NULL;
}
@@ -128,8 +125,7 @@ process_patch(resource_source_t *source,
int
-sci0_read_resource_patches(resource_source_t *source, resource_t **resource_p, int *resource_nr_p)
-{
+sci0_read_resource_patches(resource_source_t *source, resource_t **resource_p, int *resource_nr_p) {
sci_dir_t dir;
char *entry;
char *caller_cwd = sci_getcwd();
@@ -146,7 +142,7 @@ sci0_read_resource_patches(resource_source_t *source, resource_t **resource_p, i
for (i = sci_view; i < sci_invalid_resource; i++)
if (strncasecmp(sci_resource_types[i], entry,
- strlen(sci_resource_types[i])) == 0)
+ strlen(sci_resource_types[i])) == 0)
restype = i;
if (restype != sci_invalid_resource) {
@@ -156,8 +152,8 @@ sci0_read_resource_patches(resource_source_t *source, resource_t **resource_p, i
restype = sci_invalid_resource;
else {
resnumber = strtol(entry + 1 + resname_len,
- &endptr, 10); /* Get resource number */
- if ((*endptr != '\0') || (resname_len+1 == strlen(entry)))
+ &endptr, 10); /* Get resource number */
+ if ((*endptr != '\0') || (resname_len + 1 == strlen(entry)))
restype = sci_invalid_resource;
if ((resnumber < 0) || (resnumber > 1000))
@@ -165,7 +161,7 @@ sci0_read_resource_patches(resource_source_t *source, resource_t **resource_p, i
}
}
- process_patch (source, entry, restype, resnumber, resource_p, resource_nr_p);
+ process_patch(source, entry, restype, resnumber, resource_p, resource_nr_p);
entry = sci_find_next(&dir);
}
@@ -176,8 +172,7 @@ sci0_read_resource_patches(resource_source_t *source, resource_t **resource_p, i
}
int
-sci1_read_resource_patches(resource_source_t *source, resource_t **resource_p, int *resource_nr_p)
-{
+sci1_read_resource_patches(resource_source_t *source, resource_t **resource_p, int *resource_nr_p) {
sci_dir_t dir;
char *entry;
char *caller_cwd = sci_getcwd();
@@ -194,7 +189,7 @@ sci1_read_resource_patches(resource_source_t *source, resource_t **resource_p, i
for (i = sci_view; i < sci_invalid_resource; i++) {
if (dot != NULL) {
- if (strncasecmp(sci_resource_type_suffixes[i], dot+1, 3) == 0) {
+ if (strncasecmp(sci_resource_type_suffixes[i], dot + 1, 3) == 0) {
restype = i;
}
}
@@ -202,20 +197,20 @@ sci1_read_resource_patches(resource_source_t *source, resource_t **resource_p, i
if (restype != sci_invalid_resource) {
- resnumber = strtol(entry,
- &endptr, 10); /* Get resource number */
+ resnumber = strtol(entry,
+ &endptr, 10); /* Get resource number */
- if (endptr != dot)
- restype = sci_invalid_resource;
+ if (endptr != dot)
+ restype = sci_invalid_resource;
+
+ if (*(dot + 4) != '\0')
+ restype = sci_invalid_resource;
- if (*(dot + 4) != '\0')
- restype = sci_invalid_resource;
-
- if ((resnumber < 0) || (resnumber > 8192))
- restype = sci_invalid_resource;
+ if ((resnumber < 0) || (resnumber > 8192))
+ restype = sci_invalid_resource;
}
- process_patch (source, entry, restype, resnumber, resource_p, resource_nr_p);
+ process_patch(source, entry, restype, resnumber, resource_p, resource_nr_p);
entry = sci_find_next(&dir);
}
diff --git a/engines/sci/scicore/resourcecheck.cpp b/engines/sci/scicore/resourcecheck.cpp
index f4c731b01f..8af7291d34 100644
--- a/engines/sci/scicore/resourcecheck.cpp
+++ b/engines/sci/scicore/resourcecheck.cpp
@@ -31,8 +31,7 @@
/* #include "resource.h" */
-int main()
-{
- /* No checks yet... */
- return 0;
+int main() {
+ /* No checks yet... */
+ return 0;
}
diff --git a/engines/sci/scicore/sci_memory.cpp b/engines/sci/scicore/sci_memory.cpp
index 4d0395d9dd..b80d48bcbe 100644
--- a/engines/sci/scicore/sci_memory.cpp
+++ b/engines/sci/scicore/sci_memory.cpp
@@ -54,8 +54,7 @@
void *
-_SCI_MALLOC(size_t size, const char *file, int line, const char *funct)
-{
+_SCI_MALLOC(size_t size, const char *file, int line, const char *funct) {
void *res;
#ifdef MALLOC_DEBUG
INFO_MEMORY("_SCI_MALLOC()", size, file, line, funct);
@@ -71,8 +70,7 @@ _SCI_MALLOC(size_t size, const char *file, int line, const char *funct)
void *
-_SCI_CALLOC(size_t num, size_t size, const char *file, int line, const char *funct)
-{
+_SCI_CALLOC(size_t num, size_t size, const char *file, int line, const char *funct) {
void *res;
#ifdef MALLOC_DEBUG
INFO_MEMORY("_SCI_CALLOC()", size, file, line, funct);
@@ -83,8 +81,7 @@ _SCI_CALLOC(size_t num, size_t size, const char *file, int line, const char *fun
void *
-_SCI_REALLOC(void *ptr, size_t size, const char *file, int line, const char *funct)
-{
+_SCI_REALLOC(void *ptr, size_t size, const char *file, int line, const char *funct) {
void *res;
#ifdef MALLOC_DEBUG
INFO_MEMORY("_SCI_REALLOC()", size, file, line, funct);
@@ -95,15 +92,13 @@ _SCI_REALLOC(void *ptr, size_t size, const char *file, int line, const char *fun
void
-_SCI_FREE(void *ptr, const char *file, int line, const char *funct)
-{
+_SCI_FREE(void *ptr, const char *file, int line, const char *funct) {
#ifdef MALLOC_DEBUG
INFO_MEMORY("_SCI_FREE()", 0, file, line, funct);
#endif
- if (!ptr)
- {
+ if (!ptr) {
fprintf(stderr, "_SCI_FREE() [%s (%s) : %u]\n",
- file, funct, line);
+ file, funct, line);
fprintf(stderr, " attempt to free NULL pointer\n");
BREAKPOINT();
}
@@ -112,16 +107,14 @@ _SCI_FREE(void *ptr, const char *file, int line, const char *funct)
void *
-_SCI_MEMDUP(const void *ptr, size_t size, const char *file, int line, const char *funct)
-{
+_SCI_MEMDUP(const void *ptr, size_t size, const char *file, int line, const char *funct) {
void *res;
#ifdef MALLOC_DEBUG
INFO_MEMORY("_SCI_MEMDUP()", size, file, line, funct);
#endif
- if (!ptr)
- {
+ if (!ptr) {
fprintf(stderr, "_SCI_MEMDUP() [%s (%s) : %u]\n",
- file, funct, line);
+ file, funct, line);
fprintf(stderr, " attempt to memdup NULL pointer\n");
BREAKPOINT();
}
@@ -132,16 +125,14 @@ _SCI_MEMDUP(const void *ptr, size_t size, const char *file, int line, const char
char *
-_SCI_STRDUP(const char *src, const char *file, int line, const char *funct)
-{
+_SCI_STRDUP(const char *src, const char *file, int line, const char *funct) {
void *res;
#ifdef MALLOC_DEBUG
INFO_MEMORY("_SCI_STRDUP()", 0, file, line, funct);
#endif
- if (!src)
- {
+ if (!src) {
fprintf(stderr, "_SCI_STRDUP() [%s (%s) : %u]\n",
- file, funct, line);
+ file, funct, line);
fprintf(stderr, " attempt to strdup NULL pointer\n");
BREAKPOINT();
}
@@ -151,18 +142,16 @@ _SCI_STRDUP(const char *src, const char *file, int line, const char *funct)
char *
-_SCI_STRNDUP(const char *src, size_t length, const char *file, int line, const char *funct)
-{
+_SCI_STRNDUP(const char *src, size_t length, const char *file, int line, const char *funct) {
void *res;
char *strres;
size_t rlen = (int)MIN(strlen(src), length) + 1;
#ifdef MALLOC_DEBUG
INFO_MEMORY("_SCI_STRNDUP()", 0, file, line, funct);
#endif
- if (!src)
- {
+ if (!src) {
fprintf(stderr, "_SCI_STRNDUP() [%s (%s) : %u]\n",
- file, funct, line);
+ file, funct, line);
fprintf(stderr, " attempt to strndup NULL pointer\n");
BREAKPOINT();
}
@@ -180,14 +169,13 @@ _SCI_STRNDUP(const char *src, size_t length, const char *file, int line, const c
#ifdef _MSC_VER
void
-debug_win32_memory(int dbg_setting)
-{
+debug_win32_memory(int dbg_setting) {
#if defined(NDEBUG)
fprintf(stderr,
- "WARNING: Cannot debug Win32 memory in release mode.\n");
+ "WARNING: Cannot debug Win32 memory in release mode.\n");
#elif defined(SATISFY_PURIFY)
fprintf(stderr,
- "WARNING: Cannot debug Win32 memory in this mode.\n");
+ "WARNING: Cannot debug Win32 memory in this mode.\n");
#else
int tmpFlag;
@@ -196,32 +184,30 @@ debug_win32_memory(int dbg_setting)
if (dbg_setting > 0)
tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
- /* call _CrtCheckMemory at every request */
+ /* call _CrtCheckMemory at every request */
if (dbg_setting > 1)
- tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
- /* perform automatic leak checking at program exit */
+ tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
+ /* perform automatic leak checking at program exit */
if (dbg_setting > 2)
- tmpFlag |= _CRTDBG_DELAY_FREE_MEM_DF;
- /* enable debug heap allocations */
+ tmpFlag |= _CRTDBG_DELAY_FREE_MEM_DF;
+ /* enable debug heap allocations */
- if (dbg_setting > 3)
- {
+ if (dbg_setting > 3) {
PANIC((stderr, "Invalid value for debug_win32_memory!\n"));
BREAKPOINT();
}
- if (dbg_setting <= 0)
- {
+ if (dbg_setting <= 0) {
/* turn off above */
tmpFlag &= ~_CRTDBG_CHECK_ALWAYS_DF;
- tmpFlag &= ~_CRTDBG_DELAY_FREE_MEM_DF;
- tmpFlag &= ~_CRTDBG_LEAK_CHECK_DF;
+ tmpFlag &= ~_CRTDBG_DELAY_FREE_MEM_DF;
+ tmpFlag &= ~_CRTDBG_LEAK_CHECK_DF;
}
/* set new state for flag */
- _CrtSetDbgFlag( tmpFlag );
+ _CrtSetDbgFlag(tmpFlag);
#endif
}
#endif
@@ -245,11 +231,10 @@ debug_win32_memory(int dbg_setting)
extern void *
-sci_refcount_alloc(size_t length)
-{
+ sci_refcount_alloc(size_t length) {
guint32 *data = (guint32*)sci_malloc(REFCOUNT_OVERHEAD + length);
#ifdef TRACE_REFCOUNT
-fprintf(stderr, "[] REF: Real-alloc at %p\n", data);
+ fprintf(stderr, "[] REF: Real-alloc at %p\n", data);
#endif
data += 3;
@@ -257,32 +242,30 @@ fprintf(stderr, "[] REF: Real-alloc at %p\n", data);
data[-3] = REFCOUNT_MAGIC_LIVE_2;
REFCOUNT(data) = 1;
#ifdef TRACE_REFCOUNT
-fprintf(stderr, "[] 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;
}
extern void *
-sci_refcount_incref(void *data)
-{
+ sci_refcount_incref(void *data) {
if (!REFCOUNT_CHECK(data)) {
BREAKPOINT();
} else
REFCOUNT(data)++;
#ifdef TRACE_REFCOUNT
-fprintf(stderr, "[] 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)
-{
+ sci_refcount_decref(void *data) {
#ifdef TRACE_REFCOUNT
-fprintf(stderr, "[] 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();
@@ -293,18 +276,17 @@ fprintf(stderr, "[] REF: Dec'ing %p (prev ref=%d) OK=%d\n", data, REFCOUNT(data)
fdata[-3] = REFCOUNT_MAGIC_DEAD_2;
#ifdef TRACE_REFCOUNT
-fprintf(stderr, "[] REF: Freeing (%p)...\n", fdata - 3);
+ fprintf(stderr, "[] REF: Freeing (%p)...\n", fdata - 3);
#endif
sci_free(fdata - 3);
#ifdef TRACE_REFCOUNT
-fprintf(stderr, "[] REF: Done.\n");
+ fprintf(stderr, "[] REF: Done.\n");
#endif
}
}
extern void *
-sci_refcount_memdup(void *data, size_t len)
-{
+ sci_refcount_memdup(void *data, size_t len) {
void *dest = sci_refcount_alloc(len);
memcpy(dest, data, len);
return dest;
diff --git a/engines/sci/scicore/script.cpp b/engines/sci/scicore/script.cpp
index c2d0027fbe..3c2b576eb6 100644
--- a/engines/sci/scicore/script.cpp
+++ b/engines/sci/scicore/script.cpp
@@ -34,455 +34,462 @@
#define END Script_None
-opcode_format formats[128][4]={
- /*00*/
- {Script_None}, {Script_None}, {Script_None}, {Script_None},
- /*04*/
- {Script_None}, {Script_None}, {Script_None}, {Script_None},
- /*08*/
- {Script_None}, {Script_None}, {Script_None}, {Script_None},
- /*0C*/
- {Script_None}, {Script_None}, {Script_None}, {Script_None},
- /*10*/
- {Script_None}, {Script_None}, {Script_None}, {Script_None},
- /*14*/
- {Script_None}, {Script_None}, {Script_None}, {Script_SRelative, END},
- /*18*/
- {Script_SRelative, END}, {Script_SRelative, END}, {Script_SVariable, END}, {Script_None},
- /*1C*/
- {Script_SVariable, END}, {Script_None}, {Script_None}, {Script_Variable, END},
- /*20*/
- {Script_SRelative, Script_Byte, END}, {Script_Variable, Script_Byte, END}, {Script_Variable, Script_Byte, END}, {Script_Variable, Script_SVariable, Script_Byte, END},
- /*24 (24=ret)*/
- {Script_End}, {Script_Byte, END}, {Script_Invalid}, {Script_Invalid},
- /*28*/
- {Script_Variable, END}, {Script_Invalid}, {Script_Byte, END}, {Script_Variable, Script_Byte, END},
- /*2C*/
- {Script_SVariable, END}, {Script_SVariable, Script_Variable, END}, {Script_None}, {Script_Invalid},
- /*30*/
- {Script_None}, {Script_Property, END}, {Script_Property, END}, {Script_Property, END},
- /*34*/
- {Script_Property, END}, {Script_Property, END}, {Script_Property, END}, {Script_Property, END},
- /*38*/
- {Script_Property, END}, {Script_SRelative, END}, {Script_SRelative, END}, {Script_None},
- /*3C*/
- {Script_None}, {Script_None}, {Script_None}, {Script_Invalid},
- /*40-4F*/
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- /*50-5F*/
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- /*60-6F*/
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- /*70-7F*/
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
- {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END}
+opcode_format formats[128][4] = {
+ /*00*/
+ {Script_None}, {Script_None}, {Script_None}, {Script_None},
+ /*04*/
+ {Script_None}, {Script_None}, {Script_None}, {Script_None},
+ /*08*/
+ {Script_None}, {Script_None}, {Script_None}, {Script_None},
+ /*0C*/
+ {Script_None}, {Script_None}, {Script_None}, {Script_None},
+ /*10*/
+ {Script_None}, {Script_None}, {Script_None}, {Script_None},
+ /*14*/
+ {Script_None}, {Script_None}, {Script_None}, {Script_SRelative, END},
+ /*18*/
+ {Script_SRelative, END}, {Script_SRelative, END}, {Script_SVariable, END}, {Script_None},
+ /*1C*/
+ {Script_SVariable, END}, {Script_None}, {Script_None}, {Script_Variable, END},
+ /*20*/
+ {Script_SRelative, Script_Byte, END}, {Script_Variable, Script_Byte, END}, {Script_Variable, Script_Byte, END}, {Script_Variable, Script_SVariable, Script_Byte, END},
+ /*24 (24=ret)*/
+ {Script_End}, {Script_Byte, END}, {Script_Invalid}, {Script_Invalid},
+ /*28*/
+ {Script_Variable, END}, {Script_Invalid}, {Script_Byte, END}, {Script_Variable, Script_Byte, END},
+ /*2C*/
+ {Script_SVariable, END}, {Script_SVariable, Script_Variable, END}, {Script_None}, {Script_Invalid},
+ /*30*/
+ {Script_None}, {Script_Property, END}, {Script_Property, END}, {Script_Property, END},
+ /*34*/
+ {Script_Property, END}, {Script_Property, END}, {Script_Property, END}, {Script_Property, END},
+ /*38*/
+ {Script_Property, END}, {Script_SRelative, END}, {Script_SRelative, END}, {Script_None},
+ /*3C*/
+ {Script_None}, {Script_None}, {Script_None}, {Script_Invalid},
+ /*40-4F*/
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ /*50-5F*/
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ /*60-6F*/
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ /*70-7F*/
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END},
+ {Script_Global, END}, {Script_Local, END}, {Script_Temp, END}, {Script_Param, END}
};
#undef END
-void script_adjust_opcode_formats(int res_version)
-{
- switch (res_version)
- {
- case SCI_VERSION_0:
- case SCI_VERSION_01:
- break;
- case SCI_VERSION_01_VGA:
- case SCI_VERSION_01_VGA_ODD:
- case SCI_VERSION_1_EARLY:
- case SCI_VERSION_1_LATE:
- formats[op_lofsa][0]=Script_Offset;
- formats[op_lofss][0]=Script_Offset;
- break;
- default:
- sciprintf("script_adjust_opcode_formats(): Unknown script version %d\n", res_version);
+void script_adjust_opcode_formats(int res_version) {
+ switch (res_version) {
+ case SCI_VERSION_0:
+ case SCI_VERSION_01:
+ break;
+ case SCI_VERSION_01_VGA:
+ case SCI_VERSION_01_VGA_ODD:
+ case SCI_VERSION_1_EARLY:
+ case SCI_VERSION_1_LATE:
+ formats[op_lofsa][0] = Script_Offset;
+ formats[op_lofss][0] = Script_Offset;
+ break;
+ default:
+ sciprintf("script_adjust_opcode_formats(): Unknown script version %d\n", res_version);
}
}
-
+
int
-script_find_selector(state_t *s, const char *selectorname)
-{
- int i;
- for (i = 0; i < s->selector_names_nr; i++)
- if (strcmp(selectorname, s->selector_names[i]) == 0)
- return i;
-
- sciprintf("Warning: Could not map '%s' to any selector!\n", selectorname);
- return -1;
+script_find_selector(state_t *s, const char *selectorname) {
+ int i;
+ for (i = 0; i < s->selector_names_nr; i++)
+ if (strcmp(selectorname, s->selector_names[i]) == 0)
+ return i;
+
+ sciprintf("Warning: Could not map '%s' to any selector!\n", selectorname);
+ return -1;
}
#define FIND_SELECTOR(_slc_, _slcstr_) map->_slc_ = script_find_selector(s, _slcstr_);
void
-script_map_selectors(state_t *s, selector_map_t *map)
-{
- map->init = script_find_selector(s, "init");
- map->play = script_find_selector(s, "play");
- FIND_SELECTOR(replay, "replay");
- map->x = script_find_selector(s, "x");
- map->y = script_find_selector(s, "y");
- map->z = script_find_selector(s, "z");
- map->priority = script_find_selector(s, "priority");
- map->view = script_find_selector(s, "view");
- map->loop = script_find_selector(s, "loop");
- map->cel = script_find_selector(s, "cel");
- FIND_SELECTOR(brLeft, "brLeft");
- FIND_SELECTOR(brRight, "brRight");
- FIND_SELECTOR(brTop, "brTop");
- FIND_SELECTOR(brBottom, "brBottom");
- FIND_SELECTOR(xStep, "xStep");
- FIND_SELECTOR(yStep, "yStep");
- FIND_SELECTOR(nsBottom, "nsBottom");
- FIND_SELECTOR(nsTop, "nsTop");
- FIND_SELECTOR(nsLeft, "nsLeft");
- FIND_SELECTOR(nsRight, "nsRight");
- FIND_SELECTOR(font, "font");
- FIND_SELECTOR(text, "text");
- FIND_SELECTOR(type, "type");
- FIND_SELECTOR(state, "state");
- FIND_SELECTOR(doit, "doit");
- FIND_SELECTOR(delete_, "delete");
- FIND_SELECTOR(signal, "signal");
- FIND_SELECTOR(underBits, "underBits");
- FIND_SELECTOR(canBeHere, "canBeHere");
- FIND_SELECTOR(client, "client");
- FIND_SELECTOR(dx, "dx");
- FIND_SELECTOR(dy, "dy");
- FIND_SELECTOR(xStep, "xStep");
- FIND_SELECTOR(yStep, "yStep");
- FIND_SELECTOR(b_movCnt, "b-moveCnt");
- FIND_SELECTOR(b_i1, "b-i1");
- FIND_SELECTOR(b_i2, "b-i2");
- FIND_SELECTOR(b_di, "b-di");
- FIND_SELECTOR(b_xAxis, "b-xAxis");
- FIND_SELECTOR(b_incr, "b-incr");
- FIND_SELECTOR(completed, "completed");
- FIND_SELECTOR(illegalBits, "illegalBits");
- FIND_SELECTOR(dispose, "dispose");
- FIND_SELECTOR(prevSignal, "prevSignal");
- FIND_SELECTOR(message, "message");
- FIND_SELECTOR(modifiers, "modifiers");
- FIND_SELECTOR(cue, "cue");
- FIND_SELECTOR(owner, "owner");
- FIND_SELECTOR(handle, "handle");
- FIND_SELECTOR(number, "number");
- FIND_SELECTOR(max, "max");
- FIND_SELECTOR(cursor, "cursor");
- FIND_SELECTOR(claimed, "claimed");
- FIND_SELECTOR(edgeHit, "edgeHit");
- FIND_SELECTOR(wordFail, "wordFail");
- FIND_SELECTOR(syntaxFail, "syntaxFail");
- FIND_SELECTOR(semanticFail, "semanticFail");
- FIND_SELECTOR(cycler, "cycler");
- FIND_SELECTOR(elements, "elements");
- FIND_SELECTOR(lsTop, "lsTop");
- FIND_SELECTOR(lsBottom, "lsBottom");
- FIND_SELECTOR(lsLeft, "lsLeft");
- FIND_SELECTOR(lsRight, "lsRight");
- FIND_SELECTOR(baseSetter, "baseSetter");
- FIND_SELECTOR(who, "who");
- FIND_SELECTOR(distance, "distance");
- FIND_SELECTOR(mover, "mover");
- FIND_SELECTOR(looper, "looper");
- FIND_SELECTOR(isBlocked, "isBlocked");
- FIND_SELECTOR(heading, "heading");
- FIND_SELECTOR(mode, "mode");
- FIND_SELECTOR(caller, "caller");
- FIND_SELECTOR(moveDone, "moveDone");
- FIND_SELECTOR(vol, "vol");
- FIND_SELECTOR(pri, "pri");
- FIND_SELECTOR(min, "min");
- FIND_SELECTOR(sec, "sec");
- FIND_SELECTOR(frame, "frame");
- FIND_SELECTOR(dataInc, "dataInc");
- FIND_SELECTOR(size, "size");
- FIND_SELECTOR(palette, "palette");
- FIND_SELECTOR(moveSpeed, "moveSpeed");
- FIND_SELECTOR(cantBeHere, "cantBeHere");
- FIND_SELECTOR(nodePtr, "nodePtr");
- FIND_SELECTOR(flags, "flags");
- FIND_SELECTOR(points, "points");
+script_map_selectors(state_t *s, selector_map_t *map) {
+ map->init = script_find_selector(s, "init");
+ map->play = script_find_selector(s, "play");
+ FIND_SELECTOR(replay, "replay");
+ map->x = script_find_selector(s, "x");
+ map->y = script_find_selector(s, "y");
+ map->z = script_find_selector(s, "z");
+ map->priority = script_find_selector(s, "priority");
+ map->view = script_find_selector(s, "view");
+ map->loop = script_find_selector(s, "loop");
+ map->cel = script_find_selector(s, "cel");
+ FIND_SELECTOR(brLeft, "brLeft");
+ FIND_SELECTOR(brRight, "brRight");
+ FIND_SELECTOR(brTop, "brTop");
+ FIND_SELECTOR(brBottom, "brBottom");
+ FIND_SELECTOR(xStep, "xStep");
+ FIND_SELECTOR(yStep, "yStep");
+ FIND_SELECTOR(nsBottom, "nsBottom");
+ FIND_SELECTOR(nsTop, "nsTop");
+ FIND_SELECTOR(nsLeft, "nsLeft");
+ FIND_SELECTOR(nsRight, "nsRight");
+ FIND_SELECTOR(font, "font");
+ FIND_SELECTOR(text, "text");
+ FIND_SELECTOR(type, "type");
+ FIND_SELECTOR(state, "state");
+ FIND_SELECTOR(doit, "doit");
+ FIND_SELECTOR(delete_, "delete");
+ FIND_SELECTOR(signal, "signal");
+ FIND_SELECTOR(underBits, "underBits");
+ FIND_SELECTOR(canBeHere, "canBeHere");
+ FIND_SELECTOR(client, "client");
+ FIND_SELECTOR(dx, "dx");
+ FIND_SELECTOR(dy, "dy");
+ FIND_SELECTOR(xStep, "xStep");
+ FIND_SELECTOR(yStep, "yStep");
+ FIND_SELECTOR(b_movCnt, "b-moveCnt");
+ FIND_SELECTOR(b_i1, "b-i1");
+ FIND_SELECTOR(b_i2, "b-i2");
+ FIND_SELECTOR(b_di, "b-di");
+ FIND_SELECTOR(b_xAxis, "b-xAxis");
+ FIND_SELECTOR(b_incr, "b-incr");
+ FIND_SELECTOR(completed, "completed");
+ FIND_SELECTOR(illegalBits, "illegalBits");
+ FIND_SELECTOR(dispose, "dispose");
+ FIND_SELECTOR(prevSignal, "prevSignal");
+ FIND_SELECTOR(message, "message");
+ FIND_SELECTOR(modifiers, "modifiers");
+ FIND_SELECTOR(cue, "cue");
+ FIND_SELECTOR(owner, "owner");
+ FIND_SELECTOR(handle, "handle");
+ FIND_SELECTOR(number, "number");
+ FIND_SELECTOR(max, "max");
+ FIND_SELECTOR(cursor, "cursor");
+ FIND_SELECTOR(claimed, "claimed");
+ FIND_SELECTOR(edgeHit, "edgeHit");
+ FIND_SELECTOR(wordFail, "wordFail");
+ FIND_SELECTOR(syntaxFail, "syntaxFail");
+ FIND_SELECTOR(semanticFail, "semanticFail");
+ FIND_SELECTOR(cycler, "cycler");
+ FIND_SELECTOR(elements, "elements");
+ FIND_SELECTOR(lsTop, "lsTop");
+ FIND_SELECTOR(lsBottom, "lsBottom");
+ FIND_SELECTOR(lsLeft, "lsLeft");
+ FIND_SELECTOR(lsRight, "lsRight");
+ FIND_SELECTOR(baseSetter, "baseSetter");
+ FIND_SELECTOR(who, "who");
+ FIND_SELECTOR(distance, "distance");
+ FIND_SELECTOR(mover, "mover");
+ FIND_SELECTOR(looper, "looper");
+ FIND_SELECTOR(isBlocked, "isBlocked");
+ FIND_SELECTOR(heading, "heading");
+ FIND_SELECTOR(mode, "mode");
+ FIND_SELECTOR(caller, "caller");
+ FIND_SELECTOR(moveDone, "moveDone");
+ FIND_SELECTOR(vol, "vol");
+ FIND_SELECTOR(pri, "pri");
+ FIND_SELECTOR(min, "min");
+ FIND_SELECTOR(sec, "sec");
+ FIND_SELECTOR(frame, "frame");
+ FIND_SELECTOR(dataInc, "dataInc");
+ FIND_SELECTOR(size, "size");
+ FIND_SELECTOR(palette, "palette");
+ FIND_SELECTOR(moveSpeed, "moveSpeed");
+ FIND_SELECTOR(cantBeHere, "cantBeHere");
+ FIND_SELECTOR(nodePtr, "nodePtr");
+ FIND_SELECTOR(flags, "flags");
+ FIND_SELECTOR(points, "points");
}
int
-sci_hexdump(byte *data, int length, int offsetplus)
-{
- char tempstr[40];
- int i;
- for (i = 0; i < length; i+= 8) {
- int j;
-
- sprintf(tempstr, "%04x: ", i + offsetplus);
- for (j = 0; j < MIN(8, length - i); j++)
- sprintf(tempstr + 6 + (j*3) + (j > 3), "%02x ", data[i+j]);
- for (j = 0; j < MIN(8, length - i); j++) {
- int thechar;
- thechar = data[i+j];
- sprintf(tempstr + 31 + j, "%c",
- ((thechar < ' ') || (thechar > 127))? '.' : thechar );
- }
-
- for (j = 0; j < 38; j++)
- if (!tempstr[j])
- tempstr[j] = ' '; /* get rid of sprintf's \0s */
-
- sciprintf("%s\n", tempstr);
- }
- return 0;
+sci_hexdump(byte *data, int length, int offsetplus) {
+ char tempstr[40];
+ int i;
+ for (i = 0; i < length; i += 8) {
+ int j;
+
+ sprintf(tempstr, "%04x: ", i + offsetplus);
+ for (j = 0; j < MIN(8, length - i); j++)
+ sprintf(tempstr + 6 + (j*3) + (j > 3), "%02x ", data[i+j]);
+ for (j = 0; j < MIN(8, length - i); j++) {
+ int thechar;
+ thechar = data[i+j];
+ sprintf(tempstr + 31 + j, "%c",
+ ((thechar < ' ') || (thechar > 127)) ? '.' : thechar);
+ }
+
+ for (j = 0; j < 38; j++)
+ if (!tempstr[j])
+ tempstr[j] = ' '; /* get rid of sprintf's \0s */
+
+ sciprintf("%s\n", tempstr);
+ }
+ return 0;
}
static void
-script_dump_object(char *data, int seeker, int objsize, char **snames, int snames_nr)
-{
- int selectors, overloads, selectorsize;
- int species = getInt16((unsigned char *) data + 8 + seeker);
- int superclass = getInt16((unsigned char *) data + 10 + seeker);
- int namepos = getInt16((unsigned char *) data + 14 + seeker);
- int i = 0;
+script_dump_object(char *data, int seeker, int objsize, char **snames, int snames_nr) {
+ int selectors, overloads, selectorsize;
+ int species = getInt16((unsigned char *) data + 8 + seeker);
+ int superclass = getInt16((unsigned char *) data + 10 + seeker);
+ int namepos = getInt16((unsigned char *) data + 14 + seeker);
+ int i = 0;
- sciprintf("Object\n");
+ sciprintf("Object\n");
- sci_hexdump((unsigned char *) data + seeker, objsize -4, seeker);
- /*-4 because the size includes the two-word header */
+ sci_hexdump((unsigned char *) data + seeker, objsize - 4, seeker);
+ /*-4 because the size includes the two-word header */
- sciprintf("Name: %s\n", namepos? ((char *)(data + namepos)) : "<unknown>");
- sciprintf("Superclass: %x\n", superclass);
- sciprintf("Species: %x\n", species);
- sciprintf("-info-:%x\n", getInt16((unsigned char *) data + 12 + seeker) & 0xffff);
+ sciprintf("Name: %s\n", namepos ? ((char *)(data + namepos)) : "<unknown>");
+ sciprintf("Superclass: %x\n", superclass);
+ sciprintf("Species: %x\n", species);
+ sciprintf("-info-:%x\n", getInt16((unsigned char *) data + 12 + seeker) & 0xffff);
- sciprintf("Function area offset: %x\n", getInt16((unsigned char *) data + seeker + 4));
- sciprintf("Selectors [%x]:\n",
- selectors = (selectorsize = getInt16((unsigned char *) data + seeker + 6)));
+ sciprintf("Function area offset: %x\n", getInt16((unsigned char *) data + seeker + 4));
+ sciprintf("Selectors [%x]:\n",
+ selectors = (selectorsize = getInt16((unsigned char *) data + seeker + 6)));
- seeker += 8;
+ seeker += 8;
- while (selectors--) {
- sciprintf(" [#%03x] = 0x%x\n", i++, getInt16((unsigned char *) data + seeker) & 0xffff);
+ while (selectors--) {
+ sciprintf(" [#%03x] = 0x%x\n", i++, getInt16((unsigned char *) data + seeker) & 0xffff);
- seeker += 2;
- }
+ seeker += 2;
+ }
- sciprintf("Overridden functions: %x\n", selectors =
- overloads = getInt16((unsigned char *) data + seeker));
+ sciprintf("Overridden functions: %x\n", selectors =
+ overloads = getInt16((unsigned char *) data + seeker));
- seeker += 2;
+ seeker += 2;
- if (overloads < 100)
- while (overloads--) {
- int selector = getInt16((unsigned char *) data + (seeker));
+ if (overloads < 100)
+ while (overloads--) {
+ int selector = getInt16((unsigned char *) data + (seeker));
- 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);
+ 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);
- seeker += 2;
- }
+ seeker += 2;
+ }
}
static void
-script_dump_class(char *data, int seeker, int objsize, char **snames, int snames_nr)
-{
- int selectors, overloads, selectorsize;
- int species = getInt16((unsigned char *) data + 8 + seeker);
- int superclass = getInt16((unsigned char *) data + 10 + seeker);
- int namepos = getInt16((unsigned char *) data + 14 + seeker);
+script_dump_class(char *data, int seeker, int objsize, char **snames, int snames_nr) {
+ int selectors, overloads, selectorsize;
+ int species = getInt16((unsigned char *) data + 8 + seeker);
+ int superclass = getInt16((unsigned char *) data + 10 + seeker);
+ int namepos = getInt16((unsigned char *) data + 14 + seeker);
- sciprintf("Class\n");
+ sciprintf("Class\n");
- sci_hexdump((unsigned char *) data + seeker, objsize -4, seeker);
+ sci_hexdump((unsigned char *) data + seeker, objsize - 4, seeker);
- sciprintf("Name: %s\n", namepos? ((char *)data + namepos) : "<unknown>");
- sciprintf("Superclass: %x\n", superclass);
- sciprintf("Species: %x\n", species);
- sciprintf("-info-:%x\n", getInt16((unsigned char *) data + 12 + seeker) & 0xffff);
+ sciprintf("Name: %s\n", namepos ? ((char *)data + namepos) : "<unknown>");
+ sciprintf("Superclass: %x\n", superclass);
+ sciprintf("Species: %x\n", species);
+ sciprintf("-info-:%x\n", getInt16((unsigned char *) data + 12 + seeker) & 0xffff);
- sciprintf("Function area offset: %x\n", getInt16((unsigned char *) data + seeker + 4));
- sciprintf("Selectors [%x]:\n",
- selectors = (selectorsize = getInt16((unsigned char *) data + seeker + 6)));
+ sciprintf("Function area offset: %x\n", getInt16((unsigned char *) data + seeker + 4));
+ sciprintf("Selectors [%x]:\n",
+ selectors = (selectorsize = getInt16((unsigned char *) data + seeker + 6)));
- seeker += 8;
- selectorsize <<= 1;
+ seeker += 8;
+ selectorsize <<= 1;
- while (selectors--) {
- int selector = getInt16((unsigned char *) data + (seeker) + selectorsize);
+ while (selectors--) {
+ int selector = getInt16((unsigned char *) data + (seeker) + selectorsize);
- sciprintf(" [%03x] %s = 0x%x\n", 0xffff & selector,
- (snames && selector >= 0 && selector < snames_nr)? snames[selector] : "<?>",
- getInt16((unsigned char *) data + seeker) & 0xffff);
+ sciprintf(" [%03x] %s = 0x%x\n", 0xffff & selector,
+ (snames && selector >= 0 && selector < snames_nr) ? snames[selector] : "<?>",
+ getInt16((unsigned char *) data + seeker) & 0xffff);
- seeker += 2;
- }
+ seeker += 2;
+ }
- seeker += selectorsize;
+ seeker += selectorsize;
- sciprintf("Overloaded functions: %x\n", selectors =
- overloads = getInt16((unsigned char *) data + seeker));
+ sciprintf("Overloaded functions: %x\n", selectors =
+ overloads = getInt16((unsigned char *) data + seeker));
- seeker += 2;
+ seeker += 2;
- while (overloads--) {
- int selector = getInt16((unsigned char *) data + (seeker));
- 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);
+ while (overloads--) {
+ int selector = getInt16((unsigned char *) data + (seeker));
+ 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);
- seeker += 2;
- }
+ seeker += 2;
+ }
}
void
-script_dissect(resource_mgr_t *resmgr, int res_no, char **snames, int snames_nr)
-{
- int objectctr[11] = {0,0,0,0,0,0,0,0,0,0,0};
- unsigned int _seeker = 0;
- resource_t *script = scir_find_resource(resmgr, sci_script, res_no, 0);
- word_t **words;
- int word_count;
-
- if (!script) {
- sciprintf("Script not found!\n");
- return;
- }
-
- words=vocab_get_words (resmgr, &word_count);
-
- while (_seeker < script->size) {
- int objtype = getInt16(script->data + _seeker);
- int objsize;
- unsigned int seeker = _seeker + 4;
-
- if (!objtype) {
- sciprintf("End of script object (#0) encountered.\n");
- sciprintf("Classes: %i, Objects: %i, Export: %i,\n Var: %i (all base 10)",
- objectctr[6], objectctr[1], objectctr[7], objectctr[10]);
- /*vocabulary_free_snames(snames);*/
- vocab_free_words (words, word_count);
- return;
- }
-
- sciprintf("\n");
-
- objsize = getInt16(script->data + _seeker + 2);
-
- sciprintf("Obj type #%x, size 0x%x: ", objtype, objsize);
-
- _seeker += objsize;
-
- objectctr[objtype]++;
-
- switch (objtype) {
- case sci_obj_object:
- script_dump_object ((char *) script->data, seeker, objsize, snames, snames_nr);
- break;
-
- case sci_obj_code: {
- sciprintf("Code\n");
- sci_hexdump(script->data + seeker, objsize -4, seeker);
- };
- break;
-
- case 3: {
- sciprintf("<unknown>\n");
- sci_hexdump(script->data + seeker, objsize -4, seeker);
- };
- break;
-
- case sci_obj_said: {
- sciprintf("Said\n");
- sci_hexdump(script->data + seeker, objsize -4, seeker);
-
- sciprintf ("%04x: ", seeker);
- while (seeker < _seeker)
- {
- unsigned char nextitem=script->data [seeker++];
- if (nextitem == 0xFF)
- sciprintf ("\n%04x: ", seeker);
- else if (nextitem >= 0xF0)
- {
- switch (nextitem)
- {
- case 0xf0: sciprintf(", "); break;
- case 0xf1: sciprintf("& "); break;
- case 0xf2: sciprintf("/ "); break;
- case 0xf3: sciprintf("( "); break;
- case 0xf4: sciprintf(") "); break;
- case 0xf5: sciprintf("[ "); break;
- case 0xf6: sciprintf("] "); break;
- case 0xf7: sciprintf("# "); break;
- case 0xf8: sciprintf("< "); break;
- case 0xf9: sciprintf("> "); break;
- }
- }
- else {
- nextitem = nextitem << 8 | script->data [seeker++];
- sciprintf ("%s[%03x] ", vocab_get_any_group_word (nextitem, words, word_count), nextitem);
- }
- }
- sciprintf ("\n");
- }
- break;
-
- case sci_obj_strings: {
- sciprintf("Strings\n");
- while (script->data [seeker])
- {
- sciprintf ("%04x: %s\n", seeker, script->data+seeker);
- seeker += strlen ((char *) script->data+seeker)+1;
- }
- seeker++; /* the ending zero byte */
- };
- break;
-
- case sci_obj_class:
- script_dump_class ((char *) script->data, seeker, objsize, snames, snames_nr);
- break;
-
- case sci_obj_exports: {
- sciprintf("Exports\n");
- sci_hexdump((unsigned char *) script->data + seeker, objsize -4, seeker);
- };
- break;
-
- case sci_obj_pointers: {
- sciprintf("Pointers\n");
- sci_hexdump(script->data + seeker, objsize -4, seeker);
- };
- break;
-
- case 9: {
- sciprintf("<unknown>\n");
- sci_hexdump(script->data + seeker, objsize -4, seeker);
- };
- break;
-
- case sci_obj_localvars: {
- sciprintf("Local vars\n");
- sci_hexdump(script->data + seeker, objsize -4, seeker);
- };
- break;
-
- default:
- sciprintf("Unsupported!\n");
- return;
- }
-
- }
-
- sciprintf("Script ends without terminator\n");
-
- /*vocabulary_free_snames(snames);*/
+script_dissect(resource_mgr_t *resmgr, int res_no, char **snames, int snames_nr) {
+ int objectctr[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ unsigned int _seeker = 0;
+ resource_t *script = scir_find_resource(resmgr, sci_script, res_no, 0);
+ word_t **words;
+ int word_count;
+
+ if (!script) {
+ sciprintf("Script not found!\n");
+ return;
+ }
+
+ words = vocab_get_words(resmgr, &word_count);
+
+ while (_seeker < script->size) {
+ int objtype = getInt16(script->data + _seeker);
+ int objsize;
+ unsigned int seeker = _seeker + 4;
+
+ if (!objtype) {
+ sciprintf("End of script object (#0) encountered.\n");
+ sciprintf("Classes: %i, Objects: %i, Export: %i,\n Var: %i (all base 10)",
+ objectctr[6], objectctr[1], objectctr[7], objectctr[10]);
+ /*vocabulary_free_snames(snames);*/
+ vocab_free_words(words, word_count);
+ return;
+ }
+
+ sciprintf("\n");
+
+ objsize = getInt16(script->data + _seeker + 2);
+
+ sciprintf("Obj type #%x, size 0x%x: ", objtype, objsize);
+
+ _seeker += objsize;
+
+ objectctr[objtype]++;
+
+ switch (objtype) {
+ case sci_obj_object:
+ script_dump_object((char *) script->data, seeker, objsize, snames, snames_nr);
+ break;
+
+ case sci_obj_code: {
+ sciprintf("Code\n");
+ sci_hexdump(script->data + seeker, objsize - 4, seeker);
+ };
+ break;
+
+ case 3: {
+ sciprintf("<unknown>\n");
+ sci_hexdump(script->data + seeker, objsize - 4, seeker);
+ };
+ break;
+
+ case sci_obj_said: {
+ sciprintf("Said\n");
+ sci_hexdump(script->data + seeker, objsize - 4, seeker);
+
+ sciprintf("%04x: ", seeker);
+ while (seeker < _seeker) {
+ unsigned char nextitem = script->data [seeker++];
+ if (nextitem == 0xFF)
+ sciprintf("\n%04x: ", seeker);
+ else if (nextitem >= 0xF0) {
+ switch (nextitem) {
+ case 0xf0:
+ sciprintf(", ");
+ break;
+ case 0xf1:
+ sciprintf("& ");
+ break;
+ case 0xf2:
+ sciprintf("/ ");
+ break;
+ case 0xf3:
+ sciprintf("( ");
+ break;
+ case 0xf4:
+ sciprintf(") ");
+ break;
+ case 0xf5:
+ sciprintf("[ ");
+ break;
+ case 0xf6:
+ sciprintf("] ");
+ break;
+ case 0xf7:
+ sciprintf("# ");
+ break;
+ case 0xf8:
+ sciprintf("< ");
+ break;
+ case 0xf9:
+ sciprintf("> ");
+ break;
+ }
+ } else {
+ nextitem = nextitem << 8 | script->data [seeker++];
+ sciprintf("%s[%03x] ", vocab_get_any_group_word(nextitem, words, word_count), nextitem);
+ }
+ }
+ sciprintf("\n");
+ }
+ break;
+
+ case sci_obj_strings: {
+ sciprintf("Strings\n");
+ while (script->data [seeker]) {
+ sciprintf("%04x: %s\n", seeker, script->data + seeker);
+ seeker += strlen((char *) script->data + seeker) + 1;
+ }
+ seeker++; /* the ending zero byte */
+ };
+ break;
+
+ case sci_obj_class:
+ script_dump_class((char *) script->data, seeker, objsize, snames, snames_nr);
+ break;
+
+ case sci_obj_exports: {
+ sciprintf("Exports\n");
+ sci_hexdump((unsigned char *) script->data + seeker, objsize - 4, seeker);
+ };
+ break;
+
+ case sci_obj_pointers: {
+ sciprintf("Pointers\n");
+ sci_hexdump(script->data + seeker, objsize - 4, seeker);
+ };
+ break;
+
+ case 9: {
+ sciprintf("<unknown>\n");
+ sci_hexdump(script->data + seeker, objsize - 4, seeker);
+ };
+ break;
+
+ case sci_obj_localvars: {
+ sciprintf("Local vars\n");
+ sci_hexdump(script->data + seeker, objsize - 4, seeker);
+ };
+ break;
+
+ default:
+ sciprintf("Unsupported!\n");
+ return;
+ }
+
+ }
+
+ sciprintf("Script ends without terminator\n");
+
+ /*vocabulary_free_snames(snames);*/
}
diff --git a/engines/sci/scicore/tools.cpp b/engines/sci/scicore/tools.cpp
index 1ffea5a69a..7cb4831c0a 100644
--- a/engines/sci/scicore/tools.cpp
+++ b/engines/sci/scicore/tools.cpp
@@ -51,7 +51,7 @@
# include <windows.h>
# include <mmsystem.h>
-void usleep (long usec);
+void usleep(long usec);
# ifdef sleep
# undef sleep
@@ -89,12 +89,11 @@ int sci_debug_flags = 0; /* Special flags */
#define MEMTEST_HARDNESS 31
int
-memtest(const char *file, int line)
-{
+memtest(const char *file, int line) {
/* va_list argp; -- unused */
int i;
void *blocks[MEMTEST_HARDNESS + 1];
- fprintf(stderr,"Memtesting in %s, L%d\n", file, line);
+ fprintf(stderr, "Memtesting in %s, L%d\n", file, line);
for (i = 0; i < MEMTEST_HARDNESS; i++) {
blocks[i] = sci_malloc(1 + i);
@@ -108,7 +107,7 @@ memtest(const char *file, int line)
free(blocks[i]);
for (i = 0; i < MEMTEST_HARDNESS; i++) {
- blocks[i] = sci_malloc(5 + i*5);
+ blocks[i] = sci_malloc(5 + i * 5);
#ifdef HAVE_MEMFROB
memfrob(blocks[i], 5 + i*5);
#else
@@ -119,7 +118,7 @@ memtest(const char *file, int line)
free(blocks[i]);
for (i = 0; i < MEMTEST_HARDNESS; i++) {
- blocks[i] = sci_malloc(5 + i*100);
+ blocks[i] = sci_malloc(5 + i * 100);
#ifdef HAVE_MEMFROB
memfrob(blocks[i], 5 + i*100);
#else
@@ -130,7 +129,7 @@ memtest(const char *file, int line)
free(blocks[i]);
for (i = 0; i < MEMTEST_HARDNESS; i++) {
- blocks[i] = sci_malloc(5 + i*1000);
+ blocks[i] = sci_malloc(5 + i * 1000);
#ifdef HAVE_MEMFROB
memfrob(blocks[i], 5 + i * 1000);
#else
@@ -139,26 +138,23 @@ memtest(const char *file, int line)
}
for (i = 0; i < MEMTEST_HARDNESS; i++)
free(blocks[i]);
- fprintf(stderr,"Memtest succeeded!\n");
+ fprintf(stderr, "Memtest succeeded!\n");
return 0;
}
void *
-memdup(void *src, int size)
-{
+memdup(void *src, int size) {
void *b = malloc(size);
memcpy(b, src, size);
return b;
}
-int sci_ffs(int _mask)
-{
+int sci_ffs(int _mask) {
int retval = 0;
if (!_mask) return 0;
retval++;
- while (! (_mask & 1))
- {
+ while (!(_mask & 1)) {
retval++;
_mask >>= 1;
}
@@ -170,26 +166,23 @@ int sci_ffs(int _mask)
/******************** Debug functions ********************/
void
-_SCIkvprintf(FILE *file, const char *format, va_list args)
-{
+_SCIkvprintf(FILE *file, const char *format, va_list args) {
vfprintf(file, format, args);
if (con_file) vfprintf(con_file, format, args);
}
void
-_SCIkprintf(FILE *file, const char *format, ...)
-{
+_SCIkprintf(FILE *file, const char *format, ...) {
va_list args;
va_start(args, format);
_SCIkvprintf(file, format, args);
- va_end (args);
+ va_end(args);
}
void
-_SCIkwarn(state_t *s, const char *file, int line, int area, const char *format, ...)
-{
+_SCIkwarn(state_t *s, const char *file, int line, int area, const char *format, ...) {
va_list args;
if (area == SCIkERROR_NR)
@@ -202,12 +195,11 @@ _SCIkwarn(state_t *s, const char *file, int line, int area, const char *format,
va_end(args);
fflush(NULL);
- if (sci_debug_flags & _DEBUG_FLAG_BREAK_ON_WARNINGS) script_debug_flag=1;
+ if (sci_debug_flags & _DEBUG_FLAG_BREAK_ON_WARNINGS) script_debug_flag = 1;
}
void
-_SCIkdebug(state_t *s, const char *file, int line, int area, const char *format, ...)
-{
+_SCIkdebug(state_t *s, const char *file, int line, int area, const char *format, ...) {
va_list args;
if (s->debug_mode & (1 << area)) {
@@ -220,8 +212,7 @@ _SCIkdebug(state_t *s, const char *file, int line, int area, const char *format,
}
void
-_SCIGNUkdebug(const char *funcname, state_t *s, const char *file, int line, int area, const char *format, ...)
-{
+_SCIGNUkdebug(const char *funcname, state_t *s, const char *file, int line, int area, const char *format, ...) {
va_list xargs;
int error = ((area == SCIkWARNING_NR) || (area == SCIkERROR_NR));
@@ -247,8 +238,7 @@ _SCIGNUkdebug(const char *funcname, state_t *s, const char *file, int line, int
#if defined(HAVE_GETTIMEOFDAY)
void
-sci_gettime(long *seconds, long *useconds)
-{
+sci_gettime(long *seconds, long *useconds) {
struct timeval tv;
assert(!gettimeofday(&tv, NULL));
@@ -261,24 +251,21 @@ sci_gettime(long *seconds, long *useconds)
/* Warning: This function only retrieves the amount of mseconds since the start of
** the Win32 kernel; it does /not/ provide the number of seconds since the epoch!
** There are no known cases where this causes problems, though. */
-void sci_gettime(long *seconds, long *useconds)
-{
+void sci_gettime(long *seconds, long *useconds) {
DWORD tm;
- if (TIMERR_NOERROR != timeBeginPeriod(1))
- {
+ if (TIMERR_NOERROR != timeBeginPeriod(1)) {
fprintf(stderr, "timeBeginPeriod(1) failed in sci_gettime\n");
}
tm = timeGetTime();
- if (TIMERR_NOERROR != timeEndPeriod(1))
- {
+ if (TIMERR_NOERROR != timeEndPeriod(1)) {
fprintf(stderr, "timeEndPeriod(1) failed in sci_gettime\n");
}
- *seconds = tm/1000;
- *useconds = (tm%1000)*1000;
+ *seconds = tm / 1000;
+ *useconds = (tm % 1000) * 1000;
}
#else
# error "You need to provide a microsecond resolution sci_gettime implementation for your platform!"
@@ -286,8 +273,7 @@ void sci_gettime(long *seconds, long *useconds)
void
-sci_get_current_time(GTimeVal *val)
-{
+sci_get_current_time(GTimeVal *val) {
long foo, bar;
sci_gettime(&foo, &bar);
val->tv_sec = foo;
@@ -300,57 +286,46 @@ sci_get_current_time(GTimeVal *val)
/******** Dir: Win32 CODE ********/
void
-sci_init_dir(sci_dir_t *dir)
-{
+sci_init_dir(sci_dir_t *dir) {
dir->search = -1;
}
char *
-sci_find_first(sci_dir_t *dir, const char *mask)
-{
+sci_find_first(sci_dir_t *dir, const char *mask) {
dir->search = _findfirst(mask, &(dir->fileinfo));
- if (dir->search != -1)
- {
- if (dir->fileinfo.name == NULL)
- {
+ if (dir->search != -1) {
+ if (dir->fileinfo.name == NULL) {
return NULL;
}
if (strcmp(dir->fileinfo.name, ".") == 0 ||
- strcmp(dir->fileinfo.name, "..") == 0)
- {
- if (sci_find_next(dir) == NULL)
- {
+ strcmp(dir->fileinfo.name, "..") == 0) {
+ if (sci_find_next(dir) == NULL) {
return NULL;
}
}
return dir->fileinfo.name;
- }
- else
- {
- switch (errno)
- {
- case ENOENT:
- {
+ } else {
+ switch (errno) {
+ case ENOENT: {
#ifdef _DEBUG
- printf("_findfirst errno = ENOENT: no match\n");
+ printf("_findfirst errno = ENOENT: no match\n");
- if (mask)
- printf(" in: %s\n", mask);
- else
- printf(" - searching in undefined directory\n");
+ if (mask)
+ printf(" in: %s\n", mask);
+ else
+ printf(" - searching in undefined directory\n");
#endif
- break;
- }
- case EINVAL:
- {
- printf("_findfirst errno = EINVAL: invalid filename\n");
- break;
- }
- default:
- printf("_findfirst errno = unknown (%d)", errno);
+ break;
+ }
+ case EINVAL: {
+ printf("_findfirst errno = EINVAL: invalid filename\n");
+ break;
+ }
+ default:
+ printf("_findfirst errno = unknown (%d)", errno);
}
}
@@ -358,34 +333,30 @@ sci_find_first(sci_dir_t *dir, const char *mask)
}
char *
-sci_find_next(sci_dir_t *dir)
-{
- if (dir->search == -1)
- return NULL;
+sci_find_next(sci_dir_t *dir) {
+ if (dir->search == -1)
+ return NULL;
- if (_findnext(dir->search, &(dir->fileinfo)) < 0) {
- _findclose(dir->search);
- dir->search = -1;
- return NULL;
- }
+ if (_findnext(dir->search, &(dir->fileinfo)) < 0) {
+ _findclose(dir->search);
+ dir->search = -1;
+ return NULL;
+ }
- if (strcmp(dir->fileinfo.name, ".") == 0 ||
- strcmp(dir->fileinfo.name, "..") == 0)
- {
- if (sci_find_next(dir) == NULL)
- {
- return NULL;
- }
+ if (strcmp(dir->fileinfo.name, ".") == 0 ||
+ strcmp(dir->fileinfo.name, "..") == 0) {
+ if (sci_find_next(dir) == NULL) {
+ return NULL;
}
+ }
- return dir->fileinfo.name;
+ return dir->fileinfo.name;
}
void
-sci_finish_find(sci_dir_t *dir)
-{
- if(dir->search != -1) {
- _findclose(dir->search);
+sci_finish_find(sci_dir_t *dir) {
+ if (dir->search != -1) {
+ _findclose(dir->search);
dir->search = -1;
}
}
@@ -394,15 +365,13 @@ sci_finish_find(sci_dir_t *dir)
/******** Dir: UNIX CODE ********/
void
-sci_init_dir(sci_dir_t *dir)
-{
+sci_init_dir(sci_dir_t *dir) {
dir->dir = NULL;
dir->mask_copy = NULL;
}
char *
-sci_find_first(sci_dir_t *dir, const char *mask)
-{
+sci_find_first(sci_dir_t *dir, const char *mask) {
if (dir->dir)
closedir(dir->dir);
@@ -422,8 +391,7 @@ sci_find_first(sci_dir_t *dir, const char *mask)
#endif
char *
-sci_find_next(sci_dir_t *dir)
-{
+sci_find_next(sci_dir_t *dir) {
struct dirent *match;
while ((match = readdir(dir->dir))) {
@@ -439,8 +407,7 @@ sci_find_next(sci_dir_t *dir)
}
void
-sci_finish_find(sci_dir_t *dir)
-{
+sci_finish_find(sci_dir_t *dir) {
if (dir->dir) {
closedir(dir->dir);
dir->dir = NULL;
@@ -455,30 +422,29 @@ sci_finish_find(sci_dir_t *dir)
int
-sci_mkpath(const char *path)
-{
+sci_mkpath(const char *path) {
const char *path_position = path;
- char *next_separator = NULL;
+ char *next_separator = NULL;
- if (chdir(G_DIR_SEPARATOR_S)) { /* Go to root */
- sciprintf("Error: Could not change to root directory '%s'!\n",
- G_DIR_SEPARATOR_S);
- return -1;
- }
+ if (chdir(G_DIR_SEPARATOR_S)) { /* Go to root */
+ sciprintf("Error: Could not change to root directory '%s'!\n",
+ G_DIR_SEPARATOR_S);
+ return -1;
+ }
- do {
- if (next_separator)
- *next_separator = G_DIR_SEPARATOR_S[0];
- next_separator = (char *)strchr(path_position, G_DIR_SEPARATOR_S[0]);
+ do {
+ if (next_separator)
+ *next_separator = G_DIR_SEPARATOR_S[0];
+ next_separator = (char *)strchr(path_position, G_DIR_SEPARATOR_S[0]);
- if (next_separator)
- *next_separator = 0;
+ if (next_separator)
+ *next_separator = 0;
if (*path_position) { /* Unless we're at the first slash... */
if (chdir(path_position)) {
if (scimkdir(path_position, 0700) || chdir(path_position)) {
sciprintf("Error: Could not create subdirectory '%s' in",
- path_position);
+ path_position);
if (next_separator)
*next_separator = G_DIR_SEPARATOR_S[0];
sciprintf(" '%s'!\n", path);
@@ -488,16 +454,15 @@ sci_mkpath(const char *path)
}
path_position = next_separator + 1;
- } while (next_separator);
+ } while (next_separator);
- return 0;
+ return 0;
}
char *
-sci_get_homedir(void)
-{
+sci_get_homedir(void) {
#ifdef WIN32
char *_path_buf = (char*)malloc(MAX_PATH);
char *dr = getenv("HOMEDRIVE");
@@ -523,15 +488,13 @@ sci_get_homedir(void)
sci_queue_t *
-sci_init_queue(sci_queue_t *queue)
-{
+sci_init_queue(sci_queue_t *queue) {
queue->start = queue->end = NULL;
return queue;
}
sci_queue_t *
-sci_add_to_queue(sci_queue_t *queue, void *data, int type)
-{
+sci_add_to_queue(sci_queue_t *queue, void *data, int type) {
sci_queue_node_t *node = (sci_queue_node_t*)sci_malloc(sizeof(sci_queue_node_t));
node->next = NULL;
@@ -550,8 +513,7 @@ sci_add_to_queue(sci_queue_t *queue, void *data, int type)
}
void *
-sci_get_from_queue(sci_queue_t *queue, int *type)
-{
+sci_get_from_queue(sci_queue_t *queue, int *type) {
sci_queue_node_t *node = queue->end;
if (node) {
void *retval = node->data;
@@ -576,40 +538,35 @@ sci_get_from_queue(sci_queue_t *queue, int *type)
# include <sched.h>
void
-sci_sched_yield(void)
-{
+sci_sched_yield(void) {
sched_yield();
}
#elif defined (__DC__)
void
-sci_sched_yield()
-{
+sci_sched_yield() {
thd_pass();
}
#elif defined (__BEOS__)
void
-sci_sched_yield()
-{
+sci_sched_yield() {
snooze(0);
}
#elif defined (WIN32)
void
-sci_sched_yield()
-{
+sci_sched_yield() {
sleep(1);
}
#else
void
-sci_sched_yield()
-{
+sci_sched_yield() {
}
#endif /* !HAVE_SCHED_YIELD */
@@ -666,8 +623,7 @@ _fcaseseek(const char *fname, sci_dir_t *dir)
FILE *
-sci_fopen(const char *fname, const char *mode)
-{
+sci_fopen(const char *fname, const char *mode) {
sci_dir_t dir;
char *name = _fcaseseek(fname, &dir);
FILE *file = NULL;
@@ -683,8 +639,7 @@ sci_fopen(const char *fname, const char *mode)
}
int
-sci_open(const char *fname, int flags)
-{
+sci_open(const char *fname, int flags) {
sci_dir_t dir;
char *name;
int file = SCI_INVALID_FD;
@@ -695,11 +650,10 @@ sci_open(const char *fname, int flags)
sci_init_dir(&dir);
separator_position = (char *)strrchr(fname, G_DIR_SEPARATOR);
- if (separator_position)
- {
- path = (char *) malloc(separator_position-fname+1);
+ if (separator_position) {
+ path = (char *) malloc(separator_position - fname + 1);
path[separator_position-fname] = 0;
- strncpy(path, fname, separator_position-fname);
+ strncpy(path, fname, separator_position - fname);
chdir(path);
free(path);
}
@@ -718,35 +672,32 @@ sci_open(const char *fname, int flags)
}
char *
-sci_getcwd(void)
-{
+sci_getcwd(void) {
int size = 0;
char *cwd = NULL;
while (size < 8192) {
size += 256;
cwd = (char*)sci_malloc(size);
- if (getcwd(cwd, size-1))
+ if (getcwd(cwd, size - 1))
return cwd;
sci_free(cwd);
}
- fprintf(stderr,"Could not determine current working directory!\n");
+ fprintf(stderr, "Could not determine current working directory!\n");
return NULL;
}
#ifdef __DC__
int
-sci_fd_size(int fd)
-{
+sci_fd_size(int fd) {
return fs_total(fd);
}
int
-sci_file_size(const char *fname)
-{
+sci_file_size(const char *fname) {
int fd = fs_open(fname, O_RDONLY);
int retval = -1;
@@ -761,16 +712,14 @@ sci_file_size(const char *fname)
#else
int
-sci_fd_size(int fd)
-{
+sci_fd_size(int fd) {
struct stat fd_stat;
if (fstat(fd, &fd_stat)) return -1;
return fd_stat.st_size;
}
int
-sci_file_size(const char *fname)
-{
+sci_file_size(const char *fname) {
struct stat fn_stat;
if (stat(fname, &fn_stat)) return -1;
return fn_stat.st_size;
@@ -781,15 +730,13 @@ sci_file_size(const char *fname)
/* Simple heuristic to work around array handling peculiarity in SQ4:
It uses StrAt() to read the individual elements, so we must determine
whether a string is really a string or an array. */
-int is_print_str(char *str)
-{
+int is_print_str(char *str) {
int printable = 0;
int len = strlen(str);
-
+
if (len == 0) return 1;
- while (*str)
- {
+ while (*str) {
if (isprint(*str)) printable++;
str++;
}
diff --git a/engines/sci/scicore/versions.cpp b/engines/sci/scicore/versions.cpp
index 2dfb539374..d1b81603a2 100644
--- a/engines/sci/scicore/versions.cpp
+++ b/engines/sci/scicore/versions.cpp
@@ -32,8 +32,7 @@
#define VERSION_DETECT_BUF_SIZE 4096
static int
-scan_file(char *filename, sci_version_t *version)
-{
+scan_file(char *filename, sci_version_t *version) {
char buf[VERSION_DETECT_BUF_SIZE];
char result_string[10]; /* string-encoded result, copied from buf */
int characters_left;
@@ -67,16 +66,15 @@ scan_file(char *filename, sci_version_t *version)
if (isalnum((unsigned char) ch)) {
accept = (state != 1
- && state != 5
- && state != 9);
+ && state != 5
+ && state != 9);
} else if (ch == '.') {
accept = (state == 1
- || state == 5);
+ || state == 5);
} else if (state == 9) {
result_string[9] = 0; /* terminate string */
- if (!version_parse(result_string, version))
- {
+ if (!version_parse(result_string, version)) {
exe_close(f);
return 0; /* success! */
}
@@ -98,20 +96,17 @@ scan_file(char *filename, sci_version_t *version)
}
static guint32
-read_uint32(byte *data)
-{
+read_uint32(byte *data) {
return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
}
static guint16
-read_uint16(byte *data)
-{
+read_uint16(byte *data) {
return (data[0] << 8) | data[1];
}
static int
-is_mac_exe(char *filename)
-{
+is_mac_exe(char *filename) {
FILE *file;
byte buf[4];
guint32 val;
@@ -175,15 +170,14 @@ is_mac_exe(char *filename)
}
static int
-is_exe(char *filename)
-{
+is_exe(char *filename) {
FILE *file;
char buf[4];
unsigned char header[] = {0x00, 0x00, 0x03, 0xf3};
/* PC and Atari ST executable extensions */
if (strstr(filename, ".exe") || strstr(filename, ".EXE")
- || strstr(filename, ".prg") || strstr(filename, ".PRG"))
+ || strstr(filename, ".prg") || strstr(filename, ".PRG"))
return 1;
/* Check for Amiga executable */
@@ -206,41 +200,37 @@ is_exe(char *filename)
}
void
-version_require_earlier_than(state_t *s, sci_version_t version)
-{
+version_require_earlier_than(state_t *s, sci_version_t version) {
if (s->version_lock_flag)
return;
if (version <= s->min_version) {
sciprintf("Version autodetect conflict: Less than %d.%03d.%03d was requested, but "
- "%d.%03d.%03d is the current minimum\n",
- SCI_VERSION_MAJOR(version), SCI_VERSION_MINOR(version), SCI_VERSION_PATCHLEVEL(version),
- SCI_VERSION_MAJOR(s->min_version), SCI_VERSION_MINOR(s->min_version),
- SCI_VERSION_PATCHLEVEL(s->min_version));
+ "%d.%03d.%03d is the current minimum\n",
+ SCI_VERSION_MAJOR(version), SCI_VERSION_MINOR(version), SCI_VERSION_PATCHLEVEL(version),
+ SCI_VERSION_MAJOR(s->min_version), SCI_VERSION_MINOR(s->min_version),
+ SCI_VERSION_PATCHLEVEL(s->min_version));
return;
- }
- else if (version < s->max_version) {
- s->max_version = version -1;
+ } else if (version < s->max_version) {
+ s->max_version = version - 1;
if (s->max_version < s->version)
s->version = s->max_version;
}
}
void
-version_require_later_than(state_t *s, sci_version_t version)
-{
+version_require_later_than(state_t *s, sci_version_t version) {
if (s->version_lock_flag)
return;
if (version > s->max_version) {
sciprintf("Version autodetect conflict: More than %d.%03d.%03d was requested, but less than"
- "%d.%03d.%03d is required ATM\n",
- SCI_VERSION_MAJOR(version), SCI_VERSION_MINOR(version), SCI_VERSION_PATCHLEVEL(version),
- SCI_VERSION_MAJOR(s->max_version), SCI_VERSION_MINOR(s->max_version),
- SCI_VERSION_PATCHLEVEL(s->max_version));
+ "%d.%03d.%03d is required ATM\n",
+ SCI_VERSION_MAJOR(version), SCI_VERSION_MINOR(version), SCI_VERSION_PATCHLEVEL(version),
+ SCI_VERSION_MAJOR(s->max_version), SCI_VERSION_MINOR(s->max_version),
+ SCI_VERSION_PATCHLEVEL(s->max_version));
return;
- }
- else if (version > s->min_version) {
+ } else if (version > s->min_version) {
s->min_version = version;
if (s->min_version > s->version)
s->version = s->min_version;
@@ -248,15 +238,14 @@ version_require_later_than(state_t *s, sci_version_t version)
}
int
-version_parse(const char *vn, sci_version_t *result)
-{
+version_parse(const char *vn, sci_version_t *result) {
char *endptr[3];
int major = strtol(vn, &endptr[0], 10);
int minor = strtol(vn + 2, &endptr[1], 10);
int patchlevel = strtol(vn + 6, &endptr[2], 10);
if (endptr[0] != vn + 1 || endptr[1] != vn + 5
- || *endptr[2] != '\0') {
+ || *endptr[2] != '\0') {
sciprintf("Warning: Failed to parse version string '%s'\n", vn);
return 1;
}
@@ -266,8 +255,7 @@ version_parse(const char *vn, sci_version_t *result)
}
int
-version_detect_from_executable(sci_version_t *result)
-{
+version_detect_from_executable(sci_version_t *result) {
sci_dir_t dir;
char *filename;
int mac = 0;
@@ -303,17 +291,16 @@ version_detect_from_executable(sci_version_t *result)
#define HASHCODE_MAGIC_RESOURCE_001 0x00000001
const char * /* Original version by Solomon Peachy */
-version_guess_from_hashcode(sci_version_t *result, int *res_version, guint32 *code)
-{
+version_guess_from_hashcode(sci_version_t *result, int *res_version, guint32 *code) {
int i;
int fd = -1;
int left = VERSION_DETECT_HASH_SIZE;
guint32 hash_code;
guint8 buf[VERSION_DETECT_BUF_SIZE];
- if (IS_VALID_FD(fd = sci_open("resource.001", O_RDONLY|O_BINARY))) {
+ if (IS_VALID_FD(fd = sci_open("resource.001", O_RDONLY | O_BINARY))) {
hash_code = HASHCODE_MAGIC_RESOURCE_001;
- } else if (IS_VALID_FD(fd = sci_open("resource.000", O_RDONLY|O_BINARY))) {
+ } else if (IS_VALID_FD(fd = sci_open("resource.000", O_RDONLY | O_BINARY))) {
hash_code = HASHCODE_MAGIC_RESOURCE_000;
} else {
sciprintf("Warning: Could not find RESOURCE.000 or RESOURCE.001, cannot determine hash code\n");
diff --git a/engines/sci/scicore/vocab.cpp b/engines/sci/scicore/vocab.cpp
index b5b14c8e80..d2f97df1d7 100644
--- a/engines/sci/scicore/vocab.cpp
+++ b/engines/sci/scicore/vocab.cpp
@@ -43,35 +43,33 @@ int vocab_version;
VOCAB_RESOURCE_SCI1_SUFFIX_VOCAB : \
VOCAB_RESOURCE_SCI0_SUFFIX_VOCAB
-const char *class_names[] =
- {"", /* These strange names were taken from an SCI01 interpreter */
- "",
- "conj", /* conjunction */
- "ass", /* ? */
- "pos", /* preposition ? */
- "art", /* article */
- "adj", /* adjective */
- "pron", /* pronoun */
- "noun", /* noun */
- "auxv", /* auxillary verb */
- "adv", /* adverb */
- "verb", /* verb */
- "",
- "",
- "",
- ""};
+const char *class_names[] = {"", /* These strange names were taken from an SCI01 interpreter */
+ "",
+ "conj", /* conjunction */
+ "ass", /* ? */
+ "pos", /* preposition ? */
+ "art", /* article */
+ "adj", /* adjective */
+ "pron", /* pronoun */
+ "noun", /* noun */
+ "auxv", /* auxillary verb */
+ "adv", /* adverb */
+ "verb", /* verb */
+ "",
+ "",
+ "",
+ ""
+ };
int
-_vocab_cmp_words(const void *word1, const void *word2)
-{
+_vocab_cmp_words(const void *word1, const void *word2) {
return strcasecmp((*((word_t **) word1))->word, (*((word_t **) word2))->word);
}
word_t **
-vocab_get_words(resource_mgr_t *resmgr, int *word_counter)
-{
+vocab_get_words(resource_mgr_t *resmgr, int *word_counter) {
int counter = 0;
unsigned int seeker;
word_t **words;
@@ -83,18 +81,18 @@ vocab_get_words(resource_mgr_t *resmgr, int *word_counter)
/* First try to load the SCI0 vocab resource. */
resource = scir_find_resource(resmgr, sci_vocab,
- VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0);
+ VOCAB_RESOURCE_SCI0_MAIN_VOCAB, 0);
vocab_version = 0;
if (!resource) {
- fprintf(stderr,"SCI0: Could not find a main vocabulary, trying SCI01.\n");
+ fprintf(stderr, "SCI0: Could not find a main vocabulary, trying SCI01.\n");
resource = scir_find_resource(resmgr, sci_vocab,
- VOCAB_RESOURCE_SCI1_MAIN_VOCAB, 0);
+ VOCAB_RESOURCE_SCI1_MAIN_VOCAB, 0);
vocab_version = 1;
}
if (!resource) {
- fprintf(stderr,"SCI1: Could not find a main vocabulary!\n");
+ fprintf(stderr, "SCI1: Could not find a main vocabulary!\n");
return NULL; /* NOT critical: SCI1 games and some demos don't have one! */
}
@@ -121,8 +119,8 @@ vocab_get_words(resource_mgr_t *resmgr, int *word_counter)
if (vocab_version == 1) {
c = 1;
while (seeker < resource->size
- && currentwordpos < 255
- && c) {
+ && currentwordpos < 255
+ && c) {
c = resource->data[seeker++];
currentword[currentwordpos++] = c;
}
@@ -164,161 +162,153 @@ vocab_get_words(resource_mgr_t *resmgr, int *word_counter)
void
-vocab_free_words(word_t **words, int words_nr)
-{
- int i;
+vocab_free_words(word_t **words, int words_nr) {
+ int i;
- for (i = 0; i < words_nr; i++)
- free(words[i]);
+ for (i = 0; i < words_nr; i++)
+ free(words[i]);
- free(words);
+ free(words);
}
const char *
-vocab_get_any_group_word(int group, word_t **words, int words_nr)
-{
- int i;
+vocab_get_any_group_word(int group, word_t **words, int words_nr) {
+ int i;
- if (group == VOCAB_MAGIC_NUMBER_GROUP)
- return "{number}";
+ if (group == VOCAB_MAGIC_NUMBER_GROUP)
+ return "{number}";
- for (i = 0; i < words_nr; i++)
- if (words[i]->group == group)
- return words[i]->word;
+ for (i = 0; i < words_nr; i++)
+ if (words[i]->group == group)
+ return words[i]->word;
- return "{invalid}";
+ return "{invalid}";
}
static inline unsigned int
-inverse_16(unsigned int foo)
-{
- return (((foo & 0xff) << 8) | ((foo & 0xff00) >> 8));
+inverse_16(unsigned int foo) {
+ return (((foo & 0xff) << 8) | ((foo & 0xff00) >> 8));
}
suffix_t **
-vocab_get_suffices(resource_mgr_t *resmgr, int *suffices_nr)
-{
- int counter = 0;
- suffix_t **suffices;
- resource_t *resource = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1);
- unsigned int seeker = 1;
+vocab_get_suffices(resource_mgr_t *resmgr, int *suffices_nr) {
+ int counter = 0;
+ suffix_t **suffices;
+ resource_t *resource = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 1);
+ unsigned int seeker = 1;
- if (!resource) {
- fprintf(stderr,"Could not find suffix vocabulary!\n");
- return NULL; /* Not critical */
- }
+ if (!resource) {
+ fprintf(stderr, "Could not find suffix vocabulary!\n");
+ return NULL; /* Not critical */
+ }
- suffices = (suffix_t**)sci_malloc(sizeof(suffix_t *));
+ suffices = (suffix_t**)sci_malloc(sizeof(suffix_t *));
- while ((seeker < resource->size-1) && (resource->data[seeker + 1] != 0xff)) {
+ while ((seeker < resource->size - 1) && (resource->data[seeker + 1] != 0xff)) {
- char *alt_suffix = (char *) resource->data + seeker;
- int alt_len = strlen(alt_suffix);
- char *word_suffix;
- int word_len;
+ char *alt_suffix = (char *) resource->data + seeker;
+ int alt_len = strlen(alt_suffix);
+ char *word_suffix;
+ int word_len;
- suffices = (suffix_t**)sci_realloc(suffices, sizeof(suffix_t *) * (counter + 1));
+ suffices = (suffix_t**)sci_realloc(suffices, sizeof(suffix_t *) * (counter + 1));
- seeker += alt_len + 1; /* Hit end of string */
- word_suffix = (char *) resource->data + seeker + 3; /* Beginning of next string +1 (ignore '*') */
- word_len = strlen(word_suffix);
+ seeker += alt_len + 1; /* Hit end of string */
+ word_suffix = (char *) resource->data + seeker + 3; /* Beginning of next string +1 (ignore '*') */
+ word_len = strlen(word_suffix);
- suffices[counter] = (suffix_t*)sci_malloc(sizeof(suffix_t));
- /* allocate enough memory to store the strings */
+ suffices[counter] = (suffix_t*)sci_malloc(sizeof(suffix_t));
+ /* allocate enough memory to store the strings */
- suffices[counter]->word_suffix = word_suffix;
- suffices[counter]->alt_suffix = alt_suffix;
+ suffices[counter]->word_suffix = word_suffix;
+ suffices[counter]->alt_suffix = alt_suffix;
- suffices[counter]->alt_suffix_length = alt_len;
- suffices[counter]->word_suffix_length = word_len;
- suffices[counter]->class_mask = inverse_16(getInt16(resource->data + seeker)); /* Inverse endianness */
+ suffices[counter]->alt_suffix_length = alt_len;
+ suffices[counter]->word_suffix_length = word_len;
+ suffices[counter]->class_mask = inverse_16(getInt16(resource->data + seeker)); /* Inverse endianness */
- seeker += word_len + 4;
- suffices[counter]->result_class = inverse_16(getInt16(resource->data + seeker));
- seeker += 3; /* Next entry */
+ seeker += word_len + 4;
+ suffices[counter]->result_class = inverse_16(getInt16(resource->data + seeker));
+ seeker += 3; /* Next entry */
- ++counter;
+ ++counter;
- }
+ }
- *suffices_nr = counter;
- return suffices;
+ *suffices_nr = counter;
+ return suffices;
}
void
-vocab_free_suffices(resource_mgr_t *resmgr, suffix_t **suffices, int suffices_nr)
-{
- int i;
+vocab_free_suffices(resource_mgr_t *resmgr, suffix_t **suffices, int suffices_nr) {
+ int i;
- scir_unlock_resource(resmgr, scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0),
- VOCAB_RESOURCE_SUFFIX_VOCAB, sci_vocab);
+ scir_unlock_resource(resmgr, scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_SUFFIX_VOCAB, 0),
+ VOCAB_RESOURCE_SUFFIX_VOCAB, sci_vocab);
- for (i = 0; i < suffices_nr; i++)
- free(suffices[i]);
+ for (i = 0; i < suffices_nr; i++)
+ free(suffices[i]);
- free(suffices);
+ free(suffices);
}
void
-vocab_free_branches(parse_tree_branch_t *parser_branches)
-{
- if (parser_branches)
- free(parser_branches);
+vocab_free_branches(parse_tree_branch_t *parser_branches) {
+ if (parser_branches)
+ free(parser_branches);
}
parse_tree_branch_t *
-vocab_get_branches(resource_mgr_t * resmgr, int *branches_nr)
-{
- resource_t *resource = scir_find_resource(resmgr, sci_vocab,
- VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0);
- parse_tree_branch_t *retval;
- int i;
+vocab_get_branches(resource_mgr_t * resmgr, int *branches_nr) {
+ resource_t *resource = scir_find_resource(resmgr, sci_vocab,
+ VOCAB_RESOURCE_PARSE_TREE_BRANCHES, 0);
+ parse_tree_branch_t *retval;
+ int i;
- if (!resource) {
- fprintf(stderr,"No parser tree data found!\n");
- return NULL;
- }
+ if (!resource) {
+ fprintf(stderr, "No parser tree data found!\n");
+ return NULL;
+ }
- *branches_nr = resource->size / 20;
+ *branches_nr = resource->size / 20;
- if (*branches_nr == 0) {
- fprintf(stderr,"Parser tree data is empty!\n");
- return NULL;
- }
+ if (*branches_nr == 0) {
+ fprintf(stderr, "Parser tree data is empty!\n");
+ return NULL;
+ }
- retval = (parse_tree_branch_t*)sci_malloc(sizeof(parse_tree_branch_t) * *branches_nr);
+ retval = (parse_tree_branch_t*)sci_malloc(sizeof(parse_tree_branch_t) * *branches_nr);
- for (i = 0; i < *branches_nr; i++) {
- int k;
+ for (i = 0; i < *branches_nr; i++) {
+ int k;
- byte *base = resource->data + i*20;
+ byte *base = resource->data + i * 20;
- retval[i].id = getInt16(base);
+ retval[i].id = getInt16(base);
- for (k = 0; k < 9; k++)
- retval[i].data[k] = getUInt16(base + 2 + 2*k);
+ for (k = 0; k < 9; k++)
+ retval[i].data[k] = getUInt16(base + 2 + 2 * k);
- retval[i].data[9] = 0; /* Always terminate */
- }
+ retval[i].data[9] = 0; /* Always terminate */
+ }
- if (!retval[*branches_nr - 1].id) /* branch lists may be terminated by empty rules */
- --(*branches_nr);
+ if (!retval[*branches_nr - 1].id) /* branch lists may be terminated by empty rules */
+ --(*branches_nr);
- return retval;
+ return retval;
}
result_word_t *
vocab_lookup_word(char *word, int word_len,
- word_t **words, int words_nr,
- suffix_t **suffices, int suffices_nr)
-{
+ word_t **words, int words_nr,
+ suffix_t **suffices, int suffices_nr) {
word_t *tempword = (word_t*)sci_malloc(sizeof(word_t) + word_len + 256);
/* 256: For suffices. Should suffice. */
word_t **dict_word;
@@ -351,10 +341,10 @@ vocab_lookup_word(char *word, int word_len,
if (suffices[i]->alt_suffix_length <= word_len) {
int suff_index = word_len - suffices[i]->alt_suffix_length;
- /* Offset of the start of the suffix */
+ /* Offset of the start of the suffix */
if (strncasecmp(suffices[i]->alt_suffix, word + suff_index,
- suffices[i]->alt_suffix_length) == 0) { /* Suffix matched! */
+ suffices[i]->alt_suffix_length) == 0) { /* Suffix matched! */
strncpy(&(tempword->word[0]), word, word_len);
tempword->word[suff_index] = 0; /* Terminate word at suffix start position... */
@@ -383,7 +373,7 @@ vocab_lookup_word(char *word, int word_len,
memmove(tester, tester + 1, (tempword->word + word_len--) - tester);
if ((strtol(&(tempword->word[0]), &tester, 10) >= 0)
- && (*tester == '\0')) { /* Do we have a complete number here? */
+ && (*tester == '\0')) { /* Do we have a complete number here? */
free(tempword);
retval->group = VOCAB_MAGIC_NUMBER_GROUP;
@@ -398,18 +388,14 @@ vocab_lookup_word(char *word, int word_len,
}
int
-vocab_get_said_spec_length(byte *addr)
-{
+vocab_get_said_spec_length(byte *addr) {
int result = 0;
- while (*addr != 0xff)
- {
- if (*addr < 0xf0)
- {
+ while (*addr != 0xff) {
+ if (*addr < 0xf0) {
result += 2;
addr += 2;
- } else
- {
+ } else {
result += 1;
addr += 1;
}
@@ -419,8 +405,7 @@ vocab_get_said_spec_length(byte *addr)
}
void
-vocab_decypher_said_block(state_t *s, byte *addr)
-{
+vocab_decypher_said_block(state_t *s, byte *addr) {
int nextitem;
do {
@@ -429,22 +414,43 @@ vocab_decypher_said_block(state_t *s, byte *addr)
if (nextitem < 0xf0) {
nextitem = nextitem << 8 | *addr++;
sciprintf(" %s[%03x]", vocab_get_any_group_word(nextitem, s->parser_words, s->parser_words_nr),
- nextitem);
+ nextitem);
nextitem = 42; /* Make sure that group 0xff doesn't abort */
- } else switch(nextitem) {
- case 0xf0: sciprintf(" ,"); break;
- case 0xf1: sciprintf(" &"); break;
- case 0xf2: sciprintf(" /"); break;
- case 0xf3: sciprintf(" ("); break;
- case 0xf4: sciprintf(" )"); break;
- case 0xf5: sciprintf(" ["); break;
- case 0xf6: sciprintf(" ]"); break;
- case 0xf7: sciprintf(" #"); break;
- case 0xf8: sciprintf(" <"); break;
- case 0xf9: sciprintf(" >"); break;
- case 0xff: break;
- }
+ } else switch (nextitem) {
+ case 0xf0:
+ sciprintf(" ,");
+ break;
+ case 0xf1:
+ sciprintf(" &");
+ break;
+ case 0xf2:
+ sciprintf(" /");
+ break;
+ case 0xf3:
+ sciprintf(" (");
+ break;
+ case 0xf4:
+ sciprintf(" )");
+ break;
+ case 0xf5:
+ sciprintf(" [");
+ break;
+ case 0xf6:
+ sciprintf(" ]");
+ break;
+ case 0xf7:
+ sciprintf(" #");
+ break;
+ case 0xf8:
+ sciprintf(" <");
+ break;
+ case 0xf9:
+ sciprintf(" >");
+ break;
+ case 0xff:
+ break;
+ }
} while (nextitem != 0xff);
sciprintf("\n");
@@ -454,107 +460,105 @@ vocab_decypher_said_block(state_t *s, byte *addr)
#ifdef SCI_SIMPLE_SAID_CODE
static short _related_words[][2] = { /* 0 is backwards, 1 is forward */
- {0x800, 0x180}, /* preposition */
- {0x000, 0x180}, /* article */
- {0x000, 0x180}, /* adjective */
- {0x800, 0x000}, /* pronoun */
- {0x800, 0x180}, /* noun */
- {0x000, 0x800}, /* auxiliary verb */
- {0x800, 0x800}, /* adverb */
- {0x000, 0x180}, /* verb */
- {0x000, 0x180} /* number */
+ {0x800, 0x180}, /* preposition */
+ {0x000, 0x180}, /* article */
+ {0x000, 0x180}, /* adjective */
+ {0x800, 0x000}, /* pronoun */
+ {0x800, 0x180}, /* noun */
+ {0x000, 0x800}, /* auxiliary verb */
+ {0x800, 0x800}, /* adverb */
+ {0x000, 0x180}, /* verb */
+ {0x000, 0x180} /* number */
};
int
-vocab_build_simple_parse_tree(parse_tree_node_t *nodes, result_word_t *words, int words_nr)
-{
- int i, length, pos = 0;
-
- for (i = 0; i < words_nr; ++i) {
- if (words[i].classID != VOCAB_CLASS_ANYWORD) {
- nodes[pos].type = words[i].classID;
- nodes[pos].content.value = words[i].group;
- pos += 2; /* Link information is filled in below */
- }
- }
- nodes[pos].type = -1; /* terminate */
- length = pos >> 1;
-
- /* now find all referenced words */
+vocab_build_simple_parse_tree(parse_tree_node_t *nodes, result_word_t *words, int words_nr) {
+ int i, length, pos = 0;
+
+ for (i = 0; i < words_nr; ++i) {
+ if (words[i].classID != VOCAB_CLASS_ANYWORD) {
+ nodes[pos].type = words[i].classID;
+ nodes[pos].content.value = words[i].group;
+ pos += 2; /* Link information is filled in below */
+ }
+ }
+ nodes[pos].type = -1; /* terminate */
+ length = pos >> 1;
+
+ /* now find all referenced words */
#ifdef SCI_SIMPLE_SAID_DEBUG
- sciprintf("Semantic references:\n");
+ sciprintf("Semantic references:\n");
#endif
- for (i = 0; i < length; i++) {
- int j;
- int searchmask;
- int type;
+ for (i = 0; i < length; i++) {
+ int j;
+ int searchmask;
+ int type;
- pos = (i << 1);
- type = sci_ffs(nodes[pos].type);
+ pos = (i << 1);
+ type = sci_ffs(nodes[pos].type);
- if (type) {
- int found = -1;
+ if (type) {
+ int found = -1;
- type -= 5; /* 1 because ffs starts counting at 1, 4 because nodes[pos].type is a nibble off */
- if (type < 0)
- type = 0;
+ type -= 5; /* 1 because ffs starts counting at 1, 4 because nodes[pos].type is a nibble off */
+ if (type < 0)
+ type = 0;
#ifdef SCI_SIMPLE_SAID_DEBUG
- sciprintf("#%d: Word %04x: type %04x\n", i, nodes[pos].content.value, type);
+ sciprintf("#%d: Word %04x: type %04x\n", i, nodes[pos].content.value, type);
#endif
- /* search backwards */
- searchmask = _related_words[type][0];
- if (searchmask) {
- for (j = i-1; j >= 0; j--)
- if (nodes[j << 1].type & searchmask) {
- found = j << 1;
- break;
- }
- }
- nodes[pos+1].content.branches[0] = found;
+ /* search backwards */
+ searchmask = _related_words[type][0];
+ if (searchmask) {
+ for (j = i - 1; j >= 0; j--)
+ if (nodes[j << 1].type & searchmask) {
+ found = j << 1;
+ break;
+ }
+ }
+ nodes[pos+1].content.branches[0] = found;
#ifdef SCI_SIMPLE_SAID_DEBUG
- if (found > -1)
- sciprintf(" %d <\n", found >> 1);
+ if (found > -1)
+ sciprintf(" %d <\n", found >> 1);
#endif
- /* search forward */
- found = -1;
- searchmask = _related_words[type][1];
- if (searchmask) {
- for (j = i+1; j < length; j++)
- if (nodes[j << 1].type & searchmask) {
- found = j << 1;
- break;
- }
- }
+ /* search forward */
+ found = -1;
+ searchmask = _related_words[type][1];
+ if (searchmask) {
+ for (j = i + 1; j < length; j++)
+ if (nodes[j << 1].type & searchmask) {
+ found = j << 1;
+ break;
+ }
+ }
#ifdef SCI_SIMPLE_SAID_DEBUG
- if (found > -1)
- sciprintf(" > %d\n", found >> 1);
+ if (found > -1)
+ sciprintf(" > %d\n", found >> 1);
#endif
- } else {
+ } else {
#ifdef SCI_SIMPLE_SAID_DEBUG
- sciprintf("#%d: Untypified word\n", i); /* Weird, but not fatal */
+ sciprintf("#%d: Untypified word\n", i); /* Weird, but not fatal */
#endif
- nodes[pos+1].content.branches[0] = -1;
- nodes[pos+1].content.branches[1] = -1;
- }
- }
+ nodes[pos+1].content.branches[0] = -1;
+ nodes[pos+1].content.branches[1] = -1;
+ }
+ }
#ifdef SCI_SIMPLE_SAID_DEBUG
- sciprintf("/Semantic references.\n");
+ sciprintf("/Semantic references.\n");
#endif
- return 0;
+ return 0;
}
#endif
result_word_t *
vocab_tokenize_string(char *sentence, int *result_nr,
- word_t **words, int words_nr,
- suffix_t **suffices, int suffices_nr,
- char **error)
-{
+ word_t **words, int words_nr,
+ suffix_t **suffices, int suffices_nr,
+ char **error) {
char *lastword = sentence;
int pos_in_sentence = 0;
char c;
@@ -572,19 +576,19 @@ vocab_tokenize_string(char *sentence, int *result_nr,
c = sentence[pos_in_sentence++];
- if (isalnum(c) || (c=='-' && wordlen))
+ if (isalnum(c) || (c == '-' && wordlen))
++wordlen; /* Continue on this word */
- /* Words may contain a '-', but may not
- ** start with one. */
+ /* Words may contain a '-', but may not
+ ** start with one. */
else {
if (wordlen) { /* Finished a word? */
lookup_result =
- vocab_lookup_word(lastword, wordlen,
- words, words_nr,
- suffices, suffices_nr);
+ vocab_lookup_word(lastword, wordlen,
+ words, words_nr,
+ suffices, suffices_nr);
/* Look it up */
if (!lookup_result) { /* Not found? */
@@ -619,95 +623,91 @@ vocab_tokenize_string(char *sentence, int *result_nr,
void
-_vocab_recursive_ptree_dump_treelike(parse_tree_node_t *nodes, int nr, int prevnr)
-{
- if ((nr > VOCAB_TREE_NODES)/* || (nr < prevnr)*/) {
- sciprintf("Error(%04x)", nr);
- return;
- }
-
- if (nodes[nr].type == PARSE_TREE_NODE_LEAF)
- /* sciprintf("[%03x]%04x", nr, nodes[nr].content.value); */
- sciprintf("%x", nodes[nr].content.value);
- else {
- int lbranch = nodes[nr].content.branches[0];
- int rbranch = nodes[nr].content.branches[1];
- /* sciprintf("<[%03x]",nr); */
- sciprintf("<");
-
- if (lbranch)
- _vocab_recursive_ptree_dump_treelike(nodes, lbranch, nr);
- else sciprintf("NULL");
-
- sciprintf(",");
-
- if (rbranch)
- _vocab_recursive_ptree_dump_treelike(nodes, rbranch, nr);
- else sciprintf("NULL");
-
- sciprintf(">");
- }
+_vocab_recursive_ptree_dump_treelike(parse_tree_node_t *nodes, int nr, int prevnr) {
+ if ((nr > VOCAB_TREE_NODES)/* || (nr < prevnr)*/) {
+ sciprintf("Error(%04x)", nr);
+ return;
+ }
+
+ if (nodes[nr].type == PARSE_TREE_NODE_LEAF)
+ /* sciprintf("[%03x]%04x", nr, nodes[nr].content.value); */
+ sciprintf("%x", nodes[nr].content.value);
+ else {
+ int lbranch = nodes[nr].content.branches[0];
+ int rbranch = nodes[nr].content.branches[1];
+ /* sciprintf("<[%03x]",nr); */
+ sciprintf("<");
+
+ if (lbranch)
+ _vocab_recursive_ptree_dump_treelike(nodes, lbranch, nr);
+ else sciprintf("NULL");
+
+ sciprintf(",");
+
+ if (rbranch)
+ _vocab_recursive_ptree_dump_treelike(nodes, rbranch, nr);
+ else sciprintf("NULL");
+
+ sciprintf(">");
+ }
}
void
-_vocab_recursive_ptree_dump(parse_tree_node_t *nodes, int nr, int prevnr, int blanks)
-{
- int lbranch = nodes[nr].content.branches[0];
- int rbranch = nodes[nr].content.branches[1];
- int i;
-
- if (nodes[nr].type == PARSE_TREE_NODE_LEAF) {
- sciprintf("vocab_dump_parse_tree: Error: consp is nil for element %03x\n", nr);
- return;
- }
-
- if ((nr > VOCAB_TREE_NODES)/* || (nr < prevnr)*/) {
- sciprintf("Error(%04x))", nr);
- return;
- }
-
- if (lbranch) {
- if (nodes[lbranch].type == PARSE_TREE_NODE_BRANCH) {
- sciprintf("\n");
- for (i = 0; i < blanks; i++)
- sciprintf(" ");
- sciprintf("(");
- _vocab_recursive_ptree_dump(nodes, lbranch, nr, blanks + 1);
- sciprintf(")\n");
- for (i = 0; i < blanks; i++)
- sciprintf(" ");
- } else
- sciprintf("%x", nodes[lbranch].content.value);
- sciprintf(" ");
- }/* else sciprintf ("nil"); */
-
- if (rbranch) {
- if (nodes[rbranch].type == PARSE_TREE_NODE_BRANCH)
- _vocab_recursive_ptree_dump(nodes, rbranch, nr, blanks);
- else
- sciprintf("%x", nodes[rbranch].content.value);
- }/* else sciprintf("nil");*/
+_vocab_recursive_ptree_dump(parse_tree_node_t *nodes, int nr, int prevnr, int blanks) {
+ int lbranch = nodes[nr].content.branches[0];
+ int rbranch = nodes[nr].content.branches[1];
+ int i;
+
+ if (nodes[nr].type == PARSE_TREE_NODE_LEAF) {
+ sciprintf("vocab_dump_parse_tree: Error: consp is nil for element %03x\n", nr);
+ return;
+ }
+
+ if ((nr > VOCAB_TREE_NODES)/* || (nr < prevnr)*/) {
+ sciprintf("Error(%04x))", nr);
+ return;
+ }
+
+ if (lbranch) {
+ if (nodes[lbranch].type == PARSE_TREE_NODE_BRANCH) {
+ sciprintf("\n");
+ for (i = 0; i < blanks; i++)
+ sciprintf(" ");
+ sciprintf("(");
+ _vocab_recursive_ptree_dump(nodes, lbranch, nr, blanks + 1);
+ sciprintf(")\n");
+ for (i = 0; i < blanks; i++)
+ sciprintf(" ");
+ } else
+ sciprintf("%x", nodes[lbranch].content.value);
+ sciprintf(" ");
+ }/* else sciprintf ("nil"); */
+
+ if (rbranch) {
+ if (nodes[rbranch].type == PARSE_TREE_NODE_BRANCH)
+ _vocab_recursive_ptree_dump(nodes, rbranch, nr, blanks);
+ else
+ sciprintf("%x", nodes[rbranch].content.value);
+ }/* else sciprintf("nil");*/
}
void
-vocab_dump_parse_tree(const char *tree_name, parse_tree_node_t *nodes)
-{
- /* _vocab_recursive_ptree_dump_treelike(nodes, 0, 0); */
- sciprintf("(setq %s \n'(", tree_name);
- _vocab_recursive_ptree_dump(nodes, 0, 0, 1);
- sciprintf("))\n");
+vocab_dump_parse_tree(const char *tree_name, parse_tree_node_t *nodes) {
+ /* _vocab_recursive_ptree_dump_treelike(nodes, 0, 0); */
+ sciprintf("(setq %s \n'(", tree_name);
+ _vocab_recursive_ptree_dump(nodes, 0, 0, 1);
+ sciprintf("))\n");
}
void
-vocab_synonymize_tokens(result_word_t *words, int words_nr, synonym_t *synonyms, int synonyms_nr)
-{
+vocab_synonymize_tokens(result_word_t *words, int words_nr, synonym_t *synonyms, int synonyms_nr) {
int i, sync;
if (!synonyms || !synonyms_nr)
return; /* No synonyms: Nothing to check */
for (i = 0; i < words_nr; i++)
- for(sync = 0; sync < synonyms_nr; sync++)
+ for (sync = 0; sync < synonyms_nr; sync++)
if (words[i].group == synonyms[sync].replaceant)
words[i].group = synonyms[sync].replacement;
}
diff --git a/engines/sci/scicore/vocab_debug.cpp b/engines/sci/scicore/vocab_debug.cpp
index 6e22320ee2..490664da6a 100644
--- a/engines/sci/scicore/vocab_debug.cpp
+++ b/engines/sci/scicore/vocab_debug.cpp
@@ -11,264 +11,249 @@
#define SCI0_KNAMES_WELL_DEFINED 0x6e
#define SCI0_KNAMES_DEFAULT_ENTRIES_NR 0x72
-const char *sci0_default_knames[SCI0_KNAMES_DEFAULT_ENTRIES_NR] =
-{
-/*0x00*/ "Load",
-/*0x01*/ "UnLoad",
-/*0x02*/ "ScriptID",
-/*0x03*/ "DisposeScript",
-/*0x04*/ "Clone",
-/*0x05*/ "DisposeClone",
-/*0x06*/ "IsObject",
-/*0x07*/ "RespondsTo",
-/*0x08*/ "DrawPic",
-/*0x09*/ "Show",
-/*0x0a*/ "PicNotValid",
-/*0x0b*/ "Animate",
-/*0x0c*/ "SetNowSeen",
-/*0x0d*/ "NumLoops",
-/*0x0e*/ "NumCels",
-/*0x0f*/ "CelWide",
-/*0x10*/ "CelHigh",
-/*0x11*/ "DrawCel",
-/*0x12*/ "AddToPic",
-/*0x13*/ "NewWindow",
-/*0x14*/ "GetPort",
-/*0x15*/ "SetPort",
-/*0x16*/ "DisposeWindow",
-/*0x17*/ "DrawControl",
-/*0x18*/ "HiliteControl",
-/*0x19*/ "EditControl",
-/*0x1a*/ "TextSize",
-/*0x1b*/ "Display",
-/*0x1c*/ "GetEvent",
-/*0x1d*/ "GlobalToLocal",
-/*0x1e*/ "LocalToGlobal",
-/*0x1f*/ "MapKeyToDir",
-/*0x20*/ "DrawMenuBar",
-/*0x21*/ "MenuSelect",
-/*0x22*/ "AddMenu",
-/*0x23*/ "DrawStatus",
-/*0x24*/ "Parse",
-/*0x25*/ "Said",
-/*0x26*/ "SetSynonyms",
-/*0x27*/ "HaveMouse",
-/*0x28*/ "SetCursor",
-/*0x29*/ "FOpen",
-/*0x2a*/ "FPuts",
-/*0x2b*/ "FGets",
-/*0x2c*/ "FClose",
-/*0x2d*/ "SaveGame",
-/*0x2e*/ "RestoreGame",
-/*0x2f*/ "RestartGame",
-/*0x30*/ "GameIsRestarting",
-/*0x31*/ "DoSound",
-/*0x32*/ "NewList",
-/*0x33*/ "DisposeList",
-/*0x34*/ "NewNode",
-/*0x35*/ "FirstNode",
-/*0x36*/ "LastNode",
-/*0x37*/ "EmptyList",
-/*0x38*/ "NextNode",
-/*0x39*/ "PrevNode",
-/*0x3a*/ "NodeValue",
-/*0x3b*/ "AddAfter",
-/*0x3c*/ "AddToFront",
-/*0x3d*/ "AddToEnd",
-/*0x3e*/ "FindKey",
-/*0x3f*/ "DeleteKey",
-/*0x40*/ "Random",
-/*0x41*/ "Abs",
-/*0x42*/ "Sqrt",
-/*0x43*/ "GetAngle",
-/*0x44*/ "GetDistance",
-/*0x45*/ "Wait",
-/*0x46*/ "GetTime",
-/*0x47*/ "StrEnd",
-/*0x48*/ "StrCat",
-/*0x49*/ "StrCmp",
-/*0x4a*/ "StrLen",
-/*0x4b*/ "StrCpy",
-/*0x4c*/ "Format",
-/*0x4d*/ "GetFarText",
-/*0x4e*/ "ReadNumber",
-/*0x4f*/ "BaseSetter",
-/*0x50*/ "DirLoop",
-/*0x51*/ "CanBeHere",
-/*0x52*/ "OnControl",
-/*0x53*/ "InitBresen",
-/*0x54*/ "DoBresen",
-/*0x55*/ "DoAvoider",
-/*0x56*/ "SetJump",
-/*0x57*/ "SetDebug",
-/*0x58*/ "InspectObj",
-/*0x59*/ "ShowSends",
-/*0x5a*/ "ShowObjs",
-/*0x5b*/ "ShowFree",
-/*0x5c*/ "MemoryInfo",
-/*0x5d*/ "StackUsage",
-/*0x5e*/ "Profiler",
-/*0x5f*/ "GetMenu",
-/*0x60*/ "SetMenu",
-/*0x61*/ "GetSaveFiles",
-/*0x62*/ "GetCWD",
-/*0x63*/ "CheckFreeSpace",
-/*0x64*/ "ValidPath",
-/*0x65*/ "CoordPri",
-/*0x66*/ "StrAt",
-/*0x67*/ "DeviceInfo",
-/*0x68*/ "GetSaveDir",
-/*0x69*/ "CheckSaveGame",
-/*0x6a*/ "ShakeScreen",
-/*0x6b*/ "FlushResources",
-/*0x6c*/ "SinMult",
-/*0x6d*/ "CosMult",
-/*0x6e*/ "SinDiv",
-/*0x6f*/ "CosDiv",
-/*0x70*/ "Graph",
-/*0x71*/ SCRIPT_UNKNOWN_FUNCTION_STRING
+const char *sci0_default_knames[SCI0_KNAMES_DEFAULT_ENTRIES_NR] = {
+ /*0x00*/ "Load",
+ /*0x01*/ "UnLoad",
+ /*0x02*/ "ScriptID",
+ /*0x03*/ "DisposeScript",
+ /*0x04*/ "Clone",
+ /*0x05*/ "DisposeClone",
+ /*0x06*/ "IsObject",
+ /*0x07*/ "RespondsTo",
+ /*0x08*/ "DrawPic",
+ /*0x09*/ "Show",
+ /*0x0a*/ "PicNotValid",
+ /*0x0b*/ "Animate",
+ /*0x0c*/ "SetNowSeen",
+ /*0x0d*/ "NumLoops",
+ /*0x0e*/ "NumCels",
+ /*0x0f*/ "CelWide",
+ /*0x10*/ "CelHigh",
+ /*0x11*/ "DrawCel",
+ /*0x12*/ "AddToPic",
+ /*0x13*/ "NewWindow",
+ /*0x14*/ "GetPort",
+ /*0x15*/ "SetPort",
+ /*0x16*/ "DisposeWindow",
+ /*0x17*/ "DrawControl",
+ /*0x18*/ "HiliteControl",
+ /*0x19*/ "EditControl",
+ /*0x1a*/ "TextSize",
+ /*0x1b*/ "Display",
+ /*0x1c*/ "GetEvent",
+ /*0x1d*/ "GlobalToLocal",
+ /*0x1e*/ "LocalToGlobal",
+ /*0x1f*/ "MapKeyToDir",
+ /*0x20*/ "DrawMenuBar",
+ /*0x21*/ "MenuSelect",
+ /*0x22*/ "AddMenu",
+ /*0x23*/ "DrawStatus",
+ /*0x24*/ "Parse",
+ /*0x25*/ "Said",
+ /*0x26*/ "SetSynonyms",
+ /*0x27*/ "HaveMouse",
+ /*0x28*/ "SetCursor",
+ /*0x29*/ "FOpen",
+ /*0x2a*/ "FPuts",
+ /*0x2b*/ "FGets",
+ /*0x2c*/ "FClose",
+ /*0x2d*/ "SaveGame",
+ /*0x2e*/ "RestoreGame",
+ /*0x2f*/ "RestartGame",
+ /*0x30*/ "GameIsRestarting",
+ /*0x31*/ "DoSound",
+ /*0x32*/ "NewList",
+ /*0x33*/ "DisposeList",
+ /*0x34*/ "NewNode",
+ /*0x35*/ "FirstNode",
+ /*0x36*/ "LastNode",
+ /*0x37*/ "EmptyList",
+ /*0x38*/ "NextNode",
+ /*0x39*/ "PrevNode",
+ /*0x3a*/ "NodeValue",
+ /*0x3b*/ "AddAfter",
+ /*0x3c*/ "AddToFront",
+ /*0x3d*/ "AddToEnd",
+ /*0x3e*/ "FindKey",
+ /*0x3f*/ "DeleteKey",
+ /*0x40*/ "Random",
+ /*0x41*/ "Abs",
+ /*0x42*/ "Sqrt",
+ /*0x43*/ "GetAngle",
+ /*0x44*/ "GetDistance",
+ /*0x45*/ "Wait",
+ /*0x46*/ "GetTime",
+ /*0x47*/ "StrEnd",
+ /*0x48*/ "StrCat",
+ /*0x49*/ "StrCmp",
+ /*0x4a*/ "StrLen",
+ /*0x4b*/ "StrCpy",
+ /*0x4c*/ "Format",
+ /*0x4d*/ "GetFarText",
+ /*0x4e*/ "ReadNumber",
+ /*0x4f*/ "BaseSetter",
+ /*0x50*/ "DirLoop",
+ /*0x51*/ "CanBeHere",
+ /*0x52*/ "OnControl",
+ /*0x53*/ "InitBresen",
+ /*0x54*/ "DoBresen",
+ /*0x55*/ "DoAvoider",
+ /*0x56*/ "SetJump",
+ /*0x57*/ "SetDebug",
+ /*0x58*/ "InspectObj",
+ /*0x59*/ "ShowSends",
+ /*0x5a*/ "ShowObjs",
+ /*0x5b*/ "ShowFree",
+ /*0x5c*/ "MemoryInfo",
+ /*0x5d*/ "StackUsage",
+ /*0x5e*/ "Profiler",
+ /*0x5f*/ "GetMenu",
+ /*0x60*/ "SetMenu",
+ /*0x61*/ "GetSaveFiles",
+ /*0x62*/ "GetCWD",
+ /*0x63*/ "CheckFreeSpace",
+ /*0x64*/ "ValidPath",
+ /*0x65*/ "CoordPri",
+ /*0x66*/ "StrAt",
+ /*0x67*/ "DeviceInfo",
+ /*0x68*/ "GetSaveDir",
+ /*0x69*/ "CheckSaveGame",
+ /*0x6a*/ "ShakeScreen",
+ /*0x6b*/ "FlushResources",
+ /*0x6c*/ "SinMult",
+ /*0x6d*/ "CosMult",
+ /*0x6e*/ "SinDiv",
+ /*0x6f*/ "CosDiv",
+ /*0x70*/ "Graph",
+ /*0x71*/ SCRIPT_UNKNOWN_FUNCTION_STRING
};
-int getInt(unsigned char* d)
-{
- return d[0] | (d[1]<<8);
+int getInt(unsigned char* d) {
+ return d[0] | (d[1] << 8);
}
-int* vocabulary_get_classes(resource_mgr_t *resmgr, int* count)
-{
- resource_t* r;
- int *c;
- unsigned int i;
+int* vocabulary_get_classes(resource_mgr_t *resmgr, int* count) {
+ resource_t* r;
+ int *c;
+ unsigned int i;
- if((r = scir_find_resource(resmgr, sci_vocab, 996, 0)) == NULL) return 0;
+ if ((r = scir_find_resource(resmgr, sci_vocab, 996, 0)) == NULL) return 0;
- c= (int*)sci_malloc(sizeof(int)*r->size/2);
- for(i=2; i<r->size; i+=4)
- {
- c[i/4]=getInt(r->data+i);
- }
- *count=r->size/4;
+ c = (int*)sci_malloc(sizeof(int) * r->size / 2);
+ for (i = 2; i < r->size; i += 4) {
+ c[i/4] = getInt(r->data + i);
+ }
+ *count = r->size / 4;
- return c;
+ return c;
}
-int vocabulary_get_class_count(resource_mgr_t *resmgr)
-{
- resource_t* r;
- if((r = scir_find_resource(resmgr, sci_vocab, 996, 0))==0) return 0;
- return r->size/4;
+int vocabulary_get_class_count(resource_mgr_t *resmgr) {
+ resource_t* r;
+ if ((r = scir_find_resource(resmgr, sci_vocab, 996, 0)) == 0) return 0;
+ return r->size / 4;
}
-char** vocabulary_get_snames(resource_mgr_t *resmgr, int* pcount, sci_version_t version)
-{
- char** t;
- int count;
- int i,j;
- int magic;
+char** vocabulary_get_snames(resource_mgr_t *resmgr, int* pcount, sci_version_t version) {
+ char** t;
+ int count;
+ int i, j;
+ int magic;
- resource_t* r = scir_find_resource(resmgr, sci_vocab, 997, 0);
+ resource_t* r = scir_find_resource(resmgr, sci_vocab, 997, 0);
- if (!r) /* No such resource? */
- return NULL;
+ if (!r) /* No such resource? */
+ return NULL;
- count=getInt(r->data) + 1; /* Counter is slightly off */
+ count = getInt(r->data) + 1; /* Counter is slightly off */
- magic=((version==0) || (version>=SCI_VERSION_FTU_NEW_SCRIPT_HEADER))? 1 : 2;
+ magic = ((version == 0) || (version >= SCI_VERSION_FTU_NEW_SCRIPT_HEADER)) ? 1 : 2;
- t= (char**)sci_malloc(sizeof(char*)*magic*(count+1));
+ t = (char**)sci_malloc(sizeof(char*) * magic * (count + 1));
- j=0;
+ j = 0;
- for(i=0; i<count; i++)
- {
- int offset=getInt(r->data+2+i*2);
- int len=getInt(r->data+offset);
- t[j]= (char*)sci_malloc(len+1);
- memcpy(t[j], r->data+offset+2, len);
- t[j][len]='\0';
- j++;
- if ((version!=0) && (version<SCI_VERSION_FTU_NEW_SCRIPT_HEADER))
- {
- t[j]= (char*)sci_malloc(len+1);
- memcpy(t[j], r->data+offset+2, len);
- t[j][len]='\0';
- j++;
- }
- }
+ for (i = 0; i < count; i++) {
+ int offset = getInt(r->data + 2 + i * 2);
+ int len = getInt(r->data + offset);
+ t[j] = (char*)sci_malloc(len + 1);
+ memcpy(t[j], r->data + offset + 2, len);
+ t[j][len] = '\0';
+ j++;
+ if ((version != 0) && (version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER)) {
+ t[j] = (char*)sci_malloc(len + 1);
+ memcpy(t[j], r->data + offset + 2, len);
+ t[j][len] = '\0';
+ j++;
+ }
+ }
- t[j]=0;
+ t[j] = 0;
- if (pcount != NULL) *pcount=magic*count;
+ if (pcount != NULL) *pcount = magic * count;
- return t;
+ return t;
}
int
-vocabulary_lookup_sname(char **snames_list, char *sname)
-{
- int pos = 0;
- while (snames_list[pos])
- {
- if (!strcasecmp(sname, snames_list[pos])) return pos;
- pos++;
- }
-
- return -1;
+vocabulary_lookup_sname(char **snames_list, char *sname) {
+ int pos = 0;
+ while (snames_list[pos]) {
+ if (!strcasecmp(sname, snames_list[pos])) return pos;
+ pos++;
+ }
+
+ return -1;
}
void
-vocabulary_free_snames(char **snames_list)
-{
- int pos = 0;
+vocabulary_free_snames(char **snames_list) {
+ int pos = 0;
- while (snames_list[pos])
- free(snames_list[pos++]);
+ while (snames_list[pos])
+ free(snames_list[pos++]);
- free(snames_list);
+ free(snames_list);
}
-opcode* vocabulary_get_opcodes(resource_mgr_t *resmgr)
-{
+opcode* vocabulary_get_opcodes(resource_mgr_t *resmgr) {
opcode* o;
- int count, i=0;
+ int count, i = 0;
resource_t* r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_OPCODES, 0);
/* if the resource couldn't be loaded, leave */
if (r == NULL) {
- fprintf(stderr,"unable to load vocab.%03d\n", VOCAB_RESOURCE_OPCODES);
+ fprintf(stderr, "unable to load vocab.%03d\n", VOCAB_RESOURCE_OPCODES);
return NULL;
}
- count=getInt(r->data);
-
- o= (opcode*)sci_malloc(sizeof(opcode)*256);
- for(i=0; i<count; i++)
- {
- int offset=getInt(r->data+2+i*2);
- int len=getInt(r->data+offset)-2;
- o[i].type=getInt(r->data+offset+2);
- o[i].number=i;
- o[i].name= (char*)sci_malloc(len+1);
- memcpy(o[i].name, r->data+offset+4, len);
- o[i].name[len]='\0';
+ count = getInt(r->data);
+
+ o = (opcode*)sci_malloc(sizeof(opcode) * 256);
+ for (i = 0; i < count; i++) {
+ int offset = getInt(r->data + 2 + i * 2);
+ int len = getInt(r->data + offset) - 2;
+ o[i].type = getInt(r->data + offset + 2);
+ o[i].number = i;
+ o[i].name = (char*)sci_malloc(len + 1);
+ memcpy(o[i].name, r->data + offset + 4, len);
+ o[i].name[len] = '\0';
#ifdef VOCABULARY_DEBUG
- printf("Opcode %02X: %s, %d\n", i, o[i].name, o[i].type);
+ printf("Opcode %02X: %s, %d\n", i, o[i].name, o[i].type);
#endif
- }
- for(i=count; i<256; i++)
- {
- o[i].type=0;
- o[i].number=i;
- o[i].name= (char*)sci_malloc(strlen("undefined")+1);
- strcpy(o[i].name, "undefined");
- }
+ }
+ for (i = count; i < 256; i++) {
+ o[i].type = 0;
+ o[i].number = i;
+ o[i].name = (char*)sci_malloc(strlen("undefined") + 1);
+ strcpy(o[i].name, "undefined");
+ }
return o;
}
void
-vocabulary_free_opcodes(opcode *opcodes)
-{
+vocabulary_free_opcodes(opcode *opcodes) {
int i;
if (!opcodes)
return;
@@ -282,48 +267,46 @@ vocabulary_free_opcodes(opcode *opcodes)
/* Alternative kernel func names retriever. Required for KQ1/SCI (at least). */
-static char** _vocabulary_get_knames0alt(int *names, resource_t *r)
-{
- unsigned int mallocsize = 32;
- char **retval = (char**)sci_malloc(sizeof (char *) * mallocsize);
- unsigned int i = 0, index = 0;
+static char** _vocabulary_get_knames0alt(int *names, resource_t *r) {
+ unsigned int mallocsize = 32;
+ char **retval = (char**)sci_malloc(sizeof(char *) * mallocsize);
+ unsigned int i = 0, index = 0;
- while (index < r->size) {
+ while (index < r->size) {
- int slen = strlen((char *) r->data + index) + 1;
+ int slen = strlen((char *) r->data + index) + 1;
- retval[i] = (char*)sci_malloc(slen);
- memcpy(retval[i++], r->data + index, slen);
- /* Wouldn't normally read this, but the cleanup code wants to free() this */
+ retval[i] = (char*)sci_malloc(slen);
+ memcpy(retval[i++], r->data + index, slen);
+ /* Wouldn't normally read this, but the cleanup code wants to free() this */
- index += slen;
+ index += slen;
- if (i == mallocsize)
- retval = (char**)sci_realloc(retval, sizeof(char *) * (mallocsize <<= 1));
+ if (i == mallocsize)
+ retval = (char**)sci_realloc(retval, sizeof(char *) * (mallocsize <<= 1));
- }
+ }
- *names = i + 1;
- retval = (char**)sci_realloc(retval, sizeof(char *) * (i+2));
- retval[i] = (char*)sci_malloc(strlen(SCRIPT_UNKNOWN_FUNCTION_STRING) + 1);
- strcpy(retval[i], SCRIPT_UNKNOWN_FUNCTION_STRING);
- /* The mystery kernel function- one in each SCI0 package */
+ *names = i + 1;
+ retval = (char**)sci_realloc(retval, sizeof(char *) * (i + 2));
+ retval[i] = (char*)sci_malloc(strlen(SCRIPT_UNKNOWN_FUNCTION_STRING) + 1);
+ strcpy(retval[i], SCRIPT_UNKNOWN_FUNCTION_STRING);
+ /* The mystery kernel function- one in each SCI0 package */
- retval[i+1] = NULL; /* Required for cleanup */
+ retval[i+1] = NULL; /* Required for cleanup */
- return retval;
+ return retval;
}
-static char** vocabulary_get_knames0(resource_mgr_t *resmgr, int* names)
-{
+static char** vocabulary_get_knames0(resource_mgr_t *resmgr, int* names) {
char** t;
- int count, i, index=2, empty_to_add = 1;
+ int count, i, index = 2, empty_to_add = 1;
resource_t* r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_KNAMES, 0);
if (!r) { /* No kernel name table found? Fall back to default table */
- t = (char**)sci_malloc ((SCI0_KNAMES_DEFAULT_ENTRIES_NR + 1) * sizeof(char*));
+ t = (char**)sci_malloc((SCI0_KNAMES_DEFAULT_ENTRIES_NR + 1) * sizeof(char*));
*names = SCI0_KNAMES_DEFAULT_ENTRIES_NR - 1; /* index of last element */
for (i = 0; i < SCI0_KNAMES_DEFAULT_ENTRIES_NR; i++)
@@ -334,7 +317,7 @@ static char** vocabulary_get_knames0(resource_mgr_t *resmgr, int* names)
return t;
}
- count=getInt(r->data);
+ count = getInt(r->data);
if (count > 1023)
return _vocabulary_get_knames0alt(names, r);
@@ -344,75 +327,71 @@ static char** vocabulary_get_knames0(resource_mgr_t *resmgr, int* names)
sciprintf("Less than %d kernel functions; adding %d\n", SCI0_KNAMES_WELL_DEFINED, empty_to_add);
}
- t= (char**)sci_malloc(sizeof(char*)*(count+1 + empty_to_add));
- for(i=0; i<count; i++) {
- int offset=getInt(r->data+index);
- int len=getInt(r->data+offset);
+ t = (char**)sci_malloc(sizeof(char*) * (count + 1 + empty_to_add));
+ for (i = 0; i < count; i++) {
+ int offset = getInt(r->data + index);
+ int len = getInt(r->data + offset);
/*fprintf(stderr,"Getting name %d of %d...\n", i, count);*/
- index+=2;
- t[i]= (char*)sci_malloc(len+1);
+ index += 2;
+ t[i] = (char*)sci_malloc(len + 1);
memcpy(t[i], r->data + offset + 2, len);
- t[i][len]='\0';
+ t[i][len] = '\0';
}
for (i = 0; i < empty_to_add; i++) {
- t[count + i] = (char*)sci_malloc(strlen(SCRIPT_UNKNOWN_FUNCTION_STRING) +1);
+ t[count + i] = (char*)sci_malloc(strlen(SCRIPT_UNKNOWN_FUNCTION_STRING) + 1);
strcpy(t[count + i], SCRIPT_UNKNOWN_FUNCTION_STRING);
}
- t[count+empty_to_add]=0;
- *names=count + empty_to_add;
+ t[count+empty_to_add] = 0;
+ *names = count + empty_to_add;
return t;
}
/*NOTE: Untested*/
-static char** vocabulary_get_knames1(resource_mgr_t *resmgr, int *count)
-{
- char** t=NULL;
- unsigned int size=64, used=0, pos=0;
- resource_t* r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_KNAMES, 0);
-
- while(pos<r->size)
- {
- int len;
- if ((used==size-1)||(!t))
- {
- size*=2;
- t= (char**)sci_realloc(t, size*sizeof(char*));
+static char** vocabulary_get_knames1(resource_mgr_t *resmgr, int *count) {
+ char** t = NULL;
+ unsigned int size = 64, used = 0, pos = 0;
+ resource_t* r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_KNAMES, 0);
+
+ while (pos < r->size) {
+ int len;
+ if ((used == size - 1) || (!t)) {
+ size *= 2;
+ t = (char**)sci_realloc(t, size * sizeof(char*));
+ }
+ len = strlen((char *) r->data + pos);
+ t[used] = (char*)sci_malloc(len + 1);
+ strcpy(t[used], (char *) r->data + pos);
+ used++;
+ pos += len + 1;
}
- len=strlen((char *) r->data+pos);
- t[used]= (char*)sci_malloc(len+1);
- strcpy(t[used], (char *) r->data+pos);
- used++;
- pos+=len+1;
- }
- *count=used;
- t= (char**)sci_realloc(t, (used+1)*sizeof(char*));
- t[used]=NULL;
- return t;
+ *count = used;
+ t = (char**)sci_realloc(t, (used + 1) * sizeof(char*));
+ t[used] = NULL;
+ return t;
}
-char** vocabulary_get_knames(resource_mgr_t *resmgr, int* count)
-{
- switch(resmgr->sci_version)
- {
- case SCI_VERSION_0:
- case SCI_VERSION_01:
- case SCI_VERSION_01_VGA:
- case SCI_VERSION_01_VGA_ODD: return vocabulary_get_knames0(resmgr, count);
- case SCI_VERSION_1_EARLY:
- case SCI_VERSION_1_LATE:
- case SCI_VERSION_1_1:
- case SCI_VERSION_32: return vocabulary_get_knames1(resmgr, count);
- default: return 0;
+char** vocabulary_get_knames(resource_mgr_t *resmgr, int* count) {
+ switch (resmgr->sci_version) {
+ case SCI_VERSION_0:
+ case SCI_VERSION_01:
+ case SCI_VERSION_01_VGA:
+ case SCI_VERSION_01_VGA_ODD:
+ return vocabulary_get_knames0(resmgr, count);
+ case SCI_VERSION_1_EARLY:
+ case SCI_VERSION_1_LATE:
+ case SCI_VERSION_1_1:
+ case SCI_VERSION_32:
+ return vocabulary_get_knames1(resmgr, count);
+ default:
+ return 0;
}
}
-void vocabulary_free_knames(char** names)
-{
+void vocabulary_free_knames(char** names) {
int i = 0;
- while(names[i])
- {
+ while (names[i]) {
free(names[i]);
i++;
}