1994-08-25 09:02:59 +00:00
|
|
|
#include <checks.h>
|
|
|
|
|
|
|
|
#define __TABUTIL_CPP
|
|
|
|
#include <tabutil.h>
|
|
|
|
#include <extcdecl.h>
|
1997-08-27 09:53:29 +00:00
|
|
|
#include <scanner.h>
|
1994-08-25 09:02:59 +00:00
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
int TTable::name2log(const char* n)
|
|
|
|
{
|
1994-12-20 15:11:26 +00:00
|
|
|
return *n == '%' ? LF_TABCOM : (*n == '#' ? LF_TABGEN : LF_TAB);
|
1994-08-25 09:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TTable::TTable(const char* tabname, bool linkrecinst)
|
1995-01-05 17:50:40 +00:00
|
|
|
: TLocalisamfile(name2log(tabname), linkrecinst), _cod(curr(), "COD")
|
1994-08-25 09:02:59 +00:00
|
|
|
{
|
|
|
|
if ((*tabname == '%') || (*tabname == '#')) tabname++;
|
|
|
|
_tabname = tabname;
|
|
|
|
_tabname.upper();
|
1994-09-27 10:19:36 +00:00
|
|
|
curr().settab(_tabname);
|
1997-08-27 09:53:29 +00:00
|
|
|
_des_mod_loaded = FALSE;
|
1994-08-25 09:02:59 +00:00
|
|
|
}
|
|
|
|
|
1994-09-27 10:19:36 +00:00
|
|
|
TTable::~TTable()
|
1995-01-05 17:50:40 +00:00
|
|
|
{}
|
1994-08-25 09:02:59 +00:00
|
|
|
|
|
|
|
int TTable::first(word lockop)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
1994-09-27 10:19:36 +00:00
|
|
|
zero();
|
1994-08-25 09:02:59 +00:00
|
|
|
TBaseisamfile::read(_isgteq, lockop);
|
|
|
|
if (good())
|
1995-01-05 17:50:40 +00:00
|
|
|
if (_tabname != (const char *)_cod) setstatus(_isemptyfile);
|
1994-09-27 10:19:36 +00:00
|
|
|
if (bad()) zero();
|
1994-08-25 09:02:59 +00:00
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::last(word lockop)
|
|
|
|
|
1995-05-16 13:42:37 +00:00
|
|
|
{
|
1994-09-27 10:19:36 +00:00
|
|
|
zero();
|
1995-05-17 11:12:10 +00:00
|
|
|
put("CODTAB", "\xFF");
|
1994-08-25 09:02:59 +00:00
|
|
|
TBaseisamfile::read(_isgteq);
|
|
|
|
if (!eof()) TBaseisamfile::prev(lockop);
|
|
|
|
else setstatus(NOERR);
|
1995-05-16 13:42:37 +00:00
|
|
|
if (bof()) setstatus(NOERR);
|
1994-08-25 09:02:59 +00:00
|
|
|
if (good())
|
1995-01-05 17:50:40 +00:00
|
|
|
if (_tabname != (const char *)_cod) setstatus(_isemptyfile);
|
1994-09-27 10:19:36 +00:00
|
|
|
if (bad()) zero();
|
1994-08-25 09:02:59 +00:00
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::next(word lockop)
|
1996-09-26 15:28:04 +00:00
|
|
|
{
|
1994-09-27 10:19:36 +00:00
|
|
|
|
1996-09-26 15:28:04 +00:00
|
|
|
const TRecnotype nrec = recno();
|
|
|
|
/*
|
1994-09-07 17:00:25 +00:00
|
|
|
if (nrec != filehnd()->RecNo)
|
1994-09-27 10:19:36 +00:00
|
|
|
{
|
1994-09-07 17:00:25 +00:00
|
|
|
read();
|
1996-09-26 15:28:04 +00:00
|
|
|
if (bad())
|
|
|
|
{
|
|
|
|
if (status() == _iskeynotfound)
|
|
|
|
setstatus(NOERR);
|
|
|
|
return status();
|
|
|
|
}
|
1994-09-27 10:19:36 +00:00
|
|
|
}
|
1996-09-26 15:28:04 +00:00
|
|
|
*/
|
1994-08-25 09:02:59 +00:00
|
|
|
|
|
|
|
TBaseisamfile::next(lockop);
|
1995-01-05 17:50:40 +00:00
|
|
|
if (_tabname != (const char *)_cod)
|
1994-08-25 09:02:59 +00:00
|
|
|
{
|
|
|
|
if (lockop == _lock) TBaseisamfile::reread(_unlock);
|
|
|
|
TBaseisamfile::readat(nrec, lockop);
|
|
|
|
setstatus(_iseof);
|
|
|
|
}
|
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::prev(word lockop)
|
|
|
|
{
|
|
|
|
|
1996-09-26 15:28:04 +00:00
|
|
|
const TRecnotype nrec = recno();
|
|
|
|
/*
|
|
|
|
if (nrec != filehnd()->RecNo)
|
|
|
|
{
|
|
|
|
read();
|
|
|
|
if (bad())
|
|
|
|
{
|
|
|
|
if (status() == _iskeynotfound)
|
|
|
|
setstatus(NOERR);
|
|
|
|
return status();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
1994-08-25 09:02:59 +00:00
|
|
|
TBaseisamfile::prev(lockop);
|
1995-01-05 17:50:40 +00:00
|
|
|
if (_tabname != (const char *)_cod)
|
1994-08-25 09:02:59 +00:00
|
|
|
{
|
|
|
|
if (lockop == _lock) TBaseisamfile::reread(_unlock);
|
|
|
|
TBaseisamfile::readat(nrec, lockop);
|
|
|
|
setstatus(_isbof);
|
|
|
|
}
|
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::skip(TRecnotype nrec, word lockop)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (!nrec) return NOERR;
|
|
|
|
TBaseisamfile::skip(nrec, lockop);
|
1995-01-05 17:50:40 +00:00
|
|
|
if (_tabname != (const char *)_cod)
|
1994-08-25 09:02:59 +00:00
|
|
|
{
|
|
|
|
if (nrec > 0)
|
|
|
|
{
|
|
|
|
if (lockop == _lock) TBaseisamfile::reread(_unlock);
|
|
|
|
last(lockop);
|
|
|
|
setstatus(_iseof);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (lockop == _lock) TBaseisamfile::reread(_unlock);
|
|
|
|
first(lockop);
|
|
|
|
setstatus(_isbof);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::read(word op, word lockop, TDate&)
|
|
|
|
|
|
|
|
{
|
|
|
|
CHECKD(op >= _iscurr && op <= _isgteq, "Invalid read operation : ", op);
|
|
|
|
TBaseisamfile::read(op, lockop);
|
1995-01-05 17:50:40 +00:00
|
|
|
if (_tabname != (const char *)_cod)
|
1994-08-25 09:02:59 +00:00
|
|
|
{
|
|
|
|
if (lockop == _lock) TBaseisamfile::reread(_unlock);
|
|
|
|
last(lockop);
|
|
|
|
setstatus(_iseof);
|
|
|
|
}
|
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::read(TRectype& rec, word op, word lockop, TDate&)
|
|
|
|
|
|
|
|
{
|
|
|
|
CHECKD(op >= _iscurr && op <= _isgteq, "Invalid read operation : ", op);
|
|
|
|
TBaseisamfile::read(rec, op, lockop);
|
1995-01-05 17:50:40 +00:00
|
|
|
if (_tabname != (const char *)_cod)
|
1994-08-25 09:02:59 +00:00
|
|
|
{
|
|
|
|
setstatus(_iseof);
|
|
|
|
if (lockop == _lock) TBaseisamfile::reread(_unlock);
|
|
|
|
last(lockop);
|
|
|
|
}
|
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::readat(TRecnotype nrec, word lockop)
|
|
|
|
|
|
|
|
{
|
|
|
|
TBaseisamfile::readat(nrec, lockop);
|
|
|
|
|
1995-01-05 17:50:40 +00:00
|
|
|
CHECKS(_tabname == (const char * )_cod, "Invalid position : Table ", (const char *)_tabname);
|
1994-08-25 09:02:59 +00:00
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TTable::readat(TRectype& rec ,TRecnotype nrec, word lockop)
|
|
|
|
|
|
|
|
{
|
|
|
|
TBaseisamfile::readat(rec, nrec, lockop);
|
|
|
|
|
1995-01-05 17:50:40 +00:00
|
|
|
CHECKS(_tabname == (const char *)_cod, "Invalid position : Table ", (const char *)_tabname);
|
1994-08-25 09:02:59 +00:00
|
|
|
return status();
|
|
|
|
}
|
|
|
|
|
1997-08-27 09:53:29 +00:00
|
|
|
void TTable::load_module_description()
|
|
|
|
{
|
|
|
|
// Setta il modulo al quale appartiene la tabella e la relativa descrizione.
|
|
|
|
// Cerca prima in RECDESC il relativo file di descrizione: D<TAB_NAME>.DES
|
|
|
|
// Se il file esiste, se il paragrafo [TabDescr] esiste e se esiste la
|
|
|
|
// variabile Module ne prende il valore.
|
|
|
|
// Se non si verificano le suddette condizioni procede come segue:
|
|
|
|
// cerca se esiste il file ??<TAB_NAME>.MSK tramite la funzione list_files(),
|
|
|
|
// ne estrae il module dai primi 2 caratteri e la descrizione dalla intestazione
|
|
|
|
// della prima pagina.
|
|
|
|
_des_mod_loaded = TRUE;
|
|
|
|
TFilename n;
|
|
|
|
n << "recdesc/d" << _tabname;
|
|
|
|
n.ext("des");
|
|
|
|
n.lower();
|
|
|
|
if (fexist(n))
|
|
|
|
{
|
|
|
|
TConfig des(n);
|
|
|
|
_module = des.get("Module","TabDescr");
|
|
|
|
}
|
|
|
|
n = "??tb";
|
|
|
|
n << _tabname;
|
|
|
|
n.ext("msk");
|
|
|
|
n.lower();
|
|
|
|
TToken_string f;
|
|
|
|
f.add(n);
|
|
|
|
if (list_files(f) == 1)
|
|
|
|
{
|
|
|
|
n = f.get(0);
|
|
|
|
if (!fexist(n))
|
|
|
|
n.overwrite("ba",0);
|
|
|
|
if (fexist(n))
|
|
|
|
{
|
|
|
|
if (_module.empty())
|
|
|
|
_module = n.left(2);
|
|
|
|
TScanner m(n);
|
|
|
|
bool ok = TRUE;
|
|
|
|
while (ok)
|
|
|
|
{
|
|
|
|
const TString& l2 = m.line().left(2);
|
|
|
|
if (l2.empty())
|
|
|
|
ok = FALSE;
|
|
|
|
else
|
|
|
|
if (l2 == "PA")
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
const int apicia = m.token().find('"')+1;
|
|
|
|
const int apicic = m.token().find('"', apicia);
|
|
|
|
_description = m.token().sub(apicia, apicic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_module = "ba";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_module = "ba";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* TTable::module()
|
|
|
|
{
|
|
|
|
if (!_des_mod_loaded)
|
|
|
|
load_module_description();
|
|
|
|
return _module;
|
|
|
|
}
|
1994-08-25 09:02:59 +00:00
|
|
|
|
1997-08-27 09:53:29 +00:00
|
|
|
const char* TTable::description()
|
|
|
|
{
|
|
|
|
if (!_des_mod_loaded)
|
|
|
|
load_module_description();
|
|
|
|
return _description;
|
|
|
|
}
|