1994-08-12 10:52:49 +00:00
# include <stdio.h>
# include <stdlib.h>
# define __ISAM_CPP
1994-09-27 10:19:36 +00:00
# ifndef FOXPRO
1994-11-24 14:01:20 +00:00
# include <applicat.h>
1994-10-04 15:38:57 +00:00
# include <expr.h>
1994-11-24 14:01:20 +00:00
# include <execp.h>
1994-09-27 10:19:36 +00:00
# include <progind.h>
# endif
1994-11-24 14:01:20 +00:00
1994-09-27 10:19:36 +00:00
# include <config.h>
1994-08-12 10:52:49 +00:00
# include <extcdecl.h>
1994-11-24 14:01:20 +00:00
# include <mailbox.h>
# include <prefix.h>
# include <relation.h>
1994-09-27 10:19:36 +00:00
# include <scanner.h>
1994-08-12 10:52:49 +00:00
# include <utility.h>
1994-10-14 17:51:32 +00:00
# if XVT_OS==XVT_OS_SCOUNIX
# include <sys/types.h>
# include <sys/stat.h>
# include <unistd.h>
# else
# include <direct.h>
# include <process.h>
# endif
1994-08-12 10:52:49 +00:00
# define NOT_LINKED(i,f) CHECKS(i != NULL, "Record senza tracciato: impossibile eseguire ", f)
1994-12-27 14:59:25 +00:00
# define NOT_OPEN(f) CHECKS(_isamfile != NULL, "File chiuso: ", f)
1994-09-12 09:34:05 +00:00
HIDDEN void UNKNOWN_FIELD ( int num , const char * name )
{ yesnofatal_box ( " Il campo '%s' non appartiene al file %d " , name , num ) ; }
1994-08-12 10:52:49 +00:00
# define NOALLOC (char **) -1
1994-10-31 16:24:26 +00:00
HIDDEN bool __autoload = TRUE ;
void set_autoload_new_files ( bool on )
{
__autoload = on ;
}
1994-08-12 10:52:49 +00:00
class TExtrectype : public TRectype
{
1994-08-22 11:10:49 +00:00
public :
// FPUB
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
TExtrectype ( const TTrec & r ) ; // Costruisce il record a partire da r
virtual ~ TExtrectype ( ) ;
1994-08-12 10:52:49 +00:00
} ;
1994-09-12 09:34:05 +00:00
TExtrectype : : TExtrectype ( const TTrec & r ) : TRectype ( 6 )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
delete _rec ;
_length = r . len ( ) ;
_rec = new char [ _length ] ;
_i = new isdef ;
_i - > r = r . rec ( ) ;
zero ( ) ;
1994-08-12 10:52:49 +00:00
}
TExtrectype : : ~ TExtrectype ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
delete _rec ;
delete _i ;
1994-08-12 10:52:49 +00:00
}
TBaseisamfile : : TBaseisamfile ( int logicnum , bool linkrecinst )
{
1994-08-22 11:10:49 +00:00
TTrec r ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
_isamfile = NULL ;
_logicnum = logicnum ;
_lasterr = NOERR ;
_delopenrec = FALSE ;
if ( ( openrec [ _logicnum - 1 ] = = NULL ) | | ( ! linkrecinst ) )
{
_current = new TRectype ( this ) ;
1994-08-12 10:52:49 +00:00
if ( openrec [ _logicnum - 1 ] = = NULL )
1994-08-22 11:10:49 +00:00
{
openrec [ _logicnum - 1 ] = _current ;
_delopenrec = TRUE ;
}
1994-08-12 10:52:49 +00:00
_delrec = TRUE ;
}
1994-08-22 11:10:49 +00:00
else
{
1994-08-12 10:52:49 +00:00
_current = openrec [ _logicnum - 1 ] ;
_delrec = FALSE ;
}
1994-08-22 11:10:49 +00:00
r . get ( logicnum ) ;
_historicfile = ( ( r . field ( RFLD_SYS_DATE ) ! = FIELDERR ) & &
( r . field ( RFLD_SYS_FIRST ) ! = FIELDERR ) & &
( r . field ( RFLD_SYS_LAST ) ! = FIELDERR ) ) ;
1994-08-12 10:52:49 +00:00
}
TBaseisamfile : : ~ TBaseisamfile ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
if ( _delrec )
{
if ( _delopenrec )
1994-08-12 10:52:49 +00:00
openrec [ _logicnum - 1 ] = NULL ;
delete _current ;
}
1994-08-22 11:10:49 +00:00
if ( _isamfile ! = NULL )
delete _isamfile ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : gethr ( TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
TRecfield fd0 ( rec , RFLD_SYS_DATE ) ;
TDate d0 ( ( const TDate & ) fd0 ) ;
if ( d0 < atdate )
{
1994-08-12 10:52:49 +00:00
atdate = eotime ;
return NOERR ;
}
1994-08-22 11:10:49 +00:00
TRectype wr ( rec ) ;
TRecfield flf ( wr , RFLD_SYS_FIRST ) ,
fll ( wr , RFLD_SYS_LAST ) ,
fd1 ( wr , RFLD_SYS_DATE ) ;
TDate d1 ;
TRecnotype wr0 = - 1L , wr1 = - 1L ;
if ( ( wr0 = = flf . ptr ( ) ) = = - 1L ) return _iskeynotfound ;
_hf . read ( wr . string ( ) , wr0 ) ;
if ( ( d1 = ( const TDate & ) fd1 ) > atdate )
{
1994-08-12 10:52:49 +00:00
rec = wr ;
1994-08-22 11:10:49 +00:00
atdate = d0 - 1L ;
1994-08-12 10:52:49 +00:00
return _iskeynotfound ;
}
1994-08-22 11:10:49 +00:00
while ( ( d1 < atdate ) & & ( wr0 > 0 ) )
{
1994-08-12 10:52:49 +00:00
rec = wr ;
1994-08-22 11:10:49 +00:00
wr1 = wr0 ;
1994-08-12 10:52:49 +00:00
if ( ( wr0 = fll . ptr ( ) ) > 0 )
1994-08-22 11:10:49 +00:00
{
_hf . read ( wr . string ( ) , wr0 ) ;
d1 = ( const TDate & ) fd1 ;
}
1994-08-12 10:52:49 +00:00
}
1994-08-22 11:10:49 +00:00
if ( wr0 < = 0 )
atdate = d0 - 1L ;
else
atdate = d1 - 1L ;
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : addhr ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : rewhr ( const TRectype & rec , TDate & atdate )
{
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : delhr ( const TRectype & rec , TDate & atdate )
{
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
long TBaseisamfile : : items ( ) const
{
1994-08-22 11:10:49 +00:00
return filehnd ( ) - > i . Base [ filehnd ( ) - > i . PN ] . PEOD ;
1994-08-12 10:52:49 +00:00
}
const char * TBaseisamfile : : name ( ) const
{
1994-08-22 11:10:49 +00:00
sprintf ( __tmp_string , " %d " , num ( ) ) ;
return __tmp_string ;
1994-08-12 10:52:49 +00:00
}
const char * TBaseisamfile : : filename ( ) const
{
1994-12-27 14:59:25 +00:00
if ( _isamfile = = NULL )
{
TDir d ;
d . get ( num ( ) ) ;
return strcpy ( __tmp_string , d . name ( ) ) ;
}
1994-08-22 11:10:49 +00:00
return _isamfile - > d - > SysName ;
1994-08-12 10:52:49 +00:00
}
1994-10-03 08:47:32 +00:00
const char * TBaseisamfile : : description ( ) const
{
1994-12-27 14:59:25 +00:00
if ( _isamfile = = NULL )
{
TDir d ;
d . get ( num ( ) ) ;
return strcpy ( __tmp_string , d . des ( ) ) ;
}
1994-10-03 08:47:32 +00:00
return _isamfile - > d - > Des ;
}
1994-08-12 10:52:49 +00:00
void TBaseisamfile : : setkey ( int nkey )
{
1994-08-22 11:10:49 +00:00
CHECKD ( nkey > 0 & & nkey - 1 < = _isamfile - > r - > NKeys , " Chiave non valida n.ro " , nkey ) ;
NOT_OPEN ( name ( ) ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
_isamfile - > i . PN = nkey - 1 ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : getkey ( ) const
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
return _isamfile - > i . PN + 1 ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : first ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
curr ( ) . setdirty ( ) ;
cisread ( _isamfile , curr ( ) . string ( ) , _isfirst + lockop , & _lasterr ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : last ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
curr ( ) . setdirty ( ) ;
cisread ( _isamfile , curr ( ) . string ( ) , _islast + lockop , & _lasterr ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : next ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
curr ( ) . setdirty ( ) ;
cisread ( _isamfile , curr ( ) . string ( ) , _isnext + lockop , & _lasterr ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : next ( TDate & atdate )
1994-08-22 11:10:49 +00:00
{
TRectype wr ( curr ( ) ) ;
TRecfield fll ( curr ( ) , RFLD_SYS_LAST ) ,
fd ( wr , RFLD_SYS_DATE ) ;
TRecnotype wrn ;
NOT_OPEN ( name ( ) ) ;
if ( ! _historicfile )
error_box ( " %s not historic file " , filename ( ) ) ;
if ( _lasthf = = - 1L ) return _iseof ;
curr ( ) . setdirty ( ) ;
_hf . read ( curr ( ) . string ( ) , _lasthf ) ;
wrn = fll . ptr ( ) ;
if ( wrn < 0L )
{
1994-08-12 10:52:49 +00:00
readat ( - wrn ) ;
atdate = eotime ;
_lasthf = - 1L ;
}
1994-08-22 11:10:49 +00:00
else
{
1994-08-12 10:52:49 +00:00
_hf . read ( curr ( ) . string ( ) , wrn ) ;
_lasthf = wrn ;
wrn = fll . ptr ( ) ;
1994-08-22 11:10:49 +00:00
if ( wrn < 0 ) readat ( wr , - wrn ) ;
1994-08-12 10:52:49 +00:00
else _hf . read ( wr . string ( ) , wrn ) ;
atdate = ( const TDate & ) fd - 1L ;
}
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : prev ( word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
curr ( ) . setdirty ( ) ;
cisread ( _isamfile , curr ( ) . string ( ) , _isprev + lockop , & _lasterr ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : prev ( TDate & atdate )
1994-08-22 11:10:49 +00:00
{
TRecfield flf ( curr ( ) , RFLD_SYS_LAST ) ,
fd ( curr ( ) , RFLD_SYS_DATE ) ;
TRecnotype wrn ;
NOT_OPEN ( name ( ) ) ;
if ( ! _historicfile )
error_box ( " %s not historic file " , filename ( ) ) ;
if ( _lasthf = = - 1L ) return _isbof ;
curr ( ) . setdirty ( ) ;
_hf . read ( curr ( ) . string ( ) , _lasthf ) ;
wrn = flf . ptr ( ) ;
atdate = ( const TDate & ) fd - 1L ;
if ( wrn < 0L ) _lasthf = - 1L ;
else
{
1994-08-12 10:52:49 +00:00
_hf . read ( curr ( ) . string ( ) , wrn ) ;
_lasthf = wrn ;
}
1994-08-22 11:10:49 +00:00
return NOERR ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : reread ( word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
{
NOT_OPEN ( name ( ) ) ;
curr ( ) . setdirty ( ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
return cisread ( _isamfile , curr ( ) . string ( ) , _iscurr + lockop , & _lasterr ) ;
else
{
1994-08-12 10:52:49 +00:00
if ( cisread ( _isamfile , curr ( ) . string ( ) , _iscurr + lockop , & _lasterr ) = = NOERR )
_lasterr = gethr ( curr ( ) , atdate ) ;
}
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : reread ( TRectype & rec , word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
{
NOT_OPEN ( name ( ) ) ;
rec . setdirty ( ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
cisread ( _isamfile , rec . string ( ) , _iscurr + lockop , & _lasterr ) ;
else
{
1994-08-12 10:52:49 +00:00
if ( cisread ( _isamfile , rec . string ( ) , _iscurr + lockop , & _lasterr ) = = NOERR )
_lasterr = gethr ( rec , atdate ) ;
}
1994-08-22 11:10:49 +00:00
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : skip ( TRecnotype nrec , word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
if ( ! nrec ) return NOERR ;
curr ( ) . setdirty ( ) ;
if ( nrec > 0 )
cisread ( _isamfile , curr ( ) . string ( ) , _isnextn + lockop + ( UINT16 ) nrec , & _lasterr ) ;
else
cisread ( _isamfile , curr ( ) . string ( ) , _isprevn + lockop - ( UINT16 ) nrec , & _lasterr ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : read ( word op , word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
CHECKD ( op > = _iscurr & & op < = _isgteq , " Invalid read operation : " , op ) ;
NOT_OPEN ( name ( ) ) ;
curr ( ) . setdirty ( ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
cisread ( _isamfile , curr ( ) . string ( ) , op + lockop , & _lasterr ) ;
else
{
if ( cisread ( _isamfile , curr ( ) . string ( ) , op + lockop , & _lasterr ) = = NOERR )
_lasterr = gethr ( curr ( ) , atdate ) ;
}
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : read ( TRectype & rec , word op , word lockop , TDate & atdate )
1994-08-22 11:10:49 +00:00
{
CHECKD ( op > = _iscurr & & op < = _isgteq , " Invalid read operation : " , op ) ;
NOT_OPEN ( name ( ) ) ;
rec . setdirty ( ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
cisread ( _isamfile , rec . string ( ) , op + lockop , & _lasterr ) ;
else
{
1994-08-12 10:52:49 +00:00
if ( cisread ( _isamfile , rec . string ( ) , op + lockop , & _lasterr ) = = NOERR )
_lasterr = gethr ( rec , atdate ) ;
1994-08-22 11:10:49 +00:00
}
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : readat ( TRecnotype nrec , word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
curr ( ) . setdirty ( ) ;
cisreadrec ( _isamfile , nrec , curr ( ) . string ( ) , lockop , & _lasterr ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : readat ( TRectype & rec , TRecnotype nrec , word lockop )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
rec . setdirty ( ) ;
cisreadrec ( _isamfile , nrec , rec . string ( ) , lockop , & _lasterr ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : write ( TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
ciswrite ( _isamfile , curr ( ) . string ( ) , & _lasterr ) ;
else
_lasterr = addhr ( curr ( ) , atdate ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : write ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( _isamfile - > d - > SysName ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
ciswrite ( _isamfile , rec . string ( ) , & _lasterr ) ;
else
_lasterr = addhr ( rec , atdate ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : rewrite ( TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
cisrewrite ( _isamfile , curr ( ) . string ( ) , & _lasterr ) ;
else
_lasterr = rewhr ( curr ( ) , atdate ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : rewrite ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
cisrewrite ( _isamfile , rec . string ( ) , & _lasterr ) ;
else
_lasterr = rewhr ( rec , atdate ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
}
int TBaseisamfile : : rewriteat ( TRecnotype nrec )
{
NOT_OPEN ( name ( ) ) ;
return cisrewrec ( _isamfile , nrec , curr ( ) . string ( ) , & _lasterr ) ;
}
int TBaseisamfile : : rewriteat ( const TRectype & rec , TRecnotype nrec )
{
NOT_OPEN ( name ( ) ) ;
return cisrewrec ( _isamfile , nrec , curr ( ) . string ( ) , & _lasterr ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : remove ( TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
cisdelete ( _isamfile , curr ( ) . string ( ) , & _lasterr ) ;
else
_lasterr = delhr ( curr ( ) , atdate ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : remove ( const TRectype & rec , TDate & atdate )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
if ( ( ! _historicfile ) | | ( atdate = = botime ) )
cisdelete ( _isamfile , rec . string ( ) , & _lasterr ) ;
else
_lasterr = delhr ( rec , atdate ) ;
_recno = _isamfile - > RecNo ;
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : lock ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
return cislock ( _isamfile , & _lasterr ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : unlock ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_OPEN ( name ( ) ) ;
return cisunlock ( _isamfile , & _lasterr ) ;
1994-08-12 10:52:49 +00:00
}
void TBaseisamfile : : indexon ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
IndexOn ( ) ;
1994-08-12 10:52:49 +00:00
}
bool TBaseisamfile : : empty ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
return _isamfile - > i . Base [ _isamfile - > i . PN ] . PEOD = = 0 ;
}
void TBaseisamfile : : indexoff ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
IndexOff ( ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : _open ( unsigned int mode )
1994-08-22 11:10:49 +00:00
{
int err ;
if ( filehnd ( ) ! = NULL )
fatal_box ( " Il file %d e' gia' aperto " , _logicnum ) ;
if ( ( cisopen ( & _isamfile , _logicnum , NOALLOC , mode , & err ) = = NOERR ) & &
( _historicfile ) )
{
1994-08-12 10:52:49 +00:00
TFilename s ( filename ( ) ) ;
s . ext ( " hst " ) ;
_hf . len ( ) = filehnd ( ) - > d - > LenR ;
_hf . base ( ) = 1 ;
_hf . open ( s ) ;
if ( _hf . status ( ) = = 2 )
1994-08-22 11:10:49 +00:00
{
_hf . create ( s ) ;
_hf . open ( s ) ;
}
1994-08-12 10:52:49 +00:00
if ( _hf . error ( ) ) return err = _hf . status ( ) ;
_lasthf = - 1L ;
_hfhd = _hf ;
_hfhd . len ( ) = sizeof ( TRecnotype ) ;
_hfhd . base ( ) = 0 ;
}
1994-11-10 14:15:41 +00:00
if ( err = = NOERR )
{
isdef * fh = filehnd ( ) ;
const TRecnotype nitems = fh - > i . Base [ 0 ] . PEOX ;
if ( fh - > d - > EOX ! = nitems )
1994-11-24 14:01:20 +00:00
recover ( ) ;
1994-11-10 14:15:41 +00:00
}
1994-08-22 11:10:49 +00:00
_recno = - 1L ;
_current - > _i = filehnd ( ) ;
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : _close ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err = NOERR ;
if ( filehnd ( ) ! = NULL )
{
1994-08-12 10:52:49 +00:00
cisclose ( ptrfilehnd ( ) , NULL , & err ) ;
clearfilehnd ( ) ;
}
1994-08-22 11:10:49 +00:00
_current - > _i = NULL ;
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
TLocalisamfile : : TLocalisamfile ( int logicnum , bool linkrecinst )
: TBaseisamfile ( logicnum , linkrecinst )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
open ( ) ;
1994-12-07 11:10:57 +00:00
if ( ! linkrecinst ) setkey ( 1 ) ; // Dangerous change by Guy
1994-08-12 10:52:49 +00:00
}
TLocalisamfile : : ~ TLocalisamfile ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
close ( ) ;
}
int TLocalisamfile : : close ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
int err = NOERR ;
if ( ! _was_open )
{
clearfilehnd ( ) ;
}
else
{
if ( _isamfile )
{
cisclose ( & _isamfile , NULL , & err ) ;
_isamfile = NULL ;
}
}
setstatus ( err ) ;
return err ;
}
int TLocalisamfile : : open ( unsigned int mode )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
int err = NOERR ;
const int logicnum = num ( ) ;
if ( openf [ logicnum - 1 ] ! = NULL )
{
_was_open = FALSE ;
_isamfile = openf [ logicnum - 1 ] ;
1994-08-22 11:10:49 +00:00
_current - > _i = filehnd ( ) ;
}
else
{
err = _open ( ) ;
_was_open = TRUE ;
}
_isatab = FALSE ;
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator + = ( const TRecnotype npos )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
skip ( npos ) ;
return status ( ) ;
}
int TLocalisamfile : : operator - = ( const TRecnotype npos )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
skip ( - npos ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator + + ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
next ( ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator - - ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
prev ( ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
TIsamfile : : TIsamfile ( int logicnum , bool linkrecinst ) : TBaseisamfile ( logicnum , linkrecinst ) { }
TIsamfile : : ~ TIsamfile ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
close ( ) ;
1994-08-12 10:52:49 +00:00
}
int TIsamfile : : flags ( bool updateeod )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err ;
NOT_OPEN ( name ( ) ) ;
setstatus ( err ) ;
return cisupdflags ( filehnd ( ) , & err , updateeod ) ;
1994-08-12 10:52:49 +00:00
}
TIsamtempfile : : TIsamtempfile ( int logicnum , bool linkrecinst ) : TBaseisamfile ( logicnum , linkrecinst ) { }
TIsamtempfile : : ~ TIsamtempfile ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
close ( ) ;
1994-08-12 10:52:49 +00:00
}
int TIsamtempfile : : open ( char * radix , bool create , TRecnotype eod , TRecnotype eox )
1994-08-22 11:10:49 +00:00
{
int err ;
if ( filehnd ( ) ! = NULL )
fatal_box ( " File %s already open " , filename ( ) ) ;
if ( ( cisopentemp ( ptrfilehnd ( ) , _logicnum , radix , NOALLOC , create , eod , eox , & err ) = = NOERR ) & &
( _historicfile ) )
{
1994-08-12 10:52:49 +00:00
TFilename s ( filename ( ) ) ;
s . ext ( " hst " ) ;
_hf . len ( ) = filehnd ( ) - > d - > LenR ;
_hf . base ( ) = 1 ;
_hf . open ( s ) ;
if ( _hf . status ( ) = = 2 )
1994-08-22 11:10:49 +00:00
{
_hf . create ( s ) ;
_hf . open ( s ) ;
}
1994-08-12 10:52:49 +00:00
if ( _hf . error ( ) ) return err = _hf . status ( ) ;
_lasthf = - 1L ;
_hfhd = _hf ;
_hfhd . len ( ) = sizeof ( TRecnotype ) ;
_hfhd . base ( ) = 0 ;
}
1994-08-22 11:10:49 +00:00
_current - > _i = filehnd ( ) ;
_recno = - 1L ;
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
int TIsamtempfile : : close ( bool flagdel )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err ;
if ( filehnd ( ) ! = NULL )
{
1994-08-12 10:52:49 +00:00
cisclosetemp ( ptrfilehnd ( ) , NULL , flagdel , & err ) ;
clearfilehnd ( ) ;
}
1994-08-22 11:10:49 +00:00
_current - > _i = NULL ;
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : build ( TRecnotype eox )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err ;
if ( filehnd ( ) ! = NULL )
fatal_box ( " Can't recreate open file %s " , filename ( ) ) ;
1994-10-14 17:51:32 +00:00
TDir d ;
d . get ( num ( ) ) ;
TFilename f ( d . name ( ) ) ;
f = f . path ( ) ;
if ( ! fexist ( f ) )
# if XVT_OS==XVT_OS_SCOUNIX
mkdir ( f , 0777 ) ;
# else
mkdir ( f ) ;
# endif
1994-08-22 11:10:49 +00:00
cisbuild ( filehnd ( ) , num ( ) , eox , & err ) ;
setstatus ( err ) ;
clearfilehnd ( ) ;
1994-11-24 14:01:20 +00:00
# ifndef FOXPRO
1994-10-31 16:24:26 +00:00
if ( err = = NOERR & & __autoload )
{
TFilename lf ;
1994-11-22 15:03:51 +00:00
lf . format ( " %sstd/lf%04d.txt " , __ptprf , num ( ) ) ;
1994-10-31 16:24:26 +00:00
if ( fexist ( lf ) )
1994-12-02 13:06:39 +00:00
load ( lf , ' | ' , ' \0 ' , ' \n ' , TRUE , TRUE ) ;
1994-10-31 16:24:26 +00:00
}
1994-11-24 14:01:20 +00:00
# endif
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : extend ( TRecnotype eox )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err ;
if ( filehnd ( ) ! = NULL )
fatal_box ( " Can't extend open file %s " , filename ( ) ) ;
cisextend ( filehnd ( ) , num ( ) , eox , & err ) ;
setstatus ( err ) ;
clearfilehnd ( ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
long TSystemisamfile : : size ( TRecnotype eox )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err ;
const long size = cisextension ( num ( ) , eox , & err ) ;
if ( err ! = NOERR ) setstatus ( err ) ;
return size ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
1994-11-18 17:39:45 +00:00
bool TSystemisamfile : : exec_convapp ( long flev , const bool before )
{
const char * const v = before ? " BCNV " : " ACNV " ;
if ( flev = = 0 ) flev = 199401 ;
else flev + + ;
for ( long l = flev ; l < = stdlevel ; l + + )
{
TString16 paragraph ( format ( " %06ld " , l ) ) ;
TConfig conv ( CONFIG_FCONV , paragraph ) ;
if ( ! conv . new_paragraph ( ) & & conv . exist ( v , num ( ) ) )
{
int err = 0 ;
TString80 s ( conv . get ( v , NULL , num ( ) ) ) ; s < < " " < < main_app ( ) . get_firm ( ) ;
1994-11-24 14:01:20 +00:00
TExternal_app app ( s ) ;
1994-11-18 17:39:45 +00:00
if ( app . can_run ( ) )
{
app . run ( ) ;
err = app . error ( ) ;
TMailbox mail ;
TMessage * msg = mail . next ( TRUE ) ;
if ( err = = 0 & & msg ! = NULL )
err = atoi ( msg - > body ( ) ) ;
}
else err = 16 ;
if ( err )
return error_box ( " Non posso eseguire il programma di %sconversione \n del livello %ld/%ld \n Errore n.ro %d " , before ? " pre " : " post " , l / 100 , l % 100 , err ) ;
}
}
return TRUE ;
}
1994-08-12 10:52:49 +00:00
1994-09-28 10:36:08 +00:00
bool TSystemisamfile : : getlcf ( long flev )
1994-09-27 10:19:36 +00:00
{
_flds . destroy ( ) ;
_exps . destroy ( ) ;
if ( flev = = 0 ) flev = 199401 ;
else flev + + ;
for ( long l = flev ; l < = stdlevel ; l + + )
{
TString16 paragraph ( format ( " %06ld " , l ) ) ;
TConfig conv ( CONFIG_FCONV , paragraph ) ;
1994-11-18 17:39:45 +00:00
if ( ! conv . new_paragraph ( ) & & conv . exist ( " F " , num ( ) ) )
1994-09-27 10:19:36 +00:00
{
TToken_string exprline ( conv . get ( " F " , NULL , num ( ) ) ) ;
if ( exprline . empty ( ) ) return FALSE ;
TToken_string w ( " " , ' = ' ) ;
const char * wexprs = exprline . get ( ) ;
while ( wexprs ! = NULL )
{
w = wexprs ;
TFixed_string fld ( w . get ( ) ) ;
_flds . add ( new TFieldref ( fld , 0 ) ) ;
_exps . add ( new TExpression ( w . get ( ) , _strexpr ) ) ;
wexprs = exprline . get ( ) ;
}
}
}
return _flds . items ( ) > 0 ;
}
void TSystemisamfile : : makelc ( TRectype & rec )
{
for ( int i = 0 ; i < _flds . items ( ) ; i + + )
{
TFieldref & f = ( TFieldref & ) _flds [ i ] ;
TExpression & e = ( TExpression & ) _exps [ i ] ;
for ( int k = 0 ; k < e . numvar ( ) ; k + + )
e . setvar ( k , get ( e . varname ( k ) ) ) ;
f . write ( e , rec ) ;
}
}
1994-08-12 10:52:49 +00:00
int TSystemisamfile : : update ( TTrec & newrec , bool vis )
1994-08-22 11:10:49 +00:00
{
if ( filehnd ( ) ! = NULL )
fatal_box ( " Can't update description for open file %s " , filename ( ) ) ;
1994-11-10 14:15:41 +00:00
1994-08-22 11:10:49 +00:00
TDir dir ;
1994-10-31 16:24:26 +00:00
dir . get ( num ( ) , _lock , _nordir , _sysdirop ) ;
const char p = * dir . name ( ) ;
1994-11-10 14:15:41 +00:00
const bool incom = strcmp ( prefhndl - > name ( ) , " com " ) = = 0 ;
const bool toconvert = ( incom ? p = = ' % ' : p ! = ' % ' ) ;
1994-10-31 16:24:26 +00:00
int err = NOERR ;
1994-08-22 11:10:49 +00:00
TTrec oldrec ;
oldrec . get ( num ( ) ) ;
1994-11-18 17:39:45 +00:00
const long lev = prefhndl - > filelevel ( ) ;
const bool lcf = getlcf ( lev ) ;
exec_convapp ( lev , TRUE ) ;
1994-09-27 10:19:36 +00:00
1994-11-18 17:39:45 +00:00
if ( ! lcf & & newrec = = oldrec )
{
exec_convapp ( lev , FALSE ) ;
return NOERR ;
}
1994-11-10 14:15:41 +00:00
1994-08-22 11:10:49 +00:00
const TRecnotype nitems = dir . eod ( ) ;
const unsigned int lenr = newrec . len ( ) ;
1994-11-10 14:15:41 +00:00
if ( ! toconvert & & dir . eox ( ) > 0L )
{
dir . eod ( ) = 0L ;
dir . eox ( ) = 0L ;
}
1994-10-31 16:24:26 +00:00
if ( toconvert & & dir . eox ( ) > 0L )
1994-08-22 11:10:49 +00:00
{
TRecnotype ni = 0L ;
TFilename tmpfname ;
tmpfname . temp ( NULL ) ;
FILE * f = fopen ( tmpfname , " w " ) ;
err = ferror ( f ) ;
if ( f = = NULL )
{
clearerr ( f ) ;
setstatus ( err ) ;
return err ;
}
open ( _excllock ) ;
TFilename fname ( filename ( ) ) ;
TString s ( 80 ) ;
s . format ( " Aggiornamento archivio %s " , ( const char * ) fname ) ;
1994-10-31 16:24:26 +00:00
TProgind p ( nitems ? nitems : 1 , s , TRUE , TRUE , 70 ) ;
1994-08-22 11:10:49 +00:00
int nflds = curr ( ) . items ( ) ;
TArray fld ( nflds ) ;
TExtrectype nrec ( newrec ) ;
TRecnotype i ;
1994-09-27 10:19:36 +00:00
1994-08-22 11:10:49 +00:00
for ( int j = 0 ; j < nflds ; j + + )
fld . add ( TString ( curr ( ) . fieldname ( j ) ) , j ) ;
for ( i = 1 ; i < = nitems & & ! p . iscancelled ( ) ; i + + )
{
if ( ( i % 50 ) = = 0 ) p . setstatus ( i + 1 ) ;
readat ( i ) ;
if ( curr ( ) . valid ( ) )
{
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 ] ) ) ;
1994-09-27 10:19:36 +00:00
if ( lcf )
makelc ( ( TRectype & ) nrec ) ;
1994-08-22 11:10:49 +00:00
fwrite ( nrec . string ( ) , lenr , 1 , f ) ;
}
}
1994-09-27 10:19:36 +00:00
p . setstatus ( nitems ) ;
1994-08-22 11:10:49 +00:00
close ( ) ;
fclose ( f ) ;
fcopy ( tmpfname , fname ) ;
: : remove ( tmpfname ) ;
dir . eod ( ) = ni ;
}
// aggiornare il log file
dir . set_len ( lenr ) ;
dir . put ( num ( ) , _nordir , _sysdirop ) ;
newrec . put ( num ( ) ) ;
1994-10-31 16:24:26 +00:00
if ( toconvert & & dir . eox ( ) > 0L ) packindex ( ) ;
1994-11-18 17:39:45 +00:00
exec_convapp ( lev , FALSE ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : packfile ( bool vis )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err ;
if ( filehnd ( ) ! = NULL )
fatal_box ( " Can't pack open file %s " , filename ( ) ) ;
setstatus ( creorgfile ( num ( ) , vis , & err ) ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : packindex ( bool vis )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
int err ;
if ( filehnd ( ) ! = NULL )
fatal_box ( " Can't pack open file %s " , filename ( ) ) ;
setstatus ( creorgindex ( num ( ) , vis , & err ) ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
1994-12-02 13:06:39 +00:00
int TSystemisamfile : : load ( const char * from , char fs , char fd , char rs , bool vis , bool extended )
1994-08-22 11:10:49 +00:00
{
1994-09-27 10:19:36 +00:00
FILE * fl = fopen ( from , " r+ " ) ;
int err = ferror ( fl ) ;
TRecnotype r = 0 , e = 0 , nitems = 0 , nread = 0 ;
1994-12-02 13:06:39 +00:00
TString16 firm , year , attprev ( " 00000 " ) ;
if ( extended )
{
TDate d ( TODAY ) ;
TLocalisamfile ditte ( LF_NDITTE ) ;
firm . format ( " %05ld " , main_app ( ) . get_firm ( ) ) ;
year . format ( " %04d " , d . year ( ) ) ;
ditte . zero ( ) ;
ditte . put ( " CODDITTA " , firm ) ;
if ( ditte . read ( ) = = NOERR )
attprev = ditte . get ( " CODATTPREV " ) ;
}
1994-09-27 10:19:36 +00:00
if ( fl = = NULL )
1994-08-22 11:10:49 +00:00
{
1994-09-27 10:19:36 +00:00
clearerr ( fl ) ;
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
return err ;
}
1994-09-27 10:19:36 +00:00
char w [ 80 ] ;
while ( ( fgets ( w , 80 , fl ) ! = NULL ) )
{
if ( strncmp ( w , " [Data] " , 6 ) = = 0 )
{
nitems = ftell ( fl ) ;
break ;
}
}
fseek ( fl , 0L , SEEK_END ) ;
nitems = ftell ( fl ) - nitems ;
fclose ( fl ) ;
TScanner f ( from ) ;
1994-08-22 11:10:49 +00:00
open ( ) ;
1994-09-27 10:19:36 +00:00
1994-08-22 11:10:49 +00:00
TToken_string s ( 1024 , fs ) ;
bool fixedlen = ( fs = = ' \0 ' ) ;
int nflds = curr ( ) . items ( ) ;
TArray fld ( nflds ) ;
1994-09-27 10:19:36 +00:00
int len [ MaxFields ] ;
1994-08-22 11:10:49 +00:00
TString sfd ( 3 ) ;
TString s1 ( 64 ) ;
1994-09-27 10:19:36 +00:00
bool lcf = FALSE ;
if ( f . paragraph ( " Header " ) )
{
f . equal ( ) ;
const long level = atol ( f . line ( ) ) ;
if ( level > stdlevel )
1994-11-11 18:04:29 +00:00
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 , stdlevel / 100 , stdlevel % 100 ) ;
1994-09-27 10:19:36 +00:00
lcf = getlcf ( level ) ;
nflds = 0 ;
TToken_string s2 ( f . line ( ) ) ;
int p = s2 . find ( ' = ' ) ;
if ( p > 0 )
{
s1 = s2 . left ( p ) ;
s2 . ltrim ( p + 1 ) ;
}
else s1 . cut ( 0 ) ;
while ( s1 = = " Fields " )
{
for ( const char * fd = s2 . get ( ) ; fd ! = NULL ; fd = s2 . get ( ) )
{
TToken_string wfd ( fd , ' , ' ) ;
fld . add ( new TString ( wfd . get ( ) ) ) ;
len [ nflds ] = wfd . get_int ( ) ;
nflds + + ;
}
s2 = f . line ( ) ;
p = s2 . find ( ' = ' ) ;
if ( p > 0 )
{
s1 = s2 . left ( p ) ;
s2 . ltrim ( p + 1 ) ;
}
else s1 . cut ( 0 ) ;
}
}
else
1994-08-22 11:10:49 +00:00
{
1994-09-27 10:19:36 +00:00
for ( int j = 0 ; j < nflds ; j + + )
{
fld . add ( TString ( curr ( ) . fieldname ( j ) ) , j ) ;
const TString & wfld = ( const TString & ) fld [ j ] ;
len [ j ] = ( curr ( ) . type ( wfld ) = = _datefld ) ? 10 : curr ( ) . length ( wfld ) ;
}
1994-08-22 11:10:49 +00:00
}
1994-09-27 10:19:36 +00:00
if ( ! f . paragraph ( " Data " ) )
{
error_box ( " Formato dei dati non valido " ) ;
close ( ) ;
1994-11-10 14:15:41 +00:00
err = 1 ;
setstatus ( err ) ;
return err ;
1994-09-27 10:19:36 +00:00
}
1994-08-22 11:10:49 +00:00
if ( fd ) sfd < < fd ;
int last = NOERR ;
1994-11-11 18:04:29 +00:00
s1 . format ( " Imp. archivio %s \n %6ld records %6ld errori - %3d " , filename ( ) , r , e , last ) ;
1994-09-27 10:19:36 +00:00
TProgind p ( nitems , s1 , TRUE , TRUE , 70 ) ;
s = f . line ( ) ;
while ( s . not_empty ( ) & & ! p . iscancelled ( ) )
1994-08-22 11:10:49 +00:00
{
1994-12-02 13:06:39 +00:00
if ( extended )
{
int p , i ;
while ( ( p = s . find ( " %yr% " ) ) > = 0 )
for ( i = 0 ; i < 4 ; i + + ) s [ p + i ] = year [ i ] ;
while ( ( p = s . find ( " %frm% " ) ) > = 0 )
for ( i = 0 ; i < 5 ; i + + ) s [ p + i ] = firm [ i ] ;
while ( ( p = s . find ( " %att% " ) ) > = 0 )
for ( i = 0 ; i < 5 ; i + + ) s [ p + i ] = attprev [ i ] ;
}
1994-08-22 11:10:49 +00:00
if ( ( r + e ) % 50 = = 0 )
{
1994-11-11 18:04:29 +00:00
s1 . format ( " Imp. archivio %s \n %6ld records %6ld errori - %3d " , filename ( ) , r , e , last ) ;
1994-08-22 11:10:49 +00:00
p . set_text ( s1 ) ;
}
p . setstatus ( nread + 1 ) ;
nread + = s . len ( ) + 1 ;
zero ( ) ;
if ( fixedlen )
{
int pos = 0 ;
1994-09-27 10:19:36 +00:00
for ( int j = 0 ; j < nflds ; j + + )
1994-08-22 11:10:49 +00:00
{
1994-09-27 10:19:36 +00:00
s1 = s . mid ( pos , len [ j ] ) ;
s1 . rtrim ( ) ;
put ( ( const TString & ) fld [ j ] , s1 ) ;
1994-08-22 11:10:49 +00:00
pos + = len [ j ] ;
}
}
else
{
s . restart ( ) ;
1994-09-27 10:19:36 +00:00
for ( int j = 0 ; j < nflds ; j + + )
1994-08-22 11:10:49 +00:00
{
char * s2 = ( char * ) s . get ( ) ;
if ( fd )
{
s2 + + ;
s2 [ strlen ( s2 ) - 1 ] = ' \0 ' ;
}
put ( ( const TString & ) fld [ j ] , s2 ) ;
}
}
if ( write ( ) = = NOERR ) r + + ;
else
{
e + + ;
last = status ( ) ;
}
1994-09-27 10:19:36 +00:00
s = f . line ( ) ;
1994-08-22 11:10:49 +00:00
}
1994-11-11 18:04:29 +00:00
s1 . format ( " Imp. archivio %s \n %6ld records %6ld errori - %3d " , filename ( ) , r , e , last ) ;
1994-08-22 11:10:49 +00:00
p . set_text ( s1 ) ;
close ( ) ;
1994-11-10 14:15:41 +00:00
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
int TSystemisamfile : : dump ( const char * to , int nkey , char fs , char fd , char rs , bool vis , bool withdeleted )
{
1994-08-22 11:10:49 +00:00
FILE * f = fopen ( to , " w " ) ;
int err = ferror ( f ) ;
if ( withdeleted ) nkey = 0 ;
if ( f = = NULL )
{
clearerr ( f ) ;
setstatus ( err ) ;
return err ;
}
open ( ) ;
TString s ( 512 ) ;
bool fixedlen = ( fs = = ' \0 ' ) ;
int nflds = curr ( ) . items ( ) ;
TArray fld ( nflds ) ;
TBit_array rjust ( nflds ) ;
1994-09-27 10:19:36 +00:00
int len [ MaxFields ] ;
1994-08-22 11:10:49 +00:00
for ( int j = 0 ; j < nflds ; j + + )
{
fld . add ( TString ( curr ( ) . fieldname ( j ) ) , j ) ;
1994-09-27 10:19:36 +00:00
const TString & wfld = ( const TString & ) fld [ j ] ;
const TFieldtypes t = curr ( ) . type ( wfld ) ;
rjust . set ( j , t = = _intfld | | t = = _longfld | | t = = _realfld | |
t = = _wordfld | | t = = _intzerofld | | t = = _longzerofld ) ;
len [ j ] = ( t = = _datefld ) ? 10 : curr ( ) . length ( wfld ) ;
1994-08-22 11:10:49 +00:00
}
TRecnotype i = 0 ;
1994-09-01 13:28:55 +00:00
const TRecnotype nitems = nkey ? items ( ) : filehnd ( ) - > d - > EOD ;
1994-08-22 11:10:49 +00:00
s . format ( " Esportazione archivio %s " , filename ( ) ) ;
1994-10-31 16:24:26 +00:00
TProgind p ( nitems , s , TRUE , TRUE , 70 ) ;
1994-08-22 11:10:49 +00:00
TString s1 ;
1994-09-27 10:19:36 +00:00
fprintf ( f , " [Header] \n Version=%ld " , prefhndl - > filelevel ( ) ) ;
for ( int k = 0 ; k < nflds ; k + + )
{
if ( ( k % 10 ) = = 0 ) fprintf ( f , " \n Fields= " ) ;
else fprintf ( f , " | " ) ;
fprintf ( f , " %s,%d " , ( const char * ) ( const TString & ) fld [ k ] , len [ k ] ) ;
}
fprintf ( f , " \n \n [Data] \n " ) ;
1994-08-22 11:10:49 +00:00
if ( nkey )
{
setkey ( nkey ) ;
for ( first ( ) ; status ( ) = = NOERR & & ! p . iscancelled ( ) ; next ( ) , i + + )
{
p . setstatus ( i + 1 ) ;
s = " " ;
for ( j = 0 ; j < nflds ; j + + )
{
if ( fixedlen )
{
s1 = get ( ( const TString & ) fld [ j ] ) ;
if ( rjust [ j ] ) s1 . right_just ( len [ j ] ) ;
else s1 . left_just ( len [ j ] ) ;
}
else
{
s1 = " " ;
if ( j & & fs ) s1 < < fs ;
if ( fd ) s1 < < fd ;
s1 < < get ( ( const TString & ) fld [ j ] ) ;
if ( fd ) s1 < < fd ;
}
s < < s1 ;
}
fprintf ( f , " %s%c " , ( const char * ) s , rs ) ;
}
}
else
{
for ( i = 0 ; i < nitems & & ! p . iscancelled ( ) ; i + + )
{
1994-11-10 14:15:41 +00:00
zero ( ) ;
1994-08-22 11:10:49 +00:00
p . setstatus ( i + 1 ) ;
readat ( i + 1 ) ;
s = " " ;
if ( withdeleted | | curr ( ) . valid ( ) )
{
for ( j = 0 ; j < nflds ; j + + )
{
if ( fixedlen )
{
s1 = get ( ( const TString & ) fld [ j ] ) ;
if ( rjust [ j ] ) s1 . right_just ( len [ j ] ) ;
else s1 . left_just ( len [ j ] ) ;
}
else
{
s1 = " " ;
if ( j & & fs ) s1 < < fs ;
if ( fd ) s1 < < fd ;
s1 < < get ( ( const TString & ) fld [ j ] ) ;
if ( fd ) s1 < < fd ;
}
s < < s1 ;
}
fprintf ( f , " %s%c " , ( const char * ) s , rs ) ;
}
}
}
1994-09-27 10:19:36 +00:00
p . setstatus ( nitems ) ;
1994-08-22 11:10:49 +00:00
close ( ) ;
fclose ( f ) ;
1994-09-27 10:19:36 +00:00
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-11-24 14:01:20 +00:00
}
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
1994-11-24 14:01:20 +00:00
void TBaseisamfile : : recover ( )
{
isdef * fh = filehnd ( ) ;
const TRecnotype nitems = fh - > i . Base [ 0 ] . PEOX ;
CHECKD ( getkey ( ) = = 1 , " La chiave corrente non e' 1 ma " , getkey ( ) ) ;
TFilename fn = filename ( ) ;
fn = fn . name ( ) ;
# ifndef FOXPRO
1994-11-30 09:04:03 +00:00
if ( yesno_box ( " La dimensione dell'archivio %s e' errata. Cerco di recuperarlo? " , ( const char * ) fn ) )
1994-11-24 14:01:20 +00:00
{
TDir d ;
TString mess ( 80 ) ;
mess . format ( " Ricostruzione archivio %s : I Fase " , ( const char * ) fn ) ;
TProgind p ( nitems ? nitems : 1 , mess , TRUE , TRUE , 70 ) ;
1994-11-30 09:04:03 +00:00
const TDirtype dir = ( fh - > ft = = 0 ) ? _nordir : _comdir ;
d . get ( num ( ) , _lock , dir , _sysdirop ) ;
1994-11-24 14:01:20 +00:00
d . eod ( ) = fh - > d - > EOD = nitems ;
d . eox ( ) = fh - > d - > EOX = nitems ;
1994-11-30 09:04:03 +00:00
d . put ( num ( ) , dir , _sysdirop ) ;
1994-11-24 14:01:20 +00:00
for ( TRecnotype r = 1 ; r < = nitems ; r + + )
{
p . addstatus ( 1 ) ;
CRead ( & fh - > f , curr ( ) . string ( ) , r , _nolock ) ;
curr ( ) . discard ( ) ;
CWrite ( & fh - > f , curr ( ) . string ( ) , r , _nolock ) ;
}
p . close_modal ( ) ;
mess . format ( " Ricostruzione archivio %s : II Fase " , ( const char * ) fn ) ;
TProgind pi ( items ( ) ? items ( ) : 1 , mess , TRUE , TRUE , 70 ) ;
for ( first ( ) ; good ( ) ; next ( ) )
{
pi . addstatus ( 1 ) ;
curr ( ) . recall ( ) ;
rewrite ( ) ;
}
message_box ( " L'archivio %s deve essere compattato " , ( const char * ) fn ) ;
}
else
# endif
fatal_box ( " L'archivio %s e' incosistente e deve essere corretto prima di utilizzarlo " , ( const char * ) fn ) ;
}
1994-08-12 10:52:49 +00:00
////////////////////////////////////////////////////////////
// TRectype
////////////////////////////////////////////////////////////
1994-09-27 10:19:36 +00:00
TRectype : : TRectype ( int logicnum )
: _cod ( NULL )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
TDir wdir ;
_logicnum = logicnum ;
wdir . get ( _logicnum , _nolock , _nordir , _sysdirop ) ;
if ( wdir . name ( ) [ 0 ] = = ' % ' )
wdir . get ( _logicnum , _nolock , _comdir , _sysdirop ) ;
_length = wdir . len ( ) ;
_rec = new char [ _length ] ;
_i = openf [ _logicnum - 1 ] ;
1994-09-27 10:19:36 +00:00
* _tab = ' \0 ' ;
1994-09-28 15:52:37 +00:00
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
TRectype : : TRectype ( const TBaseisamfile * i )
1994-09-27 10:19:36 +00:00
: _cod ( NULL )
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = i - > num ( ) ;
if ( i - > filehnd ( ) ! = NULL )
_length = i - > filehnd ( ) - > d - > LenR ;
else
{
TDir wdir ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
wdir . get ( _logicnum , _nolock , _nordir , _sysdirop ) ;
if ( wdir . name ( ) [ 0 ] = = ' % ' )
wdir . get ( _logicnum , _nolock , _comdir , _sysdirop ) ;
_length = wdir . len ( ) ;
}
1994-09-27 10:19:36 +00:00
* _tab = ' \0 ' ;
1994-08-22 11:10:49 +00:00
_rec = new char [ _length ] ;
_i = i - > filehnd ( ) ;
1994-09-28 15:52:37 +00:00
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
TRectype : : TRectype ( const TRectype & r )
1994-09-27 10:19:36 +00:00
: _cod ( NULL )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = r . _logicnum ;
_length = r . len ( ) ;
_rec = new char [ _length ] ;
_rec [ 0 ] = r . _rec [ 0 ] ;
memcpy ( _rec + 1 , r . _rec + 1 , _length - 1 ) ;
_i = r . _i ;
1994-09-27 10:19:36 +00:00
strcpy ( _tab , r . _tab ) ;
if ( r . _cod ! = NULL )
_cod = new TRecfield ( * this , " COD " ) ;
1994-08-22 11:10:49 +00:00
setempty ( r . empty ( ) ) ;
1994-08-12 10:52:49 +00:00
}
TRectype : : ~ TRectype ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-09-27 10:19:36 +00:00
if ( _cod ! = NULL ) delete _cod ;
1994-08-22 11:10:49 +00:00
delete _rec ;
1994-08-12 10:52:49 +00:00
}
1994-09-27 10:19:36 +00:00
void TRectype : : settab ( const char * tab )
{
if ( _cod ! = NULL )
{
delete _cod ;
_cod = NULL ;
}
strcpy ( _tab , tab ) ;
if ( * _tab ! = ' \0 ' )
1994-09-28 15:52:37 +00:00
_cod = new TRecfield ( * this , " COD " ) ;
zero ( ) ;
1994-09-27 10:19:36 +00:00
}
1994-08-12 10:52:49 +00:00
TObject * TRectype : : dup ( ) const
{
1994-08-22 11:10:49 +00:00
TRectype * o = new TRectype ( * this ) ;
return o ;
1994-08-12 10:52:49 +00:00
}
HIDDEN bool fld_empty ( const char * s , int len , bool number )
{
1994-08-22 11:10:49 +00:00
/*if (number)
{
for ( ; len ; s + + , len - - )
if ( strchr ( " 0. " , * s ) = = NULL ) return FALSE ;
}
else */
if ( * s )
{
for ( ; len ; s + + , len - - )
if ( * s ! = ' ' ) return FALSE ;
}
return TRUE ;
1994-08-12 10:52:49 +00:00
}
HIDDEN int fld_cmp ( const char * a , const char * b , int len , bool number )
{
1994-08-22 11:10:49 +00:00
for ( int i = 0 ; i < len & & * a = = * b ; b + + , a + + , i + + ) ;
if ( i = = len ) return 0 ;
int res = * a - * b ;
if ( number )
{
b - = i ;
i = 0 ;
}
return fld_empty ( b , len - i , number ) ? 0 : res ;
1994-08-12 10:52:49 +00:00
}
///////////////////////////////////////////////////////////
// TRectype (record di un file)
///////////////////////////////////////////////////////////
int TRectype : : items ( ) const
{
1994-08-22 11:10:49 +00:00
return _i - > r - > NFields ;
1994-08-12 10:52:49 +00:00
}
const char * TRectype : : start ( int nf ) const
{
1994-08-22 11:10:49 +00:00
return string ( ) + _i - > r - > Fd [ nf ] . RecOff ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : compare ( const TSortable & s ) const
{
const TRectype & br = ( const TRectype & ) s ;
1994-08-22 11:10:49 +00:00
int res = 0 ;
1994-08-12 10:52:49 +00:00
if ( br . empty ( ) ) return UNDEFINED ;
for ( int i = 0 ; i < items ( ) ; i + + )
1994-08-22 11:10:49 +00:00
{
const char * b = br . start ( i ) ;
const char * a = start ( i ) ;
const byte typ = _i - > r - > Fd [ i ] . TypeF ;
/* if (typ == _boolfld) res = *a - *b;
else
{ */
const int sz = _i - > r - > Fd [ i ] . Len ;
const bool number = ( typ = = _intfld ) | | ( typ = = _realfld ) | |
( typ = = _longfld ) | | ( typ = = _wordfld ) | |
( typ = = _intzerofld ) | | ( typ = = _longzerofld )
| | ( typ = = _datefld ) ;
if ( fld_empty ( b , sz , number ) ) continue ;
res = : : fld_cmp ( a , b , sz , number ) ;
/* } */
if ( res ) return res ;
}
1994-08-12 10:52:49 +00:00
return 0 ;
}
TFieldtypes TRectype : : type ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " type " ) ;
return ( TFieldtypes ) CFieldType ( ( char * ) fieldname , _i - > r ) ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : length ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " length " ) ;
return CFieldSize ( ( char * ) fieldname , _i - > r ) ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : ndec ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " dec " ) ;
return CFieldDec ( ( char * ) fieldname , _i - > r ) ;
1994-08-12 10:52:49 +00:00
}
bool TRectype : : exist ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " exist " ) ;
return findfld ( _i - > r , ( char * ) fieldname ) ! = - 1 ;
1994-08-12 10:52:49 +00:00
}
const char * TRectype : : fieldname ( int i ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " fieldname " ) ;
return i > = 0 & & i < _i - > r - > NFields ? _i - > r - > Fd [ i ] . Name : NULL ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
int TRectype : : get_int ( const char * fieldname ) const
{
NOT_LINKED ( _i , " get_int " ) ;
if ( CGetFieldBuff ( ( char * ) fieldname , _i - > r , _rec , __tmp_string ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
return atoi ( __tmp_string ) ;
}
long TRectype : : get_long ( const char * fieldname ) const
{
NOT_LINKED ( _i , " get_long " ) ;
if ( CGetFieldBuff ( ( char * ) fieldname , _i - > r , _rec , __tmp_string ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
return atol ( __tmp_string ) ;
}
word TRectype : : get_word ( const char * fieldname ) const
{
NOT_LINKED ( _i , " get_word " ) ;
if ( CGetFieldBuff ( ( char * ) fieldname , _i - > r , _rec , __tmp_string ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
return ( word ) atoi ( __tmp_string ) ;
}
real TRectype : : get_real ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " get_real " ) ;
if ( CGetFieldBuff ( ( char * ) fieldname , _i - > r , _rec , __tmp_string ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1994-08-22 11:10:49 +00:00
real r ( __tmp_string ) ;
return r ;
1994-08-12 10:52:49 +00:00
}
char TRectype : : get_char ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " get_char " ) ;
1994-08-12 10:52:49 +00:00
if ( CGetFieldBuff ( ( char * ) fieldname , _i - > r , _rec , __tmp_string ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
return * __tmp_string ;
}
bool TRectype : : get_bool ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " get_bool " ) ;
if ( CGetFieldBuff ( ( char * ) fieldname , _i - > r , _rec , __tmp_string ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
return * __tmp_string = = ' X ' ;
1994-08-12 10:52:49 +00:00
}
# endif // FOXPRO
TDate TRectype : : get_date ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " get_date " ) ;
const TRecfield f ( ( TRectype & ) * this , fieldname ) ;
return ( TDate ) f ;
1994-08-12 10:52:49 +00:00
}
const TString & TRectype : : get ( const char * fieldname ) const
{
1994-08-22 11:10:49 +00:00
static TFixed_string s ( __tmp_string , 256 ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " get " ) ;
if ( CFieldType ( ( char * ) fieldname , _i - > r ) = = _datefld )
{
const TRecfield f ( ( TRectype & ) * this , fieldname ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
s = ( const char * ) f ;
}
else
if ( CGetFieldBuff ( ( char * ) fieldname , _i - > r , _rec , __tmp_string ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
return s ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
void TRectype : : put ( const char * fieldname , int val )
{
NOT_LINKED ( _i , " put " ) ;
if ( CPutField ( ( char * ) fieldname , _i - > r , & val , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
void TRectype : : put ( const char * fieldname , long val )
{
NOT_LINKED ( _i , " put " ) ;
if ( CPutField ( ( char * ) fieldname , _i - > r , & val , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
void TRectype : : put ( const char * fieldname , word val )
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " put " ) ;
if ( CPutField ( ( char * ) fieldname , _i - > r , & val , _rec ) = = - 1 )
1994-08-12 10:52:49 +00:00
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1994-08-22 11:10:49 +00:00
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : put ( const char * fieldname , const real & val )
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " put " ) ;
if ( CPutField ( ( char * ) fieldname , _i - > r , val . ptr ( ) , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : put ( const char * fieldname , const TDate & val )
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " put " ) ;
TRecfield f ( * this , fieldname ) ;
f = val . string ( 4 ) ;
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : put ( const char * fieldname , char val )
{
NOT_LINKED ( _i , " put " ) ;
char w [ 2 ] = { val , ' \0 ' } ;
if ( CPutFieldBuff ( ( char * ) fieldname , _i - > r , w , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
void TRectype : : put ( const char * fieldname , bool val )
{
NOT_LINKED ( _i , " put " ) ;
char * s = val ? " X " : " " ;
if ( CPutFieldBuff ( ( char * ) fieldname , _i - > r , s , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
}
# endif // FOXPRO
void TRectype : : put ( const char * fieldname , const char * val )
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " put " ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( val = = NULL | | * val = = ' \0 ' ) // Da provare
{
TRecfield f ( * this , fieldname ) ;
if ( * f . pos ( ) = = ' \0 ' ) return ;
}
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( CFieldType ( ( char * ) fieldname , _i - > r ) = = _datefld )
{
TRecfield f ( * this , fieldname ) ;
f = val ;
}
else
if ( CPutFieldBuff ( ( char * ) fieldname , _i - > r , ( char * ) val , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : zero ( const char * fieldname )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " zero " ) ;
1994-09-27 10:19:36 +00:00
if ( _cod ! = NULL & & strcmp ( fieldname , " COD " ) = = 0 )
* _cod = _tab ;
else
if ( CZeroField ( ( char * ) fieldname , _i - > r , _rec ) = = - 1 )
UNKNOWN_FIELD ( num ( ) , fieldname ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : zero ( )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
zero ( ' \0 ' ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : zero ( char c )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " zero " ) ;
recall ( ) ;
memset ( _rec + 1 , c , len ( ) - 1 ) ;
1994-09-27 10:19:36 +00:00
if ( _cod ! = NULL )
* _cod = _tab ;
1994-08-22 11:10:49 +00:00
if ( exist ( RFLD_SYS_FIRST ) )
{
put ( RFLD_SYS_FIRST , " -1 " ) ;
put ( RFLD_SYS_LAST , " -1 " ) ;
}
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
// Certified 99%
TRectype & TRectype : : operator = ( const TRectype & rec )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-09-27 10:19:36 +00:00
CHECK ( num ( ) = = rec . num ( ) , " Can't assign records of different file " ) ;
1994-08-12 10:52:49 +00:00
_i = rec . _i ; // Copy filehndl
memcpy ( _rec , rec . _rec , _length ) ; // Copy contents
setempty ( rec . empty ( ) ) ; // Copy emptiness status
return * this ;
}
// Certified 100%
TRectype & TRectype : : operator = ( const TBaseisamfile & f )
{
1994-08-22 11:10:49 +00:00
return * this = f . curr ( ) ;
1994-08-12 10:52:49 +00:00
}
// Certified 99%
TRectype & TRectype : : operator = ( const char * rec )
{
memcpy ( _rec , rec , _length ) ;
setempty ( FALSE ) ;
return * this ;
}
const char * TRectype : : key ( int numkey ) const
{
1994-08-22 11:10:49 +00:00
NOT_LINKED ( _i , " key " ) ;
CBuildKey ( _i - > r , numkey , _rec , __tmp_string ) ;
return __tmp_string ;
1994-08-12 10:52:49 +00:00
}
TRec_array : : TRec_array ( int dimension , TBaseisamfile & i )
1994-08-22 11:10:49 +00:00
: TArray ( dimension )
1994-08-12 10:52:49 +00:00
{
TRectype r ( & i ) ;
for ( int j = 0 ; j < size ( ) ; j + + ) add ( r , j ) ;
}
///////////////////////////////////////////////////////////
// TRecfield (campo/sottocampo di un record)
///////////////////////////////////////////////////////////
void TRecfield : : set ( int from , int to )
{
1994-08-22 11:10:49 +00:00
int nf ;
const isdef * bf = _rec - > filehnd ( ) ;
if ( ( nf = findfld ( bf - > r , _name ) ) = = - 1 )
{
_p = NULL ;
_len = 0 ;
_dec = 0 ;
_type = _nullfld ;
yesnofatal_box ( " File n. %d unknown field %s " , _rec - > num ( ) , _name ) ;
}
else
{
CHECK ( from > = 0 , " Invalid Start " ) ;
_p = _rec - > string ( ) + bf - > r - > Fd [ nf ] . RecOff + from ;
_dec = bf - > r - > Fd [ nf ] . Dec ;
_type = bf - > r - > Fd [ nf ] . TypeF ;
if ( to > = 0 )
{
CHECK ( from < = to & & to < = bf - > r - > Fd [ nf ] . Len ,
" Invalid Range " ) ;
_len = to - from + 1 ;
}
else _len = bf - > r - > Fd [ nf ] . Len - from ;
}
1994-08-12 10:52:49 +00:00
}
TRecfield : : TRecfield ( TRectype & rec , const char * name , int from , int to )
{
1994-08-22 11:10:49 +00:00
strcpy ( _name , name ) ;
NOT_LINKED ( rec . filehnd ( ) , " TRecfield " ) ;
_rec = & rec ;
set ( from , to ) ;
1994-08-12 10:52:49 +00:00
}
HIDDEN void __getfieldbuff ( byte l , byte t , const char * recin , char * s )
{
1994-08-22 11:10:49 +00:00
if ( recin = = NULL )
{
* s = ' \0 ' ;
return ;
}
if ( ( t ! = _alfafld ) & & ( t ! = _datefld ) )
{
while ( ( * recin = = ' ' ) & & ( l ) )
{
recin + + ;
l - - ;
}
if ( ( t ! = _realfld ) & & ( t ! = _charfld ) & &
( t ! = _intzerofld ) & & ( t ! = _longzerofld ) )
{
while ( ( * recin = = ' 0 ' ) & & ( l ) )
{
recin + + ;
l - - ;
}
}
}
if ( l )
{
strncpy ( s , recin , l ) ;
while ( s [ - - l ] = = ' ' ) ;
l + + ;
}
s [ l ] = ' \0 ' ;
if ( t = = _datefld & & * s )
{
TDate dt ( atol ( s ) ) ;
strcpy ( s , dt . string ( 4 ) ) ;
}
1994-08-12 10:52:49 +00:00
}
HIDDEN void __putfieldbuff ( byte l , byte d , byte t , const char * s , char * recout )
{
1994-08-22 11:10:49 +00:00
int len , i ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( recout = = NULL ) return ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
char s2 [ 256 ] ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
strcpy ( s2 , s ) ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( t = = _datefld )
{
if ( * s2 )
{
TDate dt ( s2 ) ;
sprintf ( s2 , " %06ld " , ( long ) dt ) ;
}
} else
if ( t = = _realfld ) setdec ( s2 , d ) ;
len = strlen ( s2 ) ;
if ( len > l ) return ;
if ( ( t = = _intfld ) | |
( t = = _longfld ) | |
( t = = _wordfld ) | |
( t = = _realfld ) )
{
if ( len = = 0 )
{
strcpy ( s2 , " 0 " ) ;
len = 1 ;
}
i = 0 ;
while ( i < l - len - 1 ) recout [ i + + ] = ' ' ;
strncpy ( & recout [ l - len - 1 ] , s2 , len ) ;
}
else
{
strncpy ( recout , s2 , len ) ;
while ( len < l ) recout [ len + + ] = ' ' ;
}
1994-08-12 10:52:49 +00:00
}
int TRecfield : : operator = ( int i )
{
1994-08-22 11:10:49 +00:00
if ( _type = = _intzerofld )
sprintf ( __tmp_string , " %0*d " , _len , i ) ;
else
sprintf ( __tmp_string , " %d " , i ) ;
__putfieldbuff ( _len , _dec , _type , __tmp_string , _p ) ;
_rec - > setempty ( FALSE ) ;
return i ;
1994-08-12 10:52:49 +00:00
}
long TRecfield : : operator = ( long l )
{
1994-08-22 11:10:49 +00:00
if ( _type = = _longzerofld )
sprintf ( __tmp_string , " %0*ld " , _len , l ) ;
else
sprintf ( __tmp_string , " %ld " , l ) ;
__putfieldbuff ( _len , _dec , _type , __tmp_string , _p ) ;
_rec - > setempty ( FALSE ) ;
return l ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
const real & TRecfield : : operator = ( const real & r )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
strcpy ( __tmp_string , r . string ( ) ) ;
__putfieldbuff ( _len , _dec , _type , __tmp_string , _p ) ;
_rec - > setempty ( FALSE ) ;
return r ;
1994-08-12 10:52:49 +00:00
}
# endif // FOXPRO
const TDate & TRecfield : : operator = ( const TDate & d )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
strcpy ( __tmp_string , ( const char * ) d ) ;
__putfieldbuff ( _len , _dec , _type , __tmp_string , _p ) ;
_rec - > setempty ( FALSE ) ;
return d ;
1994-08-12 10:52:49 +00:00
}
const char * TRecfield : : operator = ( const char * s )
{
1994-08-22 11:10:49 +00:00
__putfieldbuff ( _len , _dec , _type , s , _p ) ;
_rec - > setempty ( FALSE ) ;
return s ;
1994-08-12 10:52:49 +00:00
}
void TRecfield : : setptr ( TRecnotype r )
{
1994-08-22 11:10:49 +00:00
if ( _p = = NULL ) return ;
bool n = r < 0 ;
unsigned char * wp = ( unsigned char * ) _p ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( n ) r = - r ;
while ( wp - ( unsigned char * ) _p < = 3 )
{
* wp = r & & 0x000000FF ;
r > > = 8 ;
wp + + ;
}
if ( n ) * wp + = 128 ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator int ( ) const
{
1994-08-22 11:10:49 +00:00
__getfieldbuff ( _len , _type , _p , __tmp_string ) ;
return atoi ( __tmp_string ) ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator long ( ) const
{
1994-08-22 11:10:49 +00:00
__getfieldbuff ( _len , _type , _p , __tmp_string ) ;
return atol ( __tmp_string ) ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
TRecfield : : operator const real ( ) const
{
1994-08-22 11:10:49 +00:00
__getfieldbuff ( _len , _type , _p , __tmp_string ) ;
real r ( __tmp_string ) ;
return r ;
1994-08-12 10:52:49 +00:00
}
# endif // FOXPRO
TRecfield : : operator TDate ( ) const
{
1994-08-22 11:10:49 +00:00
static TDate d ;
__getfieldbuff ( _len , _type , _p , __tmp_string ) ;
d = __tmp_string ;
return d ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator const char * ( ) const
{
1994-08-22 11:10:49 +00:00
__getfieldbuff ( _len , _type , _p , __tmp_string ) ;
return __tmp_string ;
1994-08-12 10:52:49 +00:00
}
TRecnotype TRecfield : : ptr ( ) const
{
1994-08-22 11:10:49 +00:00
if ( _p = = NULL ) return ( - 1L ) ;
unsigned char * wp = ( unsigned char * ) _p + 3 ;
TRecnotype r = * wp ;
bool n = r > 127 ;
1994-08-12 10:52:49 +00:00
1994-08-22 11:10:49 +00:00
if ( n ) r - = 128 ;
while ( wp - - > ( unsigned char * ) _p ) r = r < < 8 + * wp ;
return n ? - r : r ;
1994-08-12 10:52:49 +00:00
}
void TTransaction : : begin ( )
{
1994-08-22 11:10:49 +00:00
StTrans ( ) ;
1994-08-12 10:52:49 +00:00
}
void TTransaction : : end ( bool success )
{
1994-08-22 11:10:49 +00:00
if ( success ) EndTrans ( ) ;
else AbTrans ( ) ;
1994-08-12 10:52:49 +00:00
}