Viswin interruption working
git-svn-id: svn://10.65.10.50/trunk@15 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
da54026c24
commit
260dd9d29f
@ -10,465 +10,482 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <utility.h>
|
#include <utility.h>
|
||||||
|
|
||||||
|
|
||||||
#define BLOCKLEN 512
|
#define BLOCKLEN 512
|
||||||
#define INVFLD 255
|
#define INVFLD 255
|
||||||
|
|
||||||
HIDDEN char _files_tmp_string[128];
|
HIDDEN char _files_tmp_string[128];
|
||||||
|
|
||||||
TFile::TFile(int lenrec, int base)
|
TFile ::TFile (int lenrec, int base)
|
||||||
|
|
||||||
{
|
{
|
||||||
_file = new SecDef;
|
_file = new SecDef;
|
||||||
if (_file == NULL) fatal_box("Can't allocate record file ");
|
if (_file == NULL)
|
||||||
_file->IOR = NOERR;
|
fatal_box ("Can't allocate record file ");
|
||||||
_len = lenrec;
|
_file->IOR = NOERR;
|
||||||
_base = base;
|
_len = lenrec;
|
||||||
_file->LockMode = _manulock;
|
_base = base;
|
||||||
_file->lpos = -1;
|
_file->LockMode = _manulock;
|
||||||
_file->name[0] = '\0';
|
_file->lpos = -1;
|
||||||
|
_file->name[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TFile ::~TFile ()
|
||||||
TFile::~TFile()
|
|
||||||
|
|
||||||
{
|
{
|
||||||
delete _file;
|
delete _file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFile ::
|
||||||
void TFile::open(const char* name, TFilelock lockmode)
|
open (const char *name, TFilelock lockmode)
|
||||||
|
|
||||||
{
|
{
|
||||||
COpen(_file, (char*) name, _len, _base, lockmode);
|
COpen (_file, (char *) name, _len, _base, lockmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TFile ::
|
||||||
bool TFile::verify(const char* name)
|
verify (const char *name)
|
||||||
|
|
||||||
{
|
{
|
||||||
CVerify(_file, (char*) name);
|
CVerify (_file, (char *) name);
|
||||||
return _file->IOR == NOERR;
|
return _file->IOR == NOERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFile ::
|
||||||
void TFile::create(const char* name, TRecnotype nrecord)
|
create (const char *name, TRecnotype nrecord)
|
||||||
|
|
||||||
{
|
{
|
||||||
CCreate(_file, (char*) name, _len, _base, (nrecord * _len) /BLOCKLEN + 1);
|
CCreate (_file, (char *) name, _len, _base, (nrecord * _len) / BLOCKLEN + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFile ::
|
||||||
void TFile::chsize(const char* name, TRecnotype nrecord)
|
chsize (const char *name, TRecnotype nrecord)
|
||||||
|
|
||||||
{
|
{
|
||||||
CChsize(_file, (char*) name, _len, _base, (nrecord * _len) /BLOCKLEN + 1);
|
CChsize (_file, (char *) name, _len, _base, (nrecord * _len) / BLOCKLEN + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFile ::
|
||||||
void TFile::close()
|
close ()
|
||||||
|
|
||||||
{
|
{
|
||||||
CClose(_file);
|
CClose (_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFile ::
|
||||||
void TFile::unlink(const char* name)
|
unlink (const char *name)
|
||||||
|
|
||||||
{
|
{
|
||||||
CDelete(_file, (char*) name);
|
CDelete (_file, (char *) name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFile ::
|
||||||
void TFile::read(char* record, TRecnotype recnum, TReclock lock)
|
read (char *record, TRecnotype recnum, TReclock lock)
|
||||||
|
|
||||||
{
|
{
|
||||||
_file->LenRec = _len;
|
_file->LenRec = _len;
|
||||||
_file->BaseFil = _base;
|
_file->BaseFil = _base;
|
||||||
CRead(_file, record, recnum, lock);
|
CRead (_file, record, recnum, lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFile ::
|
||||||
void TFile::write(char* record, TRecnotype recnum, TReclock lock)
|
write (char *record, TRecnotype recnum, TReclock lock)
|
||||||
|
|
||||||
{
|
{
|
||||||
_file->LenRec = _len;
|
_file->LenRec = _len;
|
||||||
_file->BaseFil = _base;
|
_file->BaseFil = _base;
|
||||||
CWrite(_file, record, recnum, lock);
|
CWrite (_file, record, recnum, lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TFile ::
|
||||||
|
status ()
|
||||||
|
const
|
||||||
|
|
||||||
int TFile::status() const
|
|
||||||
|
|
||||||
{
|
|
||||||
return _file->IOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TDir::TDir()
|
|
||||||
|
|
||||||
{
|
|
||||||
_dir = new FileDes;
|
|
||||||
if (_dir == NULL)
|
|
||||||
fatal_box("Can't allocate dir");
|
|
||||||
zero();
|
|
||||||
_num = - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TDir::~TDir()
|
|
||||||
|
|
||||||
{
|
|
||||||
delete _dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char* TDir::name() const
|
|
||||||
|
|
||||||
{
|
|
||||||
return _dir->SysName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char* TDir::des() const
|
|
||||||
|
|
||||||
{
|
|
||||||
return _dir->Des;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char* TDir::expr() const
|
|
||||||
|
|
||||||
{
|
|
||||||
return _dir->FCalc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TRecnotype& TDir::eod() const
|
|
||||||
|
|
||||||
{
|
|
||||||
return _dir->EOD;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TRecnotype& TDir::eox() const
|
|
||||||
|
|
||||||
{
|
|
||||||
return _dir->EOX;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TRecnotype& TDir::flags() const
|
|
||||||
|
|
||||||
{
|
|
||||||
return _dir->Flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
word& TDir::len()
|
|
||||||
|
|
||||||
{
|
|
||||||
return (word&) _dir->LenR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int TDir::status(TDirtype dirop) const
|
|
||||||
|
|
||||||
{
|
|
||||||
return fdir[dirop].IOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TDir::set_len(const UINT16 len)
|
|
||||||
{
|
|
||||||
_dir->LenR = len;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TDir::set_eox(const RecNoType eox)
|
|
||||||
{
|
|
||||||
_dir->EOX = eox;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TDir::set(const char * name, const RecNoType eod, const RecNoType flag, const char * des, const char * calc)
|
|
||||||
{
|
|
||||||
strncpy (_dir->SysName, name, sizeof(_dir->SysName));
|
|
||||||
_dir->EOD = eod;
|
|
||||||
_dir->Flags = flag;
|
|
||||||
strncpy (_dir->Des, des, sizeof(_dir->Des));
|
|
||||||
strncpy (_dir->FCalc, calc, sizeof(_dir->FCalc));
|
|
||||||
}
|
|
||||||
|
|
||||||
void TDir::get(int nfile, TReclock lock, TDirtype dirtype, TDirop op)
|
|
||||||
|
|
||||||
{
|
|
||||||
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
|
||||||
|
|
||||||
if (op == _nordirop)
|
|
||||||
COpenFile(nfile, _dir, int(lock), _whichdir);
|
|
||||||
else
|
|
||||||
CGetFile(nfile, _dir, int(lock), _whichdir);
|
|
||||||
_num = nfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TDir::put(int nfile, TDirtype dirtype, TDirop op)
|
|
||||||
|
|
||||||
{
|
|
||||||
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
|
||||||
|
|
||||||
if (nfile <= 0)
|
|
||||||
fatal_box("Bad file number %d", nfile);
|
|
||||||
if (op == _nordirop)
|
|
||||||
CCloseFile(nfile, _dir, _whichdir);
|
|
||||||
else
|
|
||||||
CPutFile(nfile, _dir, _whichdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TDir::zero()
|
|
||||||
|
|
||||||
{
|
|
||||||
zerofdes(_dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int TDir::items(TDirtype dirtype) const
|
|
||||||
|
|
||||||
{
|
|
||||||
FileDes f;
|
|
||||||
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
|
||||||
|
|
||||||
CGetFile(1, &f, _nolock, _whichdir);
|
|
||||||
return (int)f.EOD;
|
|
||||||
}
|
|
||||||
|
|
||||||
TTrec::TTrec()
|
|
||||||
|
|
||||||
{
|
|
||||||
_rec = new RecDes;
|
|
||||||
if (_rec == NULL)
|
|
||||||
fatal_box("Can't allocate record description");
|
|
||||||
zero();
|
|
||||||
_num = - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TTrec::~TTrec()
|
|
||||||
|
|
||||||
{
|
|
||||||
delete _rec;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int TTrec::compare(const TSortable& a) const
|
|
||||||
|
|
||||||
{
|
|
||||||
const TTrec& r = (const TTrec&)a;
|
|
||||||
const int res = memcmp((const void*)_rec, (const void*)r._rec, sizeof(*_rec));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TTrec::rehash()
|
|
||||||
|
|
||||||
{
|
|
||||||
setrdes(_rec);
|
|
||||||
}
|
|
||||||
|
|
||||||
TTrec& TTrec::operator =(const TTrec& b)
|
|
||||||
|
|
||||||
{
|
|
||||||
_num = b._num;
|
|
||||||
memcpy(_rec, b._rec, sizeof(*_rec));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TTrec::get(int nfile, TDirtype dirtype)
|
|
||||||
|
|
||||||
{
|
|
||||||
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
|
||||||
|
|
||||||
CGetRec(nfile, _rec, _whichdir);
|
|
||||||
_num = nfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TTrec::put(int nfile, TDirtype dirtype)
|
|
||||||
|
|
||||||
{
|
|
||||||
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
|
||||||
|
|
||||||
if (nfile <= 0)
|
|
||||||
fatal_box("Bad file number %d", nfile);
|
|
||||||
CPutRec(nfile, _rec, _whichdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TTrec::zero()
|
|
||||||
|
|
||||||
{
|
|
||||||
zerordes(_rec);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int TTrec::status(TDirtype dirop) const
|
|
||||||
|
|
||||||
{
|
|
||||||
return rdir[dirop].IOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int TTrec::field(const char* name) const
|
|
||||||
|
|
||||||
{
|
|
||||||
return findfld(_rec, (char*) name);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* TTrec::fielddef(int fld) const
|
|
||||||
|
|
||||||
{
|
|
||||||
sprintf(_files_tmp_string, "%s|%d|%d|%d", _rec->Fd[fld].Name,
|
|
||||||
(int) _rec->Fd[fld].TypeF, (int) _rec->Fd[fld].Len,
|
|
||||||
(int) _rec->Fd[fld].Dec);
|
|
||||||
return _files_tmp_string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* TTrec::keydef(int key) const
|
|
||||||
|
|
||||||
{
|
|
||||||
TFixed_string s(_files_tmp_string, 128);
|
|
||||||
|
|
||||||
s = "";
|
|
||||||
for (int j = 0 ; j < _rec->Ky[key].NkFields; j++)
|
|
||||||
{
|
|
||||||
const bool upper = _rec->Ky[key].FieldSeq[j] > MaxFields;
|
|
||||||
const int nfld = _rec->Ky[key].FieldSeq[j] - (upper ? MaxFields : 0);
|
|
||||||
|
|
||||||
if (j) s << "+";
|
|
||||||
if (upper) s << "UPPER(";
|
|
||||||
s << _rec->Fd[nfld].Name;
|
|
||||||
if (_rec->Ky[key].FromCh[j] < INVFLD)
|
|
||||||
s << format("[%d,%d]", _rec->Ky[key].FromCh[j] + 1,
|
|
||||||
_rec->Ky[key].ToCh[j] + 1);
|
|
||||||
if (upper) s << ")";
|
|
||||||
}
|
|
||||||
s << (_rec->Ky[key].DupKeys ? "|X" : "| ");
|
|
||||||
return (const char*) s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TTrec::update_fielddef(int nfld, const char* desc)
|
|
||||||
|
|
||||||
{
|
|
||||||
TToken_string s(desc);
|
|
||||||
strcpy(_rec->Fd[nfld].Name, s.get());
|
|
||||||
_rec->Fd[nfld].TypeF = s.get_int();
|
|
||||||
_rec->Fd[nfld].Len = s.get_int();
|
|
||||||
_rec->Fd[nfld].Dec = s.get_int();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TTrec::update_keydef(int key, const char* desc)
|
|
||||||
|
|
||||||
{
|
|
||||||
TExpression expr("", _strexpr);
|
|
||||||
TToken_string s(desc);
|
|
||||||
TString ke(s.get());
|
|
||||||
|
|
||||||
if (expr.set((const char*) ke, _strexpr))
|
|
||||||
{
|
|
||||||
_rec->Ky[key].DupKeys = (*s.get() != ' ');
|
|
||||||
TCodearray& c = expr.code();
|
|
||||||
c.begin();
|
|
||||||
int n = 0;
|
|
||||||
while (!c.end())
|
|
||||||
{
|
|
||||||
TCode& inst = c.step();
|
|
||||||
TCodesym sym = inst.getsym();
|
|
||||||
|
|
||||||
if (sym == _variable)
|
|
||||||
{
|
|
||||||
const char* s = inst.string();
|
|
||||||
|
|
||||||
for (int i = 0; i <_rec->NFields; i++)
|
|
||||||
if (strcmp(_rec->Fd[i].Name, s) == 0) break;
|
|
||||||
|
|
||||||
_rec->Ky[key].FieldSeq[n] = i;
|
|
||||||
_rec->Ky[key].FromCh[n] = INVFLD;
|
|
||||||
_rec->Ky[key].FromCh[n] = INVFLD;
|
|
||||||
inst = c.step();
|
|
||||||
sym = inst.getsym();
|
|
||||||
if (sym == _upper)
|
|
||||||
_rec->Ky[key].FieldSeq[n] += MaxFields;
|
|
||||||
else
|
|
||||||
if (sym == _number)
|
|
||||||
{
|
{
|
||||||
_rec->Ky[key].FromCh[n] = inst.number().integer() - 1;
|
return _file->IOR;
|
||||||
inst = c.step();
|
|
||||||
_rec->Ky[key].ToCh[n] = _rec->Ky[key].FromCh[n] + inst.number().integer() - 1;
|
|
||||||
inst = c.step();
|
|
||||||
}
|
}
|
||||||
else c.backtrace();
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_rec->Ky[key].NkFields = n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TTrec::print_on(ostream& out) const
|
TDir ::
|
||||||
|
TDir ()
|
||||||
|
|
||||||
{
|
{
|
||||||
out << num() << '\n';
|
_dir = new FileDes;
|
||||||
const int nfields = fields();
|
if (_dir == NULL)
|
||||||
TToken_string s(80);
|
fatal_box ("Can't allocate dir");
|
||||||
|
zero ();
|
||||||
out << nfields << '\n';
|
_num = -1;
|
||||||
for (int i = 0; i < nfields; i++)
|
|
||||||
{
|
|
||||||
s = fielddef(i);
|
|
||||||
out << s << '\n';
|
|
||||||
}
|
|
||||||
const int nkeys = keys();
|
|
||||||
|
|
||||||
out << nkeys << '\n';
|
|
||||||
for (i = 0; i < nkeys; i++)
|
|
||||||
{
|
|
||||||
s = keydef(i);
|
|
||||||
out << s << '\n';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TDir ::~TDir ()
|
||||||
|
|
||||||
void TTrec::read_from(istream& in)
|
{
|
||||||
|
delete _dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *TDir ::
|
||||||
|
name ()
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return _dir->SysName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *TDir ::des ()
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return _dir->Des;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *TDir ::expr ()
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return _dir->FCalc;
|
||||||
|
}
|
||||||
|
|
||||||
|
TRecnotype & TDir ::
|
||||||
|
eod ()
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return _dir->EOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
TRecnotype & TDir ::
|
||||||
|
eox ()
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return _dir->EOX;
|
||||||
|
}
|
||||||
|
|
||||||
|
TRecnotype & TDir ::
|
||||||
|
flags ()
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return _dir->Flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
word & TDir ::
|
||||||
|
len ()
|
||||||
|
|
||||||
|
{
|
||||||
|
return (word &) _dir->LenR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TDir ::
|
||||||
|
status (TDirtype dirop)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return fdir[dirop].IOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TDir ::set_len (const UINT16 len)
|
||||||
|
{
|
||||||
|
_dir->LenR = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TDir ::
|
||||||
|
set_eox (const RecNoType eox)
|
||||||
|
{
|
||||||
|
_dir->EOX = eox;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TDir ::
|
||||||
|
set (const char *name, const RecNoType eod, const RecNoType flag, const char *des, const char *calc)
|
||||||
|
{
|
||||||
|
strncpy (_dir->SysName, name, sizeof (_dir->SysName));
|
||||||
|
_dir->EOD = eod;
|
||||||
|
_dir->Flags = flag;
|
||||||
|
strncpy (_dir->Des, des, sizeof (_dir->Des));
|
||||||
|
strncpy (_dir->FCalc, calc, sizeof (_dir->FCalc));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TDir ::
|
||||||
|
get (int nfile, TReclock lock, TDirtype dirtype, TDirop op)
|
||||||
|
|
||||||
|
{
|
||||||
|
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
||||||
|
|
||||||
|
if (op == _nordirop)
|
||||||
|
COpenFile (nfile, _dir, int (lock), _whichdir);
|
||||||
|
else
|
||||||
|
CGetFile (nfile, _dir, int (lock), _whichdir);
|
||||||
|
_num = nfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TDir ::
|
||||||
|
put (int nfile, TDirtype dirtype, TDirop op)
|
||||||
|
|
||||||
|
{
|
||||||
|
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
||||||
|
|
||||||
|
if (nfile <= 0)
|
||||||
|
fatal_box ("Bad file number %d", nfile);
|
||||||
|
if (op == _nordirop)
|
||||||
|
CCloseFile (nfile, _dir, _whichdir);
|
||||||
|
else
|
||||||
|
CPutFile (nfile, _dir, _whichdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TDir ::
|
||||||
|
zero ()
|
||||||
|
|
||||||
|
{
|
||||||
|
zerofdes (_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TDir ::
|
||||||
|
items (TDirtype dirtype)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
FileDes f;
|
||||||
|
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
||||||
|
|
||||||
|
CGetFile (1, &f, _nolock, _whichdir);
|
||||||
|
return (int) f.EOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
TTrec ::
|
||||||
|
TTrec ()
|
||||||
|
|
||||||
|
{
|
||||||
|
_rec = new RecDes;
|
||||||
|
if (_rec == NULL)
|
||||||
|
fatal_box ("Can't allocate record description");
|
||||||
|
zero ();
|
||||||
|
_num = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TTrec ::~TTrec ()
|
||||||
|
|
||||||
|
{
|
||||||
|
delete _rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TTrec ::
|
||||||
|
compare (const TSortable & a)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
const TTrec & r = (const TTrec &) a;
|
||||||
|
const int res = memcmp ((const void *) _rec, (const void *) r._rec, sizeof (*_rec));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::rehash ()
|
||||||
|
|
||||||
|
{
|
||||||
|
setrdes (_rec);
|
||||||
|
}
|
||||||
|
|
||||||
|
TTrec & TTrec ::operator = (const TTrec & b)
|
||||||
|
|
||||||
|
{
|
||||||
|
_num = b._num;
|
||||||
|
memcpy (_rec, b._rec, sizeof (*_rec));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::
|
||||||
|
get (int nfile, TDirtype dirtype)
|
||||||
|
|
||||||
|
{
|
||||||
|
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
||||||
|
|
||||||
|
CGetRec (nfile, _rec, _whichdir);
|
||||||
|
_num = nfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::
|
||||||
|
put (int nfile, TDirtype dirtype)
|
||||||
|
|
||||||
|
{
|
||||||
|
int _whichdir = (dirtype == _nordir ? NORDIR : COMDIR);
|
||||||
|
|
||||||
|
if (nfile <= 0)
|
||||||
|
fatal_box ("Bad file number %d", nfile);
|
||||||
|
CPutRec (nfile, _rec, _whichdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::
|
||||||
|
zero ()
|
||||||
|
|
||||||
|
{
|
||||||
|
zerordes (_rec);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TTrec ::
|
||||||
|
status (TDirtype dirop)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return rdir[dirop].IOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TTrec ::field (const char *name)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
return findfld (_rec, (char *) name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *TTrec ::fielddef (int fld)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
sprintf (_files_tmp_string, "%s|%d|%d|%d", _rec->Fd[fld].Name,
|
||||||
|
(int) _rec->Fd[fld].TypeF, (int) _rec->Fd[fld].Len,
|
||||||
|
(int) _rec->Fd[fld].Dec);
|
||||||
|
return _files_tmp_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *TTrec ::keydef (int key)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
TFixed_string s (_files_tmp_string, 128);
|
||||||
|
|
||||||
|
s = "";
|
||||||
|
for (int j = 0; j < _rec->Ky[key].NkFields; j++)
|
||||||
|
{
|
||||||
|
const bool upper = _rec->Ky[key].FieldSeq[j] > MaxFields;
|
||||||
|
const int nfld = _rec->Ky[key].FieldSeq[j] - (upper ? MaxFields : 0);
|
||||||
|
|
||||||
|
if (j)
|
||||||
|
s << "+";
|
||||||
|
if (upper)
|
||||||
|
s << "UPPER(";
|
||||||
|
s << _rec->Fd[nfld].Name;
|
||||||
|
if (_rec->Ky[key].FromCh[j] < INVFLD)
|
||||||
|
s << format ("[%d,%d]", _rec->Ky[key].FromCh[j] + 1,
|
||||||
|
_rec->Ky[key].ToCh[j] + 1);
|
||||||
|
if (upper)
|
||||||
|
s << ")";
|
||||||
|
}
|
||||||
|
s << (_rec->Ky[key].DupKeys ? "|X" : "| ");
|
||||||
|
return (const char *) s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::
|
||||||
|
update_fielddef (int nfld, const char *desc)
|
||||||
|
|
||||||
|
{
|
||||||
|
TToken_string s (desc);
|
||||||
|
strcpy (_rec->Fd[nfld].Name, s.get ());
|
||||||
|
_rec->Fd[nfld].TypeF = s.get_int ();
|
||||||
|
_rec->Fd[nfld].Len = s.get_int ();
|
||||||
|
_rec->Fd[nfld].Dec = s.get_int ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::
|
||||||
|
update_keydef (int key, const char *desc)
|
||||||
|
|
||||||
|
{
|
||||||
|
TExpression expr ("", _strexpr);
|
||||||
|
TToken_string s (desc);
|
||||||
|
TString ke (s.get ());
|
||||||
|
|
||||||
|
if (expr.set ((const char *) ke, _strexpr))
|
||||||
|
{
|
||||||
|
_rec->Ky[key].DupKeys = (*s.get () != ' ');
|
||||||
|
TCodearray & c = expr.code ();
|
||||||
|
c.begin ();
|
||||||
|
int n = 0;
|
||||||
|
while (!c.end ())
|
||||||
|
{
|
||||||
|
TCode & inst = c.step ();
|
||||||
|
TCodesym sym = inst.getsym ();
|
||||||
|
|
||||||
|
if (sym == _variable)
|
||||||
|
{
|
||||||
|
const char *s = inst.string ();
|
||||||
|
|
||||||
|
for (int i = 0; i < _rec->NFields; i++)
|
||||||
|
if (strcmp (_rec->Fd[i].Name, s) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
_rec->Ky[key].FieldSeq[n] = i;
|
||||||
|
_rec->Ky[key].FromCh[n] = INVFLD;
|
||||||
|
_rec->Ky[key].FromCh[n] = INVFLD;
|
||||||
|
inst = c.step ();
|
||||||
|
sym = inst.getsym ();
|
||||||
|
if (sym == _upper)
|
||||||
|
_rec->Ky[key].FieldSeq[n] += MaxFields;
|
||||||
|
else if (sym == _number)
|
||||||
|
{
|
||||||
|
_rec->Ky[key].FromCh[n] = inst.number ().integer () - 1;
|
||||||
|
inst = c.step ();
|
||||||
|
_rec->Ky[key].ToCh[n] = _rec->Ky[key].FromCh[n] + inst.number ().integer () - 1;
|
||||||
|
inst = c.step ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
c.backtrace ();
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_rec->Ky[key].NkFields = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::
|
||||||
|
print_on (ostream & out)
|
||||||
|
const
|
||||||
|
|
||||||
|
{
|
||||||
|
out << num () << '\n';
|
||||||
|
const int nfields = fields ();
|
||||||
|
TToken_string s (80);
|
||||||
|
|
||||||
|
out << nfields << '\n';
|
||||||
|
for (int i = 0; i < nfields; i++)
|
||||||
|
{
|
||||||
|
s = fielddef (i);
|
||||||
|
out << s << '\n';
|
||||||
|
}
|
||||||
|
const int nkeys = keys ();
|
||||||
|
|
||||||
|
out << nkeys << '\n';
|
||||||
|
for (i = 0; i < nkeys; i++)
|
||||||
|
{
|
||||||
|
s = keydef (i);
|
||||||
|
out << s << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTrec ::
|
||||||
|
read_from (istream & in)
|
||||||
|
|
||||||
{
|
{
|
||||||
int ln;
|
int ln;
|
||||||
|
|
||||||
in.getline(_files_tmp_string, sizeof(_files_tmp_string), '\n');
|
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
|
||||||
ln = atoi(_files_tmp_string);
|
ln = atoi (_files_tmp_string);
|
||||||
if (ln != num() && !yesno_box("Descrizione relativa al file n.ro %d.\n Continuo ?", ln))
|
if (ln != num () && !yesno_box ("Descrizione relativa al file n.ro %d.\n Continuo ?", ln))
|
||||||
return;
|
return;
|
||||||
int nfields;
|
int nfields;
|
||||||
|
|
||||||
in.getline(_files_tmp_string, sizeof(_files_tmp_string), '\n');
|
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
|
||||||
nfields = atoi(_files_tmp_string);
|
nfields = atoi (_files_tmp_string);
|
||||||
set_fields(nfields);
|
set_fields (nfields);
|
||||||
for (int i = 0; i < nfields; i++)
|
for (int i = 0; i < nfields; i++)
|
||||||
{
|
{
|
||||||
in.getline(_files_tmp_string, sizeof(_files_tmp_string), '\n');
|
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
|
||||||
update_fielddef(i, _files_tmp_string);
|
update_fielddef (i, _files_tmp_string);
|
||||||
}
|
}
|
||||||
int nkeys;
|
int nkeys;
|
||||||
|
|
||||||
in.getline(_files_tmp_string, sizeof(_files_tmp_string), '\n');
|
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
|
||||||
nkeys = atoi(_files_tmp_string);
|
nkeys = atoi (_files_tmp_string);
|
||||||
set_keys(nkeys);
|
set_keys (nkeys);
|
||||||
for (i = 0; i < nkeys; i++)
|
for (i = 0; i < nkeys; i++)
|
||||||
{
|
{
|
||||||
in.getline(_files_tmp_string, sizeof(_files_tmp_string), '\n');
|
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
|
||||||
update_keydef(i, _files_tmp_string);
|
update_keydef (i, _files_tmp_string);
|
||||||
}
|
}
|
||||||
rehash();
|
rehash ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
1704
include/msksheet.cpp
1704
include/msksheet.cpp
File diff suppressed because it is too large
Load Diff
2424
include/printapp.cpp
2424
include/printapp.cpp
File diff suppressed because it is too large
Load Diff
1531
include/printer.cpp
1531
include/printer.cpp
File diff suppressed because it is too large
Load Diff
896
include/text.cpp
896
include/text.cpp
@ -1,407 +1,489 @@
|
|||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <fstream.h>
|
#include <fstream.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
static char mytmpstr[257];
|
static char mytmpstr[257];
|
||||||
|
|
||||||
class _HotSpot : public TObject
|
class _HotSpot:public TObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// TArray _spots; // tokenstrings
|
// TArray _spots; // tokenstrings
|
||||||
char _bg, _fg;
|
char _bg, _fg;
|
||||||
|
|
||||||
_HotSpot(char fg, char bg) { _fg = fg; _bg = bg; }
|
_HotSpot (char fg, char bg)
|
||||||
virtual ~_HotSpot() {}
|
{
|
||||||
};
|
_fg = fg;
|
||||||
|
_bg = bg;
|
||||||
|
}
|
||||||
void TTextfile::set_hotspots(char fg, char bg)
|
virtual ~ _HotSpot ()
|
||||||
{
|
{
|
||||||
_HotSpot* hp = new _HotSpot(fg,bg);
|
}
|
||||||
_hotspots.add(hp);
|
};
|
||||||
}
|
|
||||||
|
void TTextfile ::
|
||||||
|
set_hotspots (char fg, char bg)
|
||||||
style TTextfile::_trans_style(char ch)
|
{
|
||||||
{
|
_HotSpot *hp = new _HotSpot (fg, bg);
|
||||||
switch(ch)
|
_hotspots.add (hp);
|
||||||
{
|
}
|
||||||
case 'r': return normal; break;
|
|
||||||
case 'i': return italic; break;
|
style TTextfile ::
|
||||||
case 'b': return bold; break;
|
_trans_style (char ch)
|
||||||
case 'u': return underlined; break;
|
{
|
||||||
case 'o': return overstrike; break;
|
switch (ch)
|
||||||
case 'k': return smallcaps; break;
|
{
|
||||||
default: return normal; break;
|
case 'r':
|
||||||
}
|
return normal;
|
||||||
}
|
break;
|
||||||
|
case 'i':
|
||||||
void TTextfile::_read_page(long n)
|
return italic;
|
||||||
{
|
break;
|
||||||
switch(_direction)
|
case 'b':
|
||||||
{
|
return bold;
|
||||||
case down:
|
break;
|
||||||
_page_start = n; break;
|
case 'u':
|
||||||
case up:
|
return underlined;
|
||||||
_page_start = n + _page_size; break;
|
break;
|
||||||
case updown:
|
case 'o':
|
||||||
_page_start = n - (_page_size/2l); break;
|
return overstrike;
|
||||||
}
|
break;
|
||||||
|
case 'k':
|
||||||
if (_page_start < 0l) _page_start = 0l;
|
return smallcaps;
|
||||||
if ((_page_start + _page_size) > _lines) _page_end = _lines -1;
|
break;
|
||||||
else _page_end = _page_start + _page_size - 1;
|
default:
|
||||||
|
return normal;
|
||||||
// zap hotspots
|
break;
|
||||||
_spots.destroy();
|
}
|
||||||
|
}
|
||||||
long l = 0l;
|
|
||||||
fseek(_index, _page_start*(long)sizeof(long), SEEK_SET);
|
void TTextfile ::
|
||||||
if (_page_start != 0l)
|
_read_page (long n)
|
||||||
fread (&l, sizeof(long), 1, _index);
|
{
|
||||||
fseek(_instr,l,SEEK_SET);
|
switch (_direction)
|
||||||
|
{
|
||||||
for (long i = _page_start; i <= _page_end; i++)
|
case down:
|
||||||
{
|
_page_start = n;
|
||||||
if (feof(_instr))
|
break;
|
||||||
break;
|
case up:
|
||||||
fgets(mytmpstr, sizeof(mytmpstr),_instr);
|
_page_start = n + _page_size;
|
||||||
mytmpstr[strlen(mytmpstr) -1] = '\0';
|
break;
|
||||||
TString& ts = (TString&)_page[(int)(i-_page_start)];
|
case updown:
|
||||||
ts = mytmpstr;
|
_page_start = n - (_page_size / 2l);
|
||||||
TString hcol(6);
|
break;
|
||||||
// find hotspots and compile list
|
}
|
||||||
|
|
||||||
|
if (_page_start < 0l)
|
||||||
int len = 0; const char* cp;
|
_page_start = 0l;
|
||||||
read_line(i,0,FALSE);
|
if ((_page_start + _page_size) > _lines)
|
||||||
while (cp = piece())
|
_page_end = _lines - 1;
|
||||||
{
|
else
|
||||||
for (int z = 0; z < _hotspots.items(); z++)
|
_page_end = _page_start + _page_size - 1;
|
||||||
{
|
|
||||||
_HotSpot& hs = (_HotSpot&)_hotspots[z];
|
// zap hotspots
|
||||||
if (hs._fg == get_foreground() && hs._bg == get_background())
|
_spots.destroy ();
|
||||||
{
|
|
||||||
TToken_string* tts = new TToken_string(50);
|
long l = 0l;
|
||||||
tts->add(i); // line number
|
fseek (_index, _page_start * (long) sizeof (long), SEEK_SET);
|
||||||
tts->add(len); tts->add(len + (int)strlen(cp) ); tts->add(cp); tts->add(z);
|
if (_page_start != 0l)
|
||||||
_spots.add(tts);
|
fread (&l, sizeof (long), 1, _index);
|
||||||
break;
|
fseek (_instr, l, SEEK_SET);
|
||||||
}
|
|
||||||
}
|
for (long i = _page_start; i <= _page_end; i++)
|
||||||
len += strlen(cp);
|
{
|
||||||
}
|
if (feof (_instr))
|
||||||
}
|
break;
|
||||||
}
|
fgets (mytmpstr, sizeof (mytmpstr), _instr);
|
||||||
|
mytmpstr[strlen (mytmpstr) - 1] = '\0';
|
||||||
void TTextfile::read_line(long n, long pos, bool pg)
|
TString & ts = (TString &) _page[(int) (i - _page_start)];
|
||||||
{
|
ts = mytmpstr;
|
||||||
CHECK(_isopen, "Attempt operation on closed file");
|
TString hcol (6);
|
||||||
CHECKD(n >= 0 && n < _lines, "Line not present", n);
|
// find hotspots and compile list
|
||||||
|
|
||||||
if (pg && !_in_page(n)) _read_page(n);
|
int len = 0;
|
||||||
|
const char *cp;
|
||||||
TString* tp = (TString*)_page.objptr(int(n-_page_start));
|
read_line (i, 0, FALSE);
|
||||||
if (tp == NULL) return;
|
while (cp = piece ())
|
||||||
|
{
|
||||||
const char* sp = (const char*)(*tp);
|
for (int z = 0; z < _hotspots.items (); z++)
|
||||||
_item = 0; _line = "";
|
{
|
||||||
int ndx = 0, p = 0;
|
_HotSpot & hs = (_HotSpot &) _hotspots[z];
|
||||||
bool first = TRUE;
|
if (hs._fg == get_foreground () && hs._bg == get_background ())
|
||||||
_cur_line = n;
|
{
|
||||||
char ch;
|
TToken_string *tts = new TToken_string (50);
|
||||||
|
tts->add (i); // line number
|
||||||
int col = ((int)'w' << 8) | (int)'n';
|
|
||||||
long stl = (long)col << 16;
|
tts->add (len);
|
||||||
|
tts->add (len + (int) strlen (cp));
|
||||||
while(ch = *sp++)
|
tts->add (cp);
|
||||||
{
|
tts->add (z);
|
||||||
if (ch == '@' || (ch == '$' && *(sp) == '['))
|
_spots.add (tts);
|
||||||
{
|
break;
|
||||||
if (!first && p >= pos)
|
}
|
||||||
{
|
}
|
||||||
_styles[_item++] = stl;
|
len += strlen (cp);
|
||||||
mytmpstr[ndx] = '\0';
|
}
|
||||||
_line.add(mytmpstr);
|
}
|
||||||
ndx = 0;
|
}
|
||||||
}
|
|
||||||
while(ch && (ch == '@' || (ch == '$' && *sp == '[')))
|
void TTextfile ::
|
||||||
{
|
read_line (long n, long pos, bool pg)
|
||||||
if (ch == '@') // font style change ?
|
{
|
||||||
{
|
CHECK (_isopen, "Attempt operation on closed file");
|
||||||
style sss = _trans_style(*sp++);
|
CHECKD (n >= 0 && n < _lines, "Line not present", n);
|
||||||
if (sss == normal) stl = (long)col << 16; else stl |= (long)sss;
|
|
||||||
}
|
if (pg && !_in_page (n))
|
||||||
else if (ch == '$' && *sp == '[') // color change
|
_read_page (n);
|
||||||
{
|
|
||||||
++sp; // eat '['
|
TString *tp = (TString *) _page.objptr (int (n - _page_start));
|
||||||
col = *sp++;
|
if (tp == NULL)
|
||||||
++sp; // eat ','
|
return;
|
||||||
col |= ((int)(*sp++) << 8);
|
|
||||||
++sp; // eat ']'
|
const char *sp = (const char *) (*tp);
|
||||||
stl = (stl & 0x0000ffff) | ((long)col << 16);
|
_item = 0;
|
||||||
}
|
_line = "";
|
||||||
ch = *sp++;
|
int ndx = 0, p = 0;
|
||||||
} // while
|
bool first = TRUE;
|
||||||
}
|
_cur_line = n;
|
||||||
if (ch && p >= pos)
|
char ch;
|
||||||
{
|
|
||||||
first = FALSE;
|
int col = ((int) 'w' << 8) | (int) 'n';
|
||||||
mytmpstr[ndx++] = ch;
|
long stl = (long) col << 16;
|
||||||
}
|
|
||||||
p++;
|
while (ch = *sp++)
|
||||||
}
|
{
|
||||||
_styles[_item++] = stl;
|
if (ch == '@' || (ch == '$' && *(sp) == '['))
|
||||||
mytmpstr[ndx] = '\0';
|
{
|
||||||
_line.add(mytmpstr);
|
if (!first && p >= pos)
|
||||||
_item = 0;
|
{
|
||||||
}
|
_styles[_item++] = stl;
|
||||||
|
mytmpstr[ndx] = '\0';
|
||||||
const char* TTextfile::line(long j, long pos)
|
_line.add (mytmpstr);
|
||||||
{
|
ndx = 0;
|
||||||
if (_cur_line != j) read_line(j);
|
}
|
||||||
*mytmpstr = '\0';
|
while (ch && (ch == '@' || (ch == '$' && *sp == '[')))
|
||||||
_line.restart();
|
{
|
||||||
for (int i = 0; i < _line.items(); i++)
|
if (ch == '@') // font style change ?
|
||||||
strcat(mytmpstr, (const char*)_line.get());
|
|
||||||
return strlen(mytmpstr) > (word)pos ? &(mytmpstr[pos]) : "";
|
{
|
||||||
}
|
style sss = _trans_style (*sp++);
|
||||||
|
if (sss == normal)
|
||||||
long TTextfile::get_attribute(int pos)
|
stl = (long) col << 16;
|
||||||
{
|
else
|
||||||
long stl = 0;
|
stl |= (long) sss;
|
||||||
if (pos == -1)
|
}
|
||||||
{
|
else if (ch == '$' && *sp == '[') // color change
|
||||||
CHECK(_item > 0, "must execute piece() before style()!");
|
|
||||||
stl = _styles[_item-1];
|
{
|
||||||
}
|
++sp; // eat '['
|
||||||
else
|
|
||||||
{
|
col = *sp++;
|
||||||
int x = 0, nd = 0; const char* c;
|
++sp; // eat ','
|
||||||
_line.restart();
|
|
||||||
while(c = _line.get())
|
col |= ((int) (*sp++) << 8);
|
||||||
{
|
++sp; // eat ']'
|
||||||
x += strlen(c);
|
|
||||||
stl = _styles[nd++];
|
stl = (stl & 0x0000ffff) | ((long) col << 16);
|
||||||
if ((x-1) >= pos) break; }
|
}
|
||||||
}
|
ch = *sp++;
|
||||||
return stl;
|
} // while
|
||||||
}
|
|
||||||
|
}
|
||||||
int TTextfile::get_style(int pos)
|
if (ch && p >= pos)
|
||||||
{
|
{
|
||||||
long x = get_attribute(pos);
|
first = FALSE;
|
||||||
return (int)(x & 0x0000ffff);
|
mytmpstr[ndx++] = ch;
|
||||||
}
|
}
|
||||||
|
p++;
|
||||||
char TTextfile::get_background(int pos)
|
}
|
||||||
{
|
_styles[_item++] = stl;
|
||||||
long x = get_attribute(pos);
|
mytmpstr[ndx] = '\0';
|
||||||
return (char)(x >> 24);
|
_line.add (mytmpstr);
|
||||||
}
|
_item = 0;
|
||||||
|
}
|
||||||
char TTextfile::get_foreground(int pos)
|
|
||||||
{
|
const char *TTextfile ::
|
||||||
long x = get_attribute(pos);
|
line (long j, long pos)
|
||||||
return (char)((x >> 16) & 0x000000ff);
|
{
|
||||||
}
|
if (_cur_line != j)
|
||||||
|
read_line (j);
|
||||||
const char* TTextfile::piece()
|
*mytmpstr = '\0';
|
||||||
{
|
_line.restart ();
|
||||||
if (_item >= _line.items()) return NULL;
|
for (int i = 0; i < _line.items (); i++)
|
||||||
return strcpy (mytmpstr, (const char*)_line.get(_item++));
|
strcat (mytmpstr, (const char *) _line.get ());
|
||||||
}
|
return strlen (mytmpstr) > (word) pos ? &(mytmpstr[pos]) : "";
|
||||||
|
}
|
||||||
const char* TTextfile::word_at(long x, long y)
|
|
||||||
{
|
long TTextfile ::
|
||||||
CHECK(_isopen, "Attempt operation on closed file");
|
get_attribute (int pos)
|
||||||
TString s(line(y));
|
{
|
||||||
int x2 = 0;
|
long stl = 0;
|
||||||
|
if (pos == -1)
|
||||||
if (x < s.len())
|
{
|
||||||
{
|
CHECK (_item > 0, "must execute piece() before style()!");
|
||||||
while (isspace(s[(int)x]))
|
stl = _styles[_item - 1];
|
||||||
{
|
}
|
||||||
if (x == (s.len() - 1) && y < (_lines - 1l))
|
else
|
||||||
{ s = line(++y); x = 0l;}
|
{
|
||||||
else if (x < (s.len() - 1)) x++;
|
int x = 0, nd = 0;
|
||||||
else break;
|
const char *c;
|
||||||
}
|
_line.restart ();
|
||||||
while (isalnum(s[(int)x])) mytmpstr[x2++] = s[(int)x++];
|
while (c = _line.get ())
|
||||||
}
|
{
|
||||||
mytmpstr[x2] = '\0';
|
x += strlen (c);
|
||||||
return mytmpstr;
|
stl = _styles[nd++];
|
||||||
}
|
if ((x - 1) >= pos)
|
||||||
|
break;
|
||||||
|
}
|
||||||
bool TTextfile::append(const char* l)
|
}
|
||||||
{
|
return stl;
|
||||||
CHECK(_isopen, "Attempt operation on closed file");
|
}
|
||||||
|
|
||||||
if (!_accept) return FALSE;
|
int TTextfile ::
|
||||||
|
get_style (int pos)
|
||||||
fseek(_instr,0l,SEEK_END);
|
{
|
||||||
fseek(_index,0l,SEEK_END);
|
long x = get_attribute (pos);
|
||||||
long cpos = ftell(_instr);
|
return (int) (x & 0x0000ffff);
|
||||||
fprintf(_instr,"%s\n",l);
|
}
|
||||||
fwrite(&cpos, sizeof(long), 1, _index);
|
|
||||||
if (ferror(_index) || ferror(_instr))
|
char TTextfile ::
|
||||||
{
|
get_background (int pos)
|
||||||
error_box("Errore di scrittura file temporaneo: scrittura interrotta");
|
{
|
||||||
freeze();
|
long x = get_attribute (pos);
|
||||||
}
|
return (char) (x >> 24);
|
||||||
fflush(_index); fflush(_instr);
|
}
|
||||||
|
|
||||||
_lines++; _dirty = TRUE;
|
char TTextfile ::
|
||||||
|
get_foreground (int pos)
|
||||||
if ((_lines) < (_page_start+_page_size))
|
{
|
||||||
{
|
long x = get_attribute (pos);
|
||||||
TString* ll = new TString(l);
|
return (char) ((x >> 16) & 0x000000ff);
|
||||||
_page.add(ll);
|
}
|
||||||
_page_end++;
|
|
||||||
|
const char *TTextfile ::
|
||||||
int len = 0; const char* cp;
|
piece ()
|
||||||
read_line(_lines-1);
|
{
|
||||||
while (cp = piece())
|
if (_item >= _line.items ())
|
||||||
{
|
return NULL;
|
||||||
for (int z = 0; z < _hotspots.items(); z++)
|
return strcpy (mytmpstr, (const char *) _line.get (_item++));
|
||||||
{
|
}
|
||||||
_HotSpot& hs = (_HotSpot&)_hotspots[z];
|
|
||||||
if (hs._fg == get_foreground() && hs._bg == get_background())
|
const char *TTextfile ::
|
||||||
{
|
word_at (long x, long y)
|
||||||
TToken_string* tts = new TToken_string(50);
|
{
|
||||||
tts->add(_lines-1l); // line number
|
CHECK (_isopen, "Attempt operation on closed file");
|
||||||
tts->add(len); tts->add(len + (int)strlen(cp) );
|
TString s (line (y));
|
||||||
tts->add(cp); tts->add(z);
|
int x2 = 0;
|
||||||
_spots.add(tts);
|
|
||||||
break;
|
if (x < s.len ())
|
||||||
}
|
{
|
||||||
}
|
while (isspace (s[(int) x]))
|
||||||
len += strlen(cp);
|
{
|
||||||
}
|
if (x == (s.len () - 1) && y < (_lines - 1l))
|
||||||
return TRUE;
|
{
|
||||||
}
|
s = line (++y);
|
||||||
return FALSE;
|
x = 0l;
|
||||||
}
|
}
|
||||||
|
else if (x < (s.len () - 1))
|
||||||
void TTextfile::close()
|
x++;
|
||||||
{
|
else
|
||||||
CHECK(_isopen, "Attempt operation on closed file");
|
break;
|
||||||
fclose(_instr);
|
}
|
||||||
fclose(_index);
|
while (isalnum (s[(int) x]))
|
||||||
_instr = _index = NULL;
|
mytmpstr[x2++] = s[(int) x++];
|
||||||
_isopen = FALSE;
|
}
|
||||||
}
|
mytmpstr[x2] = '\0';
|
||||||
|
return mytmpstr;
|
||||||
void TTextfile::print()
|
}
|
||||||
{
|
|
||||||
CHECK(_isopen, "Attempt operation on closed file");
|
bool TTextfile ::
|
||||||
warning_box("Funzione non ancora implementata");
|
append (const char *l)
|
||||||
// TBI istanzia una printer inibendo la scelta di video
|
{
|
||||||
// add all lines (maybe new method: print_txt)
|
CHECK (_isopen, "Attempt operation on closed file");
|
||||||
// print
|
|
||||||
}
|
if (!_accept)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
bool TTextfile::write(const char* path, TPoint* from, TPoint* to)
|
fseek (_instr, 0l, SEEK_END);
|
||||||
{
|
fseek (_index, 0l, SEEK_END);
|
||||||
bool ok = FALSE;
|
long cpos = ftell (_instr);
|
||||||
FILE* fp;
|
fprintf (_instr, "%s\n", l);
|
||||||
if ((fp = fopen(path, "w")) != NULL)
|
fwrite (&cpos, sizeof (long), 1, _index);
|
||||||
{
|
if (ferror (_index) || ferror (_instr))
|
||||||
ok = TRUE;
|
{
|
||||||
TString256 s;
|
error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
|
||||||
long starty = from == NULL ? 0l : from->y;
|
freeze ();
|
||||||
int startx = from == NULL ? 0 : (int)from->x;
|
}
|
||||||
long endy = to == NULL ? _lines-1l: to->y;
|
fflush (_index);
|
||||||
int endx = to == NULL ? -1 : (int)to->x;
|
fflush (_instr);
|
||||||
for (long j = starty; j <= endy; j++)
|
|
||||||
{
|
_lines++;
|
||||||
s = line(j);
|
_dirty = TRUE;
|
||||||
if (j == endy && endx == -1) endx = s.len();
|
|
||||||
|
if ((_lines) < (_page_start + _page_size))
|
||||||
if (j == starty && j == endy) s = s.sub(startx,endx);
|
{
|
||||||
else if (j == starty) s = s.mid(startx);
|
TString *ll = new TString (l);
|
||||||
else if (j == endy) s = s.left(endx);
|
_page.add (ll);
|
||||||
|
_page_end++;
|
||||||
fprintf(fp,"%s\n", (const char*)s);
|
|
||||||
}
|
int len = 0;
|
||||||
fclose(fp);
|
const char *cp;
|
||||||
}
|
read_line (_lines - 1);
|
||||||
else warning_box("Impossibile scrivere il file %s; scrittura fallita", path);
|
while (cp = piece ())
|
||||||
return ok;
|
{
|
||||||
}
|
for (int z = 0; z < _hotspots.items (); z++)
|
||||||
|
{
|
||||||
|
_HotSpot & hs = (_HotSpot &) _hotspots[z];
|
||||||
void TTextfile::destroy()
|
if (hs._fg == get_foreground () && hs._bg == get_background ())
|
||||||
{
|
{
|
||||||
CHECK(_istemp,"destroy() chiamata su testo permanente!");
|
TToken_string *tts = new TToken_string (50);
|
||||||
if (_page.items() > 0)
|
tts->add (_lines - 1l); // line number
|
||||||
{
|
//
|
||||||
if (_index) fclose(_index);
|
|
||||||
if (_instr) fclose(_instr);
|
tts->add (len);
|
||||||
remove((const char*)_filename);
|
tts->add (len + (int) strlen (cp));
|
||||||
remove((const char*)_indname);
|
tts->add (cp);
|
||||||
_page_start = _lines = 0l;
|
tts->add (z);
|
||||||
_page_end = _cur_line = -1l;
|
_spots.add (tts);
|
||||||
_accept = TRUE;
|
break;
|
||||||
_instr = fopen(_filename,"a+");
|
}
|
||||||
_indname.temp();
|
}
|
||||||
_index = fopen(_indname,"w+b");
|
len += strlen (cp);
|
||||||
if (_index == NULL || _instr == NULL)
|
}
|
||||||
{
|
return TRUE;
|
||||||
error_box("Impossibile aprire files temporanei");
|
}
|
||||||
freeze();
|
return FALSE;
|
||||||
}
|
}
|
||||||
_isopen = TRUE;
|
|
||||||
_page.destroy();
|
void TTextfile ::
|
||||||
_spots.destroy();
|
close ()
|
||||||
}
|
{
|
||||||
}
|
CHECK (_isopen, "Attempt operation on closed file");
|
||||||
|
fclose (_instr);
|
||||||
|
fclose (_index);
|
||||||
TTextfile::TTextfile(const char* file, int pagesize, direction preferred) :
|
_instr = _index = NULL;
|
||||||
_page_size(pagesize), _page(pagesize), _filename(file), _lines(0l),
|
_isopen = FALSE;
|
||||||
_index(NULL), _page_start(0l), _page_end(-1l), _direction(preferred),
|
}
|
||||||
_dirty(FALSE), _istemp(FALSE), _item(0), _line(256), _cur_line(-1),
|
|
||||||
_hotspots(4), _accept(TRUE)
|
void TTextfile ::
|
||||||
{
|
print ()
|
||||||
// open file & build index
|
{
|
||||||
if (file == NULL) { _filename.temp(); _istemp = TRUE; }
|
CHECK (_isopen, "Attempt operation on closed file");
|
||||||
|
warning_box ("Funzione non ancora implementata");
|
||||||
_instr = fopen(_filename,"a+");
|
// TBI istanzia una printer inibendo la scelta di video
|
||||||
_indname.temp();
|
// add all lines (maybe new method: print_txt)
|
||||||
_index = fopen(_indname, "w+b");
|
// print
|
||||||
|
}
|
||||||
if (_index == NULL || _instr == NULL)
|
|
||||||
{
|
bool TTextfile ::
|
||||||
error_box("Impossibile aprire files temporanei");
|
write (const char *path, TPoint * from, TPoint * to)
|
||||||
freeze();
|
{
|
||||||
}
|
bool ok = FALSE;
|
||||||
if (file != NULL)
|
FILE *fp;
|
||||||
while (!feof(_instr))
|
if ((fp = fopen (path, "w")) != NULL)
|
||||||
{
|
{
|
||||||
const long l = ftell(_instr);
|
ok = TRUE;
|
||||||
fwrite(&l, sizeof(long), 1, _index);
|
TString256 s;
|
||||||
if (ferror(_index) || ferror(_instr))
|
long starty = from == NULL ? 0l : from->y;
|
||||||
{
|
int startx = from == NULL ? 0 : (int) from->x;
|
||||||
error_box("Errore di scrittura file temporaneo: scrittura interrotta");
|
long endy = to == NULL ? _lines - 1l : to->y;
|
||||||
freeze();
|
int endx = to == NULL ? -1 : (int) to->x;
|
||||||
}
|
for (long j = starty; j <= endy; j++)
|
||||||
fgets(mytmpstr, sizeof(mytmpstr), _instr);
|
{
|
||||||
_lines++;
|
s = line (j);
|
||||||
}
|
if (j == endy && endx == -1)
|
||||||
_isopen = TRUE;
|
endx = s.len ();
|
||||||
}
|
|
||||||
|
if (j == starty && j == endy)
|
||||||
|
s = s.sub (startx, endx);
|
||||||
|
else if (j == starty)
|
||||||
TTextfile::~TTextfile()
|
s = s.mid (startx);
|
||||||
{
|
else if (j == endy)
|
||||||
if (_index) fclose(_index);
|
s = s.left (endx);
|
||||||
if (_instr) fclose(_instr);
|
|
||||||
if (_istemp) remove((const char*)_filename);
|
fprintf (fp, "%s\n", (const char *) s);
|
||||||
remove((const char*)_indname);
|
}
|
||||||
}
|
fclose (fp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
warning_box ("Impossibile scrivere il file %s; scrittura fallita", path);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TTextfile ::
|
||||||
|
destroy ()
|
||||||
|
{
|
||||||
|
CHECK (_istemp, "destroy() chiamata su testo permanente!");
|
||||||
|
if (_page.items () > 0)
|
||||||
|
{
|
||||||
|
if (_index)
|
||||||
|
fclose (_index);
|
||||||
|
if (_instr)
|
||||||
|
fclose (_instr);
|
||||||
|
remove ((const char *) _filename);
|
||||||
|
remove ((const char *) _indname);
|
||||||
|
_page_start = _lines = 0l;
|
||||||
|
_page_end = _cur_line = -1l;
|
||||||
|
_accept = TRUE;
|
||||||
|
_instr = fopen (_filename, "a+");
|
||||||
|
_indname.temp ();
|
||||||
|
_index = fopen (_indname, "w+b");
|
||||||
|
if (_index == NULL || _instr == NULL)
|
||||||
|
{
|
||||||
|
error_box ("Impossibile aprire files temporanei");
|
||||||
|
freeze ();
|
||||||
|
}
|
||||||
|
_isopen = TRUE;
|
||||||
|
_page.destroy ();
|
||||||
|
_spots.destroy ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TTextfile ::TTextfile (const char *file, int pagesize, direction preferred):
|
||||||
|
_page_size (pagesize), _page (pagesize), _filename (file), _lines (0l),
|
||||||
|
_index (NULL), _page_start (0l), _page_end (-1l), _direction (preferred),
|
||||||
|
_dirty (FALSE), _istemp (FALSE), _item (0), _line (256), _cur_line (-1),
|
||||||
|
_hotspots (4),
|
||||||
|
_accept (TRUE)
|
||||||
|
{
|
||||||
|
// open file & build index
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
_filename.temp ();
|
||||||
|
_istemp = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
_instr = fopen (_filename, "a+");
|
||||||
|
_indname.temp ();
|
||||||
|
_index = fopen (_indname, "w+b");
|
||||||
|
|
||||||
|
if (_index == NULL || _instr == NULL)
|
||||||
|
{
|
||||||
|
error_box ("Impossibile aprire files temporanei");
|
||||||
|
freeze ();
|
||||||
|
}
|
||||||
|
if (file != NULL)
|
||||||
|
while (!feof (_instr))
|
||||||
|
{
|
||||||
|
const long l = ftell (_instr);
|
||||||
|
fwrite (&l, sizeof (long), 1, _index);
|
||||||
|
if (ferror (_index) || ferror (_instr))
|
||||||
|
{
|
||||||
|
error_box ("Errore di scrittura file temporaneo: scrittura interrotta");
|
||||||
|
freeze ();
|
||||||
|
}
|
||||||
|
fgets (mytmpstr, sizeof (mytmpstr), _instr);
|
||||||
|
_lines++;
|
||||||
|
}
|
||||||
|
_isopen = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
TTextfile ::~TTextfile ()
|
||||||
|
{
|
||||||
|
if (_index)
|
||||||
|
fclose (_index);
|
||||||
|
if (_instr)
|
||||||
|
fclose (_instr);
|
||||||
|
if (_istemp)
|
||||||
|
remove ((const char *) _filename);
|
||||||
|
remove ((const char *) _indname);
|
||||||
|
}
|
||||||
|
3633
include/viswin.cpp
3633
include/viswin.cpp
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user