[DEBUG] correction of the read write access in the buffer system

This commit is contained in:
Edouard DUPIN 2012-11-08 08:43:18 +01:00
parent 841f23a2db
commit 450fc0532d
5 changed files with 19 additions and 20 deletions

View File

@ -128,8 +128,7 @@ BufferText::BufferText(etk::FSNode &fileName) : Buffer(fileName)
APPL_WARNING("File can not be open in read mode : " << myFile); APPL_WARNING("File can not be open in read mode : " << myFile);
SetModify(true); SetModify(true);
} else { } else {
// TODO : Old methode to file access : m_EdnBuf.DumpFrom(myFile);
//m_EdnBuf.DumpFrom(myFile);
myFile.FileClose(); myFile.FileClose();
SetModify(false); SetModify(false);
} }
@ -157,8 +156,7 @@ void BufferText::Save(void)
if (false == myFile.FileOpenWrite()) { if (false == myFile.FileOpenWrite()) {
APPL_ERROR("Can not open in writing the specify file"); APPL_ERROR("Can not open in writing the specify file");
} else { } else {
// TODO : Old methode to file access : m_EdnBuf.DumpIn(myFile);
//m_EdnBuf.DumpIn(myFile);
myFile.FileClose(); myFile.FileClose();
SetModify(false); SetModify(false);
} }

View File

@ -89,10 +89,10 @@ EdnBuf::~EdnBuf(void)
* @return true if OK / false if an error occured * @return true if OK / false if an error occured
* *
*/ */
bool EdnBuf::DumpIn(FILE *myFile) bool EdnBuf::DumpIn(etk::FSNode &file)
{ {
// write Data // write Data
return m_data.DumpIn(myFile); return m_data.DumpIn(file);
} }
@ -104,9 +104,9 @@ bool EdnBuf::DumpIn(FILE *myFile)
* @return true if OK / false if an error occured * @return true if OK / false if an error occured
* *
*/ */
bool EdnBuf::DumpFrom(FILE *myFile) bool EdnBuf::DumpFrom(etk::FSNode &file)
{ {
if (true == m_data.DumpFrom(myFile) ) { if (true == m_data.DumpFrom(file) ) {
// set no selection // set no selection
UpdateSelection(0, 0, m_data.Size() ); UpdateSelection(0, 0, m_data.Size() );
// generate HighLight // generate HighLight

View File

@ -78,8 +78,8 @@ class EdnBuf {
void SetAll( etk::Vector<int8_t> &text); void SetAll( etk::Vector<int8_t> &text);
void GetRange( int32_t start, int32_t end, etk::Vector<int8_t> &output); void GetRange( int32_t start, int32_t end, etk::Vector<int8_t> &output);
void GetRange( int32_t start, int32_t end, etk::UString &output); void GetRange( int32_t start, int32_t end, etk::UString &output);
bool DumpIn( FILE *myFile); bool DumpIn( etk::FSNode &file);
bool DumpFrom( FILE *myFile); bool DumpFrom( etk::FSNode &file);
// replace with operator [] ... // replace with operator [] ...
int8_t operator[] (int32_t); int8_t operator[] (int32_t);
int32_t Insert( int32_t pos, etk::Vector<int8_t> &insertText); int32_t Insert( int32_t pos, etk::Vector<int8_t> &insertText);

View File

@ -114,12 +114,12 @@ static int32_t getFileSize(FILE *myFile)
* @return true if OK / false if an error occured * @return true if OK / false if an error occured
* *
*/ */
bool EdnVectorBuf::DumpIn(FILE *myFile) bool EdnVectorBuf::DumpIn(etk::FSNode &file)
{ {
bool ret = true; bool ret = true;
// write Data // write Data
(void)fwrite(m_data, sizeof(int8_t), m_gapStart, myFile); (void)file.FileWrite(m_data, sizeof(int8_t), m_gapStart);
(void)fwrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd, myFile); (void)file.FileWrite(&m_data[m_gapEnd], sizeof(int8_t), m_allocated - m_gapEnd);
return ret; return ret;
} }
@ -132,19 +132,19 @@ bool EdnVectorBuf::DumpIn(FILE *myFile)
* @return true if OK / false if an error occured * @return true if OK / false if an error occured
* *
*/ */
bool EdnVectorBuf::DumpFrom(FILE *myFile) bool EdnVectorBuf::DumpFrom(etk::FSNode &file)
{ {
bool ret = true; bool ret = true;
int32_t length = getFileSize(myFile); uint32_t length = file.FileSize();
// error case ... // error case ...
if (length < 0) { if (length > 2000000000) {
length = 0; return false;
} }
// allocate the current buffer : // allocate the current buffer :
ChangeAllocation(length + GAP_SIZE_MIN); ChangeAllocation(length + GAP_SIZE_MIN);
// insert Data // insert Data
int32_t nbReadData = fread(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length, myFile); int32_t nbReadData = file.FileRead(&m_data[GAP_SIZE_MIN], sizeof(int8_t), length);
APPL_INFO("load data : filesize=" << length << ", readData=" << nbReadData); APPL_INFO("load data : filesize=" << length << ", readData=" << nbReadData);
// check ERROR // check ERROR
if (nbReadData != length) { if (nbReadData != length) {

View File

@ -27,6 +27,7 @@
#define __EDN_VECTOR_BUF_H__ #define __EDN_VECTOR_BUF_H__
#include <etk/Vector.h> #include <etk/Vector.h>
#include <etk/os/FSNode.h>
#undef __class__ #undef __class__
#define __class__ "EdnVectorBuf" #define __class__ "EdnVectorBuf"
@ -265,8 +266,8 @@ class EdnVectorBuf
EdnVectorBuf(const EdnVectorBuf & Evb); EdnVectorBuf(const EdnVectorBuf & Evb);
~EdnVectorBuf(); ~EdnVectorBuf();
bool DumpIn( FILE *myFile); bool DumpIn( etk::FSNode &file);
bool DumpFrom( FILE *myFile); bool DumpFrom( etk::FSNode &file);
EdnVectorBuf & operator=( const EdnVectorBuf & Evb); EdnVectorBuf & operator=( const EdnVectorBuf & Evb);
int8_t operator[] (int32_t pos); int8_t operator[] (int32_t pos);