Patch level : 2.0 nopatch

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Decretata la fine della stringa temporanea globale __tmp_string!
Decretata la fine della inutile classe TMemo_field
Allungata la linea tratteggiata di salto pagina in anteprima (per risoluzioni >= 1024)


git-svn-id: svn://10.65.10.50/trunk@11054 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2003-04-23 09:25:32 +00:00
parent e4c49bb8b7
commit b17eae20c0
8 changed files with 3 additions and 492 deletions

View File

@ -3,7 +3,7 @@
<dictionary>
<entry module="ba">
<ita>Attezione: premere OK per cancellare</ita>
<eng>Atension: pres OK to dilit</eng>
<eng>Attension: pres ochei to dilit</eng>
</entry>
</dictionary>
</xml>
@ -16,7 +16,6 @@
#include <scanner.h>
#include <utility.h>
///////////////////////////////////////////////////////////
// TTraduttore
///////////////////////////////////////////////////////////

View File

@ -13,7 +13,6 @@
#include <expr.h>
#include <extcdecl.h>
#include <mailbox.h>
#include <memo.h>
#include <postman.h>
#include <prefix.h>
#include <progind.h>
@ -3142,29 +3141,6 @@ bool TRectype::get_bool(const char* fieldname) const
return *(get_str(fieldname)) == 'X';
}
// @doc EXTERNAL
// @mfunc Ritorna il contenuto di un campo memo
//
// @rdesc Ritorna sempre TRUE
bool TRectype::get_memo(
const char* fieldname, // @parm Nome del campo da cui estrarre il contenuto
TTextfile& txt) const // @parm Reference della variabile a cui assegnare il contenuto dell campo
{
TToken_string memo( get( fieldname ), '\n' );
const int last = memo.items( );
for(int i = 0; i < last; i++)
{
TString m(memo.get(i));
const int l = m.len() > 0 ? m.len()-1 : 0;
if (m[l] == '\r') m.cut(l);
txt.append( m );
}
return TRUE;
}
TDate TRectype::get_date(const char* fieldname) const
{
TDate d(get_str(fieldname));
@ -3186,26 +3162,6 @@ void TRectype::put(const char* fieldname, long val)
put_str(fieldname, tmp);
}
void TRectype::put(const char* fieldname, TTextfile& txt)
{
long val = get_long(fieldname);
const bool isnew = val == 0;
TFilename fname;
int logicnum = num();
TIsam_handle isam_handle = prefix().open_isamfile(logicnum, fname);
TMemo_file memo(fname);
prefix().close_isamfile(isam_handle);
const long id = memo.set_field(txt, isnew ? FIELDERR : val);
if (isnew) val = id;
TString16 tmp; tmp.format("%ld", val);
put_str( fieldname, tmp);
}
void TRectype::put(const char* fieldname, word val)
{
@ -3216,13 +3172,11 @@ void TRectype::put(const char* fieldname, word val)
void TRectype::put(const char* fieldname, const real& val)
{
put_str( fieldname, val.string());
setempty(FALSE);
}
void TRectype::put(const char* fieldname, const TCurrency& val)
{
put_str( fieldname, val.get_num().string());
setempty(FALSE);
}
void TRectype::put(const char* fieldname, const TDate& val)
@ -3232,7 +3186,7 @@ void TRectype::put(const char* fieldname, const TDate& val)
void TRectype::put(const char* fieldname, char val)
{
const char w[2] = {val, '\0'};
const char w[2] = {val, '\0'};
put_str( fieldname, w);
}

View File

@ -1,14 +1,10 @@
#ifndef __ISAM_H
#define __ISAM_H
#ifndef FOXPRO
#ifndef __CURRENCY_H
#include <currency.h>
#endif
#endif
#ifndef __DATE_H
#include <date.h>
#endif
@ -21,10 +17,6 @@
#include <lffiles.h>
#endif
#ifndef __TEXT_H
class TTextfile;
#endif
#ifndef __PREFIX_H
#include <prefix.h>
#endif
@ -173,7 +165,6 @@ public:
bool same_key(const TRectype& rec, int key = 1, int skip_last = 0) const
{ return compare_key(rec, key, skip_last) == 0; }
#ifndef FOXPRO
// @cmember Ritorna il reference al contenuto del campo <p fieldname>
const TString& get(const char* fieldname) const ;
// @cmember Ritorna il contenuto del campo <p fieldname> in formato int
@ -188,13 +179,9 @@ public:
bool get_bool(const char* fieldname) const ;
// @cmember Ritorna il contenuto del campo <p fieldname> in formato real
real get_real(const char* fieldname) const ;
// @cmember Ritorna il contenuto di un campo memo
bool get_memo(const char* fieldname, TTextfile& txt) const ;
#endif
// @cmember Ritorna il contenuto del campo <p fieldname> in formato data
TDate get_date(const char* fieldname) const ;
#ifndef FOXPRO
// @cmember Setta il contenuto del campo <p fieldname> in formato int
void put(const char* fieldname, int val);
// @cmember Setta il contenuto del campo <p fieldname> in formato long
@ -211,11 +198,8 @@ public:
void put(const char* fieldname, const real& val);
// @cmember Setta il contenuto del campo <p fieldname> in formato valuta
void put(const char* fieldname, const TCurrency& val);
// @cmember Setta il contenuto del campo <p fieldname> in formato memo
void put(const char* fieldname, TTextfile& txt);
// @cmember Setta il contenuto del campo <p fieldname> (non tipizzata)
void put(const char* fieldname, const char* val) { put_str(fieldname, val); }
#endif
#ifdef __LONGDOUBLE__
// @cmember Setta il contenuto del campo <p fieldname> in formato reale
@ -444,7 +428,6 @@ public:
// @cmember Numero di records presenti nel file
long items() const; // n.o di records nel file
#ifndef FOXPRO
// @cmember Ritorna il contenuto del campo <p fieldname> di tipo int
int get_int(const char* fieldname) const
{ return curr().get_int(fieldname);}
@ -463,15 +446,10 @@ public:
// @cmember Ritorna il contenuto del campo <p fieldname> di tipo real
real get_real(const char* fieldname) const
{ return curr().get_real(fieldname);}
// @cmember Ritorna il contenuto del campo <p fieldname> di tipo memo (vedi <mf TRectype::get_memo>)
bool get_memo(const char* fieldname, TTextfile& txt)
{ return curr().get_memo(fieldname, txt); }
#endif
// @cmember Ritorna il contenuto del campo <p fieldname> di tipo data
TDate get_date(const char* fieldname) const
{ return curr().get_date(fieldname);}
#ifndef FOXPRO
// @cmember Ritorna il contenuto del campo <p fieldname> (non tipizzata)
const TString& get(const char* fieldname) const
{ return curr().get(fieldname);}
@ -500,14 +478,6 @@ public:
// @cmember Setta il contenuto del campo <p fieldname> di tipo valuta
void put(const char* fieldname, const TCurrency& val)
{ curr().put(fieldname, val);}
// @cmember Setta il contenuto del campo <p fieldname> di tipo memo (vedi <mf TRectype::put_memo>)
void put(const char* fieldname, TTextfile& txt)
{ curr().put(fieldname, txt); }
#else
// @cmember Ritorna una stringa con il contenuto del campo <p fieldname>
const char* get_str(const char* fieldname) const
{ return (const char *) curr().get_str(fieldname);}
#endif
#ifdef __LONGDOUBLE__
// @cmember Setta il contenuto del campo <p fieldname> in formato reale

View File

@ -1,359 +0,0 @@
#include <memo.h>
#include <utility.h>
#include <io.h>
#include <sys/locking.h>
#define HEADER_SIZE (sizeof(long)+sizeof(char))
#define INFO_SIZE (sizeof(long)+sizeof(long))
// block size used in writes
#define BLOCK_SIZE (1024)
// max allowed size for locking is 100k
#define MAX_SIZE (100000l)
TMemo_file::TMemo_file(const char* a) :
_fname(a), _fp(NULL), _isnew(FALSE)
{
// handles: open file or create
_fname.ext("mem");
if (!(_fp = fopen(_fname,"rb+")))
{
_fp = fopen(_fname,"wb+");
_isnew = TRUE;
}
if (_fp == NULL)
error_box("File memo %s non creato per errori di disco", (const char *) _fname);
// read (write) header
if (_isnew)
{
_id_max = 0;
fwrite(&_id_max, sizeof(long), 1, _fp);
char eof = 26; // only to inhibit 'type'
fwrite(&eof, sizeof(char), 1, _fp);
}
else
fread(&_id_max, sizeof(long), 1, _fp);
}
TMemo_file::~TMemo_file()
{
if (_fp) fclose(_fp);
}
bool TMemo_file::_find_id(long id)
{
if (id > _id_max && id < 0)
error_box("File memo inconsistente");
bool dndir = FALSE /* id > (_id_max/2l) */ ;
_current = -1l;
long pos = dndir ? INFO_SIZE : HEADER_SIZE;
fseek(_fp, pos, dndir ? SEEK_END : SEEK_SET);
int ok = 0;
while (_current < id)
{
// se si va all'indietro, questa non funzia: nonostante
// fflush il file non e' tutto scritto su disco, e fread
// ritorna 0 lasciando tutto al valore precedente
// Perche'? Eh?
fread(&_current, sizeof(long), 1, _fp);
fread(&_next_ofs, sizeof(long), 1, _fp);
if (_current < id)
{
long ofs = dndir ? -_next_ofs-INFO_SIZE-INFO_SIZE :
_next_ofs+INFO_SIZE;
ok = fseek(_fp, ofs, SEEK_CUR);
}
if (ok) break;
}
_current = ok ? -1l : id;
return _current == id;
}
bool TMemo_file::get_field(TTextfile& t, long id)
{
bool ok = _find_id(id);
if (ok)
{
_current = id;
// te lo faccio io, poi so' cazzi tua se sbagli
t.destroy();
TString256 line;
// block read until done; transfer block to txt
// block by block
long size = _next_ofs < BLOCK_SIZE ? _next_ofs : BLOCK_SIZE;
int lcnt = 0;
for (long cnt = 0; cnt < _next_ofs; cnt += size)
{
if (fread(__tmp_string, sizeof(char), (int)size, _fp) != (size_t)size)
error_box("%s: unexpected end of file", (const char *) _fname);
// move block into text
for(long j = 0; j <= size; j++)
{
char ch = j < size ? __tmp_string[j] : '\0';
if (ch == '\n' || j == size)
{
line[lcnt] = '\0';
t.append(line);
lcnt = 0;
}
else line[lcnt++] = ch;
}
// size of next read
size = cnt + size < BLOCK_SIZE ? _next_ofs - cnt : BLOCK_SIZE;
}
}
return ok;
}
long TMemo_file::set_field(TTextfile& t, long id)
{
bool ok = TRUE;
long ret = 0;
// append se -1 o se l'ID e' maggiore dell'ultima presente
bool at_end = id == -1 || (id != -1 && id > _id_max);
// the casinating insertion in the middol
bool in_mid = FALSE;
if (!at_end)
{
ok = _find_id(id);
if (!ok)
{
// va inserito al posto di uno scancellato
// vediamo dove
long pos = HEADER_SIZE;
fseek(_fp, pos, SEEK_SET);
int ok = 0;
while (_current < id)
{
fread(&_current, sizeof(long), 1, _fp);
fread(&_next_ofs, sizeof(long), 1, _fp);
if (_current < id)
{
long ofs = _next_ofs+INFO_SIZE;
ok = fseek(_fp, ofs, SEEK_CUR);
}
else
{
// position the luridissim cazz at bighinnin
// of privius bifor riding ids
long oo = (long)INFO_SIZE * -1l;
fseek(_fp, oo, SEEK_CUR);
break;
}
if (ok) error_box("file error in %s", (const char *) _fname);
in_mid = TRUE;
}
}
}
if (at_end) // the easy case
{
if (id == -1) id = ++_id_max;
// append test, update info
long cnt = 0l;
fseek(_fp, 0, SEEK_END);
// lock file
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
_locking(_fileno(_fp), _LK_LOCK, MAX_SIZE);
#else
locking(fileno(_fp), LK_LOCK, MAX_SIZE);
#endif
fwrite(&id, sizeof(long), 1, _fp);
// will overwrite later with byte count
long cpos = ftell(_fp);
fwrite(&id, sizeof(long), 1, _fp);
TString256 line;
for (int i = 0; i < t.lines(); i++)
{
line = t.line(i);
char c;
for (int k = 0; c = line[k]; k++)
{
fwrite(&c, sizeof(char), 1, _fp);
cnt++;
}
if (i < t.lines() - 1)
{
c = '\n';
fwrite(&c, sizeof(char), 1, _fp);
cnt++;
}
}
//
fwrite(&id, sizeof(long), 1, _fp);
fwrite(&cnt, sizeof(long), 1, _fp);
// update count
fseek(_fp, cpos, SEEK_SET);
fwrite(&cnt, sizeof(long), 1, _fp);
fseek(_fp, 0, SEEK_SET);
fwrite(&_id_max, sizeof(long), 1, _fp);
#if XVT_OS == XVT_OS_WIN || XVT_OS == XVT_OS_WIN32
_locking(_fileno(_fp), _LK_UNLCK, MAX_SIZE);
#else
locking(fileno(_fp), LK_UNLCK, MAX_SIZE);
#endif
fflush(_fp);
ret = _find_id(id) ? id : -1;
}
else // the rognous one
{
long to = ftell(_fp) - INFO_SIZE;
long from = in_mid ? to : to + _next_ofs + (2*INFO_SIZE);
TFilename tmp; tmp.temp();
FILE* tfp = fopen(tmp, "wb+");
fseek(_fp, 0, SEEK_SET);
long size = BLOCK_SIZE;
bool stop = FALSE;
// copy file into temp up to TO pos
// use 1k blocks for speed
for (int i = 0; !stop; i++)
{
if (to < (BLOCK_SIZE * (i+1)))
{
size = to - i*BLOCK_SIZE;
stop = TRUE;
}
fread (__tmp_string, sizeof(char), (int)size, _fp);
fwrite(__tmp_string, sizeof(char), (int)size, tfp);
}
// write new text and update info
fwrite(&id, sizeof(long), 1, tfp);
// will overwrite later with byte count
long cpos = ftell(tfp);
fwrite(&id, sizeof(long), 1, tfp);
TString256 line; long cnt = 0l;
for (i = 0; i < t.lines(); i++)
{
line = t.line(i);
char c;
for (int k = 0; c = line[k]; k++)
{
fwrite(&c, sizeof(char), 1, tfp);
cnt++;
}
if (i < t.lines() - 1)
{
c = '\n';
fwrite(&c, sizeof(char), 1, tfp);
cnt++;
}
}
//
fwrite(&id, sizeof(long), 1, tfp);
fwrite(&cnt, sizeof(long), 1, tfp);
// write the rest of the file
stop = FALSE;
fseek(_fp, from, SEEK_SET);
for (i = 0; !stop; i++)
{
int size = fread (__tmp_string, sizeof(char), BLOCK_SIZE, _fp);
if (size) fwrite(__tmp_string, sizeof(char), size, tfp);
stop = size < BLOCK_SIZE;
}
// update count
fseek(tfp, cpos, SEEK_SET);
fwrite(&cnt, sizeof(long), 1, tfp);
fclose(tfp);
// move files
fclose(_fp);
fcopy(tmp, _fname);
remove(tmp);
_fp = fopen(_fname, "rb+");
ret = _find_id(id) ? 0 : -1;
}
_dirty = TRUE;
return ret;
}
bool TMemo_file::remove_field(long id)
{
bool ok = _find_id(id);
if (ok)
{
long to = ftell(_fp) - INFO_SIZE;
long from = to + _next_ofs + (2*INFO_SIZE);
TFilename tmp; tmp.temp();
FILE* tfp = fopen(tmp, "wb+");
fseek(_fp, 0, SEEK_SET);
long size = BLOCK_SIZE;
bool stop = FALSE;
// copy file into temp up to TO pos
// use 1k blocks for speed
for (int i = 0; !stop; i++)
{
if (to < (BLOCK_SIZE * (i+1)))
{
size = to - i*BLOCK_SIZE;
stop = TRUE;
}
fread (__tmp_string, sizeof(char), (int)size, _fp);
fwrite(__tmp_string, sizeof(char), (int)size, tfp);
}
// write the rest of the file
stop = FALSE;
fseek(_fp, from, SEEK_SET);
for (i = 0; !stop; i++)
{
int size = fread (__tmp_string, sizeof(char), BLOCK_SIZE, _fp);
if (size) fwrite(__tmp_string, sizeof(char), size, tfp);
stop = size < BLOCK_SIZE;
}
// move files
fclose(tfp);
fclose(_fp);
fcopy(tmp, _fname);
remove(tmp);
_fp = fopen(_fname, "rb+");
}
return ok;
}
bool TMemo_file::edit_field(long id)
{
return TRUE;
}

View File

@ -1,45 +0,0 @@
#ifndef __MEMO_H
#define __MEMO_H
#ifndef __TEXT_H
#include <text.h>
#endif
// quick and dirty memofile class
// to be used with isamfiles
// memo field is a long integer, memo file is <isamname>.mem
class TMemo_file : public TObject
{
bool _dirty;
FILE* _fp;
long _current;
TFilename _fname;
bool _isnew;
long _id_max;
long _next_ofs;
bool _find_id(long id);
public:
// retrieves text with specified ID (or last one passed);
// returns TRUE if successful
bool get_field(TTextfile& t, long id = -1l);
// sets field to specified text; if not present
// returns new ID; if error returns -1, otherwise 0
long set_field(TTextfile& t, long id = -1l);
// removes field and pakkettates file
bool remove_field(long id);
// calls editor to edit text (specified as mem into config)
bool edit_field(long id = -1l);
// returns the maximum ID used (<= n. of fields in file)
long max_id() const { return _id_max; }
// must be passed the basename of archive
TMemo_file(const char* archive);
~TMemo_file();
};
#endif

View File

@ -4,7 +4,6 @@
#include <diction.h>
#include <strings.h>
#define __UTILITY_CPP
#include <utility.h>
// @doc EXTERNAL

View File

@ -41,11 +41,4 @@ const char* unesc(const char* str); // Trasforma i caratteri '\n' nella sequenza
#define ODD(x) (x & 1)
#define EVEN(x) !(x & 1)
#ifdef __UTILITY_CPP
char __tmp_string[1024];
#else
extern char __tmp_string[1024];
#endif
#endif /* __UTILITY_H */

View File

@ -1004,7 +1004,7 @@ void TViswin::paint_row (long j)
b.h = tabx(X_OFFSET -1);
b.v = taby(row + Y_OFFSET) - 1;
e.h = tabx(132);
e.h = tabx(164);
e.v = taby(row + Y_OFFSET) - 1;
set_pen (COLOR_LTGRAY, 2, PAT_SOLID, P_DASH);
xvt_dwin_draw_set_pos (win(), b);