[Scummvm-cvs-logs] SF.net SVN: scummvm:[38555] scummvm/trunk/engines/sci/engine

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Thu Feb 19 19:08:44 CET 2009


Revision: 38555
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38555&view=rev
Author:   aquadran
Date:     2009-02-19 18:08:44 +0000 (Thu, 19 Feb 2009)

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

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/heap.cpp
    scummvm/trunk/engines/sci/engine/heap.h

Modified: scummvm/trunk/engines/sci/engine/heap.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/heap.cpp	2009-02-19 18:02:51 UTC (rev 38554)
+++ scummvm/trunk/engines/sci/engine/heap.cpp	2009-02-19 18:08:44 UTC (rev 38555)
@@ -27,7 +27,7 @@
 #include "sci/include/console.h"
 #include "sci/engine/heap.h"
 
-#define assert_in_range(pos) assert(pos>=1000 && pos<=0xffff)
+#define assert_in_range(pos) assert(pos >= 1000 && pos <= 0xffff)
 
 static void set_size(heap_t *h, int block_pos, int size) {
 	assert_in_range(block_pos);
@@ -35,28 +35,30 @@
 	putInt16(h->start + block_pos, size);
 }
 
-static void set_next(heap_t* h, int block_pos, int next) {
+static void set_next(heap_t *h, int block_pos, int next) {
 	assert_in_range(block_pos);
 	assert_in_range(next);
 	putInt16(h->start + block_pos + 2, next);
 }
 
 
-static unsigned int get_size(heap_t* h, int block_pos) {
+static unsigned int get_size(heap_t *h, int block_pos) {
 	assert_in_range(block_pos);
 	return (guint16)getInt16(h->start + block_pos);
 }
 
-static unsigned int get_next(heap_t* h, int block_pos) {
+static unsigned int get_next(heap_t *h, int block_pos) {
 	assert_in_range(block_pos);
 	return (guint16)getInt16(h->start + block_pos + 2);
 }
 
-/*Allocates a new heap*/
+// Allocates a new heap
 heap_t* heap_new() {
 	heap_t* h;
-	if ((h = (heap_t*)sci_malloc(sizeof(heap_t))) == 0) return 0;
 
+	if ((h = (heap_t*)sci_malloc(sizeof(heap_t))) == 0)
+		return 0;
+
 	if ((h->start = (byte *)sci_calloc(SCI_HEAP_SIZE, 1)) == 0) {
 		free(h);
 		return 0;
@@ -71,14 +73,13 @@
 	return h;
 }
 
-/*Deletes a heap*/
-void heap_del(heap_t* h) {
+// Deletes a heap
+void heap_del(heap_t *h) {
 	free(h->start);
 	free(h);
 }
 
-
-int heap_meminfo(heap_t* h) {
+int heap_meminfo(heap_t *h) {
 	heap_ptr current = h->first_free;
 	int total = 0;
 
@@ -91,7 +92,7 @@
 }
 
 
-int heap_largest(heap_t* h) {
+int heap_largest(heap_t *h) {
 	int current = h->first_free;
 	int best_pos = -1, best_size = 0;
 
@@ -110,7 +111,7 @@
 	return best_size;
 }
 
-heap_ptr heap_allocate(heap_t* h, int size) {
+heap_ptr heap_allocate(heap_t *h, int size) {
 	unsigned int previous = h->first_free;
 	unsigned int current = previous;
 
@@ -125,14 +126,14 @@
 		int block_size = get_size(h, current);
 		int next = get_next(h, current);
 
-		/*Is this block large enough?*/
+		// Is this block large enough?
 		if (block_size >= size) {
-			/*Swallow the block whole*/
+			// Swallow the block whole
 			if (block_size <= size + 4) {
 				size = block_size;
 				set_next(h, previous, next);
 			} else {
-				/*Split the block*/
+				// Split the block
 				int rest = current + size;
 
 				set_next(h, previous, rest);
@@ -148,16 +149,16 @@
 		current = next;
 	}
 
-	/*No large enough block was found.*/
+	// No large enough block was found.
 	return 0;
 }
 
-void heap_free(heap_t* h, unsigned int m) {
+void heap_free(heap_t *h, unsigned int m) {
 	unsigned int previous, next;
 	assert_in_range(m);
 	previous = next = h->first_free;
 
-	/*Find the previous and next blocks*/
+	// Find the previous and next blocks
 	while (next < m) {
 		previous = next;
 		assert(previous < 0xffff);
@@ -169,7 +170,7 @@
 	}
 
 	if (h->first_free > m)
-		h->first_free = m; /* Guarantee that first_free is correct */
+		h->first_free = m; // Guarantee that first_free is correct
 
 	if (previous == next) {
 		if (m < previous) {
@@ -177,7 +178,8 @@
 			if (m + get_size(h, m) == previous) {
 				set_size(h, m, get_size(h, m) + get_size(h, previous));
 				set_next(h, m, get_next(h, previous));
-			} else set_next(h, m, previous);
+			} else
+				set_next(h, m, previous);
 		} else {
 			if (previous + get_size(h, previous) == m) {
 				set_size(h, previous, get_size(h, previous) + get_size(h, m));
@@ -191,14 +193,14 @@
 		set_next(h, previous, m);
 		set_next(h, m, next);
 
-		/*Try to merge with previous*/
+		// Try to merge with previous
 		if (previous + get_size(h, previous) == m) {
 			set_size(h, previous, get_size(h, previous) + get_size(h, m));
 			set_next(h, previous, next);
 			m = previous;
 		}
 
-		/*Try to merge with next*/
+		// Try to merge with next
 		if (m + get_size(h, m) == next) {
 			set_size(h, m, get_size(h, m) + get_size(h, next));
 			set_next(h, m, get_next(h, next));
@@ -206,18 +208,16 @@
 	}
 }
 
-void save_ff(heap_t* h) {
+void save_ff(heap_t *h) {
 	h->old_ff = h->first_free;
 }
 
-void restore_ff(heap_t* h) {
+void restore_ff(heap_t *h) {
 	h->first_free = h->old_ff;
 	set_size(h, h->first_free, 0xffff - h->first_free);
 	set_next(h, h->first_free, 0xffff);
 }
 
-
-
 void heap_dump_free(heap_t *h) {
 	int freedomseeker;
 
@@ -247,38 +247,36 @@
 }
 
 /*
-
 int main(int argc, char **argv) {
-  heap_t *h = heap_new();
-  int a,b,c,d,e;
+	heap_t *h = heap_new();
+	int a, b, c, d, e;
 
-  printf("Running heap tests:\nHeap initialization:\n");
-  heap_dump_free(h);
+	printf("Running heap tests:\nHeap initialization:\n");
+	heap_dump_free(h);
 
-  printf("[a] Allocating 0x1: position is %#x\n", a = heap_allocate(h, 1));
-  heap_dump_free(h);
+	printf("[a] Allocating 0x1: position is %#x\n", a = heap_allocate(h, 1));
+	heap_dump_free(h);
 
-  printf("[b] Allocating 0x10: position is %#x\n", b = heap_allocate(h, 0x10));
-  printf("[c] Allocating 0x10: position is %#x\n", c = heap_allocate(h, 0x10));
-  printf("[d] Allocating 0x10: position is %#x\n", d = heap_allocate(h, 0x10));
-  printf("[e] Allocating 0x1000: position is %#x\n", e = heap_allocate(h, 0x1000));
-  heap_dump_free(h);
+	printf("[b] Allocating 0x10: position is %#x\n", b = heap_allocate(h, 0x10));
+	printf("[c] Allocating 0x10: position is %#x\n", c = heap_allocate(h, 0x10));
+	printf("[d] Allocating 0x10: position is %#x\n", d = heap_allocate(h, 0x10));
+	printf("[e] Allocating 0x1000: position is %#x\n", e = heap_allocate(h, 0x1000));
+	heap_dump_free(h);
 
-  printf("Freeing [b]:\n");
-  heap_free(h, b);
-  heap_dump_free(h);
+	printf("Freeing [b]:\n");
+	heap_free(h, b);
+	heap_dump_free(h);
 
-  printf("Freeing [d]:\n");
-  heap_free(h, d);
-  heap_dump_free(h);
+	printf("Freeing [d]:\n");
+	heap_free(h, d);
+	heap_dump_free(h);
 
-  printf("Freeing [c]:\n");
-  heap_free(h, c);
-  heap_dump_free(h);
+	printf("Freeing [c]:\n");
+	heap_free(h, c);
+	heap_dump_free(h);
 
-  heap_del(h);
+	heap_del(h);
 
-  return 0;
+	return 0;
 }
-
 */

Modified: scummvm/trunk/engines/sci/engine/heap.h
===================================================================
--- scummvm/trunk/engines/sci/engine/heap.h	2009-02-19 18:02:51 UTC (rev 38554)
+++ scummvm/trunk/engines/sci/engine/heap.h	2009-02-19 18:08:44 UTC (rev 38555)
@@ -32,52 +32,45 @@
 
 typedef guint16 heap_ptr;
 
-
 typedef struct {
-	byte* start;
-	byte* base;
+	byte *start;
+	byte *base;
 	unsigned int first_free;
 	int old_ff;
 } heap_t;
 
-heap_t*
-heap_new();
+heap_t *heap_new();
 /* Allocates a new heap.
 ** Parameters: (void)
 ** Returns   : (heap_t *) A new 0xffff-sized heap
 */
 
-void
-heap_del(heap_t* h);
+void heap_del(heap_t *h);
 /* Frees an allocated heap
 ** Parameters: (heap_t *) h: The heap to unallocate
 ** Returns   : (void)
 */
 
-int
-heap_meminfo(heap_t* h);
+int heap_meminfo(heap_t *h);
 /* Returns the total number of free bytes on the heap
 ** Parameters: (heap_t *) h: The heap to check
 ** Returns   : (int) The total free space in bytes
 */
 
-int
-heap_largest(heap_t* h);
+int heap_largest(heap_t *h);
 /* Returns the block size of the largest free block on the heap
 ** Parameters: (heap_t *) h: The heap to check
 ** Returns   : (int) The size of the largest free block
 */
 
-heap_ptr
-heap_allocate(heap_t* h, int size);
+heap_ptr heap_allocate(heap_t *h, int size);
 /* Allocates memory on a heap.
 ** Parameters: (heap_t *) h: The heap to work with
 **             (int) size: The block size to allocate
 ** Returns   : (heap_ptr): The heap pointer to the new block, or 0 on failure
 */
 
-void
-heap_free(heap_t* h, unsigned int m);
+void heap_free(heap_t *h, unsigned int m);
 /* Frees allocated heap memory.
 ** Parameters: (heap_t *) h: The heap to work with
 **             (int) m: The handle at which memory is to be unallocated
@@ -85,8 +78,7 @@
 ** This function automatically prevents fragmentation from happening.
 */
 
-void
-save_ff(heap_t* h);
+void save_ff(heap_t *h);
 /* Stores the current first free position
 ** Parameters: (heap_t *) h: The heap which is to be manipulated
 ** Returns   : (void)
@@ -94,8 +86,7 @@
 ** the next function)
 */
 
-void
-restore_ff(heap_t* h);
+void restore_ff(heap_t *h);
 /* Restores the first free heap state
 ** Parameters: (heap_t *) h: The heap to restore
 ** Returns   : (void)
@@ -105,18 +96,16 @@
 ** called").
 */
 
-void
-heap_dump_free(heap_t *h);
+void heap_dump_free(heap_t *h);
 /* Dumps debugging information about the stack
 ** Parameters: (heap_t *) h: The heap to check
 ** Returns   : (void)
 */
 
-void
-heap_dump_all(heap_t *h);
+void heap_dump_all(heap_t *h);
 /* Dumps all allocated/unallocated zones on the heap
 ** Parameters: (heap_t *) h: The heap to check
 ** Returns   : (void)
 */
 
-#endif /* !_SCI_HEAP_H */
+#endif // !_SCI_HEAP_H


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