[Scummvm-cvs-logs] SF.net SVN: scummvm:[46204] tools/branches/gsoc2009-gui
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Sun Nov 29 22:32:25 CET 2009
Revision: 46204
http://scummvm.svn.sourceforge.net/scummvm/?rev=46204&view=rev
Author: fingolfin
Date: 2009-11-29 21:32:25 +0000 (Sun, 29 Nov 2009)
Log Message:
-----------
TOOLS: get rid of filesize()
Modified Paths:
--------------
tools/branches/gsoc2009-gui/Makefile
tools/branches/gsoc2009-gui/degob.cpp
tools/branches/gsoc2009-gui/dekyra.cpp
tools/branches/gsoc2009-gui/util.cpp
tools/branches/gsoc2009-gui/util.h
Modified: tools/branches/gsoc2009-gui/Makefile
===================================================================
--- tools/branches/gsoc2009-gui/Makefile 2009-11-29 21:22:25 UTC (rev 46203)
+++ tools/branches/gsoc2009-gui/Makefile 2009-11-29 21:32:25 UTC (rev 46204)
@@ -141,7 +141,7 @@
decine$(EXEEXT): decine.o
$(CXX) $(LDFLAGS) -o $@ $+
-dekyra$(EXEEXT): dekyra.o dekyra_v1.o util.o
+dekyra$(EXEEXT): dekyra.o dekyra_v1.o util.o $(UTILS)
$(CXX) $(LDFLAGS) -o $@ $+
descumm$(EXEEXT): descumm-tool.o descumm.o descumm6.o descumm-common.o util.o tool.o $(UTILS)
Modified: tools/branches/gsoc2009-gui/degob.cpp
===================================================================
--- tools/branches/gsoc2009-gui/degob.cpp 2009-11-29 21:22:25 UTC (rev 46203)
+++ tools/branches/gsoc2009-gui/degob.cpp 2009-11-29 21:32:25 UTC (rev 46204)
@@ -21,13 +21,13 @@
*/
#include "degob_script.h"
-#include <iostream>
+#include "utils/file.h"
-void printHelp(const char *bin);
-int getVersion(const char *verStr);
-byte *readFile(FILE *tot, uint32 &size);
-Script *initScript(byte *totData, uint32 totSize, ExtTable *extTable, int version);
-void printInfo(Script &script);
+static void printHelp(const char *bin);
+static int getVersion(const char *verStr);
+static byte *readFile(const char *filename, uint32 &size);
+static Script *initScript(byte *totData, uint32 totSize, ExtTable *extTable, int version);
+static void printInfo(Script &script);
int main(int argc, char **argv) {
@@ -42,15 +42,11 @@
return -1;
}
- FILE *f;
byte *totData = 0, *extData = 0, *extComData = 0;
uint32 totSize = 0, extSize = 0, extComSize = 0;
int32 offset = -1;
- if (!(f = fopen(argv[2], "rb")))
- error("Couldn't open file \"%s\"", argv[2]);
- totData = readFile(f, totSize);
- fclose(f);
+ totData = readFile(argv[2], totSize);
ExtTable *extTable = 0;
if (argc > 3) {
@@ -78,18 +74,12 @@
if (argc > n) {
- if (!(f = fopen(argv[n], "rb")))
- error("Couldn't open file \"%s\"", argv[n]);
- extData = readFile(f, extSize);
- fclose(f);
+ extData = readFile(argv[n], extSize);
n++;
if (argc > n) {
- if (!(f = fopen(argv[n], "rb")))
- error("Couldn't open file \"%s\"", argv[n]);
- extComData = readFile(f, extComSize);
- fclose(f);
+ extComData = readFile(argv[n], extComSize);
}
extTable = new ExtTable(extData, extSize, extComData, extComSize);
@@ -153,11 +143,14 @@
return -1;
}
-byte *readFile(FILE *tot, uint32 &size) {
- size = fileSize(tot);
- byte *data = new byte[size];
+byte *readFile(const char *filename, uint32 &size) {
+ File f(filename, "rb");
+ if (!f.isOpen())
+ error("Couldn't open file \"%s\"", filename);
- fread(data, size, 1, tot);
+ size = f.size();
+ byte *data = new byte[size];
+ f.read(data, size);
return data;
}
Modified: tools/branches/gsoc2009-gui/dekyra.cpp
===================================================================
--- tools/branches/gsoc2009-gui/dekyra.cpp 2009-11-29 21:22:25 UTC (rev 46203)
+++ tools/branches/gsoc2009-gui/dekyra.cpp 2009-11-29 21:32:25 UTC (rev 46204)
@@ -22,6 +22,7 @@
*/
#include "dekyra.h"
+#include "utils/file.h"
#include <stdio.h>
@@ -182,24 +183,23 @@
}
bool Script::loadScript(const char *filename, ScriptData *scriptData, OpcodeEntry *opcodes, int opcodeSize) {
- FILE *scriptFile = fopen(filename, "rb");
+ File scriptFile(filename, "rb");
- if (scriptFile == NULL) {
+ if (!scriptFile.isOpen()) {
error("couldn't load file '%s'", filename);
return false;
}
- uint32 size = fileSize(scriptFile);
+ uint32 size = scriptFile.size();
scriptData->fileSize = size;
uint8 *data = new uint8[size];
assert(data);
- if (size != fread(data, sizeof(uint8), size, scriptFile)) {
+ if (size != scriptFile.read(data, size)) {
delete [] data;
error("couldn't read all bytes from file '%s'", filename);
return false;
}
- fclose(scriptFile);
- scriptFile = NULL;
+ scriptFile.close();
byte *curData = data;
Modified: tools/branches/gsoc2009-gui/util.cpp
===================================================================
--- tools/branches/gsoc2009-gui/util.cpp 2009-11-29 21:22:25 UTC (rev 46203)
+++ tools/branches/gsoc2009-gui/util.cpp 2009-11-29 21:32:25 UTC (rev 46204)
@@ -101,13 +101,3 @@
fprintf(stdout, "%s\n", buf);
}
-
-uint32 fileSize(FILE *fp) {
- uint32 sz;
- uint32 pos = ftell(fp);
- fseek(fp, 0, SEEK_END);
- sz = ftell(fp);
- fseek(fp, pos, SEEK_SET);
- return sz;
-}
-
Modified: tools/branches/gsoc2009-gui/util.h
===================================================================
--- tools/branches/gsoc2009-gui/util.h 2009-11-29 21:22:25 UTC (rev 46203)
+++ tools/branches/gsoc2009-gui/util.h 2009-11-29 21:32:25 UTC (rev 46204)
@@ -137,13 +137,6 @@
#define NORETURN_POST
#endif
-
-/**
- * Returns the size of the FILE
- * Technically all code should use the File class instead, but until then we need this
- */
-uint32 fileSize(FILE *f);
-
/* Misc stuff */
void NORETURN_PRE error(const char *s, ...) NORETURN_POST;
void warning(const char *s, ...);
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