aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/engine
diff options
context:
space:
mode:
authorFilippos Karapetis2009-03-10 18:33:36 +0000
committerFilippos Karapetis2009-03-10 18:33:36 +0000
commit073a1b3f9689478d5d1bc3d19034ad6fa06233d5 (patch)
treea5cbcbe8fcfffd927df1119d55eb00193498b4ea /engines/sci/engine
parent74cea8d75d1a173dfb6dae74980ece32fb9f50d4 (diff)
downloadscummvm-rg350-073a1b3f9689478d5d1bc3d19034ad6fa06233d5.tar.gz
scummvm-rg350-073a1b3f9689478d5d1bc3d19034ad6fa06233d5.tar.bz2
scummvm-rg350-073a1b3f9689478d5d1bc3d19034ad6fa06233d5.zip
Formatted code to conform to our coding standards. Also, added parentheses to clarify "&" operator precedence
svn-id: r39302
Diffstat (limited to 'engines/sci/engine')
-rw-r--r--engines/sci/engine/stringfrag.cpp233
1 files changed, 88 insertions, 145 deletions
diff --git a/engines/sci/engine/stringfrag.cpp b/engines/sci/engine/stringfrag.cpp
index a53b40fbb7..0d30f09d41 100644
--- a/engines/sci/engine/stringfrag.cpp
+++ b/engines/sci/engine/stringfrag.cpp
@@ -31,49 +31,41 @@ namespace Sci {
#define STRINGFRAG_SEGMENT s->string_frag_segment
// #define STRINGFRAG_SEGMENT 0xffff
- static int internal_is_valid_stringfrag(EngineState *s, reg_t *buffer)
- {
+ static int internal_is_valid_stringfrag(EngineState *s, reg_t *buffer) {
if (buffer == NULL)
return 0;
- while (buffer->offset & 0xff00 != 0 &&
- buffer->offset & 0x00ff != 0)
- {
+ while ((buffer->offset & 0xff00) != 0 &&
+ (buffer->offset & 0x00ff) != 0) {
if (buffer->segment != STRINGFRAG_SEGMENT)
return 0;
buffer++;
}
- if (buffer->segment != STRINGFRAG_SEGMENT)
- {
+ if (buffer->segment != STRINGFRAG_SEGMENT) {
return 0;
}
return 1;
}
- int is_valid_stringfrag(EngineState *s, reg_t pos)
- {
+ int is_valid_stringfrag(EngineState *s, reg_t pos) {
reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
return internal_is_valid_stringfrag(s, buffer);
}
- static int internal_stringfrag_length(EngineState *s, reg_t *buffer)
- {
+ static int internal_stringfrag_length(EngineState *s, reg_t *buffer) {
int result = 0;
- if (buffer == NULL)
- {
+ if (buffer == NULL) {
// SCIkwarn(SCIkERROR, "Error: Invalid stringfrag handle");
return 0;
}
- while (buffer->offset & 0xff00 != 0 &&
- buffer->offset & 0x00ff != 0)
- {
- if (buffer->segment != STRINGFRAG_SEGMENT)
- {
+ while ((buffer->offset & 0xff00) != 0 &&
+ (buffer->offset & 0x00ff) != 0) {
+ if (buffer->segment != STRINGFRAG_SEGMENT) {
// SCIkwarn(SCIkERROR, "Error: Invalid stringfrag handle");
return 0;
}
@@ -82,32 +74,28 @@ namespace Sci {
buffer ++;
}
- if (buffer->segment != STRINGFRAG_SEGMENT)
- {
+ if (buffer->segment != STRINGFRAG_SEGMENT) {
SCIkwarn(SCIkERROR, "Error: Invalid stringfrag handle");
return 0;
}
- if (buffer->offset & 0xff00 != 0) result++;
+ if ((buffer->offset & 0xff00) != 0) result++;
return result;
}
- int stringfrag_length(EngineState *s, reg_t pos)
- {
+ int stringfrag_length(EngineState *s, reg_t pos) {
reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
return internal_stringfrag_length(s, buffer);
}
- static void internal_stringfrag_to_ascii(EngineState *s, reg_t *buffer)
- {
+ static void internal_stringfrag_to_ascii(EngineState *s, reg_t *buffer) {
int str_length = internal_stringfrag_length(s, buffer);
char *temp = (char *) malloc(str_length + 1);
int i = 0;
- while (buffer->offset & 0xff00 != 0 &&
- buffer->offset & 0x00ff != 0)
- {
+ while ((buffer->offset & 0xff00) != 0 &&
+ (buffer->offset & 0x00ff) != 0) {
temp[i] = (buffer->offset & 0xff00) >> 8;
if (temp[i] != 0)
temp[i+1] = buffer->offset & 0xff;
@@ -115,12 +103,10 @@ namespace Sci {
buffer++;
}
- if (buffer->offset & 0xff00 != 0)
- {
+ if ((buffer->offset & 0xff00) != 0) {
temp[i] = (buffer->offset & 0xff00) >> 8;
temp[i+1] = 0;
- } else
- {
+ } else {
temp[i] = 0;
}
@@ -128,23 +114,19 @@ namespace Sci {
free(temp);
}
- void stringfrag_to_ascii(EngineState *s, reg_t pos)
- {
+ void stringfrag_to_ascii(EngineState *s, reg_t pos) {
reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
internal_stringfrag_to_ascii(s, buffer);
}
- static void internal_ascii_to_stringfrag(EngineState *s, reg_t *buffer)
- {
+ static void internal_ascii_to_stringfrag(EngineState *s, reg_t *buffer) {
int str_length = strlen((char *) buffer);
int words = str_length % 2 ? (str_length+2)/2 : (str_length + 1)/2;
char *temp = (char *) malloc(str_length + 1);
- int i;
strcpy(temp, (char *) buffer);
- for (i = 0; i < words; i++)
- {
+ for (int i = 0; i < words; i++) {
buffer[i].segment = STRINGFRAG_SEGMENT;
buffer[i].offset = temp[i*2];
if (temp[i*2])
@@ -154,43 +136,37 @@ namespace Sci {
free(temp);
}
- void ascii_to_stringfrag(EngineState *s, reg_t pos)
- {
+ void ascii_to_stringfrag(EngineState *s, reg_t pos) {
reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
internal_ascii_to_stringfrag(s, buffer);
}
- static void internal_stringfrag_append_char(EngineState *s, reg_t *buffer, unsigned char c)
- {
- while (buffer->offset & 0xff00 != 0 &&
- buffer->offset & 0x00ff != 0)
+ static void internal_stringfrag_append_char(EngineState *s, reg_t *buffer, unsigned char c) {
+ while ((buffer->offset & 0xff00) != 0 &&
+ (buffer->offset & 0x00ff) != 0)
buffer++;
- if (buffer->offset & 0xff00 == 0)
- {
+ if ((buffer->offset & 0xff00) == 0) {
buffer->offset = c << 8;
- } else
- if (buffer->offset & 0x00ff == 0)
- {
+ } else {
+ if ((buffer->offset & 0x00ff) == 0) {
buffer->offset |= c;
buffer++;
buffer->segment = STRINGFRAG_SEGMENT;
buffer->offset = 0;
}
+ }
}
- void stringfrag_append_char(EngineState *s, reg_t pos, unsigned char c)
- {
+ void stringfrag_append_char(EngineState *s, reg_t pos, unsigned char c) {
reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
internal_stringfrag_append_char(s, buffer, c);
}
- inline void stringfrag_setchar(reg_t *buffer, int pos, int offset, unsigned char c)
- {
- switch (offset)
- {
+ inline void stringfrag_setchar(reg_t *buffer, int pos, int offset, unsigned char c) {
+ switch (offset) {
case 0 :
buffer[pos].offset = (buffer[pos].offset & 0x00ff) | (c << 8);
break;
@@ -200,10 +176,8 @@ namespace Sci {
}
}
- inline unsigned char stringfrag_getchar(reg_t *buffer, int pos, int offset)
- {
- switch (offset)
- {
+ inline unsigned char stringfrag_getchar(reg_t *buffer, int pos, int offset) {
+ switch (offset) {
case 0 :
return buffer[pos].offset >> 8;
case 1 :
@@ -213,8 +187,7 @@ namespace Sci {
}
}
- void stringfrag_memmove(EngineState *s, reg_t *buffer, int sourcepos, int destpos, int count)
- {
+ void stringfrag_memmove(EngineState *s, reg_t *buffer, int sourcepos, int destpos, int count) {
/* Some of these values are not used yet. There are a couple
of cases that we could implement faster if the need arises, in
which case we would most certainly need these. */
@@ -228,11 +201,8 @@ namespace Sci {
int dest_end_pos = (destpos+count-1)/2;
int dest_end_offset = (destpos+count-1)%2;
- if (sourcepos < destpos)
- {
- int n;
- for (n = count-1; n >= 0; n--)
- {
+ if (sourcepos < destpos) {
+ for (int n = count-1; n >= 0; n--) {
buffer[dest_end_pos].segment = STRINGFRAG_SEGMENT;
stringfrag_setchar(buffer, dest_end_pos, dest_end_offset,
stringfrag_getchar(buffer, source_end_pos, source_end_offset));
@@ -241,11 +211,8 @@ namespace Sci {
if (dest_end_offset ^= 1)
dest_end_pos --;
}
- } else
- {
- int n;
- for (n = 0; n < count; n++)
- {
+ } else {
+ for (int n = 0; n < count; n++) {
buffer[dest_begin_pos].segment = STRINGFRAG_SEGMENT;
stringfrag_setchar(buffer, dest_begin_pos, dest_begin_offset,
stringfrag_getchar(buffer, source_begin_pos, source_begin_offset));
@@ -257,34 +224,29 @@ namespace Sci {
}
}
- static void internal_stringfrag_insert_char(EngineState *s, reg_t *buffer, int p, unsigned char c)
- {
+ static void internal_stringfrag_insert_char(EngineState *s, reg_t *buffer, int p, unsigned char c) {
reg_t *save = buffer + p/2;
reg_t *seeker = buffer + p/2;
int restore_nul_offset;
int restore_nul_pos;
int len = internal_stringfrag_length(s, buffer);
- while (seeker->offset & 0xff00 != 0 &&
- seeker->offset & 0x00ff != 0)
+ while ((seeker->offset & 0xff00) != 0 &&
+ (seeker->offset & 0x00ff) != 0)
seeker++;
/* The variables restore_null_offset and restore_null_pos will
indicate where the NUL character should be PUT BACK after
inserting c, as this operation might overwrite the NUL. */
- if (seeker->offset & 0xff00)
- {
+ if (seeker->offset & 0xff00) {
restore_nul_offset = 1;
restore_nul_pos = 0;
- }
- else
- {
+ } else {
restore_nul_offset = 0;
restore_nul_pos = 1;
}
- if (seeker-save == 0) // So p is at the end, use fast method
- {
+ if (seeker-save == 0) { // So p is at the end, use fast method
internal_stringfrag_append_char(s, seeker, c);
return;
}
@@ -294,35 +256,30 @@ namespace Sci {
stringfrag_setchar(seeker, restore_nul_pos, restore_nul_offset, 0);
}
- void stringfrag_insert_char(EngineState *s, reg_t pos, int p, unsigned char c)
- {
+ void stringfrag_insert_char(EngineState *s, reg_t pos, int p, unsigned char c) {
reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
internal_stringfrag_insert_char(s, buffer, p, c);
}
- static void internal_stringfrag_delete_char(EngineState *s, reg_t *buffer, int p)
- {
+ static void internal_stringfrag_delete_char(EngineState *s, reg_t *buffer, int p) {
//reg_t *save = buffer + p;
reg_t *seeker = buffer + p;
int restore_nul_offset;
int restore_nul_pos;
int len = internal_stringfrag_length(s, buffer);
- while (seeker->offset & 0xff00 != 0 &&
- seeker->offset & 0x00ff != 0)
+ while ((seeker->offset & 0xff00) != 0 &&
+ (seeker->offset & 0x00ff) != 0)
seeker++;
/* The variables restore_null_offset and restore_null_pos will
indicate where the NUL character should be PUT BACK after
deletion, as this operation might overwrite the NUL. */
- if (seeker->offset & 0xff00)
- {
+ if (seeker->offset & 0xff00) {
restore_nul_offset = 1;
restore_nul_pos = -1;
- }
- else
- {
+ } else {
restore_nul_offset = 0;
restore_nul_pos = 0;
}
@@ -331,18 +288,15 @@ namespace Sci {
stringfrag_setchar(seeker, restore_nul_pos, restore_nul_offset, 0);
}
- void stringfrag_delete_char(EngineState *s, reg_t pos, int p)
- {
+ void stringfrag_delete_char(EngineState *s, reg_t pos, int p) {
reg_t *buffer = kernel_dereference_reg_pointer(s, pos, 1);
internal_stringfrag_delete_char(s, buffer, p);
}
- void internal_stringfrag_strcpy(EngineState *s, reg_t *dest, reg_t *src)
- {
- while (src->offset & 0xff00 != 0 &&
- src->offset & 0x00ff != 0)
- {
+ void internal_stringfrag_strcpy(EngineState *s, reg_t *dest, reg_t *src) {
+ while ((src->offset & 0xff00) != 0 &&
+ (src->offset & 0x00ff) != 0) {
*dest = *src;
dest++;
src++;
@@ -351,27 +305,23 @@ namespace Sci {
*dest = *src;
}
- void stringfrag_strcpy(EngineState *s, reg_t dest, reg_t src)
- {
+ void stringfrag_strcpy(EngineState *s, reg_t dest, reg_t src) {
reg_t *destbuf = kernel_dereference_reg_pointer(s, dest, 1);
reg_t *srcbuf = kernel_dereference_reg_pointer(s, src, 1);
internal_stringfrag_strcpy(s, destbuf, srcbuf);
}
- void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int len)
- {
- while (src->offset & 0xff00 != 0 &&
- src->offset & 0x00ff != 0 &&
- (len -= 2) > 1)
- {
+ void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int len) {
+ while ((src->offset & 0xff00) != 0 &&
+ (src->offset & 0x00ff) != 0 &&
+ (len -= 2) > 1) {
*dest = *src;
dest++;
src++;
}
- for ( ; len > 1 ; len -= 2)
- {
+ for ( ; len > 1 ; len -= 2) {
dest->segment = STRINGFRAG_SEGMENT;
dest->offset = 0;
len -= 2;
@@ -383,86 +333,79 @@ namespace Sci {
*dest = *src;
}
- void stringfrag_strncpy(EngineState *s, reg_t dest, reg_t src, int len)
- {
+ void stringfrag_strncpy(EngineState *s, reg_t dest, reg_t src, int len) {
reg_t *destbuf = kernel_dereference_reg_pointer(s, dest, 1);
reg_t *srcbuf = kernel_dereference_reg_pointer(s, src, 1);
internal_stringfrag_strncpy(s, destbuf, srcbuf, len);
}
- int internal_stringfrag_strcmp(EngineState *s, reg_t *s1, reg_t *s2)
- {
- while (1)
- {
- if (s1->offset & 0xff00 == 0 && s2->offset & 0xff00 == 0)
+ int internal_stringfrag_strcmp(EngineState *s, reg_t *s1, reg_t *s2) {
+ while (1) {
+ if ((s1->offset & 0xff00) == 0 && (s2->offset & 0xff00) == 0)
return 0;
- if (s1->offset & 0xff00 == 0)
+ if ((s1->offset & 0xff00) == 0)
return -1;
- if (s2->offset & 0xff00 == 0)
+ if ((s2->offset & 0xff00) == 0)
return 1;
- if (s1->offset & 0xff00 < s2->offset & 0xff00)
+ if ((s1->offset & 0xff00) < (s2->offset & 0xff00))
return -1;
- if (s1->offset & 0xff00 > s2->offset & 0xff00)
+ if ((s1->offset & 0xff00) > (s2->offset & 0xff00))
return 1;
- if (s1->offset & 0x00ff == 0 && s2->offset & 0x00ff == 0)
+ if ((s1->offset & 0x00ff) == 0 && (s2->offset & 0x00ff) == 0)
return 0;
- if (s1->offset & 0x00ff == 0)
+ if ((s1->offset & 0x00ff) == 0)
return -1;
- if (s2->offset & 0x00ff == 0)
+ if ((s2->offset & 0x00ff) == 0)
return 1;
- if (s1->offset & 0x00ff < s2->offset & 0x00ff)
+ if ((s1->offset & 0x00ff) < (s2->offset & 0x00ff))
return -1;
- if (s1->offset & 0x00ff > s2->offset & 0x00ff)
+ if ((s1->offset & 0x00ff) > (s2->offset & 0x00ff))
return 1;
}
return 0;
}
- void stringfrag_strcmp(EngineState *s, reg_t s1, reg_t s2)
- {
+ void stringfrag_strcmp(EngineState *s, reg_t s1, reg_t s2) {
reg_t *s1buf = kernel_dereference_reg_pointer(s, s1, 1);
reg_t *s2buf = kernel_dereference_reg_pointer(s, s2, 1);
internal_stringfrag_strcmp(s, s1buf, s2buf);
}
- int internal_stringfrag_strncmp(EngineState *s, reg_t *s1, reg_t *s2, int len)
- {
- while (len)
- {
+ int internal_stringfrag_strncmp(EngineState *s, reg_t *s1, reg_t *s2, int len) {
+ while (len) {
if (len--) return 0;
- if (s1->offset & 0xff00 == 0 && s2->offset & 0xff00 == 0)
+ if ((s1->offset & 0xff00) == 0 && (s2->offset & 0xff00) == 0)
return 0;
- if (s1->offset & 0xff00 == 0)
+ if ((s1->offset & 0xff00) == 0)
return -1;
- if (s2->offset & 0xff00 == 0)
+ if ((s2->offset & 0xff00) == 0)
return 1;
- if (s1->offset & 0xff00 < s2->offset & 0xff00)
+ if ((s1->offset & 0xff00) < (s2->offset & 0xff00))
return -1;
- if (s1->offset & 0xff00 > s2->offset & 0xff00)
+ if ((s1->offset & 0xff00) > (s2->offset & 0xff00))
return 1;
if (len--) return 0;
- if (s1->offset & 0x00ff == 0 && s2->offset & 0x00ff == 0)
+ if ((s1->offset & 0x00ff) == 0 && (s2->offset & 0x00ff) == 0)
return 0;
- if (s1->offset & 0x00ff == 0)
+ if ((s1->offset & 0x00ff) == 0)
return -1;
- if (s2->offset & 0x00ff == 0)
+ if ((s2->offset & 0x00ff) == 0)
return 1;
- if (s1->offset & 0x00ff < s2->offset & 0x00ff)
+ if ((s1->offset & 0x00ff) < (s2->offset & 0x00ff))
return -1;
- if (s1->offset & 0x00ff > s2->offset & 0x00ff)
+ if ((s1->offset & 0x00ff) > (s2->offset & 0x00ff))
return 1;
}
return 0;
}
- void stringfrag_strncmp(EngineState *s, reg_t s1, reg_t s2, int len)
- {
+ void stringfrag_strncmp(EngineState *s, reg_t s1, reg_t s2, int len) {
reg_t *s1buf = kernel_dereference_reg_pointer(s, s1, 1);
reg_t *s2buf = kernel_dereference_reg_pointer(s, s2, 1);