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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Feb 22 20:45:53 CET 2009


Revision: 38791
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38791&view=rev
Author:   fingolfin
Date:     2009-02-22 19:45:53 +0000 (Sun, 22 Feb 2009)

Log Message:
-----------
SCI: Replaced two uses of sci_fopen by Common::File; moved is_print_str() to the only spot it is used

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/kstring.cpp
    scummvm/trunk/engines/sci/gfx/gfx_resource.h
    scummvm/trunk/engines/sci/gfx/resource/sci_pal_1.cpp
    scummvm/trunk/engines/sci/sfx/softseq/amiga.cpp
    scummvm/trunk/engines/sci/tools.cpp
    scummvm/trunk/engines/sci/tools.h

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2009-02-22 19:32:44 UTC (rev 38790)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2009-02-22 19:45:53 UTC (rev 38791)
@@ -24,6 +24,7 @@
  */
 
 #include "common/system.h"
+#include "common/file.h"
 
 #include "sci/include/sciresource.h"
 #include "sci/include/engine.h"
@@ -139,10 +140,10 @@
 		}
 	} else {
 		// Check for Amiga palette file.
-		FILE *f = sci_fopen("spal", "rb");
-		if (f) {
-			s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, f);
-			fclose(f);
+		Common::File file;
+		if (file.open("spal")) {
+			s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, file);
+			file.close();
 			_sci1_alloc_system_colors(s);
 		} else {
 			resource = scir_find_resource(s->resmgr, sci_palette, 999, 1);

Modified: scummvm/trunk/engines/sci/engine/kstring.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/kstring.cpp	2009-02-22 19:32:44 UTC (rev 38790)
+++ scummvm/trunk/engines/sci/engine/kstring.cpp	2009-02-22 19:45:53 UTC (rev 38791)
@@ -408,7 +408,24 @@
 	return argv[0];
 }
 
+/* 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. */
+static int is_print_str(char *str) {
+	int printable = 0;
+	int len = strlen(str);
 
+	if (len == 0) return 1;
+
+	while (*str) {
+		if (isprint(*str)) printable++;
+		str++;
+	}
+
+	return ((float)printable / (float)len >= 0.5);
+}
+
+
 reg_t kStrAt(EngineState *s, int funct_nr, int argc, reg_t *argv) {
 	unsigned char *dest = (unsigned char *) kernel_dereference_bulk_pointer(s, argv[0], 0);
 	reg_t *dest2;

Modified: scummvm/trunk/engines/sci/gfx/gfx_resource.h
===================================================================
--- scummvm/trunk/engines/sci/gfx/gfx_resource.h	2009-02-22 19:32:44 UTC (rev 38790)
+++ scummvm/trunk/engines/sci/gfx/gfx_resource.h	2009-02-22 19:45:53 UTC (rev 38791)
@@ -31,6 +31,10 @@
 #include "sci/gfx/gfx_system.h"
 #include "sci/gfx/gfx_driver.h"
 
+namespace Common {
+	class File;
+}
+
 namespace Sci {
 
 /*** Styles for pic0 drawing ***/
@@ -355,7 +359,7 @@
 ** Returns   : (gfx_pixmap_color_t *) *colors_nr color_t entries with the colors
 */
 
-gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, FILE *f);
+gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, Common::File &file);
 /* Reads an SCI1 palette
 ** Parameters: (int *) colors_nr: Pointer to the variable the number of colors
 **                                will be stored in

Modified: scummvm/trunk/engines/sci/gfx/resource/sci_pal_1.cpp
===================================================================
--- scummvm/trunk/engines/sci/gfx/resource/sci_pal_1.cpp	2009-02-22 19:32:44 UTC (rev 38790)
+++ scummvm/trunk/engines/sci/gfx/resource/sci_pal_1.cpp	2009-02-22 19:45:53 UTC (rev 38791)
@@ -25,6 +25,7 @@
 
 /* SCI1 palette resource defrobnicator */
 
+#include "common/file.h"
 #include "sci/include/sci_memory.h"
 #include "sci/gfx/gfx_system.h"
 #include "sci/gfx/gfx_resource.h"
@@ -132,7 +133,7 @@
 	return retval;
 }
 
-gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, FILE *f) {
+gfx_pixmap_color_t *gfxr_read_pal1_amiga(int *colors_nr, Common::File &file) {
 	int i;
 	gfx_pixmap_color_t *retval;
 
@@ -141,8 +142,8 @@
 	for (i = 0; i < 32; i++) {
 		int b1, b2;
 
-		b1 = fgetc(f);
-		b2 = fgetc(f);
+		b1 = file.readByte();
+		b2 = file.readByte();
 
 		if (b1 == EOF || b2 == EOF) {
 			GFXERROR("Palette file ends prematurely\n");

Modified: scummvm/trunk/engines/sci/sfx/softseq/amiga.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/softseq/amiga.cpp	2009-02-22 19:32:44 UTC (rev 38790)
+++ scummvm/trunk/engines/sci/sfx/softseq/amiga.cpp	2009-02-22 19:45:53 UTC (rev 38791)
@@ -27,6 +27,7 @@
 #include "sci/include/sci_memory.h"
 #include "sci/sfx/softseq.h"
 
+#include "common/file.h"
 #include "common/frac.h"
 
 namespace Sci {
@@ -112,7 +113,7 @@
 static int volume = 127;
 
 /* Frequencies for every note */
-static int freq_table[] = {
+static const int freq_table[] = {
 	58, 62, 65, 69, 73, 78, 82, 87,
 	92, 98, 104, 110, 117, 124, 131, 139,
 	147, 156, 165, 175, 185, 196, 208, 220,
@@ -360,7 +361,7 @@
 	return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
 }
 
-static instrument_t *read_instrument(FILE *file, int *id) {
+static instrument_t *read_instrument(Common::File &file, int *id) {
 	instrument_t *instrument;
 	byte header[61];
 	int size;
@@ -368,7 +369,7 @@
 	int loop_offset;
 	int i;
 
-	if (fread(header, 1, 61, file) < 61) {
+	if (file.read(header, 61) < 61) {
 		sciprintf("[sfx:seq:amiga] Error: failed to read instrument header\n");
 		return NULL;
 	}
@@ -411,7 +412,7 @@
 	sciprintf("                Segment offsets: 0 %i %i\n", loop_offset, read_int32(header + 43));
 #endif
 	instrument->samples = (int8 *) sci_malloc(size + 1);
-	if (fread(instrument->samples, 1, size, file) < (unsigned int)size) {
+	if (file.read(instrument->samples, size) < (unsigned int)size) {
 		sciprintf("[sfx:seq:amiga] Error: failed to read instrument samples\n");
 		return NULL;
 	}
@@ -451,20 +452,17 @@
 }
 
 static int ami_init(sfx_softseq_t *self, byte *patch, int patch_len, byte *patch2, int patch2_len) {
-	FILE *file;
+	Common::File file;
 	byte header[40];
 	int i;
 
-	file = sci_fopen("bank.001", "rb");
-
-	if (!file) {
+	if (!file.open("bank.001")) {
 		sciprintf("[sfx:seq:amiga] Error: file bank.001 not found\n");
 		return SFX_ERROR;
 	}
 
-	if (fread(header, 1, 40, file) < 40) {
+	if (file.read(header, 40) < 40) {
 		sciprintf("[sfx:seq:amiga] Error: failed to read header of file bank.001\n");
-		fclose(file);
 		return SFX_ERROR;
 	}
 
@@ -494,7 +492,6 @@
 
 		if (!instrument) {
 			sciprintf("[sfx:seq:amiga] Error: failed to read bank.001\n");
-			fclose(file);
 			return SFX_ERROR;
 		}
 
@@ -506,8 +503,6 @@
 		bank.instruments[id] = instrument;
 	}
 
-	fclose(file);
-
 	return SFX_OK;
 }
 

Modified: scummvm/trunk/engines/sci/tools.cpp
===================================================================
--- scummvm/trunk/engines/sci/tools.cpp	2009-02-22 19:32:44 UTC (rev 38790)
+++ scummvm/trunk/engines/sci/tools.cpp	2009-02-22 19:45:53 UTC (rev 38791)
@@ -53,16 +53,6 @@
 
 namespace Sci {
 
-// FIXME: Get rid of G_DIR_SEPARATOR  / G_DIR_SEPARATOR_S
-#if _MSC_VER
-#  define G_DIR_SEPARATOR_S "\\"
-#  define G_DIR_SEPARATOR '\\'
-#else
-#  define G_DIR_SEPARATOR_S "/"
-#  define G_DIR_SEPARATOR '/'
-#endif
-
-
 #ifndef _MSC_VER
 #  include <sys/time.h>
 #endif
@@ -331,11 +321,6 @@
 	// Expects *dir to be uninitialized and the caller to
 	// free it afterwards  */
 
-	if (strchr(fname, G_DIR_SEPARATOR)) {
-		fprintf(stderr, "_fcaseseek() does not support subdirs\n");
-		BREAKPOINT();
-	}
-
 	// Look up the file, ignoring case
 	Common::ArchiveMemberList files;
 	SearchMan.listMatchingMembers(files, fname);
@@ -388,27 +373,7 @@
 	return NULL;
 }
 
-#ifdef __DC__
-
 int sci_fd_size(int fd) {
-	return fs_total(fd);
-}
-
-int sci_file_size(const char *fname) {
-	int fd = fs_open(fname, O_RDONLY);
-	int retval = -1;
-
-	if (fd != 0) {
-		retval = sci_fd_size(fd);
-		fs_close(fd);
-	}
-
-	return retval;
-}
-
-#else
-
-int sci_fd_size(int fd) {
 	struct stat fd_stat;
 
 	if (fstat(fd, &fd_stat))
@@ -426,23 +391,4 @@
 	return fn_stat.st_size;
 }
 
-#endif
-
-/* 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 printable = 0;
-	int len = strlen(str);
-
-	if (len == 0) return 1;
-
-	while (*str) {
-		if (isprint(*str)) printable++;
-		str++;
-	}
-
-	return ((float)printable / (float)len >= 0.5);
-}
-
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/tools.h
===================================================================
--- scummvm/trunk/engines/sci/tools.h	2009-02-22 19:32:44 UTC (rev 38790)
+++ scummvm/trunk/engines/sci/tools.h	2009-02-22 19:45:53 UTC (rev 38791)
@@ -182,11 +182,6 @@
 ** Returns   : (int) filesize of the file, -1 on error
 */
 
-/* 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);
-
 /** Find first set bit in bits and return its index. Returns 0 if bits is 0. */
 int sci_ffs(int bits);
 


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