Correezioni per compilazione
git-svn-id: svn://10.65.10.50/trunk@1470 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
720e9a0326
commit
182b649bde
@ -9,7 +9,7 @@
|
|||||||
#define BLOCK_SIZE 1024
|
#define BLOCK_SIZE 1024
|
||||||
|
|
||||||
TMemo_file::TMemo_file(const char* a) :
|
TMemo_file::TMemo_file(const char* a) :
|
||||||
_fname(a), _fp(NULL), _isnew(NULL)
|
_fname(a), _fp(NULL), _isnew(NULL)
|
||||||
{
|
{
|
||||||
// handles: open file or create
|
// handles: open file or create
|
||||||
_fname.ext("mem");
|
_fname.ext("mem");
|
||||||
@ -38,12 +38,12 @@ TMemo_file::~TMemo_file()
|
|||||||
{
|
{
|
||||||
if (_fp) fclose(_fp);
|
if (_fp) fclose(_fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMemo_file::_find_id(long id)
|
bool TMemo_file::_find_id(long id)
|
||||||
{
|
{
|
||||||
if (id > _id_max && id < 0)
|
if (id > _id_max && id < 0)
|
||||||
error_box("File memo inconsistente");
|
error_box("File memo inconsistente");
|
||||||
|
|
||||||
bool dndir = FALSE /* id > (_id_max/2l) */ ;
|
bool dndir = FALSE /* id > (_id_max/2l) */ ;
|
||||||
|
|
||||||
_current = -1l;
|
_current = -1l;
|
||||||
@ -52,7 +52,7 @@ bool TMemo_file::_find_id(long id)
|
|||||||
fseek(_fp, pos, dndir ? SEEK_END : SEEK_SET);
|
fseek(_fp, pos, dndir ? SEEK_END : SEEK_SET);
|
||||||
|
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
while (_current < id)
|
while (_current < id)
|
||||||
{
|
{
|
||||||
// se si va all'indietro, questa non funzia: nonostante
|
// se si va all'indietro, questa non funzia: nonostante
|
||||||
@ -64,8 +64,8 @@ bool TMemo_file::_find_id(long id)
|
|||||||
if (_current < id)
|
if (_current < id)
|
||||||
{
|
{
|
||||||
long ofs = dndir ? -_next_ofs-INFO_SIZE-INFO_SIZE :
|
long ofs = dndir ? -_next_ofs-INFO_SIZE-INFO_SIZE :
|
||||||
_next_ofs+INFO_SIZE;
|
_next_ofs+INFO_SIZE;
|
||||||
|
|
||||||
ok = fseek(_fp, ofs, SEEK_CUR);
|
ok = fseek(_fp, ofs, SEEK_CUR);
|
||||||
}
|
}
|
||||||
if (ok) break;
|
if (ok) break;
|
||||||
@ -74,22 +74,22 @@ bool TMemo_file::_find_id(long id)
|
|||||||
_current = ok ? -1l : id;
|
_current = ok ? -1l : id;
|
||||||
return _current == id;
|
return _current == id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMemo_file::get_field(TTextfile& t, long id)
|
bool TMemo_file::get_field(TTextfile& t, long id)
|
||||||
{
|
{
|
||||||
bool ok = _find_id(id);
|
bool ok = _find_id(id);
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
_current = id;
|
_current = id;
|
||||||
|
|
||||||
// te lo faccio io, poi so' cazzi tua se sbagli
|
// te lo faccio io, poi so' cazzi tua se sbagli
|
||||||
t.destroy();
|
t.destroy();
|
||||||
|
|
||||||
TString256 line;
|
TString256 line;
|
||||||
|
|
||||||
// block read until done; transfer block to txt
|
// block read until done; transfer block to txt
|
||||||
// block by block
|
// block by block
|
||||||
|
|
||||||
long size = _next_ofs < BLOCK_SIZE ? _next_ofs : BLOCK_SIZE;
|
long size = _next_ofs < BLOCK_SIZE ? _next_ofs : BLOCK_SIZE;
|
||||||
int lcnt = 0;
|
int lcnt = 0;
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ bool TMemo_file::get_field(TTextfile& t, long id)
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
long TMemo_file::set_field(TTextfile& t, long id)
|
long TMemo_file::set_field(const TTextfile& t, long id)
|
||||||
{
|
{
|
||||||
bool ok = TRUE;
|
bool ok = TRUE;
|
||||||
long ret = 0;
|
long ret = 0;
|
||||||
@ -127,7 +127,7 @@ long TMemo_file::set_field(TTextfile& t, long id)
|
|||||||
bool at_end = id == -1 || (id != -1 && id > _id_max);
|
bool at_end = id == -1 || (id != -1 && id > _id_max);
|
||||||
// the casinating insertion in the middol
|
// the casinating insertion in the middol
|
||||||
bool in_mid = FALSE;
|
bool in_mid = FALSE;
|
||||||
|
|
||||||
if (!at_end)
|
if (!at_end)
|
||||||
{
|
{
|
||||||
ok = _find_id(id);
|
ok = _find_id(id);
|
||||||
@ -137,17 +137,17 @@ long TMemo_file::set_field(TTextfile& t, long id)
|
|||||||
// vediamo dove
|
// vediamo dove
|
||||||
long pos = HEADER_SIZE;
|
long pos = HEADER_SIZE;
|
||||||
fseek(_fp, pos, SEEK_SET);
|
fseek(_fp, pos, SEEK_SET);
|
||||||
|
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
while (_current < id)
|
while (_current < id)
|
||||||
{
|
{
|
||||||
fread(&_current, sizeof(long), 1, _fp);
|
fread(&_current, sizeof(long), 1, _fp);
|
||||||
fread(&_next_ofs, sizeof(long), 1, _fp);
|
fread(&_next_ofs, sizeof(long), 1, _fp);
|
||||||
if (_current < id)
|
if (_current < id)
|
||||||
{
|
{
|
||||||
long ofs = _next_ofs+INFO_SIZE;
|
long ofs = _next_ofs+INFO_SIZE;
|
||||||
ok = fseek(_fp, ofs, SEEK_CUR);
|
ok = fseek(_fp, ofs, SEEK_CUR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -179,7 +179,7 @@ long TMemo_file::set_field(TTextfile& t, long id)
|
|||||||
{
|
{
|
||||||
line = t.line(i);
|
line = t.line(i);
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
for (int k = 0; c = line[k]; k++)
|
for (int k = 0; c = line[k]; k++)
|
||||||
{
|
{
|
||||||
fwrite(&c, sizeof(char), 1, _fp);
|
fwrite(&c, sizeof(char), 1, _fp);
|
||||||
@ -212,10 +212,10 @@ long TMemo_file::set_field(TTextfile& t, long id)
|
|||||||
FILE* tfp = fopen(tmp, "wb+");
|
FILE* tfp = fopen(tmp, "wb+");
|
||||||
|
|
||||||
fseek(_fp, 0, SEEK_SET);
|
fseek(_fp, 0, SEEK_SET);
|
||||||
|
|
||||||
long size = BLOCK_SIZE;
|
long size = BLOCK_SIZE;
|
||||||
bool stop = FALSE;
|
bool stop = FALSE;
|
||||||
|
|
||||||
// copy file into temp up to TO pos
|
// copy file into temp up to TO pos
|
||||||
// use 1k blocks for speed
|
// use 1k blocks for speed
|
||||||
for (int i = 0; !stop; i++)
|
for (int i = 0; !stop; i++)
|
||||||
@ -240,7 +240,7 @@ long TMemo_file::set_field(TTextfile& t, long id)
|
|||||||
{
|
{
|
||||||
line = t.line(i);
|
line = t.line(i);
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
for (int k = 0; c = line[k]; k++)
|
for (int k = 0; c = line[k]; k++)
|
||||||
{
|
{
|
||||||
fwrite(&c, sizeof(char), 1, tfp);
|
fwrite(&c, sizeof(char), 1, tfp);
|
||||||
@ -283,7 +283,7 @@ long TMemo_file::set_field(TTextfile& t, long id)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMemo_file::remove_field(long id)
|
bool TMemo_file::remove_field(long id)
|
||||||
{
|
{
|
||||||
bool ok = _find_id(id);
|
bool ok = _find_id(id);
|
||||||
@ -296,10 +296,10 @@ bool TMemo_file::remove_field(long id)
|
|||||||
FILE* tfp = fopen(tmp, "wb+");
|
FILE* tfp = fopen(tmp, "wb+");
|
||||||
|
|
||||||
fseek(_fp, 0, SEEK_SET);
|
fseek(_fp, 0, SEEK_SET);
|
||||||
|
|
||||||
long size = BLOCK_SIZE;
|
long size = BLOCK_SIZE;
|
||||||
bool stop = FALSE;
|
bool stop = FALSE;
|
||||||
|
|
||||||
// copy file into temp up to TO pos
|
// copy file into temp up to TO pos
|
||||||
// use 1k blocks for speed
|
// use 1k blocks for speed
|
||||||
for (int i = 0; !stop; i++)
|
for (int i = 0; !stop; i++)
|
||||||
@ -331,7 +331,7 @@ bool TMemo_file::remove_field(long id)
|
|||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TMemo_file::edit_field(long id)
|
bool TMemo_file::edit_field(long id)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -20,7 +20,7 @@ class TMemo_file : public TObject
|
|||||||
long _next_ofs;
|
long _next_ofs;
|
||||||
|
|
||||||
bool _find_id(long id);
|
bool _find_id(long id);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// retrieves text with specified ID (or last one passed);
|
// retrieves text with specified ID (or last one passed);
|
||||||
@ -33,10 +33,10 @@ public:
|
|||||||
bool remove_field(long id);
|
bool remove_field(long id);
|
||||||
// calls editor to edit text (specified as mem into config)
|
// calls editor to edit text (specified as mem into config)
|
||||||
bool edit_field(long id = -1l);
|
bool edit_field(long id = -1l);
|
||||||
|
|
||||||
// returns the maximum ID used (<= n. of fields in file)
|
// returns the maximum ID used (<= n. of fields in file)
|
||||||
long max_id() const { return _id_max; }
|
long max_id() const { return _id_max; }
|
||||||
|
|
||||||
// must be passed the basename of archive
|
// must be passed the basename of archive
|
||||||
TMemo_file(const char* archive);
|
TMemo_file(const char* archive);
|
||||||
~TMemo_file();
|
~TMemo_file();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user