diff --git a/include/File.h b/include/File.h index eafc1f1d2d6352cd96712d2253efab46bffbc1b0..39bb238ddde4432684368469d32e866bac4b5232 100644 --- a/include/File.h +++ b/include/File.h @@ -114,6 +114,9 @@ public: /// Count the number of string lines into a text file. long getNumberOfStringLines(); + + /// The dimension of the file + dword fsize(); static dword byte_read; diff --git a/include/InputFile.h b/include/InputFile.h index 0697cf010c1e657a496a4fbe727094c90433f9af..fe9abb26b442ba86523395f197e3b7b63b492f16 100644 --- a/include/InputFile.h +++ b/include/InputFile.h @@ -35,16 +35,18 @@ public: virtual bool open( char** parameters ) throw(PacketExceptionIO*); - virtual void close() throw(PacketExceptionIO*); + virtual void close() throw(PacketExceptionIO*); virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); - virtual char* readString() throw(PacketExceptionIO*); + virtual char* readString() throw(PacketExceptionIO*); virtual int getType() { return 0; }; + + virtual dword setpos(dword offset) throw(PacketExceptionIO*); protected: diff --git a/include/OutputFile.h b/include/OutputFile.h index bf0e98ba30a6a4a3d28876ae5f7b37557c60ae48..d53d4259eaf23a689936fd0ca801e911e00f16c2 100644 --- a/include/OutputFile.h +++ b/include/OutputFile.h @@ -36,6 +36,8 @@ public: virtual void close() throw(PacketExceptionIO*); + ///first parameter: filename + ///second parameter: fopen modes: w, r, a (optional) virtual bool open(char** parameters) throw(PacketExceptionIO*); virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); diff --git a/src/File.cpp b/src/File.cpp index 4c51abb0640a54e4d8420a2403bae930bb91f400..c8616458297cb290c5b3b434ae53a9621bf6b0ed 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -345,3 +345,18 @@ bool File::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) return true; } + +dword File::fsize(){ + if(closed) + return 0; + + long prev=ftell(fp); + if(prev == -1L) + return 0; + fseek(fp, 0L, SEEK_END); + long sz=ftell(fp); + if(sz == -1L) + return 0; + fseek(fp,prev,SEEK_SET); //go back to where we were + return sz; +} diff --git a/src/InputFile.cpp b/src/InputFile.cpp index 8176966f07e2b5abe376ed0aa55d55d7383a00aa..2e15db016434b91b0de0eb208d7db931089257ec 100644 --- a/src/InputFile.cpp +++ b/src/InputFile.cpp @@ -74,3 +74,7 @@ char* InputFile::readString() throw(PacketExceptionIO*) eof = file->isEOF(); return c; } + +dword InputFile::setpos(dword offset) throw(PacketExceptionIO*) { + return file->setpos(offset); +} diff --git a/src/OutputFile.cpp b/src/OutputFile.cpp index f6a93dbc5109b6088ea099885e09685a6899d354..8725e483f718cacbdc63daf58d58d661c5002e80 100644 --- a/src/OutputFile.cpp +++ b/src/OutputFile.cpp @@ -44,7 +44,12 @@ void OutputFile::close() throw(PacketExceptionIO*) bool OutputFile::open(char** parameters) throw(PacketExceptionIO*) { - file->open(parameters[0], "w"); + if(parameters[1] != 0) { + file->open(parameters[0], parameters[1]); + } + else { + file->open(parameters[0], "w"); + } filename = parameters[0]; isclosed = false; return true;