Resa const la variabile botime

git-svn-id: svn://10.65.10.50/trunk@184 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1994-09-07 17:00:25 +00:00
parent 60064f97d3
commit c48cfadb7d
11 changed files with 321 additions and 301 deletions

View File

@ -446,8 +446,8 @@ bool TApplication::set_firm(long newfirm)
enable_menu_item(M_FILE_NEW); enable_menu_item(M_FILE_NEW);
if (k == K_ENTER) if (k == K_ENTER)
{ {
newfirm = atol(mask.get(F_CODDITTA)); newfirm = mask.get_long(F_CODDITTA);
const int tipodir = atoi(mask.get(F_TIPO)); const int tipodir = mask.get_int(F_TIPO);
if (tipodir > 0) if (tipodir > 0)
{ {

View File

@ -9,10 +9,10 @@
#include <strings.h> #include <strings.h>
#include <utility.h> #include <utility.h>
#define DAYBIAS 36525L #define DAYBIAS 36525L
#define NULLDATE -99999L #define NULLDATE -99999L
TDate nodate, botime, eotime(31,12,2050); const TDate nodate, botime, eotime(31,12,2050);
HIDDEN TDate __tmp_date; HIDDEN TDate __tmp_date;
HIDDEN char __date_tmp_string[20]; HIDDEN char __date_tmp_string[20];

View File

@ -83,7 +83,7 @@ const char* itom(byte month); // Ritorna il nome del mese (1-12)
const char* itow(byte dayofweek); // Ritorna il nome del giorno (1-7) const char* itow(byte dayofweek); // Ritorna il nome del giorno (1-7)
// @DPUB // @DPUB
extern TDate nodate, botime, eotime; extern const TDate nodate, botime, eotime;
// @END // @END
#endif // __DATE_H #endif // __DATE_H

View File

@ -40,9 +40,6 @@
const int MAX_KEYS = 8; const int MAX_KEYS = 8;
// @END // @END
class TBaseisamfile;
class TExtrectype;
// @C // @C
// Classe TRectype : public TObject // Classe TRectype : public TObject
// //
@ -173,7 +170,7 @@ class TBaseisamfile : public TObject
friend class TIsamfile; friend class TIsamfile;
friend class TIsamtempfile; friend class TIsamtempfile;
friend class TRecfield; friend class TRecfield;
// friend class TCursor; // friend class TCursor;
// @END // @END
// @FPRIV // @FPRIV
// friend TRecnotype __buildcursor(TFilecursor* tic, TRecnotype rp); // friend TRecnotype __buildcursor(TFilecursor* tic, TRecnotype rp);
@ -196,30 +193,30 @@ protected:
public: public:
// @FPUB // @FPUB
void setkey(int nkey); // Attiva una chiave void setkey(int nkey); // Attiva una chiave
int getkey() const; // Ritorna la chiave int getkey() const; // Ritorna la chiave
void setstatus(int status) { _lasterr = status;} // Setta _lasterr void setstatus(int status) { _lasterr = status; } // Setta _lasterr
virtual int first(word lockop = _nolock); virtual int first(word lockop = _nolock);
virtual int last(word lockop = _nolock); virtual int last(word lockop = _nolock);
virtual int next(word lockop = _nolock); virtual int next(word lockop = _nolock);
virtual int next(TDate& atdate); virtual int next(TDate& atdate);
virtual int prev(word lockop = _nolock); virtual int prev(word lockop = _nolock);
virtual int prev(TDate& atdate); virtual int prev(TDate& atdate);
virtual int reread(word lockop = _nolock, TDate& atdate = botime); virtual int reread(word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int reread(TRectype& rec, word lockop = _nolock, TDate& atdate = botime); virtual int reread(TRectype& rec, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int skip(TRecnotype nrec, word lockop = _nolock); virtual int skip(TRecnotype nrec, word lockop = _nolock);
virtual int read(word op = _isequal, word lockop = _nolock, TDate& atdate = botime); virtual int read(word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& atdate = botime); virtual int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual int readat(TRecnotype nrec, word lockop = _nolock); virtual int readat(TRecnotype nrec, word lockop = _nolock);
virtual int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock); virtual int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock);
virtual int write(TDate& atdate = botime); virtual int write(TDate& atdate = (TDate&)botime);
virtual int write(const TRectype& rec, TDate& atdate = botime); virtual int write(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual int rewrite(TDate& atdate = botime); virtual int rewrite(TDate& atdate = (TDate&)botime);
virtual int rewrite(const TRectype& rec, TDate& atdate = botime); virtual int rewrite(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual int rewriteat(TRecnotype nrec); virtual int rewriteat(TRecnotype nrec);
virtual int rewriteat(const TRectype& rec, TRecnotype nrec); virtual int rewriteat(const TRectype& rec, TRecnotype nrec);
virtual int remove(TDate& atdate = botime); virtual int remove(TDate& atdate = (TDate&)botime);
virtual int remove(const TRectype& rec, TDate& atdate = botime); virtual int remove(const TRectype& rec, TDate& atdate = (TDate&)botime);
virtual const char* name() const; virtual const char* name() const;
TRecnotype recno() const { return _recno;} TRecnotype recno() const { return _recno;}

View File

@ -1,224 +1,225 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define __PREFIX_CPP #define __PREFIX_CPP
#include <prefix.h> #include <prefix.h>
#ifndef FOXPRO #ifndef FOXPRO
#include <applicat.h> #include <applicat.h>
#endif #endif
#include <array.h> #include <array.h>
#include <extcdecl.h> #include <extcdecl.h>
#include <scanner.h> #include <scanner.h>
#include <utility.h> #include <utility.h>
HIDDEN const char* const glockname = "xx"; HIDDEN const char* const glockname = "xx";
TPrefix::TPrefix() TPrefix::TPrefix()
{ {
CHECK(prefhndl == NULL, "Can't create two prefix objects"); CHECK(prefhndl == NULL, "Can't create two prefix objects");
_prefix = "."; _prefix = ".";
_dirfl = dirfl; _dirfl = dirfl;
_recfl = recfl; _recfl = recfl;
_fdir = fdir; _fdir = fdir;
_rdir = rdir; _rdir = rdir;
} }
TPrefix::~TPrefix() TPrefix::~TPrefix()
{ {
set(); set();
} }
HIDDEN int closeall(bool changestudy, TBit_array& excl) HIDDEN int closeall(bool changestudy, TBit_array& excl)
{ {
if (!openf) return 0; if (!openf) return 0;
TDir d; TDir d;
d.get(1); d.get(1);
const int max = (int) d.eod(); const int max = (int) d.eod();
int err = NOERR; int err = NOERR;
for (int i = 1; i < max; i++) for (int i = 1; i < max; i++)
if (openf[i] != NULL) if (openf[i] != NULL)
{ {
isfdptr isfd = openf[i]; isfdptr isfd = openf[i];
d.get(i + 1, _nolock, _nordir, _sysdirop); d.get(i + 1, _nolock, _nordir, _sysdirop);
if (changestudy || d.name()[0] != '%') if (changestudy || d.name()[0] != '%')
{ {
excl.set(i, isfd->f.LockMode == _excllock); excl.set(i, isfd->f.LockMode == _excllock);
CClose(&isfd->f); CClose(&isfd->f);
CBCloseFile(&isfd->i, &err); CBCloseFile(&isfd->i, &err);
exclunlock(CInsPref((char*) glockname, _nordir), FALSE); exclunlock(CInsPref((char*) glockname, _nordir), FALSE);
} }
} }
return max; return max;
} }
HIDDEN void openall(bool changestudy, TBit_array& excl, int oldmax) HIDDEN void openall(bool changestudy, TBit_array& excl, int oldmax)
{ {
if (!openf) return ; if (!openf) return ;
TDir d; TDir d;
d.get(1); d.get(1);
const int max = (int) d.eod(); const int max = (int) d.eod();
for (int i = max; i < oldmax; i++) for (int i = max; i < oldmax; i++)
if (openf[i] != NULL) if (openf[i] != NULL)
{ {
d.get(i + 1, _nolock, _nordir, _sysdirop); d.get(i + 1, _nolock, _nordir, _sysdirop);
if (changestudy || d.name()[0] != '%') if (changestudy || d.name()[0] != '%')
fatal_box("Can't reopen file n. %d", i + 1); fatal_box("Can't reopen file n. %d", i + 1);
} }
int err = NOERR; int err = NOERR;
for (i = 1; i < max; i++) for (i = 1; i < max; i++)
if (openf[i] != NULL) if (openf[i] != NULL)
{ {
isfdptr isfd = openf[i]; isfdptr isfd = openf[i];
d.get(i + 1, _nolock, _nordir, _sysdirop); d.get(i + 1, _nolock, _nordir, _sysdirop);
if (changestudy || d.name()[0] != '%') if (changestudy || d.name()[0] != '%')
{ {
isfd->ft = d.name()[0] == '%' ? _comdir : _nordir; isfd->ft = d.name()[0] == '%' ? _comdir : _nordir;
d.get(i + 1, _nolock, (TDirtype) isfd->ft); d.get(i + 1, _nolock, (TDirtype) isfd->ft);
*isfd->d = *d.filedesc(); *isfd->d = *d.filedesc();
TTrec r; TTrec r;
r.get(i + 1, (TDirtype) isfd->ft); r.get(i + 1, (TDirtype) isfd->ft);
*isfd->r = *r.rec(); *isfd->r = *r.rec();
if (excllock(CInsPref((char*) glockname, NORDIR), FALSE) == -1 && errno == EACCES) if (excllock(CInsPref((char*) glockname, NORDIR), FALSE) == -1 && errno == EACCES)
fatal_box("Can't reopen file n. %d : file in use", i + 1); fatal_box("Can't reopen file n. %d : file in use", i + 1);
COpen(&isfd->f, isfd->d->SysName, isfd->d->LenR, 0, excl[i]); COpen(&isfd->f, isfd->d->SysName, isfd->d->LenR, 0, excl[i]);
if ((err = isfd->f.IOR) == NOERR) if ((err = isfd->f.IOR) == NOERR)
CBOpenFile (&isfd->i, CGetIdxName(isfd->d->SysName), excl[i], &err); CBOpenFile (&isfd->i, CGetIdxName(isfd->d->SysName), excl[i], &err);
if (err != NOERR) if (err != NOERR)
fatal_box("Can't reopen file n. %d : error n. %d", i + 1, err); fatal_box("Can't reopen file n. %d : error n. %d", i + 1, err);
} }
} }
} }
void TPrefix::set(const char* name, bool force, TFilelock mode) void TPrefix::set(const char* name, bool force, TFilelock mode)
{ {
if (name == NULL) if (name == NULL)
{ {
CCloseDir(NORDIR); CCloseDir(NORDIR);
CCloseDir(COMDIR); CCloseDir(COMDIR);
CCloseRecDir(NORDIR); CCloseRecDir(NORDIR);
CCloseRecDir(COMDIR); CCloseRecDir(COMDIR);
return; return;
} }
if (_prefix == name) return; if (_prefix == name) return;
if (!force && !test(name)) return; if (!force && !test(name)) return;
TBit_array excl; TBit_array excl;
int max = 0; int max = 0;
if (_prefix != ".") if (_prefix != ".")
{ {
max = closeall(FALSE, excl); max = closeall(FALSE, excl);
CCloseDir(NORDIR); CCloseDir(NORDIR);
CCloseDir(COMDIR); CCloseDir(COMDIR);
CCloseRecDir(NORDIR); CCloseRecDir(NORDIR);
CCloseRecDir(COMDIR); CCloseRecDir(COMDIR);
} }
if (strcmp(name, "DEF") == 0) if (strcmp(name, "DEF") == 0)
{ {
CGetPref(); CGetPref();
_prefix = cprefix; _prefix = cprefix;
const int l = strlen(__ptprf); const int l = strlen(__ptprf);
if (l > 0) _prefix.ltrim(l); if (l > 0) _prefix.ltrim(l);
} }
else else
{ {
_prefix = name; _prefix = name;
if (*__ptprf && *name) strcpy(cprefix, __ptprf); if (*__ptprf && *name) strcpy(cprefix, __ptprf);
else strcpy(cprefix, ""); else strcpy(cprefix, "");
strcat(cprefix, name); strcat(cprefix, name);
} }
if (!test(_prefix)) if (!test(_prefix))
fatal_box("Impossibile utilizzare la ditta %s", name); fatal_box("Impossibile utilizzare la ditta %s", name);
COpenDir((int) mode, NORDIR); COpenDir((int) mode, NORDIR);
COpenDir((int) mode, COMDIR); COpenDir((int) mode, COMDIR);
COpenRecDir((int) mode, NORDIR); COpenRecDir((int) mode, NORDIR);
COpenRecDir((int) mode, COMDIR); COpenRecDir((int) mode, COMDIR);
if (_prefix != ".") if (_prefix != ".")
openall(FALSE, excl, max); openall(FALSE, excl, max);
} }
bool TPrefix::test(const char* s) const bool TPrefix::test(const char* s) const
{ {
if (s && *s && strcmp(s, "DEF")) if (s && *s && strcmp(s, "DEF"))
{ {
TString80 s1; s1 << __ptprf << s << "/dir.gen"; TString80 s1(__ptprf);
if (!fexist(s1)) s1 << s << "/dir.gen";
return error_box("Impossibile trovare il file '%s'", (const char*)s1); if (!fexist(s1))
} return error_box("Impossibile trovare il file '%s'", (const char*)s1);
}
if ((_dirfl[0] > 1) || (_dirfl[1] > 1) ||
(_recfl[0] > 1) || (_recfl[1] > 1)) if ((_dirfl[0] > 1) || (_dirfl[1] > 1) ||
return error_box("Impossibile cambiare ditta (dir.gen o trc.gen in uso)"); (_recfl[0] > 1) || (_recfl[1] > 1))
return error_box("Impossibile cambiare ditta (dir.gen o trc.gen in uso)");
return TRUE;
} return TRUE;
}
void TPrefix::put()
void TPrefix::put()
{
CPutPref((char*)(const char*)_prefix); {
} CPutPref((char*)(const char*)_prefix);
}
bool TPrefix::test(long codditta) const
{ bool TPrefix::test(long codditta) const
TString16 s; s.format("%05lda", codditta); {
return test(s); TString16 s; s.format("%05lda", codditta);
} return test(s);
}
long TPrefix::get_codditta() const
long TPrefix::get_codditta() const
{
const long codditta = atol((const char*)_prefix); {
return codditta; const long codditta = atol((const char*)_prefix);
} return codditta;
}
bool TPrefix::set_codditta(long codditta, bool force)
{ bool TPrefix::set_codditta(long codditta, bool force)
if (force || test(codditta)) {
{ if (force || test(codditta))
TString16 s; s.format("%05lda", codditta); {
set(s, force); TString16 s; s.format("%05lda", codditta);
put(); set(s, force);
return TRUE; put();
} return TRUE;
else return FALSE; }
} else return FALSE;
}
const char* firm2dir(long codditta)
{ const char* firm2dir(long codditta)
TFixed_string dir(__tmp_string, 256); {
dir.format("%05lda", codditta); TFixed_string dir(__tmp_string, 256);
dir.insert(__ptprf, 0); dir.format("%05lda", codditta);
return __tmp_string; dir.insert(__ptprf, 0);
} return __tmp_string;
}

View File

@ -1,4 +1,4 @@
// $Id: relation.cpp,v 1.6 1994-09-01 13:31:24 alex Exp $ // $Id: relation.cpp,v 1.7 1994-09-07 17:00:16 guy Exp $
// relation.cpp // relation.cpp
// fv 12/8/93 // fv 12/8/93
// relation class for isam files // relation class for isam files
@ -516,7 +516,7 @@ bool TRelation::next_match(int logicnum, const char* fieldlist, int nkey)
} }
// Riposiziona gli eventuali files successivi // Riposiziona gli eventuali files successivi
position_rels(_isequal, _nolock, botime, j+1); position_rels(_isequal, _nolock, (TDate&)botime, j+1);
reldef(j)->_first_match = FALSE; reldef(j)->_first_match = FALSE;
return ok; return ok;
@ -535,6 +535,9 @@ bool TRelation::is_first_match(int logicnum)
return err == NOERR; return err == NOERR;
} }
#ifdef DBG
bool TRelation::isconsistent(bool reset) bool TRelation::isconsistent(bool reset)
{ {
const int MAXREL = 24; const int MAXREL = 24;
@ -552,7 +555,7 @@ bool TRelation::isconsistent(bool reset)
if (bad) if (bad)
return _errors = bad; return _errors = bad;
position_rels(_isequal, _nolock, botime); position_rels(_isequal, _nolock, (TDate&)botime);
for (i = 0; i < _files.items(); i++) for (i = 0; i < _files.items(); i++)
if (file(i)->recno() != recnos[i]) if (file(i)->recno() != recnos[i])
{ {
@ -568,6 +571,9 @@ bool TRelation::isconsistent(bool reset)
return this->_errors = bad; return this->_errors = bad;
} }
#endif
int TRelation::write(bool force, TDate& atdate) int TRelation::write(bool force, TDate& atdate)
{ {
_errors = NOERR; _errors = NOERR;

View File

@ -1,4 +1,4 @@
/* $Id: relation.h,v 1.2 1994-08-26 14:06:07 alex Exp $ */ /* $Id: relation.h,v 1.3 1994-09-07 17:00:18 guy Exp $ */
// join.h // join.h
// fv 12/8/93 // fv 12/8/93
// join class for isam files // join class for isam files
@ -47,7 +47,7 @@ protected:
// adatto su un file, svuota il record corrente e non ritorna errore. // adatto su un file, svuota il record corrente e non ritorna errore.
// write etc. poi procedono normalmente // write etc. poi procedono normalmente
// @END // @END
int position_rels(TIsamop op = _isequal, TReclock lockop = _nolock, TDate& atdate = botime, int first = 0); int position_rels(TIsamop op = _isequal, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime, int first = 0);
friend class TCursor; friend class TCursor;
@ -62,7 +62,7 @@ public:
virtual int first(TReclock lockop = _nolock) { return file()->first(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } virtual int first(TReclock lockop = _nolock) { return file()->first(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); }
virtual int last(TReclock lockop = _nolock) { return file()->last(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } virtual int last(TReclock lockop = _nolock) { return file()->last(lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); }
virtual int skip(TRecnotype nrec, TReclock lockop = _nolock) { return file()->skip(nrec, lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); } virtual int skip(TRecnotype nrec, TReclock lockop = _nolock) { return file()->skip(nrec, lockop) == NOERR ? position_rels(_isequal, lockop) : file()->status(); }
virtual int read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = botime) { return file()->read(op, lockop, atdate) == NOERR ? position_rels(_isequal, lockop, atdate) : file()->status();} virtual int read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime) { return file()->read(op, lockop, atdate) == NOERR ? position_rels(_isequal, lockop, atdate) : file()->status();}
TLocalisamfile* lfile(int logicnum = 0) const; TLocalisamfile* lfile(int logicnum = 0) const;
TLocalisamfile* lfile(const char* name) const; TLocalisamfile* lfile(const char* name) const;
@ -88,9 +88,9 @@ public:
// @DES write methods // @DES write methods
// @FPUB // @FPUB
virtual int write (bool force = TRUE, TDate& atdate = botime); virtual int write (bool force = TRUE, TDate& atdate = (TDate&)botime);
virtual int rewrite(bool force = TRUE, TDate& atdate = botime); virtual int rewrite(bool force = TRUE, TDate& atdate = (TDate&)botime);
virtual int remove (TDate& atdate = botime); virtual int remove (TDate& atdate = (TDate&)botime);
// @DES checking methods // @DES checking methods
// @FPUB // @FPUB
@ -197,7 +197,7 @@ public:
TRectype& curr(int log = 0) const { return _if->curr(log); } TRectype& curr(int log = 0) const { return _if->curr(log); }
TRectype& curr(const char * tab) const TRectype& curr(const char * tab) const
{ return _if->lfile(tab)->curr(); } { return _if->lfile(tab)->curr(); }
TRecnotype read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = botime); TRecnotype read(TIsamop op = _isgteq, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime);
virtual bool ok() const; virtual bool ok() const;
const char* filter() const { return _filter; } const char* filter() const { return _filter; }

View File

@ -16,7 +16,7 @@
#include <utility.h> #include <utility.h>
HIDDEN const int MAXSTR = 257; HIDDEN const int MAXSTR = 301;
HIDDEN char __spark[MAXSTR]; // Utility buffer HIDDEN char __spark[MAXSTR]; // Utility buffer
TFixed_string spark(__spark, MAXSTR); TFixed_string spark(__spark, MAXSTR);
@ -54,7 +54,7 @@ int TString::make_room(int s)
const int lun = len(); const int lun = len();
const int spare = size() - lun; const int spare = size() - lun;
if (spare < s) if (spare < s)
resize(size() + 2*s, TRUE); resize(size() + 2*s, TRUE); // Melius abundare ...
return lun; return lun;
} }
@ -97,7 +97,7 @@ TString& TString::operator <<(char c)
TString& TString::operator <<(int n) TString& TString::operator <<(int n)
{ {
const int pos = make_room(6); const int pos = make_room(8);
sprintf(&_str[pos], "%d", n); sprintf(&_str[pos], "%d", n);
return *this; return *this;
} }
@ -215,8 +215,7 @@ bool TString::match(const char* s) const
#if XVT_OS == XVT_OS_SCOUNIX #if XVT_OS == XVT_OS_SCOUNIX
HIDDEN char* strstr(const char* string1, const char* string2) HIDDEN char* strstr(const char* string1, const char* string2)
{ {
int len = strlen(string2); const int len = strlen(string2);
while (*string1) while (*string1)
{ {
if (strncmp(string1, string2, len) == 0) return (char*) string1; if (strncmp(string1, string2, len) == 0) return (char*) string1;
@ -258,13 +257,13 @@ const char* TString::mid(int from, int count) const
{ {
const int l = len(); const int l = len();
#ifdef DBG
if (from < 0) if (from < 0)
{ {
#ifdef DBG
error_box("Ivalid MID parameter: from = %d", from); error_box("Ivalid MID parameter: from = %d", from);
#endif
from = 0; from = 0;
} }
#endif
if (from > l) from = l; if (from > l) from = l;
if (count < 1) count = l-from; if (count < 1) count = l-from;
@ -274,7 +273,7 @@ const char* TString::mid(int from, int count) const
} }
// Certified 90% (uses mid) // Certified 100% (uses mid)
const char* TString::sub(int from, int to) const const char* TString::sub(int from, int to) const
{ {
const int count = to-from; const int count = to-from;
@ -346,7 +345,7 @@ TString& TString::trim()
return *this; return *this;
} }
// Certified 99% // Certified 100%
TString& TString::fill(char c, int n) TString& TString::fill(char c, int n)
{ {
if (n < 0) n = size(); else if (n < 0) n = size(); else
@ -356,7 +355,7 @@ TString& TString::fill(char c, int n)
return *this; return *this;
} }
// Certified 100%
TString& TString::right_just(int n, char c) TString& TString::right_just(int n, char c)
{ {
if (n < 0) n = size(); if (n < 0) n = size();
@ -368,6 +367,7 @@ TString& TString::right_just(int n, char c)
return *this; return *this;
} }
// Certified 100%
TString& TString::center_just(int n, char c) TString& TString::center_just(int n, char c)
{ {
if (n < 0) n = size(); if (n < 0) n = size();
@ -380,6 +380,7 @@ TString& TString::center_just(int n, char c)
return *this; return *this;
} }
// Certified 100%
TString& TString::left_just(int n, char c) TString& TString::left_just(int n, char c)
{ {
if (n < 0) n = size(); if (n < 0) n = size();
@ -418,7 +419,7 @@ TString& TString::format(const char* fmt, ...)
const int tot = vsprintf(__spark, fmt, pars); const int tot = vsprintf(__spark, fmt, pars);
va_end(pars); va_end(pars);
CHECK(tot >= 0 && tot < sizeof(__spark)-1, "Ue'! Quanto scrivi?"); CHECK(tot >= 0 && tot < spark.size(), "Ue'! Quanto scrivi?");
if (tot > size()) resize(tot, FALSE); if (tot > size()) resize(tot, FALSE);
strcpy(_str, __spark); strcpy(_str, __spark);
@ -489,7 +490,7 @@ word TString::hash() const
TFixed_string::TFixed_string(const char* str, int size) TFixed_string::TFixed_string(const char* str, int size)
: TString((char*)str, (size < 1) ? strlen(str) : size-1) : TString((char*)str, (size < 1) ? strlen(str) : size-1)
{ {
if (size > 0 && memchr(str, 0, size) == NULL) if (size > 0 && memchr(str, '\0', size) == NULL)
cut(0); cut(0);
} }
@ -503,8 +504,7 @@ TFixed_string::~TFixed_string()
void TFixed_string::resize(int size, bool) void TFixed_string::resize(int size, bool)
{ {
#ifdef DBG #ifdef DBG
fatal_box("Impossibile ridimensionare una stringa fissa da %d a %d", fatal_box("Impossibile ridimensionare una stringa fissa da %d a %d", _size, size);
_size, size);
#endif #endif
} }
@ -517,6 +517,20 @@ void TFixed_string::strncpy(const char* s, int n)
_str[i] = '\0'; _str[i] = '\0';
} }
// Certified 99%
// More efficient than TString::format, it does not use spark
TString& TFixed_string::format(const char* fmt, ...)
{
va_list pars;
va_start(pars, fmt);
const int tot = vsprintf(_str, fmt, pars);
va_end(pars);
CHECK(tot >= 0 && tot < size(), "Ue'! Quanto scrivi?");
return *this;
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Filename // Filename
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -625,7 +639,7 @@ TToken_string::TToken_string(const char* s, char separator)
// Certified 100% // Certified 100%
TToken_string::TToken_string(int n, char separator) TToken_string::TToken_string(int n, char separator)
: TString(n), _separator(separator), _last(-2) : TString(n), _separator(separator), _last(0)
{} {}
@ -662,8 +676,7 @@ const char* TToken_string::get()
{ {
const int k = find(_separator, start); const int k = find(_separator, start);
_last = (k >= 0) ? k+1 : -1; _last = (k >= 0) ? k+1 : -1;
if (k) return sub(start, k);
return sub(start, k);
} }
return ""; return "";
} }
@ -671,15 +684,13 @@ const char* TToken_string::get()
// Certified 50% // Certified 50%
const char* TToken_string::get(int n) const char* TToken_string::get(int n)
{ {
if (_last == -2) return NULL;
if (n < 0) if (n < 0)
{ {
if (n == -2) if (n == -2)
{ {
const char* sep = strrchr(_str, _separator); const char* sep = strrchr(_str, _separator);
_last = -1; _last = -1;
return sep ? sep+1 : NULL; return sep ? sep+1 : _str;
} }
else return get(); else return get();
} }
@ -732,7 +743,7 @@ int TToken_string::get_int(int n)
long TToken_string::get_long(int n) long TToken_string::get_long(int n)
{ {
const char* num = get(n); const char* num = get(n);
return num ? atol(num) : 0; return num ? atol(num) : 0L;
} }
@ -785,9 +796,13 @@ bool TToken_string::empty_items() const
// Certified 80% // Certified 80%
int TToken_string::items() const int TToken_string::items() const
{ {
if (_last == -2 || empty()) return 0; int t = 0;
int t = 1; if (not_empty())
for (const char* s = _str; *s; s++) if (*s == _separator) t++; {
t++;
for (const char* s = _str; *s; s++)
if (*s == _separator) t++;
}
return t; return t;
} }

View File

@ -92,7 +92,7 @@ public:
TString& left_just(int n = -1, char c = ' '); // Giustifica a sinistra TString& left_just(int n = -1, char c = ' '); // Giustifica a sinistra
TString& picture(const char* pic, const char* s); TString& picture(const char* pic, const char* s);
TString& format(const char* fmt, ...); virtual TString& format(const char* fmt, ...);
TString& cut(int n); // Inserisce un '\0' alla posizione n-esima. TString& cut(int n); // Inserisce un '\0' alla posizione n-esima.
@ -142,9 +142,10 @@ public:
TFixed_string(const char* str, int size = -1); TFixed_string(const char* str, int size = -1);
virtual ~TFixed_string(); virtual ~TFixed_string();
virtual TString& format(const char* fmt, ...);
const TString& operator =(const TString& s) { return set((const char*)s); } const TString& operator =(const TString& s) { return set((const char*)s); }
const TString& operator=(const char* s) { return set(s); } const TString& operator=(const char* s) { return set(s); }
void strncpy(const char* s, int n); void strncpy(const char* s, int n);
}; };

View File

@ -64,14 +64,15 @@ int TTable::last(word lockop)
int TTable::next(word lockop) int TTable::next(word lockop)
{ {
TRecfield codtab(curr(), "CODTAB"); TRecfield codtab(curr(), "CODTAB");
read(); const TRecnotype nrec = recno();
if (bad()) return status(); if (nrec != filehnd()->RecNo)
{
TRecnotype nrec = recno(); read();
if (bad()) return status();
}
TBaseisamfile::next(lockop); TBaseisamfile::next(lockop);
const char *c = (const char *) codtab; const char *c = (const char *) codtab;
@ -87,7 +88,6 @@ int TTable::next(word lockop)
int TTable::prev(word lockop) int TTable::prev(word lockop)
{ {
TRecfield codtab(curr(), "CODTAB"); TRecfield codtab(curr(), "CODTAB");

View File

@ -2,7 +2,7 @@
#define __TABUTIL_H #define __TABUTIL_H
#ifndef __ISAM_H #ifndef __ISAM_H
#include <isam.h> #include <isam.h>
#endif #endif
/* /*
@ -30,19 +30,19 @@ public:
int last(word lockop = _nolock); int last(word lockop = _nolock);
int next(word lockop = _nolock); int next(word lockop = _nolock);
int prev(word lockop = _nolock); int prev(word lockop = _nolock);
int reread(word lockop = _nolock, TDate& = botime); int reread(word lockop = _nolock, TDate& = (TDate&)botime);
int reread(TRectype& rec, word lockop = _nolock, TDate& = botime); int reread(TRectype& rec, word lockop = _nolock, TDate& = (TDate&)botime);
int skip(TRecnotype nrec, word lockop = _nolock); int skip(TRecnotype nrec, word lockop = _nolock);
int read(word op = _isequal, word lockop = _nolock, TDate& = botime); int read(word op = _isequal, word lockop = _nolock, TDate& = (TDate&)botime);
int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& = botime); int read(TRectype& rec, word op = _isequal, word lockop = _nolock, TDate& = (TDate&)botime);
int readat(TRecnotype nrec, word lockop = _nolock); int readat(TRecnotype nrec, word lockop = _nolock);
int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock); int readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock);
int write(TDate& = botime); int write(TDate& = (TDate&)botime);
int write(const TRectype& rec, TDate& = botime); int write(const TRectype& rec, TDate& = (TDate&)botime);
int rewrite(TDate& = botime); int rewrite(TDate& = (TDate&)botime);
int rewrite(const TRectype& rec, TDate& = botime); int rewrite(const TRectype& rec, TDate& = (TDate&)botime);
int remove(TDate& = botime); int remove(TDate& = (TDate&)botime);
int remove(const TRectype& rec, TDate& = botime); int remove(const TRectype& rec, TDate& = (TDate&)botime);
virtual const char* name() const { return (const char*) _tabname;} virtual const char* name() const { return (const char*) _tabname;}