[Scummvm-cvs-logs] SF.net SVN: scummvm:[38699] scummvm/trunk/engines/sci/scicore/vocab_debug. cpp

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Sat Feb 21 16:25:37 CET 2009


Revision: 38699
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38699&view=rev
Author:   aquadran
Date:     2009-02-21 15:25:37 +0000 (Sat, 21 Feb 2009)

Log Message:
-----------
formating

Modified Paths:
--------------
    scummvm/trunk/engines/sci/scicore/vocab_debug.cpp

Modified: scummvm/trunk/engines/sci/scicore/vocab_debug.cpp
===================================================================
--- scummvm/trunk/engines/sci/scicore/vocab_debug.cpp	2009-02-21 15:20:41 UTC (rev 38698)
+++ scummvm/trunk/engines/sci/scicore/vocab_debug.cpp	2009-02-21 15:25:37 UTC (rev 38699)
@@ -29,7 +29,7 @@
 
 namespace Sci {
 
-/* Default kernel name table */
+// Default kernel name table
 #define SCI0_KNAMES_WELL_DEFINED 0x6e
 #define SCI0_KNAMES_DEFAULT_ENTRIES_NR 0x72
 
@@ -150,19 +150,19 @@
 	/*0x71*/ SCRIPT_UNKNOWN_FUNCTION_STRING
 };
 
-
 int getInt(unsigned char* d) {
 	return d[0] | (d[1] << 8);
 }
 
-int* vocabulary_get_classes(ResourceManager *resmgr, int* count) {
+int *vocabulary_get_classes(ResourceManager *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);
+	c = (int *)sci_malloc(sizeof(int) * r->size / 2);
 	for (i = 2; i < r->size; i += 4) {
 		c[i/4] = getInt(r->data + i);
 	}
@@ -173,7 +173,10 @@
 
 int vocabulary_get_class_count(ResourceManager *resmgr) {
 	resource_t* r;
-	if ((r = scir_find_resource(resmgr, sci_vocab, 996, 0)) == 0) return 0;
+
+	if ((r = scir_find_resource(resmgr, sci_vocab, 996, 0)) == 0)
+		return 0;
+
 	return r->size / 4;
 }
 
@@ -185,26 +188,26 @@
 
 	resource_t* r = scir_find_resource(resmgr, sci_vocab, 997, 0);
 
-	if (!r) /* No such resource? */
+	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;
 
-	t = (char**)sci_malloc(sizeof(char*) * magic * (count + 1));
+	t = (char **)sci_malloc(sizeof(char*) * magic * (count + 1));
 
 	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);
+		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);
+			t[j] = (char *)sci_malloc(len + 1);
 			memcpy(t[j], r->data + offset + 2, len);
 			t[j][len] = '\0';
 			j++;
@@ -213,24 +216,25 @@
 
 	t[j] = 0;
 
-	if (pcount != NULL) *pcount = magic * count;
+	if (pcount != NULL)
+		*pcount = magic * count;
 
 	return t;
 }
 
-int
-vocabulary_lookup_sname(char **snames_list, char *sname) {
+int vocabulary_lookup_sname(char **snames_list, char *sname) {
 	int pos = 0;
+
 	while (snames_list[pos]) {
-		if (!scumm_stricmp(sname, snames_list[pos])) return pos;
+		if (!scumm_stricmp(sname, snames_list[pos]))
+			return pos;
 		pos++;
 	}
 
 	return -1;
 }
 
-void
-vocabulary_free_snames(char **snames_list) {
+void vocabulary_free_snames(char **snames_list) {
 	int pos = 0;
 
 	while (snames_list[pos])
@@ -244,7 +248,7 @@
 	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 the resource couldn't be loaded, leave
 	if (r == NULL) {
 		fprintf(stderr, "unable to load vocab.%03d\n", VOCAB_RESOURCE_OPCODES);
 		return NULL;
@@ -258,7 +262,7 @@
 		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);
+		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
@@ -268,14 +272,13 @@
 	for (i = count; i < 256; i++) {
 		o[i].type = 0;
 		o[i].number = i;
-		o[i].name = (char*)sci_malloc(strlen("undefined") + 1);
+		o[i].name = (char *)sci_malloc(strlen("undefined") + 1);
 		strcpy(o[i].name, "undefined");
 	}
 	return o;
 }
 
-void
-vocabulary_free_opcodes(opcode *opcodes) {
+void vocabulary_free_opcodes(opcode *opcodes) {
 	int i;
 	if (!opcodes)
 		return;
@@ -287,54 +290,49 @@
 	free(opcodes);
 }
 
-
-/* Alternative kernel func names retriever. Required for KQ1/SCI (at least). */
-static char** _vocabulary_get_knames0alt(int *names, resource_t *r) {
+// 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);
+	char **retval = (char **)sci_malloc(sizeof(char *) * mallocsize);
 	unsigned int i = 0, index = 0;
 
 	while (index < r->size) {
-
 		int slen = strlen((char *) r->data + index) + 1;
 
-		retval[i] = (char*)sci_malloc(slen);
+		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 */
+		// Wouldn't normally read this, but the cleanup code wants to free() this
 
 		index += slen;
 
 		if (i == mallocsize)
-			retval = (char**)sci_realloc(retval, sizeof(char *) * (mallocsize <<= 1));
-
+			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);
+	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 */
+	// 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;
 }
 
-
-static char** vocabulary_get_knames0(ResourceManager *resmgr, int* names) {
+static char **vocabulary_get_knames0(ResourceManager *resmgr, int* names) {
 	char** t;
 	int count, i, index = 2, empty_to_add = 1;
-	resource_t* r = scir_find_resource(resmgr, sci_vocab, VOCAB_RESOURCE_KNAMES, 0);
+	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*));
+		*names = SCI0_KNAMES_DEFAULT_ENTRIES_NR - 1; // index of last element
 
-	if (!r) { /* No kernel name table found? Fall back to default table */
-		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++)
 			t[i] = sci_strdup(sci0_default_knames[i]);
 
-		t[SCI0_KNAMES_DEFAULT_ENTRIES_NR] = NULL; /* Terminate list */
+		t[SCI0_KNAMES_DEFAULT_ENTRIES_NR] = NULL; // Terminate list
 
 		return t;
 	}
@@ -349,52 +347,54 @@
 		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));
+	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);*/
+		//fprintf(stderr,"Getting name %d of %d...\n", i, count);
 		index += 2;
-		t[i] = (char*)sci_malloc(len + 1);
+		t[i] = (char *)sci_malloc(len + 1);
 		memcpy(t[i], r->data + offset + 2, len);
 		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;
+
 	return t;
 }
 
-/*NOTE: Untested*/
-static char** vocabulary_get_knames1(ResourceManager *resmgr, int *count) {
-	char** t = NULL;
+//NOTE: Untested
+static char **vocabulary_get_knames1(ResourceManager *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);
+	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*));
+			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);
+		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 = (char **)sci_realloc(t, (used + 1) * sizeof(char*));
 	t[used] = NULL;
+
 	return t;
 }
 
-char** vocabulary_get_knames(ResourceManager *resmgr, int* count) {
+char **vocabulary_get_knames(ResourceManager *resmgr, int *count) {
 	switch (resmgr->sci_version) {
 	case SCI_VERSION_0:
 	case SCI_VERSION_01:
@@ -411,8 +411,9 @@
 	}
 }
 
-void vocabulary_free_knames(char** names) {
-	int i	= 0;
+void vocabulary_free_knames(char **names) {
+	int i = 0;
+
 	while (names[i]) {
 		free(names[i]);
 		i++;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list