Corrette la packfile() e la packindex() nel caso vengano chiamate dal

direttorio di una ditta per compattare un file residente nel direttorio
comune.
Modificati i costruttori di TRectype: tolto il controllo di '%' su
filename; analogamente per la getisfd().
Modificate la build() e la update() nel caso venga passato un tracciato
record vuoto.


git-svn-id: svn://10.65.10.50/trunk@1622 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
angelo 1995-07-20 09:10:38 +00:00
parent 4db02131c2
commit 252c1f05f3

View File

@ -139,7 +139,7 @@ HIDDEN void getisfd(isfdptr & isfd, int logicnum)
isfd->d = new FileDes ;
CGetFile(logicnum, isfd->d, _nolock, _nordir);
const TFixed_string name(isfd->d->SysName);
if (name.not_empty() && name[0] == '%')
if (name.not_empty() && name[0] != '$')
isfd->ft = _comdir;
else
isfd->ft = _nordir;
@ -1369,36 +1369,39 @@ int TSystemisamfile::build(TRecnotype eox)
d.get(num());
r.get(num());
CHECK(r.len() != 0, "Can't create a file with empty field info");
TFilename f(d.name());
f = f.path(); if (!is_not_slash(f.right(1)[0])) f.rtrim(1);
if (!fexist(f))
make_dir(f);
err=DB_build(d.name(),r.rec());
if (err == NOERR)
{
isfdptr i;
getisfd(i,num());
i->d->EOX = eox;
relisfd(i);
}
else
err = get_error(err);
setstatus(err);
clearfilehnd();
if (r.len() != 0)
{
err=DB_build(d.name(),r.rec());
if (err == NOERR)
{
isfdptr i;
getisfd(i,num());
i->d->EOX = eox;
relisfd(i);
}
else
err = get_error(err);
setstatus(err);
clearfilehnd();
#ifndef FOXPRO
if (err == NOERR && __autoload)
{
TFilename lf;
lf.format("%sstd/lf%04d.txt", __ptprf, num());
if (fexist(lf))
load(lf, '|', '\0', '\n', TRUE, TRUE);
}
if (err == NOERR && __autoload)
{
TFilename lf;
lf.format("%sstd/lf%04d.txt", __ptprf, num());
if (fexist(lf))
load(lf, '|', '\0', '\n', TRUE, TRUE);
}
#endif
}
return err;
}
@ -1520,7 +1523,8 @@ int TSystemisamfile::update(TTrec& newrec, bool vis)
{
CHECKS(filehnd() == NULL, "Can't update open file", (const char*)filename());
CHECK(newrec.len() != 0, "Can't update to file with empty field info");
TDir dir;
dir.get(num(), _unlock, _nordir, _sysdirop);
@ -1532,110 +1536,113 @@ int TSystemisamfile::update(TTrec& newrec, bool vis)
TTrec oldrec;
oldrec.get(num());
const long lev = prefix().filelevel();
const bool lcf = getlcf(lev);
exec_convapp(lev, TRUE);
if (!lcf && newrec == oldrec)
if (newrec.len() != 0)
{
exec_convapp(lev, FALSE);
return NOERR;
}
const TRecnotype nitems = dir.eod();
const unsigned int lenr = newrec.len();
if (!toconvert && dir.eox() > 0L)
{
dir.eod() = 0L;
dir.eox() = 0L;
}
if (toconvert && dir.eox() > 0L)
{
TRecnotype ni = 0L;
isfdptr i0;
TFilename tmpfname("tmpf");
const long lev = prefix().filelevel();
const bool lcf = getlcf(lev);
exec_convapp(lev, TRUE);
open(_excllock);
getisfd(i0, num());
err=DB_build((const char*) tmpfname, newrec.rec());
if (err != NOERR)
if (!lcf && newrec == oldrec)
{
err=get_error(err);
return (err);
exec_convapp(lev, FALSE);
return NOERR;
}
i0->fhnd=DB_open((const char*)tmpfname,0);
if (i0->fhnd < 0 ) err=get_error(i0->fhnd);
TFilename fname(filename());
TString s(80);
s.format("Aggiornamento archivio %s", (const char*) fname);
TProgind p(nitems ? nitems : 1, s, TRUE, TRUE, 70);
int nflds = curr().items();
TArray fld(nflds);
TExtrectype nrec(newrec);
TRecnotype i = 0;
for (int j = 0; j < nflds; j++)
fld.add(TString(curr().fieldname(j)), j);
for (first(); good(); next())
const TRecnotype nitems = dir.eod();
const unsigned int lenr = newrec.len();
if (!toconvert && dir.eox() > 0L)
{
if ((i++ % 50) == 0) p.setstatus(i + 1);
nrec.zero();
ni++;
for (j = 0; j < nflds; j++)
if (nrec.exist((const TString&) fld[j]))
nrec.put((const TString&) fld[j], get((const TString&) fld[j]));
if (lcf)
makelc((TRectype &)nrec);
memcpy(DB_getrecord(i0->fhnd),nrec.string(),DB_reclen(i0->fhnd));
err=DB_add(i0->fhnd);
if (err != NOERR) err=get_error(err);
setstatus(err);
dir.eod() = 0L;
dir.eox() = 0L;
}
err=DB_close(i0->fhnd);
close();
if (err!=NOERR) err=get_error(err);
relisfd(i0);
p.setstatus(nitems);
if (err == NOERR)
{
long c = DB_getconf();
fname.ext("dbf");
tmpfname.ext("dbf");
fcopy((const char*)tmpfname,(const char*)fname);
::remove((const char*)tmpfname);
if (c & 1) // FOXPRO format
tmpfname.ext("cdx");
if (c & 4) // DBIV format
tmpfname.ext("mdx");
if (c & 8 || c & 2)
{
tmpfname.ext("cgp");
char in[16];
FILE *fp=fopen((const char *) tmpfname,"r");
while (fgets(in,16,fp)!=NULL)
{
TFilename a(in);
a.rtrim(1); // Cut \n
if (c & 8) // DBIII format
a.ext("ndx");
else
a.ext("ntx"); // CLIPPER format
::remove((const char *)a);
}
fclose(fp);
if (toconvert && dir.eox() > 0L)
{
TRecnotype ni = 0L;
isfdptr i0;
TFilename tmpfname("tmpf");
open(_excllock);
getisfd(i0, num());
err=DB_build((const char*) tmpfname, newrec.rec());
if (err != NOERR)
{
err=get_error(err);
return (err);
}
i0->fhnd=DB_open((const char*)tmpfname,0);
if (i0->fhnd < 0 ) err=get_error(i0->fhnd);
TFilename fname(filename());
TString s(80);
s.format("Aggiornamento archivio %s", (const char*) fname);
TProgind p(nitems ? nitems : 1, s, TRUE, TRUE, 70);
int nflds = curr().items();
TArray fld(nflds);
TExtrectype nrec(newrec);
TRecnotype i = 0;
for (int j = 0; j < nflds; j++)
fld.add(TString(curr().fieldname(j)), j);
for (first(); good(); next())
{
if ((i++ % 50) == 0) p.setstatus(i + 1);
nrec.zero();
ni++;
for (j = 0; j < nflds; j++)
if (nrec.exist((const TString&) fld[j]))
nrec.put((const TString&) fld[j], get((const TString&) fld[j]));
if (lcf)
makelc((TRectype &)nrec);
memcpy(DB_getrecord(i0->fhnd),nrec.string(),DB_reclen(i0->fhnd));
err=DB_add(i0->fhnd);
if (err != NOERR) err=get_error(err);
setstatus(err);
}
err=DB_close(i0->fhnd);
close();
if (err!=NOERR) err=get_error(err);
relisfd(i0);
p.setstatus(nitems);
if (err == NOERR)
{
long c = DB_getconf();
fname.ext("dbf");
tmpfname.ext("dbf");
fcopy((const char*)tmpfname,(const char*)fname);
::remove((const char*)tmpfname);
if (c & 1) // FOXPRO format
tmpfname.ext("cdx");
if (c & 4) // DBIV format
tmpfname.ext("mdx");
if (c & 8 || c & 2)
{
tmpfname.ext("cgp");
char in[16];
FILE *fp=fopen((const char *) tmpfname,"r");
while (fgets(in,16,fp)!=NULL)
{
TFilename a(in);
a.rtrim(1); // Cut \n
if (c & 8) // DBIII format
a.ext("ndx");
else
a.ext("ntx"); // CLIPPER format
::remove((const char *)a);
}
fclose(fp);
}
::remove((const char*)tmpfname);
dir.eod() = ni;
}
::remove((const char*)tmpfname);
dir.eod() = ni;
}
dir.set_len(lenr);
dir.put(num(), _nordir, _sysdirop);
newrec.put(num());
if (toconvert && dir.eox() > 0L) packindex();
exec_convapp(lev, FALSE);
}
dir.set_len(lenr);
dir.put(num(), _nordir, _sysdirop);
newrec.put(num());
if (toconvert && dir.eox() > 0L) packindex();
exec_convapp(lev, FALSE);
setstatus(err);
return err;
}
@ -1647,7 +1654,8 @@ int TSystemisamfile::packfile(bool vis)
int err=NOERR;
TDir d;
d.get(num());
d.get(num(),_nolock, _nordir,_sysdirop);
d.get(num(),_nolock, (d.is_com()) ? _comdir : _nordir);
CHECKS(filehnd() == NULL, "Can't pack open file", (const char*)filename());
err=DB_packfile(vis,d.name(),d.eod());
if (err != NOERR) err = get_error(err);
@ -1668,7 +1676,8 @@ int TSystemisamfile::packindex(bool vis)
CHECKS(filehnd() == NULL, "Can't pack index of open file", (const char*)filename());
r.get(num());
d.get(num());
d.get(num(),_nolock, _nordir,_sysdirop);
d.get(num(),_nolock, (d.is_com()) ? _comdir : _nordir);
err=DB_packindex(vis,d.name(),r.rec(),&peod);
if (err != NOERR) err = get_error(err);
if (err != NOERR) error_box("Errore in compattamento indici.\nFile %d : %d", num(),err);
@ -1676,7 +1685,7 @@ int TSystemisamfile::packindex(bool vis)
if (peod >= 0 && peod != d.eod())
{
d.eod() = peod;
d.put(num());
d.put(num(),(d.is_com() ? _comdir : _nordir));
}
setstatus(err);
return err;
@ -1998,7 +2007,7 @@ TRectype::TRectype(int logicnum) : _cod(NULL)
{
TDir wdir;
wdir.get(_logicnum, _nolock, _nordir, _sysdirop);
if (wdir.name()[0] == '%')
if (wdir.is_com())
wdir.get(_logicnum, _nolock, _comdir, _sysdirop);
_length = wdir.len();
}
@ -2017,7 +2026,7 @@ TRectype::TRectype(const TBaseisamfile* i): _cod(NULL)
TDir wdir;
wdir.get(_logicnum, _nolock, _nordir, _sysdirop);
if (wdir.name()[0] == '%')
if (wdir.is_com())
wdir.get(_logicnum, _nolock, _comdir, _sysdirop);
_length = wdir.len();
}