filetext.* Aggiunto supporto per saltare le prime _skiplines di un file
form.cpp Rimodernato uso della clessidra: niente piu' main_app().begin_wait(); e main_app().end_wait(); ma solo e semplicemente TWait_cursor hourglass; isam.* Aggiunto metodo TBaseisamfile::open_ex che non da' errore fatale se non puo' aprire un file, bensi' ritorna un codice d'errore appropriato. Aggiunto parametro zap alla TSystemisamfile::pack_file che permette di azzerare completamente i record di un file lffiles.h Aggiunta #define LF_EXTERNAL 1000 per indicare la base dei numeri logici dei file dbf esterni git-svn-id: svn://10.65.10.50/trunk@6041 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
33e30f1df6
commit
af43d798cd
@ -73,8 +73,10 @@ const TString& TFile_text::fpicture(const TTracciato_campo &tc ) const
|
|||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////// TTracciato_record ////////////////////////////////////////
|
//////////////////////////////////////// TTracciato_record ////////////////////////////////////////
|
||||||
void TTracciato_record::set_relation(TRelation * rel)
|
|
||||||
|
void TTracciato_record::set_relation(TRelation* rel)
|
||||||
{
|
{
|
||||||
|
if (_rel) delete _rel;
|
||||||
_rel = rel;
|
_rel = rel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,8 +169,10 @@ void TFile_text::set_gen_parm(TConfig& config, const TString& section)
|
|||||||
_recordsize = config.get_int("RECORDSIZE",section); // solo se a lung. fissa
|
_recordsize = config.get_int("RECORDSIZE",section); // solo se a lung. fissa
|
||||||
_fieldsep = config.get_char("FIELDSEP",section); // solo se a lung. variabile
|
_fieldsep = config.get_char("FIELDSEP",section); // solo se a lung. variabile
|
||||||
_recordsep = config.get("RECORDSEP",section); // solo se a lung. variabile
|
_recordsep = config.get("RECORDSEP",section); // solo se a lung. variabile
|
||||||
if (_recordsize <= 0 && (_recordsep.empty())) // separatore di record standard
|
if (_recordsize <= 0 && _recordsep.empty()) // separatore di record standard
|
||||||
_recordsep = "\r\n";
|
_recordsep = "\r\n";
|
||||||
|
_skiplines = config.get_int("SKIPLINES",section); // righe iniziali da ignorare
|
||||||
|
|
||||||
_typefield = config.get_int("TYPEFIELD",section); // Numero del campo tipo (puo' essere -1)
|
_typefield = config.get_int("TYPEFIELD",section); // Numero del campo tipo (puo' essere -1)
|
||||||
_fixedlen = _fieldsep <= ' '; // && _recordsep.blank();
|
_fixedlen = _fieldsep <= ' '; // && _recordsep.blank();
|
||||||
_typepos = -1;
|
_typepos = -1;
|
||||||
@ -276,7 +280,7 @@ void TFile_text::set_rec_parm(TConfig& config, const char* section)
|
|||||||
if (exp.empty()) yesnofatal_box("JOIN senza espressioni INTO");
|
if (exp.empty()) yesnofatal_box("JOIN senza espressioni INTO");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (isdigit(j[0]))
|
if (j[0] >= '0' && j[0] <= '9')
|
||||||
{
|
{
|
||||||
tmprel->add(atoi(j), exp, nkey, to, alias); // join file
|
tmprel->add(atoi(j), exp, nkey, to, alias); // join file
|
||||||
tmprel->write_enable(atoi(j),key.left(6)!="JOINRO");
|
tmprel->write_enable(atoi(j),key.left(6)!="JOINRO");
|
||||||
@ -378,7 +382,7 @@ void TFile_text::set_rec_parm(TConfig& config, const char* section)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TFile_text::TFile_text(const char* file_name, const char* config_name)
|
TFile_text::TFile_text(const char* file_name, const char* config_name)
|
||||||
: _name(file_name)
|
: _name(file_name), _skiplines(0)
|
||||||
{
|
{
|
||||||
_read_file = NULL;
|
_read_file = NULL;
|
||||||
_write_file = NULL;
|
_write_file = NULL;
|
||||||
@ -428,10 +432,9 @@ int TFile_text::read(TRecord_text& rec)
|
|||||||
CHECK(_read_file, "Impossibile leggere da un file chiuso.");
|
CHECK(_read_file, "Impossibile leggere da un file chiuso.");
|
||||||
|
|
||||||
TToken_string buffer(_recordsize), lavoro;
|
TToken_string buffer(_recordsize), lavoro;
|
||||||
if (_recordsize>0)
|
if (_recordsize > 0)
|
||||||
{
|
{
|
||||||
buffer.cut(0);
|
_read_file->read(buffer.get_buffer(), _recordsize);
|
||||||
_read_file->read(buffer.get_buffer(),buffer.size());
|
|
||||||
if (!ok_r()) return 1; //non ritorna errore se fine file ed il record e' completo!
|
if (!ok_r()) return 1; //non ritorna errore se fine file ed il record e' completo!
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -491,7 +494,6 @@ int TFile_text::read(TRecord_text& rec)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Scrive su file il record_text (valido anche per header e footer)
|
//Scrive su file il record_text (valido anche per header e footer)
|
||||||
@ -830,11 +832,36 @@ int TFile_text::open(char mode)
|
|||||||
delete _read_file;
|
delete _read_file;
|
||||||
|
|
||||||
_read_file = new ifstream(_name, ios::binary | ios::nocreate);
|
_read_file = new ifstream(_name, ios::binary | ios::nocreate);
|
||||||
if (!ok_r())
|
if (!ok_r())
|
||||||
{
|
{
|
||||||
error_box("Impossibile aprire il file %s in lettura", (const char *)_name);
|
error_box("Impossibile aprire il file %s in lettura", (const char *)_name);
|
||||||
return _read_file->rdstate() != ios::goodbit;
|
return _read_file->rdstate() != ios::goodbit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_skiplines > 0)
|
||||||
|
{
|
||||||
|
if (_recordsize > 0)
|
||||||
|
{
|
||||||
|
streamoff bytestoskip = streamoff(_recordsize) * _skiplines;
|
||||||
|
_read_file->seekg(bytestoskip, ios::beg);
|
||||||
|
} else
|
||||||
|
if (_recordsep.not_empty())
|
||||||
|
{
|
||||||
|
int s = _skiplines;
|
||||||
|
for (int c = _read_file->get(); c != EOF; c = _read_file->get())
|
||||||
|
{
|
||||||
|
if (c == _recordsep[0])
|
||||||
|
{
|
||||||
|
for (int k = _recordsep.len()-1; k > 0; k--)
|
||||||
|
c = _read_file->get();
|
||||||
|
if (--s == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (c == EOF)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (mode == 'w')//apertura in scrittura
|
if (mode == 'w')//apertura in scrittura
|
||||||
{
|
{
|
||||||
|
@ -140,6 +140,7 @@ class TFile_text : public TObject
|
|||||||
TRecord_text* _current;//puntatore al record_text corrente
|
TRecord_text* _current;//puntatore al record_text corrente
|
||||||
TAssoc_array _tipi;//tracciati campo per i vari tipi predefiniti
|
TAssoc_array _tipi;//tracciati campo per i vari tipi predefiniti
|
||||||
TAssoc_array _tracciati_record;//tracciati record per i vari tipi di record
|
TAssoc_array _tracciati_record;//tracciati record per i vari tipi di record
|
||||||
|
int _skiplines;//Righe iniziali da ignorare
|
||||||
char _decsep;//separatore decimale
|
char _decsep;//separatore decimale
|
||||||
int _recordsize;//dimensione dei record
|
int _recordsize;//dimensione dei record
|
||||||
TString _recordsep;//separatore di record a lunghezza variabile (blank() se lung.fissa)
|
TString _recordsep;//separatore di record a lunghezza variabile (blank() se lung.fissa)
|
||||||
@ -205,6 +206,7 @@ public:
|
|||||||
const int typepos() const {return _typepos;}
|
const int typepos() const {return _typepos;}
|
||||||
const int typelen() const {return _typelen;}
|
const int typelen() const {return _typelen;}
|
||||||
const int typefield() const {return _typefield;}
|
const int typefield() const {return _typefield;}
|
||||||
|
const int skiplines() const {return _skiplines;}
|
||||||
const TRecord_text& curr() const {return *_current;}//ritorna il record corrente
|
const TRecord_text& curr() const {return *_current;}//ritorna il record corrente
|
||||||
void set_curr(TRecord_text& rec) {_current = &rec;}//setta il record corrente a rec
|
void set_curr(TRecord_text& rec) {_current = &rec;}//setta il record corrente a rec
|
||||||
void set_curr(TRecord_text* rec) {_current = rec;}//setta il record corrente a rec
|
void set_curr(TRecord_text* rec) {_current = rec;}//setta il record corrente a rec
|
||||||
@ -241,7 +243,6 @@ public:
|
|||||||
const TString& get_field(const TRecord_text& rec, int ncampo);
|
const TString& get_field(const TRecord_text& rec, int ncampo);
|
||||||
//scarica dal record_text il campo di nome <name>
|
//scarica dal record_text il campo di nome <name>
|
||||||
const TString& get_field(const TRecord_text& rec, const char* name);
|
const TString& get_field(const TRecord_text& rec, const char* name);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //__FILETEXT_H
|
#endif //__FILETEXT_H
|
@ -2187,7 +2187,7 @@ HIDDEN bool font_handler(TMask_field& f, KEY key)
|
|||||||
{
|
{
|
||||||
if (key == K_SPACE)
|
if (key == K_SPACE)
|
||||||
{
|
{
|
||||||
main_app().begin_wait();
|
TWait_cursor hourglass;
|
||||||
|
|
||||||
const char* family = f.get();
|
const char* family = f.get();
|
||||||
const int MAXSIZES = 16;
|
const int MAXSIZES = 16;
|
||||||
@ -2218,8 +2218,6 @@ HIDDEN bool font_handler(TMask_field& f, KEY key)
|
|||||||
TList_field& lst = (TList_field&)f.mask().field(F_SIZE);
|
TList_field& lst = (TList_field&)f.mask().field(F_SIZE);
|
||||||
lst.replace_items(pn1, pn2);
|
lst.replace_items(pn1, pn2);
|
||||||
lst.set(format("%d",printer().get_char_size()));
|
lst.set(format("%d",printer().get_char_size()));
|
||||||
|
|
||||||
main_app().end_wait();
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -5003,7 +5001,7 @@ bool TForm::validate(TForm_item &cf, TToken_string &s)
|
|||||||
|
|
||||||
void TForm::print_on(ostream& out) const
|
void TForm::print_on(ostream& out) const
|
||||||
{
|
{
|
||||||
main_app().begin_wait();
|
TWait_cursor hourglass;
|
||||||
|
|
||||||
if (relation())
|
if (relation())
|
||||||
{
|
{
|
||||||
@ -5019,8 +5017,6 @@ void TForm::print_on(ostream& out) const
|
|||||||
print_section(out, 'F');
|
print_section(out, 'F');
|
||||||
|
|
||||||
out << "END" << endl;
|
out << "END" << endl;
|
||||||
|
|
||||||
main_app().end_wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -5221,7 +5217,7 @@ void TForm::read(
|
|||||||
_editlevel= lev;
|
_editlevel= lev;
|
||||||
_desc= desc;
|
_desc= desc;
|
||||||
|
|
||||||
main_app().begin_wait();
|
TWait_cursor hourglass;
|
||||||
|
|
||||||
if (_code.not_empty())
|
if (_code.not_empty())
|
||||||
{
|
{
|
||||||
@ -5314,8 +5310,6 @@ void TForm::read(
|
|||||||
_fontsize = pr.get_char_size();
|
_fontsize = pr.get_char_size();
|
||||||
}
|
}
|
||||||
set_fink_mode(TRUE);
|
set_fink_mode(TRUE);
|
||||||
|
|
||||||
main_app().end_wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TForm::set_compulsory_specials()
|
void TForm::set_compulsory_specials()
|
||||||
|
210
include/isam.cpp
210
include/isam.cpp
@ -33,7 +33,6 @@
|
|||||||
#define RECLOCKTYPES 0xFF00
|
#define RECLOCKTYPES 0xFF00
|
||||||
#define READTYPES 0x00FF
|
#define READTYPES 0x00FF
|
||||||
#define INVFLD 255
|
#define INVFLD 255
|
||||||
#define EXTERNAL_FILE 1000 // Files with id >= are considered to be externals
|
|
||||||
|
|
||||||
isfdptr* ext_files;
|
isfdptr* ext_files;
|
||||||
isfdptr* openf;
|
isfdptr* openf;
|
||||||
@ -396,7 +395,7 @@ HIDDEN const char * translate_key(const char* key) // Traduce l'espressione chia
|
|||||||
|
|
||||||
HIDDEN void getisfd(isfdptr & isfd, int logicnum)
|
HIDDEN void getisfd(isfdptr & isfd, int logicnum)
|
||||||
{
|
{
|
||||||
CHECK(logicnum < EXTERNAL_FILE, "Incorrect use of getisfd() with external file definition");
|
CHECK(logicnum < LF_EXTERNAL, "Incorrect use of getisfd() with external file definition");
|
||||||
isfd = new isdef ;
|
isfd = new isdef ;
|
||||||
isfd->r = new RecDes ;
|
isfd->r = new RecDes ;
|
||||||
isfd->d = new FileDes ;
|
isfd->d = new FileDes ;
|
||||||
@ -814,7 +813,7 @@ TBaseisamfile::TBaseisamfile(
|
|||||||
for (int i=0; i<max; i++)
|
for (int i=0; i<max; i++)
|
||||||
if (ext_files[i]==NULL)
|
if (ext_files[i]==NULL)
|
||||||
{
|
{
|
||||||
_logicnum = _isamfile->ln = i+EXTERNAL_FILE; // Primo slot libero
|
_logicnum = _isamfile->ln = i+LF_EXTERNAL; // Primo slot libero
|
||||||
ext_files[i] = _isamfile;
|
ext_files[i] = _isamfile;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -853,7 +852,7 @@ const char* TBaseisamfile::name() const
|
|||||||
|
|
||||||
const char* TBaseisamfile::filename() const
|
const char* TBaseisamfile::filename() const
|
||||||
{
|
{
|
||||||
if (_isamfile == NULL && num() < EXTERNAL_FILE)
|
if (_isamfile == NULL && num() < LF_EXTERNAL)
|
||||||
{
|
{
|
||||||
TDir d;
|
TDir d;
|
||||||
d.get(num());
|
d.get(num());
|
||||||
@ -869,7 +868,7 @@ const char* TBaseisamfile::filename() const
|
|||||||
|
|
||||||
const char* TBaseisamfile::description()
|
const char* TBaseisamfile::description()
|
||||||
{
|
{
|
||||||
if (_isamfile == NULL && num() < EXTERNAL_FILE)
|
if (_isamfile == NULL && num() < LF_EXTERNAL)
|
||||||
{
|
{
|
||||||
TDir d;
|
TDir d;
|
||||||
d.get(num());
|
d.get(num());
|
||||||
@ -1377,6 +1376,69 @@ int TBaseisamfile::_open(
|
|||||||
return (_lasterr);
|
return (_lasterr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TBaseisamfile::_open_ex(
|
||||||
|
unsigned int mode, // @parm Indica il modo di apertura del file (default _manulock)
|
||||||
|
bool index) // @parm Indica se aprire con indici o meno (default TRUE)
|
||||||
|
|
||||||
|
// @comm Il parametro <p mode> puo' assumere i valori:
|
||||||
|
//
|
||||||
|
// @flag _manulock | Il lock dei record viene fatto manualmente
|
||||||
|
// @flag _exclock | Il file viene aperte in modo esclusivo
|
||||||
|
// @flag _autolock | Il lock dei record viene fatto in modo automatico
|
||||||
|
// @comm Il parametro <p index> puo' assumere i valori:
|
||||||
|
//
|
||||||
|
// @flag TRUE | Il file viene aperto con indici
|
||||||
|
// @flag FALSE | Il file viene aperto senza indici
|
||||||
|
|
||||||
|
{
|
||||||
|
if (openf[num() - 1] != NULL)
|
||||||
|
return _isalropen; // Gia' aperto
|
||||||
|
|
||||||
|
getisfd(_isamfile,num());
|
||||||
|
|
||||||
|
if (filehnd()->r->NKeys <= 0)
|
||||||
|
{
|
||||||
|
relisfd(_isamfile);
|
||||||
|
return _lasterr = _ispatherr; // Nessun indice
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((filehnd()->fhnd = DB_open(filehnd()->d->SysName,mode==_excllock,index)) >= 0)
|
||||||
|
{
|
||||||
|
TRecnotype n=DB_reccount(filehnd()->fhnd);
|
||||||
|
TDir d;
|
||||||
|
d.get(num(),_nolock,_nordir,_sysdirop);
|
||||||
|
if (d.is_com()) d.get(num(),_nolock,_comdir,_sysdirop);
|
||||||
|
if ((filehnd()->d->EOD != n && n > 0) || (n > d.eox()))
|
||||||
|
{
|
||||||
|
filehnd()->d->EOD = d.eod() = n;
|
||||||
|
filehnd()->d->EOX = d.eox() = n;
|
||||||
|
if (d.is_com())
|
||||||
|
d.put(num(),_comdir,_sysdirop);
|
||||||
|
else
|
||||||
|
d.put(num(),_nordir,_sysdirop);
|
||||||
|
}
|
||||||
|
filehnd()->ln = num();
|
||||||
|
openf[num() - 1] = filehnd();
|
||||||
|
_recno = RECORD_NON_FISICO;
|
||||||
|
|
||||||
|
setkey(1);
|
||||||
|
_lasterr = NOERR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_lasterr = get_error(filehnd()->fhnd);
|
||||||
|
if (_lasterr == -60)
|
||||||
|
{
|
||||||
|
if (fexist(filename()))
|
||||||
|
_lasterr = _islocked;
|
||||||
|
else
|
||||||
|
_lasterr = 2;
|
||||||
|
}
|
||||||
|
relisfd(_isamfile);
|
||||||
|
}
|
||||||
|
return _lasterr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int TBaseisamfile::_close()
|
int TBaseisamfile::_close()
|
||||||
|
|
||||||
@ -1404,7 +1466,7 @@ int TBaseisamfile::_close()
|
|||||||
err=DB_close(filehnd()->fhnd);
|
err=DB_close(filehnd()->fhnd);
|
||||||
if (err != NOERR) err = get_error(err);
|
if (err != NOERR) err = get_error(err);
|
||||||
if ((err == NOERR) && (num() > 0))
|
if ((err == NOERR) && (num() > 0))
|
||||||
openf[num() - 1] = NULL ;
|
openf[num() - 1] = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (filehnd() == NULL)
|
if (filehnd() == NULL)
|
||||||
@ -1463,7 +1525,8 @@ TLocalisamfile::TLocalisamfile(
|
|||||||
{
|
{
|
||||||
if (linkrecinst <= TRUE)
|
if (linkrecinst <= TRUE)
|
||||||
{
|
{
|
||||||
open();
|
if (open() != NOERR)
|
||||||
|
fatal_box("Impossibile aprire il file %d", logicnum);
|
||||||
if (_was_open)
|
if (_was_open)
|
||||||
_oldkey = getkey();
|
_oldkey = getkey();
|
||||||
setkey(1);
|
setkey(1);
|
||||||
@ -1541,7 +1604,7 @@ int TLocalisamfile::open(unsigned int mode)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = _open(mode, TRUE);
|
err = _open_ex(mode, TRUE);
|
||||||
_was_open = FALSE;
|
_was_open = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1855,7 +1918,7 @@ int TExternisamfile::close()
|
|||||||
if (err != NOERR) err = get_error(err);
|
if (err != NOERR) err = get_error(err);
|
||||||
if (err == NOERR)
|
if (err == NOERR)
|
||||||
{
|
{
|
||||||
ext_files[_isamfile->ln - EXTERNAL_FILE] = NULL;
|
ext_files[_isamfile->ln - LF_EXTERNAL] = NULL;
|
||||||
relisfd(_isamfile);
|
relisfd(_isamfile);
|
||||||
clearfilehnd();
|
clearfilehnd();
|
||||||
}
|
}
|
||||||
@ -2252,7 +2315,8 @@ int TSystemisamfile::update(
|
|||||||
// @rdesc Ritorna NOERR se l'operazione di compattamento e' riuscita, altrimenti il codice di
|
// @rdesc Ritorna NOERR se l'operazione di compattamento e' riuscita, altrimenti il codice di
|
||||||
// di errore generato (vedi <t TIsamerr>).
|
// di errore generato (vedi <t TIsamerr>).
|
||||||
int TSystemisamfile::packfile(
|
int TSystemisamfile::packfile(
|
||||||
bool vis) // @parm Indica se visualizzare lo stato dell'operazione
|
bool vis, // @parm Indica se visualizzare lo stato dell'operazione
|
||||||
|
bool zap) // @parm Indica se distruggere tutti i records
|
||||||
|
|
||||||
// @xref <mf TSystemisamfile::packindex>
|
// @xref <mf TSystemisamfile::packindex>
|
||||||
|
|
||||||
@ -2260,14 +2324,22 @@ int TSystemisamfile::packfile(
|
|||||||
int err=NOERR;
|
int err=NOERR;
|
||||||
TDir d;
|
TDir d;
|
||||||
|
|
||||||
d.get(num(),_nolock, _nordir,_sysdirop);
|
// d.get(num(),_nolock, _nordir,_sysdirop);
|
||||||
d.get(num(),_nolock, (d.is_com()) ? _comdir : _nordir);
|
d.get(num(),_nolock, (d.is_com()) ? _comdir : _nordir);
|
||||||
CHECKS(filehnd() == NULL, "Can't pack open file", (const char*)filename());
|
CHECKS(filehnd() == NULL, "Can't pack open file", (const char*)filename());
|
||||||
err=DB_packfile(vis,d.name(),d.eod());
|
err=DB_packfile(vis, d.name(), zap ? 0L : d.eod());
|
||||||
|
|
||||||
|
if (zap && err == NOERR)
|
||||||
|
err = packindex(vis, FALSE);
|
||||||
if (err == NOERR && curr().has_memo())
|
if (err == NOERR && curr().has_memo())
|
||||||
err = DB_packmemo(vis,d.name());
|
err = DB_packmemo(vis,d.name());
|
||||||
if (err != NOERR) err = get_error(err);
|
|
||||||
if (err != NOERR) error_box("Errore in compattamento dati.\nFile %d : %d", num(),err);
|
if (err != NOERR)
|
||||||
|
{
|
||||||
|
err = get_error(err);
|
||||||
|
if (err != NOERR)
|
||||||
|
error_box("Errore in compattamento dati.\nFile %d : %d", num(),err);
|
||||||
|
}
|
||||||
setstatus(err);
|
setstatus(err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -2339,12 +2411,12 @@ int TSystemisamfile::load(
|
|||||||
// @xref <mf TSystemisamfile::dump>
|
// @xref <mf TSystemisamfile::dump>
|
||||||
|
|
||||||
{
|
{
|
||||||
FILE* fl = fopen(from, "r");
|
|
||||||
int err=NOERR;
|
int err=NOERR;
|
||||||
|
FILE* fl = fopen(from, "r");
|
||||||
if (fl == NULL)
|
if (fl == NULL)
|
||||||
{
|
{
|
||||||
error_box("Non riesco ad aprire il file %s",from);
|
error_box("Impossibile aprire il file %s",from);
|
||||||
return 2;
|
return err = 2;
|
||||||
}
|
}
|
||||||
TRecnotype r = 0, e = 0, nitems = 0, nread = 0;
|
TRecnotype r = 0, e = 0, nitems = 0, nread = 0;
|
||||||
TString16 firm, year, attprev("00000");
|
TString16 firm, year, attprev("00000");
|
||||||
@ -2362,7 +2434,7 @@ int TSystemisamfile::load(
|
|||||||
attprev = ditte.get("CODATTPREV");
|
attprev = ditte.get("CODATTPREV");
|
||||||
}
|
}
|
||||||
if (fl == NULL)
|
if (fl == NULL)
|
||||||
{
|
{ // Come fa' ad arrivare qui, se fl non puo' essere NULL????
|
||||||
clearerr(fl);
|
clearerr(fl);
|
||||||
setstatus(err);
|
setstatus(err);
|
||||||
return err;
|
return err;
|
||||||
@ -2379,14 +2451,20 @@ int TSystemisamfile::load(
|
|||||||
fseek(fl, 0L, SEEK_END);
|
fseek(fl, 0L, SEEK_END);
|
||||||
nitems = ftell(fl) - nitems;
|
nitems = ftell(fl) - nitems;
|
||||||
fclose(fl);
|
fclose(fl);
|
||||||
|
|
||||||
|
const bool open_now = filehnd() == NULL;
|
||||||
|
if (open_now)
|
||||||
|
{
|
||||||
|
err = open_ex(_excllock);
|
||||||
|
setstatus(err);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
TScanner f(from);
|
TScanner f(from);
|
||||||
|
|
||||||
open();
|
|
||||||
|
|
||||||
TToken_string s(1024, fs);
|
TToken_string s(1024, fs);
|
||||||
bool fixedlen = (fs == '\0');
|
bool fixedlen = (fs == '\0');
|
||||||
int nflds = curr().items();
|
int nflds = curr().items();
|
||||||
TArray fld(nflds);
|
TString_array fld(nflds);
|
||||||
int len[MaxFields];
|
int len[MaxFields];
|
||||||
TString sfd(3);
|
TString sfd(3);
|
||||||
TString s1(64);
|
TString s1(64);
|
||||||
@ -2394,38 +2472,40 @@ int TSystemisamfile::load(
|
|||||||
|
|
||||||
if (f.paragraph("Header"))
|
if (f.paragraph("Header"))
|
||||||
{
|
{
|
||||||
f.equal();
|
int equal;
|
||||||
const long level = atol(f.line());
|
TString key;
|
||||||
if (level > get_std_level())
|
|
||||||
error_box("L'archivio %s e' stato generato con gli archivi di livello %ld%/%ld.\n Il livello attuale e' %ld/%ld.\n Convertire gli archivi e ripetere l' operazione.",
|
|
||||||
from, level/100, level%100, get_std_level()/100, get_std_level()%100);
|
|
||||||
lcf = getlcf(level);
|
|
||||||
nflds = 0;
|
nflds = 0;
|
||||||
TToken_string s2(f.line());
|
while ((equal = f.line().find('=')) > 0)
|
||||||
int p = s2.find('=');
|
|
||||||
if (p > 0)
|
|
||||||
{
|
{
|
||||||
s1 = s2.left(p);
|
key = f.token().left(equal);
|
||||||
s2.ltrim(p+1);
|
key.trim();
|
||||||
}
|
if (key == "Version")
|
||||||
else s1.cut(0);
|
|
||||||
while (s1 == "Fields")
|
|
||||||
{
|
|
||||||
for (const char * fd = s2.get(); fd != NULL; fd = s2.get())
|
|
||||||
{
|
{
|
||||||
TToken_string wfd(fd, ',');
|
const long level = atol(f.token().mid(equal+1));
|
||||||
fld.add(new TString(wfd.get()));
|
if (level > prefix().filelevel())
|
||||||
len[nflds] = wfd.get_int();
|
error_box("L'archivio %s e' stato generato con gli archivi di livello %ld%/%ld.\n Il livello attuale e' %ld/%ld.\n Convertire gli archivi e ripetere l' operazione.",
|
||||||
nflds++;
|
from, level/100, level%100, get_std_level()/100, get_std_level()%100);
|
||||||
}
|
lcf = getlcf(level);
|
||||||
s2 = f.line();
|
} else
|
||||||
p = s2.find('=');
|
if (key == "File")
|
||||||
if (p > 0)
|
|
||||||
{
|
{
|
||||||
s1 = s2.left(p);
|
const int logic = atoi(f.token().mid(equal+1));
|
||||||
s2.ltrim(p+1);
|
if (logic != num())
|
||||||
|
error_box("L'archivio %s e' stato generato dal file %d",
|
||||||
|
from, logic);
|
||||||
|
} else
|
||||||
|
if (key == "Fields")
|
||||||
|
{
|
||||||
|
TToken_string riga = f.token().mid(equal+1);
|
||||||
|
TToken_string wfd(32, ',');
|
||||||
|
FOR_EACH_TOKEN(riga, fd)
|
||||||
|
{
|
||||||
|
wfd = fd; wfd.strip_spaces();
|
||||||
|
fld.add(wfd.get(0));
|
||||||
|
len[nflds] = wfd.get_int();
|
||||||
|
nflds++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else s1.cut(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2437,6 +2517,7 @@ int TSystemisamfile::load(
|
|||||||
len[j] = (curr().type(wfld) == _datefld) ? 10 : curr().length(wfld);
|
len[j] = (curr().type(wfld) == _datefld) ? 10 : curr().length(wfld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!f.paragraph("Data"))
|
if (!f.paragraph("Data"))
|
||||||
{
|
{
|
||||||
error_box("Formato dei dati non valido");
|
error_box("Formato dei dati non valido");
|
||||||
@ -2451,8 +2532,7 @@ int TSystemisamfile::load(
|
|||||||
|
|
||||||
s1.format("Imp. archivio %s\n%6ld records %6ld errori - %3d", filename(), r, e, last);
|
s1.format("Imp. archivio %s\n%6ld records %6ld errori - %3d", filename(), r, e, last);
|
||||||
TProgind p(nitems, s1, TRUE, TRUE, 70);
|
TProgind p(nitems, s1, TRUE, TRUE, 70);
|
||||||
s = f.line();
|
for (s = f.line(); s.not_empty() && !p.iscancelled(); s = f.line())
|
||||||
while (s.not_empty() && !p.iscancelled())
|
|
||||||
{
|
{
|
||||||
if (extended)
|
if (extended)
|
||||||
{
|
{
|
||||||
@ -2498,20 +2578,27 @@ int TSystemisamfile::load(
|
|||||||
put((const TString&) fld[j], s2);
|
put((const TString&) fld[j], s2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (write() == NOERR) r++;
|
|
||||||
|
int err = write();
|
||||||
|
if (err == _isreinsert)
|
||||||
|
err = rewrite();
|
||||||
|
|
||||||
|
if (err == NOERR)
|
||||||
|
r++;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#ifdef DBG
|
error_box("Errore di scrittura alla riga %ld", r+e+1);
|
||||||
yesnofatal_box("Numero linea relativa all'errore: %ld",r+e+1);
|
|
||||||
#endif
|
|
||||||
e++;
|
e++;
|
||||||
last = status();
|
last = status();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
s = f.line();
|
|
||||||
}
|
}
|
||||||
s1.format("Imp. archivio %s\n%6ld records %6ld errori - %3d", filename(), r, e, last);
|
s1.format("Imp. archivio %s\n%6ld records %6ld errori - %3d", filename(), r, e, last);
|
||||||
p.set_text(s1);
|
p.set_text(s1);
|
||||||
close();
|
|
||||||
|
if (!open_now)
|
||||||
|
close();
|
||||||
|
|
||||||
setstatus(err);
|
setstatus(err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -2568,7 +2655,8 @@ int TSystemisamfile::dump(
|
|||||||
TProgind p(nitems, s, TRUE, TRUE, 70);
|
TProgind p(nitems, s, TRUE, TRUE, 70);
|
||||||
TString s1;
|
TString s1;
|
||||||
|
|
||||||
fprintf(f, "[Header]\nVersion=%ld", prefix().filelevel());
|
fprintf(f, "[Header]\nVersion=%ld\nFile=%d",
|
||||||
|
prefix().filelevel(), num());
|
||||||
for (int k = 0; k < nflds; k++)
|
for (int k = 0; k < nflds; k++)
|
||||||
{
|
{
|
||||||
if ((k % 10) == 0) fprintf(f, "\nFields=");
|
if ((k % 10) == 0) fprintf(f, "\nFields=");
|
||||||
@ -2693,13 +2781,13 @@ TRectype::TRectype(const TBaseisamfile* i)
|
|||||||
bool has_memo_fld = FALSE;
|
bool has_memo_fld = FALSE;
|
||||||
|
|
||||||
_logicnum = i->num();
|
_logicnum = i->num();
|
||||||
if (i->filehnd() != NULL && _logicnum < EXTERNAL_FILE)
|
if (i->filehnd() != NULL && _logicnum < LF_EXTERNAL)
|
||||||
{
|
{
|
||||||
_length = DB_reclen(i->filehnd()->fhnd);
|
_length = DB_reclen(i->filehnd()->fhnd);
|
||||||
has_memo_fld = rec_has_memo(rec_des());
|
has_memo_fld = rec_has_memo(rec_des());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (_logicnum >= EXTERNAL_FILE)
|
if (_logicnum >= LF_EXTERNAL)
|
||||||
{
|
{
|
||||||
_length = i->filehnd()->d->LenR;
|
_length = i->filehnd()->d->LenR;
|
||||||
has_memo_fld = rec_has_memo(i->filehnd()->r);
|
has_memo_fld = rec_has_memo(i->filehnd()->r);
|
||||||
@ -2889,7 +2977,7 @@ HIDDEN int fld_cmp(const char* a, const char* b, int len, bool number)
|
|||||||
|
|
||||||
RecDes* TRectype::rec_des() const
|
RecDes* TRectype::rec_des() const
|
||||||
{
|
{
|
||||||
const isdef* i = _logicnum < EXTERNAL_FILE ? openf[_logicnum-1] : ext_files[_logicnum - EXTERNAL_FILE];
|
const isdef* i = _logicnum < LF_EXTERNAL ? openf[_logicnum-1] : ext_files[_logicnum - LF_EXTERNAL];
|
||||||
CHECKD(i, "Can't use a record of closed file ", _logicnum);
|
CHECKD(i, "Can't use a record of closed file ", _logicnum);
|
||||||
RecDes* r = i->r;
|
RecDes* r = i->r;
|
||||||
CHECKD(r, "Missing record description of file", _logicnum);
|
CHECKD(r, "Missing record description of file", _logicnum);
|
||||||
|
@ -332,6 +332,8 @@ protected:
|
|||||||
void recover();
|
void recover();
|
||||||
// @cmember Apre il file isam di base con lock, permettendo di specificare se usare gli indici o no
|
// @cmember Apre il file isam di base con lock, permettendo di specificare se usare gli indici o no
|
||||||
int _open(unsigned int mode = _manulock, bool index = TRUE);
|
int _open(unsigned int mode = _manulock, bool index = TRUE);
|
||||||
|
int _open_ex(unsigned int mode = _manulock, bool index = TRUE);
|
||||||
|
|
||||||
// @cmember Chiude il file isam di base
|
// @cmember Chiude il file isam di base
|
||||||
int _close();
|
int _close();
|
||||||
|
|
||||||
@ -556,7 +558,11 @@ public:
|
|||||||
int flags(bool updateeod = FALSE);
|
int flags(bool updateeod = FALSE);
|
||||||
// @cmember Apre un file di isam con lock (vedi <mf TBaseisamfile::_open>)
|
// @cmember Apre un file di isam con lock (vedi <mf TBaseisamfile::_open>)
|
||||||
int open(unsigned int mode = _manulock, bool index = TRUE)
|
int open(unsigned int mode = _manulock, bool index = TRUE)
|
||||||
{ return _open(mode, index);}
|
{ return _open(mode, index); }
|
||||||
|
|
||||||
|
int open_ex(unsigned int mode = _manulock, bool index = TRUE)
|
||||||
|
{ return _open_ex(mode, index); }
|
||||||
|
|
||||||
// @cmember Chiude il file di isam
|
// @cmember Chiude il file di isam
|
||||||
int close()
|
int close()
|
||||||
{ return _close();}
|
{ return _close();}
|
||||||
@ -608,7 +614,7 @@ public:
|
|||||||
// @cmember Esegue sia <mf TSystemisamfile::packfile> e <mf TSystemisamfile::packindex>
|
// @cmember Esegue sia <mf TSystemisamfile::packfile> e <mf TSystemisamfile::packindex>
|
||||||
int pack(bool vis = TRUE, bool ask = TRUE);
|
int pack(bool vis = TRUE, bool ask = TRUE);
|
||||||
// @cmember Rimuove fisicamente i record cancellati
|
// @cmember Rimuove fisicamente i record cancellati
|
||||||
int packfile(bool vis = TRUE);
|
int packfile(bool vis = TRUE, bool zap = FALSE);
|
||||||
// @cmember Rimuove fisicamente gli indici cancellati
|
// @cmember Rimuove fisicamente gli indici cancellati
|
||||||
int packindex(bool vis = TRUE, bool ask = TRUE);
|
int packindex(bool vis = TRUE, bool ask = TRUE);
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@
|
|||||||
#define LF_BENEM 94
|
#define LF_BENEM 94
|
||||||
#define LF_FAMIGLIE 95
|
#define LF_FAMIGLIE 95
|
||||||
#define LF_SEZIONI 96
|
#define LF_SEZIONI 96
|
||||||
#define LF_MEDICI 97
|
#define LF_MEDICI 97
|
||||||
|
|
||||||
#define LF_RIGHEF 98
|
#define LF_RIGHEF 98
|
||||||
#define LF_RIGHEF1 99
|
#define LF_RIGHEF1 99
|
||||||
@ -137,6 +137,8 @@
|
|||||||
#define LF_ATOPERA 130
|
#define LF_ATOPERA 130
|
||||||
#define LF_ATROPERA 131
|
#define LF_ATROPERA 131
|
||||||
|
|
||||||
|
#define LF_EXTERNAL 1000 // Files with id >= are considered to be externals
|
||||||
|
|
||||||
#define CNF_GENERAL 10000
|
#define CNF_GENERAL 10000
|
||||||
#define CNF_STUDIO CNF_GENERAL + 1
|
#define CNF_STUDIO CNF_GENERAL + 1
|
||||||
#define CNF_DITTA CNF_GENERAL + 2
|
#define CNF_DITTA CNF_GENERAL + 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user