1994-08-12 10:52:49 +00:00
# include <stdio.h>
1995-07-04 14:06:19 +00:00
# include <stdlib.h>
1994-08-12 10:52:49 +00:00
# define __ISAM_CPP
1994-09-27 10:19:36 +00:00
# ifndef FOXPRO
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
1998-05-04 08:54:51 +00:00
# include <codeb.h>
1994-09-27 10:19:36 +00:00
# include <config.h>
1994-08-12 10:52:49 +00:00
# include <extcdecl.h>
1995-07-03 07:49:30 +00:00
# include <mailbox.h>
1994-11-24 14:01:20 +00:00
# include <prefix.h>
# include <relation.h>
1994-09-27 10:19:36 +00:00
# include <scanner.h>
1995-07-03 07:49:30 +00:00
# include <utility.h>
1995-06-12 10:49:19 +00:00
# include <memo.h>
1996-09-02 14:20:24 +00:00
# include <varrec.h>
1995-04-10 15:28:03 +00:00
1998-10-01 13:59:39 +00:00
# ifdef DBG
# define JOURNAL
# endif
# ifdef JOURNAL
# include <journal.h>
static FILE * _journal = ( FILE * ) 0xFFFF ;
FILE * get_journal ( )
{
if ( _journal = = ( FILE * ) 0xFFFF )
{
TConfig ini ( CONFIG_INSTALL , " Main " ) ;
const TString & name = ini . get ( " Journal " ) ;
if ( name . not_empty ( ) )
_journal = fopen ( name , " ab " ) ;
else
_journal = NULL ;
}
return _journal ;
}
TJournalHeader & get_journal_header ( int num , const char * op , const char * type )
{
static TJournalHeader jh ;
const int size = sizeof ( TJournalHeader ) ;
CHECKD ( size = = 64 , " Invalid journal header: " , size ) ;
memset ( & jh , 0 , size ) ;
strcpy ( jh . _signature , " J00 " ) ;
jh . _header_length = size ;
time ( & jh . _time ) ;
jh . _firm = prefix ( ) . get_codditta ( ) ;
jh . _logic_num = num ;
strcpy ( jh . _operation , op ) ;
strcpy ( jh . _type , type ) ;
jh . _data_size = 0 ;
return jh ;
}
void write_journal ( TJournalHeader & jh , void * data , int len )
{
FILE * j = get_journal ( ) ;
jh . _data_size = len ;
fwrite ( & jh , sizeof ( TJournalHeader ) , 1 , j ) ;
fwrite ( data , len , 1 , j ) ;
fflush ( j ) ;
}
# endif
1995-07-03 07:49:30 +00:00
# define RECLOCKTYPES 0xFF00
# define READTYPES 0x00FF
1996-09-26 15:26:47 +00:00
# define INVFLD 255
1995-07-03 07:49:30 +00:00
Str80 cprefix ;
1995-04-20 14:35:14 +00:00
HIDDEN char _isam_string [ 257 ] ;
1994-09-12 09:34:05 +00:00
1994-08-12 10:52:49 +00:00
# define NOALLOC (char **) -1
1996-09-26 15:26:47 +00:00
HIDDEN bool __autoload = TRUE ;
// @doc INTERNAL
////////////////////////////////////////////////////////////////////////////////////////////////////
// Funzioni C
////////////////////////////////////////////////////////////////////////////////////////////////////
int hashfun ( const char * s )
{
int l = strlen ( s ) ;
unsigned short temp = 0 , * pw = ( unsigned short * ) s ;
const unsigned short * end = ( unsigned short * ) ( s + ( l - 1 ) ) ;
while ( ( char * ) pw < ( char * ) end )
{
temp ^ = * pw ;
pw + + ;
}
if ( ODD ( l ) )
temp ^ = ( unsigned short ) ( 8192 + s [ l - 1 ] ) ;
l = ( short ) ( temp % ( MaxFields - 3 ) ) ;
CHECKS ( l > = 0 , " Negative remainder on " , s ) ;
return ( l ) ;
}
int findfld ( const RecDes * recd , const char * s )
{
1996-11-12 09:09:43 +00:00
short stp = hashfun ( s ) ;
1996-09-26 15:26:47 +00:00
for ( byte i = 0 ; i < MaxFields ; i + + )
{
if ( stp + i > = MaxFields )
stp - = MaxFields ;
byte p = stp + i ;
const int fp = recd - > SortFd [ p ] ;
if ( fp = = INVFLD ) return ( FIELDERR ) ;
const int cmp = strcmp ( recd - > Fd [ fp ] . Name , s ) ;
if ( ! cmp )
return ( int ) fp ;
else
if ( cmp > 0 ) return ( FIELDERR ) ;
}
return ( FIELDERR ) ;
}
void __getfieldbuff ( byte l , byte t , const char * recin , char * s )
1996-02-05 19:00:53 +00:00
1996-09-26 15:26:47 +00:00
{
CHECK ( recin , " Can't read from a Null record " ) ;
if ( t ! = _alfafld & & t ! = _datefld )
{
if ( t = = _intzerofld | | t = = _longzerofld )
{
byte i = 0 ;
for ( char * c = ( char * ) recin ; * c = = ' ' & & i < l ; c + + , i + + )
* c = ' 0 ' ;
if ( i = = l )
l = 0 ;
}
else
{
while ( ( * recin = = ' ' ) & & ( l ) )
{
recin + + ;
l - - ;
}
if ( ( t ! = _realfld ) & & ( t ! = _charfld ) )
{
while ( ( * recin = = ' 0 ' ) & & ( l ) )
{
recin + + ;
l - - ;
}
}
}
}
if ( l )
{
while ( l > 0 & & recin [ l - 1 ] = = ' ' ) l - - ;
if ( l )
strncpy ( s , recin , l ) ;
}
s [ l ] = ' \0 ' ;
if ( l )
{
if ( t = = _datefld )
{
1997-12-02 12:05:16 +00:00
TDate dt ( s ) ;
# ifdef _DEMO_
int y = dt . year ( ) ;
if ( y & 0x0001 ) y - - ;
y > > = 3 ;
y + + ;
y / = 10 ;
if ( y > = 25 )
{
int m = dt . month ( ) ;
if ( m > 3 )
dt . set_month ( rand ( ) % 3 + 1 ) ;
}
# endif
1996-09-26 15:26:47 +00:00
strcpy ( s , dt . string ( full ) ) ;
}
else
if ( t = = _boolfld )
{
const char ok = toupper ( * s ) ;
if ( ok = = ' T ' | | ok = = ' Y ' | | ok = = ' S ' | | ok = = ' X ' )
strcpy ( s , " X " ) ;
else
strcpy ( s , " " ) ;
}
}
}
void __putfieldbuff ( byte l , byte d , byte t , const char * s , char * recout )
{
int len , i ;
CHECK ( recout , " Can't write null record " ) ;
char s2 [ 40 ] ;
if ( t = = _datefld )
{
if ( * s )
{
const TDate dt ( s ) ;
strcpy ( s2 , dt . string ( ANSI ) ) ;
s = s2 ;
}
}
else
if ( t = = _boolfld )
{
1998-10-01 13:59:39 +00:00
strcpy ( s2 , ( * s & & strchr ( " 1STXY " , toupper ( * s ) ) ! = NULL ) ? " T " : " F " ) ;
1996-09-26 15:26:47 +00:00
s = s2 ;
}
else
if ( t = = _realfld )
{
real r ( s ) ;
strcpy ( s2 , r . string ( l , d ) ) ;
s = s2 ;
}
len = strlen ( s ) ;
1997-10-16 14:06:40 +00:00
const bool exceeded = len > l ;
1996-09-26 15:26:47 +00:00
if ( ( t = = _intfld ) | |
( t = = _longfld ) | |
( t = = _wordfld ) | |
( t = = _realfld ) | |
( t = = _intzerofld ) | |
( t = = _longzerofld )
)
{
1997-10-16 14:06:40 +00:00
if ( len = = 0 | | exceeded )
1996-09-26 15:26:47 +00:00
{
strcpy ( s2 , " 0 " ) ;
s = s2 ;
len = 1 ;
}
const char c = ( t = = _intzerofld | | t = = _longzerofld ) ? ' 0 ' : ' ' ;
for ( i = l - len - 1 ; i > = 0 ; i - - ) recout [ i ] = c ;
strncpy ( & recout [ l - len ] , s , len ) ;
}
else
{
1997-10-16 14:06:40 +00:00
if ( exceeded )
len = l ;
1996-09-26 15:26:47 +00:00
strncpy ( recout , s , len ) ;
for ( i = l - 1 ; i > = len ; i - - ) recout [ i ] = ' ' ;
}
}
1995-07-03 07:49:30 +00:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// Funzioni implementate per la gestione file dati tramite Codebase
////////////////////////////////////////////////////////////////////////////////////////////////////
// Inizio(@)
1996-02-05 19:00:53 +00:00
// @doc INTERNAL
1995-12-12 17:47:56 +00:00
// @func Ritorna una Token_string con in nome dell'indice
void get_idx_names (
int logicnum , // @parm Numero logico del file di cui riconoscere l'indice
TToken_string & i_names ) // @parm Token_string in cui inserire il nome dell'indice
// @comm Ritorna il nome con il prefisso corrente
1995-07-03 07:49:30 +00:00
{
long c = DB_getconf ( ) ;
TDir d ;
TTrec r ;
d . get ( logicnum ) ;
r . get ( logicnum ) ;
TFilename f ( d . name ( ) ) ;
if ( c & 1 ) f . ext ( " cdx " ) ;
if ( c & 4 ) f . ext ( " mdx " ) ;
i_names . cut ( 0 ) ;
i_names . add ( f ) ;
f . ext ( " " ) ;
f . rtrim ( 1 ) ;
if ( c & 2 | | c & 8 ) // DBIII or CLIPPER format, returns f_name + .cgp, f_nameX + .n{d|t}x
for ( int j = 1 ; j < = r . keys ( ) ; j + + )
{
TString xx = f . name ( ) ;
if ( xx . len ( ) < 8 )
f < < ( ' 0 ' + j ) ;
else
f [ 8 ] = ( ' 0 ' + j ) ;
if ( c & 2 ) // CLIPPER
f . ext ( " ndx " ) ;
else // DBIII
f . ext ( " ntx " ) ;
i_names . add ( f ) ;
}
i_names . restart ( ) ;
}
1998-03-30 13:43:36 +00:00
// Converte un errore di codebase in un errore isam
1995-07-03 07:49:30 +00:00
int get_error ( int err )
{
1998-03-30 13:43:36 +00:00
// Codici negativi
HIDDEN int error_codes_g [ ] = { - 1 , _isnotopen , - 1 , - 1 , - 1 , _islocked , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , _isfilefull ,
- 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , - 1 , _iskeynotfound , _ispatherr , - 1 , - 1 , _isdupkey } ;
// Codici da 0 a 9
HIDDEN int error_codes_ra [ ] = { NOERR , NOERR , _iskeynotfound , _iseof , _isbof , _isnrecerr } ;
// Codici da 10 a ...
HIDDEN int error_codes_rb [ ] = { - 1 , - 1 , _isreinsert , - 1 , - 1 , _islocked , - 1 , _isalropen , _iskeyerr } ;
int isamerr = NOERR ;
1995-07-03 07:49:30 +00:00
if ( err > 0 )
{
if ( err > = 10 )
{
1998-03-30 13:43:36 +00:00
if ( err > 80 | | error_codes_rb [ err / 10 ] = = - 1 )
isamerr = err ;
1995-07-03 07:49:30 +00:00
else
1998-03-30 13:43:36 +00:00
isamerr = error_codes_rb [ err / 10 ] ;
1995-07-03 07:49:30 +00:00
}
else
1998-03-30 13:43:36 +00:00
isamerr = error_codes_ra [ err ] ;
1995-07-03 07:49:30 +00:00
}
else
if ( err < 0 )
{
1998-03-30 13:43:36 +00:00
if ( err = = - 1 )
isamerr = _isnotopen ;
else
{
int ierr = DB_get_error ( ) ;
if ( ierr = = 0 ) ierr = - err ; // DB_get_error already called
if ( ierr < 0 ) ierr = - ierr ;
if ( ierr > 340 | | error_codes_g [ ierr / 10 ] = = - 1 )
isamerr = - ierr ;
else
isamerr = error_codes_g [ ierr / 10 ] ;
}
1995-07-03 07:49:30 +00:00
}
DB_zero_error ( ) ;
1998-03-30 13:43:36 +00:00
return isamerr ;
1995-07-03 07:49:30 +00:00
}
1998-03-30 13:43:36 +00:00
HIDDEN bool rec_has_memo ( const RecDes * rd )
1995-12-06 14:44:14 +00:00
{
1996-09-26 15:26:47 +00:00
for ( int i = rd - > NFields - 1 ; i > = 0 ; i - - )
if ( rd - > Fd [ i ] . TypeF = = _memofld )
return TRUE ;
return FALSE ;
1995-12-06 14:44:14 +00:00
}
1995-07-03 07:49:30 +00:00
HIDDEN void browse_null ( char * start , int nc )
{
for ( int i = nc - 1 ; i > = 0 ; i - - ) // Anche il primo byte(deletion flag) deve essere cambiato. nc comprende il primo byte
if ( start [ i ] = = ' \0 ' ) start [ i ] = ' ' ;
}
1998-03-30 13:43:36 +00:00
HIDDEN int __build_key ( const RecDes * recd , int numkey , RecType recin , char * key , bool build_x_cb )
1995-07-05 11:12:13 +00:00
/* *recd; descrittore record */
/* numkey; numero chiave */
/* recin; buffer contenente il record */
/* *key; valore della chiave */
/* build_x_cb flag di costruzione per codebase */
1995-11-13 12:08:59 +00:00
{
CHECKD ( numkey > 0 , " Can't build key " , numkey ) ;
1997-02-03 15:12:38 +00:00
1997-03-28 12:07:58 +00:00
const char null_char = - 1 ;
1995-07-05 14:38:49 +00:00
key [ 0 ] = ' \0 ' ;
1995-07-03 07:49:30 +00:00
if ( numkey - - < = recd - > NKeys )
1995-07-05 14:38:49 +00:00
{
1996-05-10 09:26:40 +00:00
int l = 0 ;
1995-07-05 14:38:49 +00:00
for ( int i = 0 ; i < recd - > Ky [ numkey ] . NkFields ; i + + )
{
const KeyDes & kd = recd - > Ky [ numkey ] ;
const bool upp = kd . FieldSeq [ i ] > MaxFields ;
const int nf = upp ? kd . FieldSeq [ i ] - MaxFields : kd . FieldSeq [ i ] ;
const RecFieldDes & rf = recd - > Fd [ nf ] ;
1996-05-10 09:26:40 +00:00
const TFieldtypes f = ( TFieldtypes ) rf . TypeF ;
1995-07-05 14:38:49 +00:00
int off , len ;
if ( kd . FromCh [ i ] = = 255 )
1995-07-03 07:49:30 +00:00
{
1995-07-05 14:38:49 +00:00
off = rf . RecOff ;
len = rf . Len ;
1995-07-03 07:49:30 +00:00
}
else
{
1995-07-05 14:38:49 +00:00
off = rf . RecOff + kd . FromCh [ i ] ;
len = kd . ToCh [ i ] - kd . FromCh [ i ] + 1 ;
1995-07-03 07:49:30 +00:00
}
if ( ( l + len ) > 80 )
{
1995-07-05 14:38:49 +00:00
key [ 0 ] = ' \0 ' ;
1995-07-03 07:49:30 +00:00
return ( _iskeylenerr ) ;
}
1996-09-26 15:26:47 +00:00
if ( f = = _boolfld )
1996-05-30 13:53:00 +00:00
{
const bool on = * ( recin + off ) > ' ' & & strchr ( " STXY " , * ( recin + off ) ) ! = NULL ;
key [ l ] = on ? ' T ' : ' F ' ;
}
else
1996-05-10 09:26:40 +00:00
strncpy ( ( key + l ) , ( recin + off ) , len ) ;
1995-07-05 14:38:49 +00:00
if ( recin [ off ] = = ' \0 ' )
{
memset ( key + l , ' ' , len ) ;
1997-02-03 15:12:38 +00:00
if ( ( f = = _intfld ) | | ( f = = _longfld ) | | ( f = = _wordfld ) | |
( f = = _intzerofld ) | | ( f = = _longzerofld ) )
key [ l + len - 1 ] = build_x_cb ? ' 0 ' : null_char ;
1995-07-05 14:38:49 +00:00
}
1995-07-03 07:49:30 +00:00
else
1995-07-19 09:57:25 +00:00
if ( ( f = = _intfld ) | | ( f = = _longfld ) | | ( f = = _wordfld ) | | ( f = = _intzerofld ) | | ( f = = _longzerofld ) )
1995-07-05 14:38:49 +00:00
{
1995-07-03 07:49:30 +00:00
int w = l , j = l + len ;
while ( w < j & & key [ w ] = = ' ' ) w + + ;
1995-07-06 15:05:23 +00:00
while ( w < j & & key [ w ] = = ' 0 ' ) key [ w + + ] = ' ' ;
1997-06-02 10:06:58 +00:00
if ( w = = j ) key [ w - 1 ] = build_x_cb ? ' 0 ' : null_char ;
1995-07-06 15:05:23 +00:00
}
1995-07-05 14:38:49 +00:00
if ( upp )
for ( int i = l + len - 1 ; i > = l ; i - - )
key [ i ] = toupper ( key [ i ] ) ;
1995-07-03 07:49:30 +00:00
l + = len ;
}
1995-07-05 14:38:49 +00:00
1996-05-10 09:26:40 +00:00
// rtrim
1997-02-03 15:12:38 +00:00
if ( build_x_cb )
{
for ( l - - ; l > = 0 & & key [ l ] = = ' ' ; l - - ) ;
key [ l + 1 ] = ' \0 ' ;
}
else
{
for ( l - - ; l > = 0 & & ( key [ l ] = = ' ' | | key [ l ] = = null_char ) ; l - - ) ;
key [ l + 1 ] = ' \0 ' ;
for ( ; l > = 0 ; l - - )
if ( key [ l ] = = null_char )
key [ l ] = ' 0 ' ;
}
1995-07-03 07:49:30 +00:00
return ( NOERR ) ;
}
return ( _ispatherr ) ;
}
1998-03-30 13:43:36 +00:00
HIDDEN int cisread ( int fhnd , int knum , TRectype & record , int mode , TRecnotype & curr_recno )
1995-07-03 07:49:30 +00:00
{
1998-07-20 13:07:00 +00:00
CHECKD ( fhnd > = 0 , " Can't use codebase handle " , fhnd ) ;
1998-03-30 13:43:36 +00:00
const int rmode = ( mode & READTYPES ) ;
const int lmode = ( mode & RECLOCKTYPES ) ;
1995-07-05 14:38:49 +00:00
1995-07-03 07:49:30 +00:00
// Non usare mai _isnextn o _isprevn, usare il metodo skip!
1995-07-05 14:38:49 +00:00
CHECK ( rmode ! = _isnextn & & rmode ! = _isprevn , " _isnextn and _isprevn not supported in cisread " ) ;
1995-07-03 07:49:30 +00:00
1998-03-30 13:43:36 +00:00
TString256 keystr ;
char * key = keystr . get_buffer ( ) ;
1995-07-03 07:49:30 +00:00
int err = NOERR ;
do
1996-05-10 09:26:40 +00:00
{
1998-03-30 13:43:36 +00:00
if ( rmode > = _isequal & & rmode < = _isgteq )
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
const RecDes * r = record . rec_des ( ) ;
err = __build_key ( r , knum , record . string ( ) , key , TRUE ) ;
1995-07-03 07:49:30 +00:00
if ( err = = NOERR )
{
1998-03-30 13:43:36 +00:00
err = DB_seek ( fhnd , key ) ;
if ( err = = NOERR & & rmode = = _isgreat )
err = DB_next ( fhnd ) ;
1995-11-07 10:05:30 +00:00
if ( err ! = NOERR )
err = get_error ( err ) ;
1995-07-03 07:49:30 +00:00
}
1995-11-07 10:05:30 +00:00
if ( rmode ! = _isequal & & err = = _iskeynotfound )
err = NOERR ;
1995-07-03 07:49:30 +00:00
}
1995-07-05 14:38:49 +00:00
else
{
if ( rmode = = _isfirst )
1998-03-30 13:43:36 +00:00
err = DB_first ( fhnd ) ;
1997-12-02 12:05:16 +00:00
else
if ( rmode = = _islast )
1998-03-30 13:43:36 +00:00
err = DB_last ( fhnd ) ;
1997-12-02 12:05:16 +00:00
else
if ( rmode = = _isnext )
{
1998-03-30 13:43:36 +00:00
if ( curr_recno ! = DB_recno ( fhnd ) )
1997-12-02 12:05:16 +00:00
{
1998-03-30 13:43:36 +00:00
RecDes * r = record . rec_des ( ) ;
err = __build_key ( r , knum , record . string ( ) , key , TRUE ) ;
1997-12-02 12:05:16 +00:00
if ( err = = NOERR )
{
1998-03-30 13:43:36 +00:00
err = DB_seek ( fhnd , key ) ;
1997-12-02 12:05:16 +00:00
err = get_error ( err ) ;
if ( err ! = NOERR & & err ! = _iskeynotfound )
fatal_box ( " Errore nella next %d : non posso riposizionarmi " , err ) ;
else
if ( err = = NOERR )
1998-03-30 13:43:36 +00:00
err = DB_next ( fhnd ) ;
1997-12-02 12:05:16 +00:00
}
}
else
1998-03-30 13:43:36 +00:00
err = DB_next ( fhnd ) ;
1997-12-02 12:05:16 +00:00
}
else
if ( rmode = = _isprev )
{
1998-03-30 13:43:36 +00:00
if ( curr_recno ! = DB_recno ( fhnd ) )
1997-12-02 12:05:16 +00:00
{
1998-03-30 13:43:36 +00:00
RecDes * r = record . rec_des ( ) ;
err = __build_key ( r , knum , record . string ( ) , key , TRUE ) ;
1997-12-02 12:05:16 +00:00
if ( err = = NOERR )
{
1998-03-30 13:43:36 +00:00
err = DB_seek ( fhnd , key ) ;
1997-12-02 12:05:16 +00:00
err = get_error ( err ) ;
if ( err ! = NOERR & & err ! = _iseof )
fatal_box ( " Errore nella next %d : non posso riposizionarmi " , err ) ;
else
if ( err = = NOERR )
1998-03-30 13:43:36 +00:00
err = DB_prev ( fhnd ) ;
1997-12-02 12:05:16 +00:00
}
}
else
1998-03-30 13:43:36 +00:00
err = DB_prev ( fhnd ) ;
1997-12-02 12:05:16 +00:00
}
else
if ( rmode = = _iscurr )
1998-03-30 13:43:36 +00:00
err = DB_go ( fhnd , DB_recno ( fhnd ) ) ;
if ( err ! = NOERR )
err = get_error ( err ) ;
1995-07-05 14:38:49 +00:00
}
1995-07-04 14:06:19 +00:00
if ( err = = _iseof )
1998-03-30 13:43:36 +00:00
DB_last ( fhnd ) ;
1995-07-04 07:31:04 +00:00
if ( err = = NOERR & & ( lmode = = _lock | | lmode = = _testandlock ) ) // _lock e _testandlock
{
1998-03-30 13:43:36 +00:00
err = DB_lock ( fhnd ) ;
if ( err ! = NOERR )
err = get_error ( err ) ;
if ( err = = _islocked & & lmode = = _testandlock )
break ;
1995-07-04 07:31:04 +00:00
}
1995-09-14 13:12:18 +00:00
if ( err = = _islocked )
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
RecDes * r = record . rec_des ( ) ;
record = ( const char * ) DB_getrecord ( fhnd ) ;
__build_key ( r , knum , record . string ( ) , key , TRUE ) ;
1995-07-03 07:49:30 +00:00
message_box ( " Codice %s in uso da parte \n di un altro utente. " , key ) ;
}
1995-09-14 13:12:18 +00:00
} while ( err = = _islocked ) ;
1995-07-05 14:38:49 +00:00
if ( err = = NOERR & & lmode = = _unlock )
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
err = DB_unlock ( fhnd ) ;
if ( err ! = NOERR )
err = get_error ( err ) ;
1995-07-03 07:49:30 +00:00
}
1996-09-26 15:26:47 +00:00
1998-03-30 13:43:36 +00:00
curr_recno = DB_recno ( fhnd ) ;
record = ( const char * ) DB_getrecord ( fhnd ) ;
1995-07-03 07:49:30 +00:00
1998-03-30 13:43:36 +00:00
return err ;
1995-07-03 07:49:30 +00:00
}
1997-06-02 10:06:58 +00:00
1995-07-03 07:49:30 +00:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// Funzioni implementate per la gestione file dati tramite Codebase
////////////////////////////////////////////////////////////////////////////////////////////////////
// Fine(@)
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @func Setta il valore della variabile <p __autoload>
void set_autoload_new_files (
bool on ) // @parm Valore da assegnare
// @comm Il valore di <p __autoload> indica il caricamento dei valori standard dei file
1994-10-31 16:24:26 +00:00
{
__autoload = on ;
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TBaseisamfile
///////////////////////////////////////////////////////////
1998-03-13 10:25:37 +00:00
TBaseisamfile : : TBaseisamfile ( int logicnum )
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = logicnum ;
1998-03-30 13:43:36 +00:00
_isam_handle = 0 ;
_curr_key = 0 ;
1994-08-22 11:10:49 +00:00
_lasterr = NOERR ;
1998-03-13 10:25:37 +00:00
_current = new TRectype ( this ) ;
1994-08-12 10:52:49 +00:00
}
1997-07-22 09:49:11 +00:00
// @doc EXTERNAL
// @mfunc Reperisce il tracciato dal file stesso.
//
TBaseisamfile : : TBaseisamfile (
1998-03-30 13:43:36 +00:00
const char * name , int mode , bool index ) // @parm Indica il nome del file
1997-07-22 09:49:11 +00:00
// @comm Esiste la possibilita' di codificare i valori di pathpref e prefix in <p name>
// % si riferisce ai dati comuni
// $ si riferisce ai dati di ditta corrente
// # si riferisce al direttorio indicato da PATHPREF.INI
{
_lasterr = NOERR ;
1998-03-30 13:43:36 +00:00
TFilename filename ( name ) ;
1997-07-22 09:49:11 +00:00
// Espande il nome!
1998-03-30 13:43:36 +00:00
const char c = filename [ 0 ] ;
1997-07-22 09:49:11 +00:00
if ( c = = ' % ' | | c = = ' $ ' )
1998-03-30 13:43:36 +00:00
filename = CAddPref ( filename . get_buffer ( ) ) ;
1997-07-22 09:49:11 +00:00
else
if ( c = = ' # ' )
{
1998-03-30 13:43:36 +00:00
filename . ltrim ( 1 ) ;
filename . format ( " %s/%s " , __ptprf , ( const char * ) filename ) ;
}
_logicnum = LF_EXTERNAL ;
_isam_handle = prefix ( ) . open_isamfile ( _logicnum , filename , mode = = _excllock , index ) ;
1997-07-22 09:49:11 +00:00
_current = new TRectype ( this ) ;
}
1994-08-12 10:52:49 +00:00
TBaseisamfile : : ~ TBaseisamfile ( )
{
1998-03-13 10:25:37 +00:00
if ( _current )
1994-08-12 10:52:49 +00:00
delete _current ;
}
1998-03-30 13:43:36 +00:00
TCodeb_handle TBaseisamfile : : handle ( int key ) const
{
return prefix ( ) . get_handle ( _isam_handle , key > 0 ? key : _curr_key ) ;
}
1994-08-12 10:52:49 +00:00
long TBaseisamfile : : items ( ) const
1995-12-04 11:06:12 +00:00
{
1998-03-30 13:43:36 +00:00
return DB_reccount ( handle ( ) ) ;
1994-08-12 10:52:49 +00:00
}
const char * TBaseisamfile : : name ( ) const
1995-04-10 15:28:03 +00:00
{
1995-04-20 14:35:14 +00:00
sprintf ( _isam_string , " %d " , num ( ) ) ;
1995-04-10 15:28:03 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
const char * TBaseisamfile : : filename ( ) const
1998-03-30 13:43:36 +00:00
{
const int n = _isam_handle > 0 ? _isam_handle : num ( ) ;
1998-06-24 07:11:33 +00:00
strcpy ( _isam_string , prefix ( ) . get_filename ( n ) ) ;
1998-03-30 13:43:36 +00:00
strcat ( _isam_string , " .dbf " ) ;
1995-07-17 16:58:43 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
1997-08-27 09:53:29 +00:00
const char * TBaseisamfile : : description ( )
1994-10-03 08:47:32 +00:00
{
1998-03-30 13:43:36 +00:00
const int n = _isam_handle > 0 ? _isam_handle : num ( ) ;
const FileDes & d = prefix ( ) . get_filedes ( n ) ;
return d . Des ;
1994-10-03 08:47:32 +00:00
}
1995-07-03 07:49:30 +00:00
TRecnotype TBaseisamfile : : eod ( ) const
{
1998-03-30 13:43:36 +00:00
return items ( ) ;
1995-07-03 07:49:30 +00:00
}
1994-10-03 08:47:32 +00:00
1996-09-02 14:20:24 +00:00
void TBaseisamfile : : set_curr ( TRectype * curr )
{
1998-03-30 13:43:36 +00:00
CHECK ( curr ! = NULL , " You must set a valid current record " ) ;
CHECK ( num ( ) = = curr - > num ( ) , " You must set a coherent current record " ) ;
1996-09-02 14:20:24 +00:00
if ( _current ! = NULL )
delete _current ;
_current = curr ;
}
1994-08-12 10:52:49 +00:00
void TBaseisamfile : : setkey ( int nkey )
{
1998-03-30 13:43:36 +00:00
_curr_key = nkey ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : getkey ( ) const
{
1998-03-30 13:43:36 +00:00
return _curr_key ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : first ( word lockop )
{
1997-12-02 12:05:16 +00:00
return TBaseisamfile : : read ( curr ( ) , _isfirst , lockop ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : last ( word lockop )
{
1997-12-02 12:05:16 +00:00
return TBaseisamfile : : read ( curr ( ) , _islast , lockop ) ;
1994-08-12 10:52:49 +00:00
}
1997-05-23 14:02:46 +00:00
int TBaseisamfile : : next ( word lockop )
{
1997-12-02 12:05:16 +00:00
return TBaseisamfile : : read ( curr ( ) , _isnext , lockop ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : prev ( word lockop )
{
1997-12-02 12:05:16 +00:00
return TBaseisamfile : : read ( curr ( ) , _isprev , lockop ) ;
1994-08-12 10:52:49 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : reread ( word lockop )
1998-03-30 13:43:36 +00:00
1994-08-22 11:10:49 +00:00
{
1997-12-02 12:05:16 +00:00
return TBaseisamfile : : reread ( curr ( ) , lockop ) ;
1994-08-12 10:52:49 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : reread ( TRectype & rec , word lockop )
1994-08-22 11:10:49 +00:00
{
1997-12-02 12:05:16 +00:00
return rec . read ( * this , _iscurr , lockop ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : skip ( TRecnotype nrec , word lockop )
1995-07-03 07:49:30 +00:00
{
1994-08-22 11:10:49 +00:00
if ( ! nrec ) return NOERR ;
1995-07-03 07:49:30 +00:00
curr ( ) . setdirty ( ) ;
1998-03-30 13:43:36 +00:00
const int fhnd = handle ( ) ;
// controllo se mi sono spostato dall'ultima lettura
if ( _recno ! = DB_recno ( fhnd ) )
1995-09-14 13:12:18 +00:00
{
1998-03-30 13:43:36 +00:00
_lasterr = DB_go ( fhnd , _recno ) ;
1995-09-14 13:12:18 +00:00
if ( _lasterr ! = NOERR )
{
_lasterr = get_error ( _lasterr ) ;
if ( _lasterr ! = _islocked )
fatal_box ( " Errore nella skip %d : non posso riposizionarmi " , _lasterr ) ;
}
}
1998-03-30 13:43:36 +00:00
_lasterr = DB_skip ( fhnd , nrec ) ;
if ( _lasterr ! = NOERR )
_lasterr = get_error ( _lasterr ) ;
while ( _lasterr = = _islocked )
{
const RecDes & r = prefix ( ) . get_recdes ( num ( ) ) ;
TString key ( 128 ) ;
__build_key ( & r , _curr_key , curr ( ) . string ( ) , key . get_buffer ( ) , TRUE ) ;
message_box ( " Codice %s in uso da parte \n di un altro utente. " , ( const char * ) key ) ;
_lasterr = cisread ( fhnd , getkey ( ) , curr ( ) , _iscurr + lockop , _recno ) ;
}
if ( curr ( ) . has_memo ( ) )
curr ( ) . init_memo ( _recno ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1997-05-23 14:02:46 +00:00
// funzione di lettura dei file
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : _read ( TRectype & rec , word op , word lockop )
1994-08-12 10:52:49 +00:00
{
1998-03-30 13:43:36 +00:00
const TCodeb_handle fhnd = handle ( ) ;
1997-05-23 14:02:46 +00:00
rec . setdirty ( ) ;
1998-08-10 10:20:31 +00:00
_lasterr = cisread ( fhnd , getkey ( ) , rec , op + lockop , _recno ) ;
1998-03-30 13:43:36 +00:00
if ( rec . has_memo ( ) )
1997-05-23 14:02:46 +00:00
rec . init_memo ( _recno ) ;
1998-08-10 10:20:31 +00:00
if ( _lasterr = = NOERR )
1998-03-30 13:43:36 +00:00
{
if ( lockop = = _lock )
prefix ( ) . lock_record ( _isam_handle , _recno ) ;
if ( lockop = = _unlock )
prefix ( ) . unlock_record ( _isam_handle , _recno ) ;
}
1998-08-10 10:20:31 +00:00
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : read ( TRectype & rec , word op , word lockop )
1994-08-22 11:10:49 +00:00
{
1997-06-02 10:06:58 +00:00
_lasterr = rec . read ( * this , op , lockop ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : read ( word op , word lockop )
1998-03-30 13:43:36 +00:00
1997-05-23 14:02:46 +00:00
{
1997-12-02 12:05:16 +00:00
return TBaseisamfile : : read ( curr ( ) , op , lockop ) ;
1997-05-23 14:02:46 +00:00
}
int TBaseisamfile : : readat ( TRectype & rec , TRecnotype nrec , word lockop )
{
1997-12-02 12:05:16 +00:00
return rec . readat ( * this , nrec , lockop ) ;
1997-05-23 14:02:46 +00:00
}
1994-08-12 10:52:49 +00:00
int TBaseisamfile : : readat ( TRecnotype nrec , word lockop )
{
1997-12-02 12:05:16 +00:00
return TBaseisamfile : : readat ( curr ( ) , nrec , lockop ) ;
1994-08-12 10:52:49 +00:00
}
1997-05-23 14:02:46 +00:00
int TBaseisamfile : : _readat ( TRectype & rec , TRecnotype nrec , word lockop )
1994-08-12 10:52:49 +00:00
{
1998-03-30 13:43:36 +00:00
const int fhnd = handle ( ) ;
1994-08-22 11:10:49 +00:00
rec . setdirty ( ) ;
1998-03-30 13:43:36 +00:00
_lasterr = DB_go ( fhnd , nrec ) ;
1997-05-23 14:02:46 +00:00
if ( _lasterr ! = NOERR )
_lasterr = get_error ( _lasterr ) ;
1995-07-03 07:49:30 +00:00
else
1998-03-30 13:43:36 +00:00
rec = ( const char * ) DB_getrecord ( fhnd ) ;
_recno = DB_recno ( fhnd ) ;
if ( rec . has_memo ( ) )
rec . init_memo ( _recno ) ;
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : _write ( const TRectype & rec )
1994-08-12 10:52:49 +00:00
{
1997-05-23 14:02:46 +00:00
CHECK ( ! rec . empty ( ) , " Can't write an empty record " ) ;
1998-03-30 13:43:36 +00:00
1997-12-02 12:05:16 +00:00
# ifdef _DEMO_
1998-03-30 13:43:36 +00:00
if ( ( num ( ) > LF_COMUNI & & num ( ) < LF_ANALISI ) | | num ( ) > LF_RELANA )
1997-12-02 12:05:16 +00:00
{
if ( items ( ) > 979L )
return _isfilefull ;
}
# endif
1997-05-23 14:02:46 +00:00
1998-03-30 13:43:36 +00:00
// Forza l'uso della chiave principale (per chiavi duplicate?)
const int fhnd = handle ( 1 ) ;
const int dst_len = DB_reclen ( fhnd ) ;
if ( dst_len ! = rec . len ( ) )
NFCHECK ( " Record size mismatch on file %d: RecDes=%d, DB_reclen=%d " ,
_logicnum , rec . len ( ) , dst_len ) ;
1997-05-23 14:02:46 +00:00
1998-02-24 10:37:28 +00:00
browse_null ( rec . string ( ) , dst_len ) ;
1998-03-30 13:43:36 +00:00
memcpy ( DB_getrecord ( fhnd ) , rec . string ( ) , dst_len ) ;
_lasterr = DB_add ( fhnd ) ;
1998-10-01 13:59:39 +00:00
if ( _lasterr = = NOERR )
{
1998-11-03 10:27:35 +00:00
notify_change ( ) ;
1998-10-01 13:59:39 +00:00
# ifdef JOURNAL
if ( get_journal ( ) )
{
TJournalHeader & jh = get_journal_header ( num ( ) , " ADD " , " REC " ) ;
write_journal ( jh , rec . string ( ) , dst_len ) ;
}
# endif
}
else
_lasterr = get_error ( _lasterr ) ;
1998-02-24 10:37:28 +00:00
1998-03-30 13:43:36 +00:00
_recno = DB_recno ( fhnd ) ;
1997-05-23 14:02:46 +00:00
if ( _lasterr = = NOERR & & rec . has_memo ( ) )
1998-03-30 13:43:36 +00:00
( ( TRectype & ) rec ) . write_memo ( fhnd , _recno ) ;
1998-10-01 13:59:39 +00:00
1997-05-23 14:02:46 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : write ( const TRectype & rec )
1997-05-23 14:02:46 +00:00
{
1997-06-02 10:06:58 +00:00
return rec . write ( * this ) ;
1997-05-23 14:02:46 +00:00
}
1994-08-12 10:52:49 +00:00
1997-05-23 14:02:46 +00:00
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : write ( )
1997-05-23 14:02:46 +00:00
{
1997-06-02 10:06:58 +00:00
return TBaseisamfile : : write ( curr ( ) ) ;
1997-05-23 14:02:46 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : _rewrite ( const TRectype & rec )
1994-08-12 10:52:49 +00:00
{
1995-07-07 14:43:41 +00:00
CHECK ( ! rec . empty ( ) , " Can't write an empty record " ) ;
1995-07-03 07:49:30 +00:00
TRectype save_rec ( rec ) ;
1998-03-30 13:43:36 +00:00
// Forza l'uso della chiave principale (per chiavi duplicate?)
const int fhnd = handle ( 1 ) ;
_lasterr = cisread ( fhnd , 1 , save_rec , _isequal + _nolock , _recno ) ; // Si Posiziona per sicurezza...
1995-07-03 07:49:30 +00:00
if ( _lasterr = = NOERR )
1995-07-04 14:06:19 +00:00
{
1998-03-30 13:43:36 +00:00
const int len = DB_reclen ( fhnd ) ;
if ( len ! = save_rec . len ( ) )
NFCHECK ( " Record size mismatch on file %d: RecDes=%d, DB_reclen=%d " ,
_logicnum , save_rec . len ( ) , len ) ;
1996-09-26 15:26:47 +00:00
browse_null ( rec . string ( ) , len ) ;
if ( memcmp ( rec . string ( ) , save_rec . string ( ) , len ) ! = 0 )
{
1998-03-30 13:43:36 +00:00
memcpy ( DB_getrecord ( fhnd ) , rec . string ( ) , len ) ;
_lasterr = DB_rewrite ( fhnd ) ;
1998-10-01 13:59:39 +00:00
if ( _lasterr = = NOERR )
{
1998-11-03 10:27:35 +00:00
notify_change ( ) ;
1998-10-01 13:59:39 +00:00
# ifdef JOURNAL
if ( get_journal ( ) )
{
TJournalHeader & jh = get_journal_header ( num ( ) , " MOD " , " REC " ) ;
write_journal ( jh , rec . string ( ) , len ) ;
}
# endif
}
else
1998-03-30 13:43:36 +00:00
_lasterr = get_error ( _lasterr ) ;
1996-09-26 15:26:47 +00:00
}
else
1998-03-30 13:43:36 +00:00
DB_unlock ( fhnd ) ;
_recno = DB_recno ( fhnd ) ;
1996-09-26 15:26:47 +00:00
if ( _lasterr = = NOERR & & curr ( ) . has_memo ( ) )
1998-03-30 13:43:36 +00:00
( ( TRectype & ) rec ) . write_memo ( fhnd , _recno ) ;
1995-07-04 14:06:19 +00:00
}
1998-10-01 13:59:39 +00:00
1994-08-22 11:10:49 +00:00
return _lasterr ;
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : rewrite ( const TRectype & rec )
1994-08-22 11:10:49 +00:00
{
1997-06-02 10:06:58 +00:00
return rec . rewrite ( * this ) ;
1997-05-23 14:02:46 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : rewrite ( )
1997-05-23 14:02:46 +00:00
{
1997-06-02 10:06:58 +00:00
return TBaseisamfile : : rewrite ( curr ( ) ) ;
1994-08-22 11:10:49 +00:00
}
int TBaseisamfile : : rewriteat ( const TRectype & rec , TRecnotype nrec )
{
1998-03-30 13:43:36 +00:00
const int fhnd = handle ( ) ;
if ( ( _lasterr = DB_go ( fhnd , nrec ) ) = = NOERR )
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
browse_null ( rec . string ( ) , DB_reclen ( fhnd ) ) ;
memcpy ( DB_getrecord ( fhnd ) , rec . string ( ) , DB_reclen ( fhnd ) ) ;
_lasterr = DB_rewrite ( fhnd ) ;
1995-07-03 07:49:30 +00:00
if ( _lasterr ! = NOERR ) _lasterr = get_error ( _lasterr ) ;
} else
_lasterr = get_error ( _lasterr ) ;
1998-03-30 13:43:36 +00:00
_recno = DB_recno ( fhnd ) ;
1996-09-26 15:26:47 +00:00
if ( _lasterr = = NOERR & & curr ( ) . has_memo ( ) )
1998-03-30 13:43:36 +00:00
( ( TRectype & ) rec ) . write_memo ( fhnd , _recno ) ;
1995-07-03 07:49:30 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1997-05-23 14:02:46 +00:00
int TBaseisamfile : : rewriteat ( TRecnotype nrec )
1994-08-12 10:52:49 +00:00
{
1997-05-23 14:02:46 +00:00
return TBaseisamfile : : rewriteat ( curr ( ) , nrec ) ;
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : _remove ( const TRectype & rec )
1997-05-23 14:02:46 +00:00
{
CHECK ( ! rec . empty ( ) , " Can't remove an empty record " ) ;
1995-07-07 14:43:41 +00:00
1998-10-01 13:59:39 +00:00
TRectype save_rec ( rec ) ;
// Forza l'uso della chiave principale (per chiavi duplicate?)
1998-03-30 13:43:36 +00:00
const int fhnd = handle ( 1 ) ;
1998-10-01 13:59:39 +00:00
_lasterr = cisread ( fhnd , 1 , save_rec , _isequal + _nolock , _recno ) ; // Si Posiziona per sicurezza...
if ( _lasterr = = NOERR )
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
_lasterr = DB_delete ( fhnd ) ; // Put only deletion flag on record, must remove keys too!
1998-10-01 13:59:39 +00:00
if ( _lasterr = = NOERR )
{
1998-11-03 10:27:35 +00:00
notify_change ( ) ;
1998-10-01 13:59:39 +00:00
DB_flush ( fhnd ) ;
# ifdef JOURNAL
if ( get_journal ( ) )
{
const int len = DB_reclen ( fhnd ) ;
TJournalHeader & jh = get_journal_header ( num ( ) , " DEL " , " REC " ) ;
write_journal ( jh , rec . string ( ) , len ) ;
}
# endif
}
else
1997-06-02 10:06:58 +00:00
{
_lasterr = get_error ( _lasterr ) ;
1998-03-30 13:43:36 +00:00
DB_recall ( fhnd ) ;
1997-06-02 10:06:58 +00:00
}
1995-07-03 07:49:30 +00:00
}
1997-05-23 14:02:46 +00:00
1996-09-02 14:20:24 +00:00
if ( _lasterr = = NOERR & & curr ( ) . has_memo ( ) )
1996-09-26 15:26:47 +00:00
curr ( ) . memo_recno ( ) ;
1997-05-23 14:02:46 +00:00
1994-08-22 11:10:49 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : remove ( const TRectype & rec )
1994-08-12 10:52:49 +00:00
{
1997-06-02 10:06:58 +00:00
return rec . remove ( * this ) ;
1997-05-23 14:02:46 +00:00
}
1997-06-02 10:06:58 +00:00
int TBaseisamfile : : remove ( )
1997-05-23 14:02:46 +00:00
{
1997-06-02 10:06:58 +00:00
return TBaseisamfile : : remove ( curr ( ) ) ;
1994-08-12 10:52:49 +00:00
}
int TBaseisamfile : : lock ( )
{
1998-03-30 13:43:36 +00:00
const int fhnd = handle ( ) ;
_lasterr = DB_lockfile ( fhnd ) ;
if ( _lasterr ! = NOERR )
_lasterr = get_error ( _lasterr ) ;
1995-07-03 07:49:30 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1998-03-13 10:25:37 +00:00
int TBaseisamfile : : unlock ( )
1994-08-12 10:52:49 +00:00
{
1998-03-30 13:43:36 +00:00
const int fhnd = handle ( ) ;
_lasterr = DB_unlock ( fhnd ) ;
if ( _lasterr ! = NOERR )
_lasterr = get_error ( _lasterr ) ;
1995-07-03 07:49:30 +00:00
return ( _lasterr ) ;
1994-08-12 10:52:49 +00:00
}
void TBaseisamfile : : indexon ( )
{
}
1998-03-30 13:43:36 +00:00
void TBaseisamfile : : indexoff ( )
{
}
1994-08-12 10:52:49 +00:00
bool TBaseisamfile : : empty ( )
{
1998-03-30 13:43:36 +00:00
return items ( ) < = 0 ;
1994-08-12 10:52:49 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1994-08-12 10:52:49 +00:00
1995-12-12 17:47:56 +00:00
// @mfunc Apre il file isam di base con lock
//
// @rdesc Ritorna NOERR se e' riuscita ad aprire il file, altrimenti ritorna il numero di errore
1995-12-29 12:09:48 +00:00
// generato (vedi <t TIsamerr>).
1995-12-12 17:47:56 +00:00
int TBaseisamfile : : _open (
1997-10-16 14:06:40 +00:00
unsigned int mode , // @parm Indica il modo di apertura del file (default _manulock)
bool index ) // @parm Indica se aprire con indici o meno (default TRUE)
1994-08-12 10:52:49 +00:00
1995-12-12 17:47:56 +00:00
// @comm Il parametro <p mode> puo' assumere i valori:
//
// @flag _manulock | Il lock dei record viene fatto manualmente
// @flag _exclock | Il file viene aperte in modo esclusivo
// @flag _autolock | Il lock dei record viene fatto in modo automatico
1997-10-16 14:06:40 +00:00
// @comm Il parametro <p index> puo' assumere i valori:
//
// @flag TRUE | Il file viene aperto con indici
// @flag FALSE | Il file viene aperto senza indici
1994-08-22 11:10:49 +00:00
{
1998-03-30 13:43:36 +00:00
CHECKD ( _isam_handle = = 0 , " Can't reopen file " , _logicnum ) ;
_curr_key = index ? 1 : 0 ;
TFilename filename ;
_isam_handle = prefix ( ) . open_isamfile ( _logicnum , filename , mode = = _excllock , index ) ;
if ( _isam_handle > 0 )
1995-07-03 07:49:30 +00:00
{
1995-11-22 13:46:11 +00:00
_recno = RECORD_NON_FISICO ;
1995-07-03 07:49:30 +00:00
_lasterr = NOERR ;
1995-07-03 16:19:39 +00:00
}
else
1995-07-03 07:49:30 +00:00
{
1996-01-18 18:20:47 +00:00
TString e_msg ;
1998-03-30 13:43:36 +00:00
_lasterr = get_error ( _isam_handle ) ;
1996-01-18 18:20:47 +00:00
if ( _lasterr = = - 60 )
{
1998-03-30 13:43:36 +00:00
if ( ! filename . exist ( ) )
e_msg . format ( " Il file %d(%s) non esiste, errore %d " , num ( ) , ( const char * ) filename , _lasterr ) ;
1996-01-18 18:20:47 +00:00
else
1998-03-30 13:43:36 +00:00
e_msg . format ( " Il file %d(%s) e' aperto in modo esclusivo da un'altra applicazione " ,
num ( ) , ( const char * ) filename ) ;
1996-01-18 18:20:47 +00:00
}
if ( e_msg . empty ( ) )
1998-03-30 13:43:36 +00:00
e_msg . format ( " Il file %d(%s) non puo' essere aperto, errore %d " , num ( ) , ( const char * ) filename , _lasterr ) ;
1996-01-18 18:20:47 +00:00
fatal_box ( ( const char * ) e_msg ) ;
1994-08-12 10:52:49 +00:00
}
1998-03-30 13:43:36 +00:00
return _lasterr ;
1994-08-12 10:52:49 +00:00
}
1998-01-28 08:29:13 +00:00
int TBaseisamfile : : _open_ex (
unsigned int mode , // @parm Indica il modo di apertura del file (default _manulock)
bool index ) // @parm Indica se aprire con indici o meno (default TRUE)
// @comm Il parametro <p mode> puo' assumere i valori:
//
// @flag _manulock | Il lock dei record viene fatto manualmente
// @flag _exclock | Il file viene aperte in modo esclusivo
// @flag _autolock | Il lock dei record viene fatto in modo automatico
// @comm Il parametro <p index> puo' assumere i valori:
//
// @flag TRUE | Il file viene aperto con indici
// @flag FALSE | Il file viene aperto senza indici
{
1998-03-30 13:43:36 +00:00
CHECKD ( _isam_handle = = 0 , " Can't reopen file " , _logicnum ) ;
_curr_key = index ? 1 : 0 ;
1998-01-28 08:29:13 +00:00
1998-03-30 13:43:36 +00:00
TFilename filename ;
_isam_handle = prefix ( ) . open_isamfile ( _logicnum , filename , mode = = _excllock , index ) ;
if ( _isam_handle > 0 )
{
if ( prefix ( ) . get_reclen ( _logicnum ) > 0 )
1998-01-28 08:29:13 +00:00
{
1998-03-30 13:43:36 +00:00
const int fhnd = handle ( ) ;
if ( fhnd > = 0 )
{
_recno = RECORD_NON_FISICO ;
_lasterr = NOERR ;
}
1998-01-28 08:29:13 +00:00
else
1998-03-30 13:43:36 +00:00
_lasterr = get_error ( fhnd ) ;
1998-01-28 08:29:13 +00:00
}
1998-03-30 13:43:36 +00:00
else
_lasterr = _isbadtrc ;
1998-01-28 08:29:13 +00:00
}
else
1998-03-30 13:43:36 +00:00
{
_isam_handle = 0 ;
_lasterr = get_error ( _isam_handle ) ;
1998-01-28 08:29:13 +00:00
}
1998-03-30 13:43:36 +00:00
return _lasterr ;
1998-01-28 08:29:13 +00:00
}
1994-08-12 10:52:49 +00:00
int TBaseisamfile : : _close ( )
{
1998-05-13 15:07:41 +00:00
int err = NOERR ;
if ( prefix_valid ( ) )
{
err = prefix ( ) . close_isamfile ( _isam_handle ) ;
setstatus ( err ) ;
}
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1995-11-15 17:51:04 +00:00
int TBaseisamfile : : is_valid ( )
1998-03-30 13:43:36 +00:00
{ // Ritorna NOERR se il file puo' essere aperto senza errori
CHECKD ( _isam_handle = = 0 , " Can't reopen file " , _logicnum ) ;
TFilename filename ;
TIsam_handle isam_handle = prefix ( ) . open_isamfile ( _logicnum , filename , FALSE , TRUE ) ;
int err = isam_handle > 0 ? prefix ( ) . get_handle ( isam_handle , 1 ) : - 60 ;
if ( err < 0 )
err = get_error ( err ) ;
else
1995-11-15 18:20:51 +00:00
{
1998-03-30 13:43:36 +00:00
if ( prefix ( ) . get_reclen ( _logicnum ) > 0 )
err = NOERR ;
else
err = _isbadtrc ;
1995-11-15 18:20:51 +00:00
}
1998-03-30 13:43:36 +00:00
if ( isam_handle > 0 )
prefix ( ) . close_isamfile ( isam_handle ) ;
1995-11-15 17:51:04 +00:00
return err ;
}
1994-08-12 10:52:49 +00:00
1998-11-03 10:27:35 +00:00
void TBaseisamfile : : notify_change ( ) const
{
prefix ( ) . notify_change ( _isam_handle ) ;
}
bool TBaseisamfile : : is_changed_since ( long clk ) const
{
const clock_t last = prefix ( ) . last_change ( _isam_handle ) ;
return clk < last ;
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TLocalisamfile
///////////////////////////////////////////////////////////
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-02-22 14:21:34 +00:00
1996-02-05 19:00:53 +00:00
// @mfunc Costruttore
//
// @rdesc Ritorna l'oggetto <c TLocalisamfile>
TLocalisamfile : : TLocalisamfile (
1998-03-13 10:25:37 +00:00
int logicnum ) // @parm Numero del logico del file
: TBaseisamfile ( logicnum )
1995-02-10 17:42:33 +00:00
{
1998-03-13 10:25:37 +00:00
if ( open ( ) ! = NOERR )
fatal_box ( " Impossibile aprire il file %d " , logicnum ) ;
1994-08-12 10:52:49 +00:00
}
1997-07-22 09:49:11 +00:00
// @mfunc Costruttore
//
// @rdesc Ritorna l'oggetto <c TLocalisamfile>
TLocalisamfile : : TLocalisamfile (
1998-03-30 13:43:36 +00:00
const char * name , // @parm Nome del file esterno da aprire
int mode ,
bool index )
: TBaseisamfile ( name , mode , index )
1997-07-22 09:49:11 +00:00
{
}
1994-08-12 10:52:49 +00:00
1998-03-13 10:25:37 +00:00
TLocalisamfile : : TLocalisamfile ( int logicnum , bool tmpfile )
: TBaseisamfile ( logicnum )
{
1998-03-30 13:43:36 +00:00
CHECK ( tmpfile = = TRUE , " Protected constructor badly used " ) ;
1998-03-13 10:25:37 +00:00
}
1994-08-12 10:52:49 +00:00
TLocalisamfile : : ~ TLocalisamfile ( )
1995-01-04 15:39:38 +00:00
{
1998-11-04 18:04:26 +00:00
if ( _isamfile & & openf [ num ( ) - 1 ] ! = NULL )
{
if ( _was_open )
setkey ( _oldkey ) ;
close ( ) ;
}
1994-08-12 10:52:49 +00:00
}
1998-11-04 18:04:26 +00:00
1994-08-12 10:52:49 +00:00
int TLocalisamfile : : close ( )
{
1998-03-30 13:43:36 +00:00
return TBaseisamfile : : _close ( ) ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : open ( unsigned int mode )
{
1998-03-30 13:43:36 +00:00
return TBaseisamfile : : _open ( mode ) ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator + = ( const TRecnotype npos )
{
skip ( npos ) ;
return status ( ) ;
}
int TLocalisamfile : : operator - = ( const TRecnotype npos )
{
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
next ( ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
int TLocalisamfile : : operator - - ( )
{
1994-08-22 11:10:49 +00:00
prev ( ) ;
return status ( ) ;
1994-08-12 10:52:49 +00:00
}
1997-05-23 14:02:46 +00:00
1998-03-13 10:25:37 +00:00
TIsamfile : : TIsamfile ( int logicnum )
: TBaseisamfile ( logicnum )
{ }
1994-08-12 10:52:49 +00:00
TIsamfile : : ~ TIsamfile ( )
{
1994-08-22 11:10:49 +00:00
close ( ) ;
1994-08-12 10:52:49 +00:00
}
1998-03-30 13:43:36 +00:00
/*
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-29 12:09:48 +00:00
// @mfunc Aggiorna i flags associati al file
1995-12-12 17:47:56 +00:00
//
1998-03-30 13:43:36 +00:00
// @rdesc Ritorna NOERR se e' riuscita ad eseguire l'operazione, altrimenti ritorna il numero
1995-12-29 12:09:48 +00:00
// di errore generato (vedi <t TIsamerr>).
1995-12-12 17:47:56 +00:00
int TIsamfile : : flags (
bool updateeod ) // @parm Indica se aggiornare anche l'EOD del file
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1998-03-30 13:43:36 +00:00
if ( num ( ) < = 0 )
return NOERR ;
1995-07-03 07:49:30 +00:00
1998-03-30 13:43:36 +00:00
TDir d ;
const TDirtype dirtype = prefix ( ) . get_dirtype ( _filename ) ;
1995-07-03 07:49:30 +00:00
d . get ( num ( ) , _lock , dirtype ) ;
1998-03-30 13:43:36 +00:00
int err = d . status ( dirtype ) ;
if ( err = = NOERR )
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
const FileDes & fd = prefix ( ) . get_filedes ( _filename ) ;
d . flags ( ) = fd . Flags ;
if ( updateeod )
d . eod ( ) = fd . EOD ;
1995-07-03 07:49:30 +00:00
d . put ( num ( ) , dirtype ) ;
}
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
1995-07-03 07:49:30 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1998-03-30 13:43:36 +00:00
*/
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
// TIsamtempfile
///////////////////////////////////////////////////////////
1994-08-12 10:52:49 +00:00
1997-10-16 12:49:07 +00:00
TIsamtempfile : : TIsamtempfile ( int logicnum , const char * radix , bool create , bool autodel )
1998-03-13 10:25:37 +00:00
: TLocalisamfile ( logicnum , TRUE )
1995-02-10 17:42:33 +00:00
{
TRecnotype eod = 0 ;
TRecnotype eox = 100 ;
1995-03-24 11:16:17 +00:00
TFilename n ;
if ( radix & & * radix )
{
if ( * radix = = ' % ' )
1997-10-08 10:46:39 +00:00
n = radix + 1 ;
1995-03-24 11:16:17 +00:00
else
{
n . tempdir ( ) ;
1997-10-08 10:46:39 +00:00
n < < SLASH < < radix ;
1995-03-24 11:16:17 +00:00
}
1997-10-08 10:46:39 +00:00
n . ext ( " dbf " ) ;
1995-03-24 11:16:17 +00:00
}
1997-10-08 10:46:39 +00:00
else
n . temp ( NULL , " dbf " ) ;
1995-02-10 17:42:33 +00:00
if ( ! create )
{
TDir dir ; dir . get ( logicnum ) ;
1995-03-24 11:16:17 +00:00
const word & len = dir . len ( ) ;
1998-03-05 13:54:51 +00:00
FILE * f = fopen ( n , " rb " ) ;
if ( f = = NULL )
fatal_box ( " Impossibile aprire il file temporaneo %s: %s " , ( const char * ) n , ( const char * ) _strerror ( NULL ) ) ;
1995-03-24 11:16:17 +00:00
1995-02-10 17:42:33 +00:00
fseek ( f , 0 , SEEK_END ) ;
eod = eox = ftell ( f ) / len ;
fclose ( f ) ;
}
1998-03-05 13:54:51 +00:00
CHECK ( create = = FALSE | | create = = TRUE , " Il flag di autodel ora si setta con il terzo parametro del costruttore " ) ;
_autodel = autodel | | ( create ! = FALSE & & create ! = TRUE ) ;
1997-10-16 12:49:07 +00:00
1997-10-13 15:26:11 +00:00
n . insert ( " % " , 0 ) ;
1997-10-16 12:49:07 +00:00
1995-02-10 17:42:33 +00:00
open ( n , create , eod , eox ) ;
}
1994-08-12 10:52:49 +00:00
TIsamtempfile : : ~ TIsamtempfile ( )
{
1994-08-22 11:10:49 +00:00
close ( ) ;
1994-08-12 10:52:49 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Apre il file
//
// @rdesc Ritorna NOERR se e' riuscita ad aprire il file, altrimenti ritorna il numero di errore
1995-12-29 12:09:48 +00:00
// generato (vedi <t TIsamerr>).
1995-12-12 17:47:56 +00:00
int TIsamtempfile : : open (
const char * radix , // @parm Radice del path del file
1998-06-24 07:11:33 +00:00
bool create , // @parm Indica se va creato un nuovo file (se FALSE il file esiste gia')
TRecnotype eod , // @parm Numero di record presenti nel file
TRecnotype eox ) // @parm Numero di record da aggiungere al file
1994-08-12 10:52:49 +00:00
1995-12-12 17:47:56 +00:00
// @comm Nel case <p create> sia TRUE allora viene settato automaticamente il valore di <p _autodel>
// a TRUE, cioe' viene abilitata l'eliminazione del file in chiusura.
1994-08-22 11:10:49 +00:00
{
1995-07-03 07:49:30 +00:00
int err = NOERR ;
1994-08-22 11:10:49 +00:00
1998-03-30 13:43:36 +00:00
TFilename filename ;
1995-07-03 07:49:30 +00:00
if ( radix [ 0 ] = = ' % ' )
1998-06-24 07:11:33 +00:00
filename = radix + 1 ;
1995-07-03 07:49:30 +00:00
else
1998-03-30 13:43:36 +00:00
filename . temp ( radix ) ;
filename . ext ( " " ) ;
CHECKS ( _isam_handle = = 0 , " File already open " , ( const char * ) filename ) ;
1995-07-03 07:49:30 +00:00
if ( create )
{
1998-03-30 13:43:36 +00:00
RecDes * r = ( RecDes * ) & prefix ( ) . get_recdes ( num ( ) ) ;
err = DB_build ( filename , r ) ;
if ( err ! = NOERR )
1995-07-03 07:49:30 +00:00
{
err = get_error ( err ) ;
1998-03-30 13:43:36 +00:00
fatal_box ( " Can't create temp file '%s' num. %d: Error n. %d " , ( const char * ) filename , num ( ) , err ) ;
1994-08-22 11:10:49 +00:00
}
1995-07-03 07:49:30 +00:00
}
1998-03-30 13:43:36 +00:00
_isam_handle = prefix ( ) . open_isamfile ( _logicnum , filename ) ;
TCodeb_handle fhnd = handle ( _curr_key = 1 ) ;
if ( fhnd < 0 )
err = get_error ( fhnd ) ;
1995-07-03 07:49:30 +00:00
if ( err ! = NOERR )
{
1998-03-30 13:43:36 +00:00
filename . ext ( " dbf " ) ;
1997-06-10 14:38:12 +00:00
if ( err = = - 60 )
{
1998-03-30 13:43:36 +00:00
if ( ! filename . exist ( ) ) // check for existance
fatal_box ( " Apertura file %s : errore n. %d. File non esistente. " , ( const char * ) filename , err ) ;
1997-06-10 14:38:12 +00:00
else
1998-03-30 13:43:36 +00:00
fatal_box ( " Apertura file %s : errore n. %d. File aperto in uso esclusivo da un'altra applicazione. " , ( const char * ) filename , err ) ;
1997-06-10 14:38:12 +00:00
}
else
1998-03-30 13:43:36 +00:00
fatal_box ( " Apertura file %s : errore n. %d " , ( const char * ) filename , err ) ;
1994-08-12 10:52:49 +00:00
}
1998-03-30 13:43:36 +00:00
1995-11-22 13:46:11 +00:00
_recno = RECORD_NON_FISICO ;
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
int TIsamtempfile : : close ( )
1994-08-12 10:52:49 +00:00
{
1998-03-30 13:43:36 +00:00
TFilename f = filename ( ) ;
int err = prefix ( ) . close_isamfile ( _isam_handle ) ;
if ( err = = NOERR & & _autodel )
1994-08-22 11:10:49 +00:00
{
1998-06-24 07:11:33 +00:00
const long c = DB_getconf ( ) ;
1998-03-30 13:43:36 +00:00
f . ext ( " dbf " ) ;
: : remove ( f ) ;
1998-06-24 07:11:33 +00:00
if ( c & 1 )
f . ext ( " fpt " ) ;
else
f . ext ( " dbt " ) ;
: : remove ( f ) ;
1998-03-30 13:43:36 +00:00
if ( c & 1 ) // FOXPRO format
f . ext ( " cdx " ) ;
if ( c & 4 ) // DBIV format
f . ext ( " mdx " ) ;
if ( c & 8 | | c & 2 ) // CLIPPER and DBIII format
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
f . ext ( " cgp " ) ;
1998-06-24 07:11:33 +00:00
FILE * fp = fopen ( f , " r " ) ;
1998-03-30 13:43:36 +00:00
char in [ 16 ] ;
while ( fgets ( in , 16 , fp ) ! = NULL )
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
TFilename a ( in ) ;
if ( c & 8 ) // DBIII format
a . ext ( " ndx " ) ;
else
a . ext ( " ntx " ) ; // CLIPPER format
: : remove ( ( const char * ) a ) ;
1995-07-03 07:49:30 +00:00
}
1998-03-30 13:43:36 +00:00
fclose ( fp ) ;
1995-07-03 07:49:30 +00:00
}
1998-03-30 13:43:36 +00:00
: : remove ( f ) ;
1994-08-12 10:52:49 +00:00
}
1998-03-30 13:43:36 +00:00
1994-08-22 11:10:49 +00:00
setstatus ( err ) ;
return err ;
1994-08-12 10:52:49 +00:00
}
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
1997-07-22 09:49:11 +00:00
// TExternisamfile
///////////////////////////////////////////////////////////
1998-03-30 13:43:36 +00:00
TExternisamfile : : TExternisamfile ( const char * name , int mode , bool index )
: TLocalisamfile ( name , mode , index )
1997-07-22 09:49:11 +00:00
{
}
TExternisamfile : : ~ TExternisamfile ( )
{
1998-03-30 13:43:36 +00:00
_close ( ) ;
1997-07-22 09:49:11 +00:00
}
const char * TExternisamfile : : name ( ) const
{
1998-03-30 13:43:36 +00:00
return filename ( ) ;
1997-07-22 09:49:11 +00:00
}
///////////////////////////////////////////////////////////
// TSystemisamfile
1995-02-10 17:42:33 +00:00
///////////////////////////////////////////////////////////
1994-08-12 10:52:49 +00:00
1997-06-12 15:52:14 +00:00
int TSystemisamfile : : build ( TRecnotype eox , const TTrec & r )
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
int err = NOERR ;
1994-10-14 17:51:32 +00:00
TDir d ;
d . get ( num ( ) ) ;
1995-07-20 09:10:38 +00:00
CHECK ( r . len ( ) ! = 0 , " Can't create a file with empty field info " ) ;
1997-06-12 15:52:14 +00:00
1998-03-30 13:43:36 +00:00
TFilename f ( filename ( ) ) ;
TFilename fname ( f ) ; fname . ext ( " " ) ; // sostituto per _filename
1994-10-14 17:51:32 +00:00
1995-04-28 13:14:15 +00:00
f = f . path ( ) ; if ( ! is_not_slash ( f . right ( 1 ) [ 0 ] ) ) f . rtrim ( 1 ) ;
1994-10-14 17:51:32 +00:00
if ( ! fexist ( f ) )
1995-04-10 15:28:03 +00:00
make_dir ( f ) ;
1995-07-20 09:10:38 +00:00
if ( r . len ( ) ! = 0 )
{
1998-03-30 13:43:36 +00:00
err = DB_build ( fname , r . rec ( ) ) ;
if ( err ! = NOERR )
1995-07-20 09:10:38 +00:00
err = get_error ( err ) ;
setstatus ( err ) ;
1994-11-24 14:01:20 +00:00
# ifndef FOXPRO
1995-07-20 09:10:38 +00:00
if ( err = = NOERR & & __autoload )
{
1998-03-13 10:25:37 +00:00
TFilename lf ;
1995-07-20 09:10:38 +00:00
lf . format ( " %sstd/lf%04d.txt " , __ptprf , num ( ) ) ;
if ( fexist ( lf ) )
load ( lf , ' | ' , ' \0 ' , ' \n ' , TRUE , TRUE ) ;
}
1994-11-24 14:01:20 +00:00
# endif
1995-07-20 09:10:38 +00:00
}
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1997-06-12 15:52:14 +00:00
int TSystemisamfile : : build ( TRecnotype eox )
{
TTrec r ;
r . get ( num ( ) ) ;
return build ( eox , r ) ;
}
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
{
1995-07-03 07:49:30 +00:00
int err = NOERR ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
long TSystemisamfile : : size ( TRecnotype eox )
{
1995-09-08 11:02:29 +00:00
return 51200L ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
1996-02-05 19:00:53 +00:00
// @doc INTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Esegue la conversione del file
//
// @rdesc Ritorna il rusultato dell'operazione
1996-09-26 15:26:47 +00:00
//
// @flag TRUE | Se la conversione e' stata effettuata correttamente
// @flag FALSE | Se h stato rilevato un errore durante la conversione (viene emesso un <f error_box>)
1996-06-17 09:05:05 +00:00
int TSystemisamfile : : exec_convapp (
1995-12-12 17:47:56 +00:00
long flev , // @parm Livello a cui aggiornare l'archivio
1995-12-29 12:09:48 +00:00
const bool before ) // @parm Indica se viene chiamata prima o dopo la conversione
1994-11-18 17:39:45 +00:00
{
const char * const v = before ? " BCNV " : " ACNV " ;
1996-06-17 09:05:05 +00:00
int err = 0 ;
1994-11-18 17:39:45 +00:00
if ( flev = = 0 ) flev = 199401 ;
else flev + + ;
1998-03-30 13:43:36 +00:00
TConfig conv ( CONFIG_FCONV ) ;
TString16 paragraph ;
TString_array paralist ;
conv . list_paragraphs ( paralist ) ;
1996-06-17 09:05:05 +00:00
for ( long l = flev ; err = = 0 & & l < = get_std_level ( ) ; l + + )
1994-11-18 17:39:45 +00:00
{
1998-03-30 13:43:36 +00:00
paragraph . format ( " %06ld " , l ) ;
if ( paralist . find ( paragraph ) < 0 )
continue ;
if ( conv . set_paragraph ( paragraph ) & & conv . exist ( v , num ( ) ) )
1994-11-18 17:39:45 +00:00
{
1997-06-12 15:52:14 +00:00
TToken_string s ( conv . get ( v , NULL , num ( ) ) , ' ' ) ;
TFilename f ( s . get ( 0 ) ) ;
f . ext ( " .exe " ) ;
1997-12-17 14:36:43 +00:00
s < < " " < < prefix ( ) . get_codditta ( ) ;
1994-11-24 14:01:20 +00:00
TExternal_app app ( s ) ;
1998-02-24 10:37:28 +00:00
if ( f . exist ( ) )
1994-11-18 17:39:45 +00:00
{
1998-03-13 10:25:37 +00:00
err = app . run ( FALSE , 0x3 ) ; // Synchronous Spawn with User
1998-02-24 10:37:28 +00:00
TMailbox mail ;
TMessage * msg = mail . next ( TRUE ) ;
if ( err = = 0 & & msg ! = NULL )
err = atoi ( msg - > body ( ) ) ;
1994-11-18 17:39:45 +00:00
}
1996-06-17 09:05:05 +00:00
if ( err & & err ! = 8 )
1995-04-10 15:28:03 +00:00
return error_box ( " Impossibile eseguire il programma di %sconversione \n del livello %ld/%ld \n Errore n.ro %d " , before ? " pre " : " post " , l / 100 , l % 100 , err ) ;
1994-11-18 17:39:45 +00:00
}
}
1996-06-17 09:05:05 +00:00
return err ;
1994-11-18 17:39:45 +00:00
}
1994-08-12 10:52:49 +00:00
1996-02-05 19:00:53 +00:00
// @doc INTERNAL
1995-12-29 12:09:48 +00:00
// @mfunc Recupera le conversioni logiche da effettuare sul file
//
// @rdesc Ritorna TRUE se occorre effettuare la conversione sul file
bool TSystemisamfile : : getlcf (
long flev ) // @parm livello archivi di partenza della convesione
// @comm Recupera le conversioni logiche da effettuare sul file per per passare dal
1996-01-18 18:20:47 +00:00
// livello archivi <p flev> a quello attuale degli archivi standard.
1994-09-27 10:19:36 +00:00
{
_flds . destroy ( ) ;
_exps . destroy ( ) ;
if ( flev = = 0 ) flev = 199401 ;
else flev + + ;
1998-03-30 13:43:36 +00:00
TConfig conv ( CONFIG_FCONV ) ;
TString16 paragraph ;
TString_array paralist ;
conv . list_paragraphs ( paralist ) ;
1995-03-22 09:07:04 +00:00
for ( long l = flev ; l < = get_std_level ( ) ; l + + )
1994-09-27 10:19:36 +00:00
{
1998-03-30 13:43:36 +00:00
paragraph . format ( " %06ld " , l ) ;
if ( paralist . find ( paragraph ) < 0 )
continue ;
1994-09-27 10:19:36 +00:00
1998-03-30 13:43:36 +00:00
if ( conv . set_paragraph ( 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 ) ) ) ;
1998-08-25 18:07:30 +00:00
f . write ( e . as_string ( ) , rec ) ;
1994-09-27 10:19:36 +00:00
}
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Esegue la conversione del tracciato record del file
//
// @rdesc Ritorna il risulato della conversione, altrimenti il codice di errore generato
1995-12-29 12:09:48 +00:00
// (vedi <t TIsamerr>)
1998-03-30 13:43:36 +00:00
1995-12-12 17:47:56 +00:00
int TSystemisamfile : : update (
1996-09-26 15:26:47 +00:00
const TTrec & newrec , // @parm Nuovo tracciato record con cui aggiornare il file
1995-12-12 17:47:56 +00:00
bool vis ) // @parm Indica se visualizzare lo stato dell'operazione
1994-08-22 11:10:49 +00:00
1995-04-10 15:28:03 +00:00
{
1998-03-30 13:43:36 +00:00
CHECK ( newrec . len ( ) ! = 0 , " Can't update file with empty field info " ) ;
int err = NOERR ;
1995-07-20 09:10:38 +00:00
1996-09-26 15:26:47 +00:00
TTrec wrec ( newrec ) ;
1995-12-12 17:47:56 +00:00
TDir dir ;
1994-10-31 16:24:26 +00:00
1995-04-28 13:14:15 +00:00
dir . get ( num ( ) , _unlock , _nordir , _sysdirop ) ;
1995-03-22 09:07:04 +00:00
const bool is_com = prefix ( ) . is_com ( ) ;
1995-02-02 18:08:50 +00:00
const bool toconvert = is_com ? dir . is_com ( ) : dir . is_firm ( ) ;
1994-10-31 16:24:26 +00:00
1994-08-22 11:10:49 +00:00
TTrec oldrec ;
oldrec . get ( num ( ) ) ;
1998-03-30 13:43:36 +00:00
const int lenr = wrec . len ( ) ;
if ( lenr ! = 0 )
1994-11-18 17:39:45 +00:00
{
1995-07-20 09:10:38 +00:00
const long lev = prefix ( ) . filelevel ( ) ;
const bool lcf = getlcf ( lev ) ;
1996-06-17 09:05:05 +00:00
1998-03-30 13:43:36 +00:00
if ( toconvert )
1996-06-17 09:05:05 +00:00
{
1998-03-30 13:43:36 +00:00
err = exec_convapp ( lev , TRUE ) ; // Pre-conversion
if ( err ! = NOERR )
{
setstatus ( err ) ;
return err ;
}
1995-07-03 07:49:30 +00:00
1998-03-30 13:43:36 +00:00
if ( ! lcf & & wrec = = oldrec )
{
err = exec_convapp ( lev , FALSE ) ; // Post-conversion
setstatus ( err ) ;
return err ;
}
1994-08-22 11:10:49 +00:00
}
1998-03-30 13:43:36 +00:00
else
1994-08-22 11:10:49 +00:00
{
1998-03-30 13:43:36 +00:00
if ( dir . eox ( ) > 0L )
{
dir . eod ( ) = 0L ;
dir . eox ( ) = 0L ;
}
1994-08-22 11:10:49 +00:00
}
1998-02-09 11:54:26 +00:00
1998-03-30 13:43:36 +00:00
TFilename fname ;
if ( toconvert )
fname = filename ( ) ;
1998-07-20 13:07:00 +00:00
if ( toconvert ) //&& (dir.eox() > 0L || fname.exist()))
1995-07-20 09:10:38 +00:00
{
TRecnotype ni = 0L ;
1998-03-30 13:43:36 +00:00
TFilename tmpfname ; tmpfname . temp ( " tf " ) ;
1995-07-20 09:10:38 +00:00
1998-03-30 13:43:36 +00:00
err = DB_build ( tmpfname , wrec . rec ( ) ) ;
1998-07-20 13:07:00 +00:00
1995-07-20 09:10:38 +00:00
if ( err ! = NOERR )
{
err = get_error ( err ) ;
return ( err ) ;
}
1998-03-30 13:43:36 +00:00
1998-11-04 18:04:26 +00:00
if ( dir . eod ( ) > 0 & & oldrec . len ( ) > 0 )
1998-03-30 13:43:36 +00:00
{
1998-07-20 13:07:00 +00:00
err = _open_ex ( _excllock ) ;
if ( err ! = NOERR )
return err ;
1998-03-30 13:43:36 +00:00
1998-07-20 13:07:00 +00:00
// Apro il file destinazione in modo esclusivo e senza indici
int tmpnum = num ( ) ;
TIsam_handle ishandle = prefix ( ) . open_isamfile ( tmpnum , tmpfname , TRUE , FALSE ) ;
TCodeb_handle fhnd = prefix ( ) . get_handle ( ishandle ) ;
if ( fhnd < 0 )
{
err = get_error ( fhnd ) ;
return err ;
}
TString s ( 80 ) ;
s . format ( " Aggiornamento archivio %s \n Tempo stimato alla fine del processo: " , ( const char * ) fname ) ;
1998-03-30 13:43:36 +00:00
1998-07-20 13:07:00 +00:00
const TRecnotype nitems = items ( ) ;
TProgind p ( nitems > 0 ? nitems : 1 , s , FALSE , TRUE , 70 ) ;
1998-03-30 13:43:36 +00:00
1998-07-20 13:07:00 +00:00
TExtrectype nrec ( wrec ) ;
1998-03-30 13:43:36 +00:00
1998-07-20 13:07:00 +00:00
const int nflds = curr ( ) . items ( ) ;
TArray infld , outfld ;
for ( int j = 0 ; j < nflds ; j + + )
1997-10-22 12:58:17 +00:00
{
1998-07-20 13:07:00 +00:00
const char * fld_name = curr ( ) . fieldname ( j ) ;
infld . add ( new TRecfield ( curr ( ) , fld_name ) , j ) ;
if ( nrec . exist ( fld_name ) )
outfld . add ( new TRecfield ( nrec , fld_name ) , j ) ;
1997-10-22 12:58:17 +00:00
}
1998-03-30 13:43:36 +00:00
1998-07-20 13:07:00 +00:00
const clock_t start_time = clock ( ) ;
for ( first ( ) ; good ( ) ; next ( ) )
1998-03-30 13:43:36 +00:00
{
1998-07-20 13:07:00 +00:00
const bool tick = p . addstatus ( 1 ) ;
ni + + ;
if ( curr ( ) . isdeleted ( ) )
continue ;
nrec . zero ( ) ;
1998-08-10 10:20:31 +00:00
for ( j = outfld . last ( ) ; j > = 0 ; j = outfld . pred ( j ) )
1998-07-20 13:07:00 +00:00
{
1998-08-10 10:20:31 +00:00
TRecfield * in_fld = ( TRecfield * ) infld . objptr ( j ) ;
TRecfield * out_fld = ( TRecfield * ) outfld . objptr ( j ) ;
if ( in_fld ! = NULL & & out_fld ! = NULL )
{
const char * fld_val = * in_fld ;
* out_fld = fld_val ;
}
1998-07-20 13:07:00 +00:00
}
if ( lcf )
makelc ( ( TRectype & ) nrec ) ;
1998-08-10 10:20:31 +00:00
browse_null ( nrec . string ( ) , lenr ) ;
memcpy ( DB_getrecord ( fhnd ) , nrec . string ( ) , lenr ) ;
1998-07-20 13:07:00 +00:00
err = DB_add ( fhnd ) ;
if ( err = = NOERR & & nrec . has_memo ( ) )
nrec . write_memo ( fhnd , DB_recno ( fhnd ) ) ;
if ( err ! = NOERR )
err = get_error ( err ) ;
setstatus ( err ) ;
if ( tick )
{
const clock_t elapsed_ticks = clock ( ) - start_time ;
const clock_t total_ticks = elapsed_ticks * nitems / ni ;
const clock_t estimated_ticks = total_ticks - elapsed_ticks ;
long secs = estimated_ticks / CLOCKS_PER_SEC ;
CHECK ( secs > = 0 , " Bad time estimation " ) ;
const int hours = int ( secs / 3600L ) ;
secs % = 3600L ;
const int mins = int ( secs / 60L ) ;
secs % = 60L ;
const int append_pos = s . find ( " o: " ) + 3 ;
s . cut ( append_pos ) ;
s < < format ( " %02d:%02d:%02ld " , hours , mins , secs ) ;
p . set_text ( s ) ;
}
1998-03-30 13:43:36 +00:00
}
1998-07-20 13:07:00 +00:00
close ( ) ;
prefix ( ) . close_isamfile ( ishandle ) ;
if ( err ! = NOERR ) err = get_error ( err ) ;
1998-03-30 13:43:36 +00:00
1998-07-20 13:07:00 +00:00
p . setstatus ( nitems ) ;
}
1998-03-30 13:43:36 +00:00
1995-07-20 09:10:38 +00:00
if ( err = = NOERR )
{
long c = DB_getconf ( ) ;
fname . ext ( " dbf " ) ;
tmpfname . ext ( " dbf " ) ;
1998-03-30 13:43:36 +00:00
fcopy ( tmpfname , fname ) ;
: : remove ( tmpfname ) ;
1995-12-15 15:40:37 +00:00
if ( c & 1 )
tmpfname . ext ( " fpt " ) ;
else
tmpfname . ext ( " dbt " ) ;
1998-03-30 13:43:36 +00:00
if ( tmpfname . exist ( ) )
1995-12-05 11:49:39 +00:00
{
1995-12-15 15:40:37 +00:00
if ( c & 1 )
fname . ext ( " fpt " ) ;
else
fname . ext ( " dbt " ) ;
1998-03-30 13:43:36 +00:00
fcopy ( tmpfname , fname ) ;
: : remove ( tmpfname ) ;
1995-12-05 11:49:39 +00:00
}
1995-07-20 09:10:38 +00:00
if ( c & 1 ) // FOXPRO format
tmpfname . ext ( " cdx " ) ;
if ( c & 4 ) // DBIV format
tmpfname . ext ( " mdx " ) ;
if ( c & 8 | | c & 2 )
{
tmpfname . ext ( " cgp " ) ;
1998-03-30 13:43:36 +00:00
TFilename a ;
FILE * fp = fopen ( tmpfname , " rb " ) ;
while ( fgets ( a . get_buffer ( ) , 16 , fp ) ! = NULL )
1995-07-20 09:10:38 +00:00
{
a . rtrim ( 1 ) ; // Cut \n
if ( c & 8 ) // DBIII format
a . ext ( " ndx " ) ;
else
a . ext ( " ntx " ) ; // CLIPPER format
1998-03-30 13:43:36 +00:00
: : remove ( a ) ;
1995-07-20 09:10:38 +00:00
}
fclose ( fp ) ;
1995-07-03 07:49:30 +00:00
}
1998-03-30 13:43:36 +00:00
: : remove ( tmpfname ) ;
1995-07-20 09:10:38 +00:00
dir . eod ( ) = ni ;
1995-07-03 07:49:30 +00:00
}
}
1998-04-30 15:31:34 +00:00
if ( err = = NOERR )
{
dir . set_len ( lenr ) ;
dir . put ( num ( ) , _nordir , _sysdirop ) ;
wrec . put ( num ( ) ) ;
prefix ( ) . update_recdes ( num ( ) ) ;
if ( toconvert )
1998-07-20 13:07:00 +00:00
packindex ( ) ;
1998-08-25 18:07:30 +00:00
if ( err = = NOERR )
err = exec_convapp ( lev , FALSE ) ; // Post - conversion
1998-03-30 13:43:36 +00:00
}
1994-08-22 11:10:49 +00:00
}
1998-03-30 13:43:36 +00:00
1995-07-03 07:49:30 +00:00
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Rimuove fisicamente i record cancellati
//
// @rdesc Ritorna NOERR se l'operazione di compattamento e' riuscita, altrimenti il codice di
1995-12-29 12:09:48 +00:00
// di errore generato (vedi <t TIsamerr>).
1995-12-12 17:47:56 +00:00
int TSystemisamfile : : packfile (
1998-01-28 08:29:13 +00:00
bool vis , // @parm Indica se visualizzare lo stato dell'operazione
bool zap ) // @parm Indica se distruggere tutti i records
1994-08-12 10:52:49 +00:00
1995-12-12 17:47:56 +00:00
// @xref <mf TSystemisamfile::packindex>
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
{
TDir d ;
1998-08-10 10:20:31 +00:00
d . get ( num ( ) , _nolock , _nordir , _sysdirop ) ; // Chi commenta muore!
1995-07-20 09:10:38 +00:00
d . get ( num ( ) , _nolock , ( d . is_com ( ) ) ? _comdir : _nordir ) ;
1998-03-30 13:43:36 +00:00
// CHECKS(filehnd() == NULL, "Can't pack open file", (const char*)filename());
1998-08-10 10:20:31 +00:00
int err = DB_packfile ( vis , d . name ( ) , zap ? 0L : d . eod ( ) ) ;
1998-01-28 08:29:13 +00:00
if ( zap & & err = = NOERR )
err = packindex ( vis , FALSE ) ;
1996-09-02 14:20:24 +00:00
if ( err = = NOERR & & curr ( ) . has_memo ( ) )
1995-12-06 14:44:14 +00:00
err = DB_packmemo ( vis , d . name ( ) ) ;
1998-01-28 08:29:13 +00:00
if ( err ! = NOERR )
{
err = get_error ( err ) ;
if ( err ! = NOERR )
error_box ( " Errore in compattamento dati. \n File %d : %d " , num ( ) , err ) ;
}
1995-07-03 07:49:30 +00:00
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Rimuove fisicamente gli indici cancellati
//
// @rdesc Ritorna NOERR se l'operazione di compattamento e' riuscita, altrimenti il codice di
1995-12-29 12:09:48 +00:00
// di errore generato (vedi <t TIsamerr>).
1995-12-12 17:47:56 +00:00
int TSystemisamfile : : packindex (
1996-03-28 11:40:04 +00:00
bool vis , // @parm Indica se visualizzare lo stato dell'operazione
bool ask ) // @parm Indica se chiedere il recupero dei record duplicati
1994-08-12 10:52:49 +00:00
1995-12-12 17:47:56 +00:00
// @xref <mf TSystemisamfile::packfile>
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1995-07-03 07:49:30 +00:00
int err = NOERR ;
TRecnotype peod ;
TTrec r ;
TDir d ;
r . get ( num ( ) ) ;
1995-08-03 15:07:29 +00:00
d . get ( num ( ) , _nolock , _nordir , _sysdirop ) ;
bool is_com = d . is_com ( ) ;
d . get ( num ( ) , _nolock , is_com ? _comdir : _nordir ) ;
1996-03-28 11:40:04 +00:00
err = DB_packindex ( vis , d . name ( ) , r . rec ( ) , & peod , ask ) ;
1998-03-30 13:43:36 +00:00
if ( err ! = NOERR )
err = get_error ( err ) ;
if ( err ! = NOERR )
error_box ( " Errore in compattamento indici. \n File %d : %d " , num ( ) , err ) ;
1995-07-03 07:49:30 +00:00
else
if ( peod > = 0 & & peod ! = d . eod ( ) )
{
d . eod ( ) = peod ;
1995-08-03 15:07:29 +00:00
d . put ( num ( ) , is_com ? _comdir : _nordir ) ;
1995-07-03 07:49:30 +00:00
}
setstatus ( err ) ;
1994-08-22 11:10:49 +00:00
return err ;
1994-08-12 10:52:49 +00:00
}
1996-03-28 11:40:04 +00:00
int TSystemisamfile : : pack ( bool vis , bool ask )
1995-07-03 07:49:30 +00:00
{
1998-08-10 10:20:31 +00:00
int err = packfile ( vis ) ;
if ( err = = NOERR )
err = packindex ( vis , ask ) ;
1995-07-03 07:49:30 +00:00
setstatus ( err ) ;
return err ;
}
1994-08-12 10:52:49 +00:00
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Importa un file ascii
//
// @rdesc Ritorna NOERR se l'operazione di lettura e' riuscita, altrimenti il codice di
1995-12-29 12:09:48 +00:00
// di errore generato (vedi <t TIsamerr>).
1995-12-12 17:47:56 +00:00
int TSystemisamfile : : load (
const char * from , // @parm Nome del file da importare
char fs , // @parm Carattere separatore di campo (default <pipe>)
char fd , // @parm Carattere delimitatore di campi (default '\\0')
char rs , // @parm Carattere separatore di record (default '\\n')
bool vis , // @parm Indica se visualizzare lo stato dell'operazione (default TRUE)
1995-12-29 12:09:48 +00:00
bool extended ) // @parm Indica se interpretare alcune stringhe come macro (default FALSE)
// @comm Se <p extended> e' TRUE e trova alcune stringhe col formato %stringa% (es. %frm%)
1996-01-18 18:20:47 +00:00
// ne sostituisce i valori (es. ditta corrente).
1995-12-12 17:47:56 +00:00
// @xref <mf TSystemisamfile::dump>
1994-08-22 11:10:49 +00:00
{
1995-09-20 09:39:06 +00:00
int err = NOERR ;
1998-01-28 08:29:13 +00:00
FILE * fl = fopen ( from , " r " ) ;
1995-09-20 09:39:06 +00:00
if ( fl = = NULL )
1995-08-03 15:07:29 +00:00
{
1998-01-28 08:29:13 +00:00
error_box ( " Impossibile aprire il file %s " , from ) ;
return err = 2 ;
1995-08-03 15:07:29 +00:00
}
1998-08-10 10:20:31 +00:00
TRecnotype r = 0 , e = 0 , nitems = 0 ;
1994-12-02 13:06:39 +00:00
TString16 firm , year , attprev ( " 00000 " ) ;
if ( extended )
{
TDate d ( TODAY ) ;
TLocalisamfile ditte ( LF_NDITTE ) ;
1997-12-17 14:36:43 +00:00
firm . format ( " %05ld " , prefix ( ) . get_codditta ( ) ) ;
1994-12-02 13:06:39 +00:00
year . format ( " %04d " , d . year ( ) ) ;
ditte . zero ( ) ;
ditte . put ( " CODDITTA " , firm ) ;
if ( ditte . read ( ) = = NOERR )
attprev = ditte . get ( " CODATTPREV " ) ;
}
1998-08-10 10:20:31 +00:00
1994-09-27 10:19:36 +00:00
fseek ( fl , 0L , SEEK_END ) ;
1998-08-10 10:20:31 +00:00
nitems = ftell ( fl ) ;
1994-09-27 10:19:36 +00:00
fclose ( fl ) ;
1998-03-30 13:43:36 +00:00
1998-08-10 10:20:31 +00:00
err = _open_ex ( ) ;
if ( err ! = NOERR )
1998-01-28 08:29:13 +00:00
{
1998-08-10 10:20:31 +00:00
error_box ( " Impossibile aprire il file %d " , _logicnum ) ;
return err ;
1998-01-28 08:29:13 +00:00
}
TScanner f ( from ) ;
1994-08-22 11:10:49 +00:00
TToken_string s ( 1024 , fs ) ;
bool fixedlen = ( fs = = ' \0 ' ) ;
int nflds = curr ( ) . items ( ) ;
1998-01-28 08:29:13 +00:00
TString_array 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 " ) )
1998-01-28 08:29:13 +00:00
{
int equal ;
TString key ;
1994-09-27 10:19:36 +00:00
nflds = 0 ;
1998-01-28 08:29:13 +00:00
while ( ( equal = f . line ( ) . find ( ' = ' ) ) > 0 )
1994-09-27 10:19:36 +00:00
{
1998-01-28 08:29:13 +00:00
key = f . token ( ) . left ( equal ) ;
key . trim ( ) ;
if ( key = = " Version " )
1994-09-27 10:19:36 +00:00
{
1998-01-28 08:29:13 +00:00
const long level = atol ( f . token ( ) . mid ( equal + 1 ) ) ;
if ( level > prefix ( ) . filelevel ( ) )
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 , get_std_level ( ) / 100 , get_std_level ( ) % 100 ) ;
lcf = getlcf ( level ) ;
} else
if ( key = = " File " )
1994-09-27 10:19:36 +00:00
{
1998-01-28 08:29:13 +00:00
const int logic = atoi ( f . token ( ) . mid ( equal + 1 ) ) ;
if ( logic ! = num ( ) )
error_box ( " L'archivio %s e' stato generato dal file %d " ,
from , logic ) ;
} else
if ( key = = " Fields " )
{
TToken_string riga = f . token ( ) . mid ( equal + 1 ) ;
TToken_string wfd ( 32 , ' , ' ) ;
FOR_EACH_TOKEN ( riga , fd )
{
wfd = fd ; wfd . strip_spaces ( ) ;
fld . add ( wfd . get ( 0 ) ) ;
len [ nflds ] = wfd . get_int ( ) ;
nflds + + ;
}
}
1994-09-27 10:19:36 +00:00
}
}
1998-03-13 10:25:37 +00:00
if ( nflds = = 0 | | fld . items ( ) = = 0 )
{
nflds = curr ( ) . items ( ) ;
1994-09-27 10:19:36 +00:00
for ( int j = 0 ; j < nflds ; j + + )
{
1998-03-13 10:25:37 +00:00
fld . add ( curr ( ) . fieldname ( j ) , j ) ;
1994-09-27 10:19:36 +00:00
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
}
1998-01-28 08:29:13 +00:00
1994-09-27 10:19:36 +00:00
if ( ! f . paragraph ( " Data " ) )
{
1998-03-13 10:25:37 +00:00
error_box ( " Formato file non valido: manca il paragrafo [Data] " ) ;
1994-09-27 10:19:36 +00:00
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 ;
1998-08-10 10:20:31 +00:00
s1 . format ( " Imp. archivio %d \n %6ld records %6ld errori - %3d " , _logicnum , r , e , last ) ;
1994-09-27 10:19:36 +00:00
TProgind p ( nitems , s1 , TRUE , TRUE , 70 ) ;
1998-01-28 08:29:13 +00:00
for ( s = f . line ( ) ; s . not_empty ( ) & & ! p . iscancelled ( ) ; s = f . line ( ) )
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 )
{
1998-08-10 10:20:31 +00:00
s1 . format ( " Imp. archivio %d \n %6ld records %6ld errori - %3d " , _logicnum , r , e , last ) ;
1994-08-22 11:10:49 +00:00
p . set_text ( s1 ) ;
}
1998-08-10 10:20:31 +00:00
p . setstatus ( f . tellg ( ) ) ;
1994-08-22 11:10:49 +00:00
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 ) ;
}
}
1998-01-28 08:29:13 +00:00
int err = write ( ) ;
if ( err = = _isreinsert )
err = rewrite ( ) ;
if ( err = = NOERR )
r + + ;
1994-08-22 11:10:49 +00:00
else
{
1998-01-28 08:29:13 +00:00
error_box ( " Errore di scrittura alla riga %ld " , r + e + 1 ) ;
1994-08-22 11:10:49 +00:00
e + + ;
last = status ( ) ;
1998-01-28 08:29:13 +00:00
break ;
1994-08-22 11:10:49 +00:00
}
}
1998-08-10 10:20:31 +00:00
s1 . format ( " Imp. archivio %d \n %6ld records %6ld errori - %3d " , _logicnum , r , e , last ) ;
1994-08-22 11:10:49 +00:00
p . set_text ( s1 ) ;
1998-01-28 08:29:13 +00:00
1998-08-10 10:20:31 +00:00
close ( ) ;
1998-01-28 08:29:13 +00:00
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
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Esporta VERSO un file ascii.
//
// @rdesc Ritorna NOERR se l'operazione di esportazione e' riuscita, altrimenti il codice di
1995-12-29 12:09:48 +00:00
// di errore generato (vedi <t TIsamerr>).
1995-12-12 17:47:56 +00:00
int TSystemisamfile : : dump (
const char * to , // @parm Nome del file verso quale esportare
int nkey , // @parm Numero della chiave di ordinamento con cui scaricare i dati (defualt 1)
char fs , // @parm Carattere seperatore di campo (defualt <pipe>)
char fd , // @parm Carattere delimitatore di campo (default '\\0')
char rs , // @parm Carattere separatore di record (default '\\n')
bool vis , // @parm Indica se visualizzare lo stato dell'operazione (defualt TRUE)
bool withdeleted ) // @parm Indica se scaricare anche i record cancellati (dafault FALSE)
// @xref <mf TSystemisamfile::load>
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
FILE * f = fopen ( to , " w " ) ;
if ( f = = NULL )
{
1996-07-10 07:28:26 +00:00
setstatus ( 2 ) ;
return 2 ;
1994-08-22 11:10:49 +00:00
}
1996-07-10 07:28:26 +00:00
if ( withdeleted ) nkey = 0 ;
int err = ferror ( f ) ;
1997-10-16 14:06:40 +00:00
open ( FALSE , nkey ? TRUE : FALSE ) ;
1994-08-22 11:10:49 +00:00
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 ;
1998-03-30 13:43:36 +00:00
// const TRecnotype nitems = nkey ? items() : filehnd()->d->EOD;
const TRecnotype nitems = items ( ) ;
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
1998-01-28 08:29:13 +00:00
fprintf ( f , " [Header] \n Version=%ld \n File=%d " ,
prefix ( ) . filelevel ( ) , num ( ) ) ;
1994-09-27 10:19:36 +00:00
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 ( )
{
}
1994-08-12 10:52:49 +00:00
////////////////////////////////////////////////////////////
// TRectype
////////////////////////////////////////////////////////////
1996-09-26 15:26:47 +00:00
TRectype : : TRectype ( int logicnum )
: _cod ( NULL ) , _memo_data ( NULL ) , _memo_dirty ( NULL )
1994-08-22 11:10:49 +00:00
1995-07-03 07:49:30 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = logicnum ;
1998-03-30 13:43:36 +00:00
_length = prefix ( ) . get_reclen ( logicnum ) ;
_rec = new char [ _length ] ;
1994-09-27 10:19:36 +00:00
* _tab = ' \0 ' ;
1998-03-30 13:43:36 +00:00
if ( _length > 0 )
{
1995-08-03 13:54:45 +00:00
zero ( ) ;
1998-03-30 13:43:36 +00:00
if ( rec_has_memo ( rec_des ( ) ) )
init_memo ( RECORD_NON_FISICO ) ;
}
1995-08-03 13:54:45 +00:00
else
1996-09-26 15:26:47 +00:00
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
1996-09-26 15:26:47 +00:00
TRectype : : TRectype ( const TBaseisamfile * i )
: _cod ( NULL ) , _memo_data ( NULL ) , _memo_dirty ( NULL )
1994-08-12 10:52:49 +00:00
{
1994-08-22 11:10:49 +00:00
_logicnum = i - > num ( ) ;
1998-03-30 13:43:36 +00:00
_length = prefix ( ) . get_reclen ( _logicnum ) ;
_rec = new char [ _length ] ;
* _tab = ' \0 ' ;
if ( _length > 0 )
1996-09-26 15:26:47 +00:00
{
1995-08-03 13:54:45 +00:00
zero ( ) ;
1998-03-30 13:43:36 +00:00
if ( rec_has_memo ( rec_des ( ) ) )
init_memo ( RECORD_NON_FISICO ) ;
}
1995-08-03 13:54:45 +00:00
else
1995-11-22 13:46:11 +00:00
setempty ( TRUE ) ;
1994-08-12 10:52:49 +00:00
}
TRectype : : TRectype ( const TRectype & r )
1998-03-30 13:43:36 +00:00
: _logicnum ( r . _logicnum ) , _cod ( NULL ) ,
_memo_data ( NULL ) , _memo_dirty ( NULL )
1994-08-22 11:10:49 +00:00
1994-08-12 10:52:49 +00:00
{
1996-09-26 15:26:47 +00:00
if ( r . _memo_data )
{
init_memo ( ) ;
* _memo_data = * r . _memo_data ;
CHECK ( r . _memo_dirty , " memo_dirty NULL con memo_data valido " ) ;
* _memo_dirty = * r . _memo_dirty ;
}
1994-08-22 11:10:49 +00:00
_length = r . len ( ) ;
_rec = new char [ _length ] ;
1998-10-01 13:59:39 +00:00
memcpy ( _rec , r . _rec , _length ) ;
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-09-27 10:19:36 +00:00
if ( _cod ! = NULL ) delete _cod ;
1995-08-09 09:54:36 +00:00
if ( _rec ! = NULL ) delete _rec ;
1996-09-26 15:26:47 +00:00
if ( _memo_data ! = NULL ) delete _memo_data ;
if ( _memo_dirty ! = NULL ) delete _memo_dirty ;
1994-08-12 10:52:49 +00:00
}
1996-09-02 14:20:24 +00:00
void TRectype : : unknown_field ( const char * name ) const
{
1998-11-03 10:27:35 +00:00
NFCHECK ( " Il campo '%s' non appartiene al file %d " , name , _logicnum ) ;
1996-09-02 14:20:24 +00:00
}
1998-03-30 13:43:36 +00:00
void TRectype : : write_memo ( int fhnd , const TRecnotype recno )
1996-09-02 14:20:24 +00:00
{
1996-09-26 15:26:47 +00:00
memo_recno ( recno ) ;
CHECK ( _memo_recno > 0 , " Maiale! Non fare le GO con _recno < 0 " ) ;
1998-03-30 13:43:36 +00:00
DB_go ( fhnd , _memo_recno ) ;
1996-09-26 15:26:47 +00:00
RecDes * r = rec_des ( ) ;
for ( int i = _memo_data - > last ( ) ; i > 0 ; i = _memo_data - > pred ( i ) )
1998-03-30 13:43:36 +00:00
DB_memowrite ( fhnd , r - > Fd [ i ] . Name , ( char * ) ( const char * ) _memo_data - > row ( i ) ) ;
* this = ( const char * ) DB_getrecord ( fhnd ) ;
1996-09-26 15:26:47 +00:00
init_memo ( recno ) ;
1996-09-02 14:20:24 +00:00
}
1996-09-26 15:26:47 +00:00
1996-09-02 14:20:24 +00:00
void TRectype : : init_memo ( const TRecnotype recno )
{
1996-09-26 15:26:47 +00:00
memo_recno ( recno ) ;
if ( _memo_data = = NULL )
_memo_data = new TString_array ( ) ;
else
_memo_data - > destroy ( ) ;
if ( _memo_dirty = = NULL )
_memo_dirty = new TBit_array ( ) ;
else
_memo_dirty - > reset ( ) ;
1996-09-02 14:20:24 +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
}
1995-11-10 13:37:28 +00:00
const char * TRectype : : build_key ( int num ) const
{
1996-09-26 15:26:47 +00:00
__build_key ( rec_des ( ) , num , string ( ) , __tmp_string , TRUE ) ;
1995-11-10 13:37:28 +00:00
return __tmp_string ;
}
1995-11-13 12:08:59 +00:00
const char * TRectype : : last_key_field ( int key ) const
{
const KeyDes & kd = rec_des ( ) - > Ky [ key ] ;
const int last = kd . NkFields - 1 ;
const bool upp = kd . FieldSeq [ last ] > MaxFields ;
const int nf = upp ? kd . FieldSeq [ last ] - MaxFields : kd . FieldSeq [ last ] ;
const RecFieldDes & rf = rec_des ( ) - > Fd [ nf ] ;
return rf . Name ;
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-12-12 17:47:56 +00:00
// @mfunc Confronta le chiavi di due record
//
// @rdesc Ritorna il risultato di una <f strcmp>:
//
// @flag 0 | Se le due chiavi sono uguali
// @flag <lt><gt>0 | Se le due chiavi sono diverse
int TRectype : : compare_key (
const TRectype & rec , // @parm Record di cui confrontare le chiavi
int key , // @parm Numero della chiave del presente record (defautl 1)
1996-09-19 10:21:32 +00:00
int skip_last ) const // @parm Numero di campi da ignorare nella comparazione a partire dall'ultimo
1995-12-12 17:47:56 +00:00
// @xref <mf TRectype::build_key>
1995-11-10 13:37:28 +00:00
{
TString256 key1 = build_key ( key ) ;
TString256 key2 = rec . build_key ( key ) ;
1995-11-13 12:08:59 +00:00
if ( skip_last > 0 )
{
const KeyDes & kd = rec_des ( ) - > Ky [ key - 1 ] ;
const int last = kd . NkFields - 1 ;
CHECKD ( last > = skip_last , " Can't ignore so many fields in key: " , skip_last ) ;
for ( int l = 0 ; l < skip_last ; l + + )
{
int nf = kd . FieldSeq [ last - l ] ;
if ( nf > MaxFields ) nf - = MaxFields ;
const RecFieldDes & rf = rec_des ( ) - > Fd [ nf ] ;
key1 . rtrim ( rf . Len ) ;
key2 . rtrim ( rf . Len ) ;
}
}
const int res = strcmp ( key1 , key2 ) ;
return res ;
1995-11-10 13:37:28 +00:00
}
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 ( * 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)
///////////////////////////////////////////////////////////
1997-12-23 11:29:38 +00:00
RecDes * TRectype : : rec_des ( ) const
1997-07-22 09:49:11 +00:00
{
1998-03-30 13:43:36 +00:00
return ( RecDes * ) & prefix ( ) . get_recdes ( _logicnum ) ;
1995-04-10 15:28:03 +00:00
}
1994-08-12 10:52:49 +00:00
int TRectype : : items ( ) const
{
1995-04-10 15:28:03 +00:00
return rec_des ( ) - > NFields ;
1994-08-12 10:52:49 +00:00
}
const char * TRectype : : start ( int nf ) const
{
1995-04-10 15:28:03 +00:00
return string ( ) + rec_des ( ) - > 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 ;
1995-08-09 09:54:36 +00:00
const RecDes & rd = * rec_des ( ) ;
1994-08-12 10:52:49 +00:00
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 ) ;
1995-08-09 09:54:36 +00:00
const byte typ = rd . Fd [ i ] . TypeF ;
const int sz = rd . Fd [ i ] . Len ;
1994-08-22 11:10:49 +00:00
const bool number = ( typ = = _intfld ) | | ( typ = = _realfld ) | |
( typ = = _longfld ) | | ( typ = = _wordfld ) | |
1998-11-03 10:27:35 +00:00
( typ = = _intzerofld ) | | ( typ = = _longzerofld ) | | ( typ = = _datefld ) ;
1994-08-22 11:10:49 +00:00
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
{
1998-03-30 13:43:36 +00:00
const RecDes * recd = rec_des ( ) ;
1998-11-03 10:27:35 +00:00
int p = findfld ( recd , fieldname ) ;
1996-09-26 15:26:47 +00:00
1998-11-03 10:27:35 +00:00
if ( p ! = FIELDERR )
return ( TFieldtypes ) recd - > Fd [ p ] . TypeF ;
else
return _nullfld ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : length ( const char * fieldname ) const
{
1996-09-26 15:26:47 +00:00
const RecDes * recd = rec_des ( ) ;
1998-11-03 10:27:35 +00:00
int p = findfld ( recd , fieldname ) ;
1996-09-26 15:26:47 +00:00
1998-11-03 10:27:35 +00:00
if ( p ! = FIELDERR )
return ( recd - > Fd [ p ] . Len ) ;
else
return ( 0 ) ;
1994-08-12 10:52:49 +00:00
}
int TRectype : : ndec ( const char * fieldname ) const
{
1996-09-26 15:26:47 +00:00
const RecDes * recd = rec_des ( ) ;
1998-11-03 10:27:35 +00:00
int p = findfld ( recd , fieldname ) ;
1996-09-26 15:26:47 +00:00
1998-11-03 10:27:35 +00:00
if ( p ! = FIELDERR )
return ( recd - > Fd [ p ] . Dec ) ;
else
return ( 0 ) ;
1994-08-12 10:52:49 +00:00
}
bool TRectype : : exist ( const char * fieldname ) const
1996-09-26 15:26:47 +00:00
{
1998-11-03 10:27:35 +00:00
const bool ok = findfld ( rec_des ( ) , fieldname ) ! = FIELDERR ;
1996-09-26 15:26:47 +00:00
return ok ;
1994-08-12 10:52:49 +00:00
}
const char * TRectype : : fieldname ( int i ) const
{
1996-09-26 15:26:47 +00:00
const RecDes * recd = rec_des ( ) ;
return i > = 0 & & i < recd - > NFields ? recd - > Fd [ i ] . Name : NULL ;
}
1994-08-12 10:52:49 +00:00
1998-03-30 13:43:36 +00:00
const TString & TRectype : : get_str ( const char * fieldname ) const
1996-09-26 15:26:47 +00:00
{
1996-09-02 14:20:24 +00:00
char * s = _isam_string ;
static TFixed_string tmp ( _isam_string , sizeof ( _isam_string ) ) ;
1996-09-26 15:26:47 +00:00
const RecDes * recd = rec_des ( ) ;
int nf = findfld ( recd , fieldname ) ;
1995-04-20 14:35:14 +00:00
1996-09-26 15:26:47 +00:00
if ( nf = = FIELDERR )
{
unknown_field ( fieldname ) ;
* s = ' \0 ' ;
1995-04-20 14:35:14 +00:00
}
else
1996-09-26 15:26:47 +00:00
__getfieldbuff ( recd - > Fd [ nf ] . Len , recd - > Fd [ nf ] . TypeF ,
_rec + recd - > Fd [ nf ] . RecOff , s ) ;
1996-09-02 14:20:24 +00:00
return tmp ;
1995-04-20 14:35:14 +00:00
}
1994-08-12 10:52:49 +00:00
# ifndef FOXPRO
1995-04-20 14:35:14 +00:00
const TString & TRectype : : get ( const char * fieldname ) const
{
1996-09-26 15:26:47 +00:00
if ( type ( fieldname ) = = _memofld )
1995-11-22 13:46:11 +00:00
{
1996-09-26 15:26:47 +00:00
int index ( findfld ( rec_des ( ) , ( char * ) fieldname ) ) ;
if ( _memo_data - > objptr ( index ) & & ( * _memo_dirty ) [ index ] )
return _memo_data - > row ( index ) ;
if ( _memo_recno > = 0L )
{
1998-03-30 13:43:36 +00:00
TFilename fname ;
int lnum = num ( ) ;
TIsam_handle isam_handle = prefix ( ) . open_isamfile ( lnum , fname ) ;
TCodeb_handle cb_handle = prefix ( ) . get_handle ( isam_handle ) ;
CHECKD ( cb_handle > = 0 , " Can't read memo from file " , lnum ) ;
DB_go ( cb_handle , _memo_recno ) ;
_memo_data - > add ( DB_memoptr ( cb_handle , fieldname ) , index ) ;
prefix ( ) . close_isamfile ( isam_handle ) ;
1996-09-26 15:26:47 +00:00
}
else
_memo_data - > add ( " " , index ) ;
return _memo_data - > row ( index ) ;
1995-11-22 13:46:11 +00:00
}
1996-09-26 15:26:47 +00:00
return get_str ( fieldname ) ;
1995-04-20 14:35:14 +00:00
}
1994-08-12 10:52:49 +00:00
int TRectype : : get_int ( const char * fieldname ) const
{
1996-09-26 15:26:47 +00:00
1996-09-02 14:20:24 +00:00
return atoi ( get_str ( fieldname ) ) ;
1994-08-12 10:52:49 +00:00
}
long TRectype : : get_long ( const char * fieldname ) const
{
1996-09-02 14:20:24 +00:00
return atol ( get_str ( fieldname ) ) ;
1994-08-12 10:52:49 +00:00
}
word TRectype : : get_word ( const char * fieldname ) const
{
1996-09-02 14:20:24 +00:00
return ( word ) atoi ( get_str ( fieldname ) ) ;
1994-08-12 10:52:49 +00:00
}
real TRectype : : get_real ( const char * fieldname ) const
{
1996-09-02 14:20:24 +00:00
real r ( get_str ( fieldname ) ) ;
1994-08-22 11:10:49 +00:00
return r ;
1994-08-12 10:52:49 +00:00
}
char TRectype : : get_char ( const char * fieldname ) const
{
1996-09-02 14:20:24 +00:00
return * ( get_str ( fieldname ) ) ;
1994-08-12 10:52:49 +00:00
}
bool TRectype : : get_bool ( const char * fieldname ) const
{
1996-09-02 14:20:24 +00:00
return * ( get_str ( fieldname ) ) = = ' X ' ;
1994-08-12 10:52:49 +00:00
}
1996-02-05 19:00:53 +00:00
// @doc EXTERNAL
1995-06-12 10:49:19 +00:00
1995-12-12 17:47:56 +00:00
// @mfunc Ritorna il contenuto di un campo memo
//
// @rdesc Ritorna sempre TRUE
bool TRectype : : get_memo (
const char * fieldname , // @parm Nome del campo da cui estrarre il contenuto
TTextfile & txt ) const // @parm Reference della variabile a cui assegnare il contenuto dell campo
1995-06-12 10:49:19 +00:00
{
1995-11-22 13:46:11 +00:00
TToken_string memo ( get ( fieldname ) , ' \n ' ) ;
1996-07-15 07:14:58 +00:00
const int last = memo . items ( ) ;
for ( int i = 0 ; i < last ; i + + )
{
TString m ( memo . get ( i ) ) ;
const int l = m . len ( ) > 0 ? m . len ( ) - 1 : 0 ;
if ( m [ l ] = = ' \r ' ) m . cut ( l ) ;
txt . append ( m ) ;
}
1995-11-22 13:46:11 +00:00
return TRUE ;
1995-06-12 10:49:19 +00:00
}
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
TDate TRectype : : get_date ( const char * fieldname ) const
{
1996-09-02 14:20:24 +00:00
TDate d ( get_str ( fieldname ) ) ;
1995-10-30 10:19:44 +00:00
return d ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
void TRectype : : put ( const char * fieldname , int val )
1996-09-26 15:26:47 +00:00
{
1996-09-02 14:20:24 +00:00
sprintf ( _isam_string , " %d " , val ) ;
put_str ( fieldname , _isam_string ) ;
1994-08-12 10:52:49 +00:00
setempty ( FALSE ) ;
}
void TRectype : : put ( const char * fieldname , long val )
{
1996-09-02 14:20:24 +00:00
sprintf ( _isam_string , " %ld " , val ) ;
put_str ( fieldname , _isam_string ) ;
1994-08-12 10:52:49 +00:00
setempty ( FALSE ) ;
}
1995-06-13 08:23:45 +00:00
void TRectype : : put ( const char * fieldname , TTextfile & txt )
1995-06-12 10:49:19 +00:00
{
long val = get_long ( fieldname ) ;
1998-03-30 13:43:36 +00:00
const bool isnew = val = = 0 ;
TFilename fname ;
int logicnum = num ( ) ;
TIsam_handle isam_handle = prefix ( ) . open_isamfile ( logicnum , fname ) ;
1995-06-12 10:49:19 +00:00
1998-03-30 13:43:36 +00:00
TMemo_file memo ( fname ) ;
prefix ( ) . close_isamfile ( isam_handle ) ;
1995-06-12 10:49:19 +00:00
1998-03-30 13:43:36 +00:00
const long id = memo . set_field ( txt , isnew ? FIELDERR : val ) ;
1995-06-22 09:30:05 +00:00
if ( isnew ) val = id ;
1996-09-02 14:20:24 +00:00
sprintf ( _isam_string , " %ld " , val ) ;
put_str ( fieldname , _isam_string ) ;
1995-06-12 10:49:19 +00:00
setempty ( FALSE ) ;
}
1994-08-12 10:52:49 +00:00
void TRectype : : put ( const char * fieldname , word val )
{
1996-09-02 14:20:24 +00:00
sprintf ( _isam_string , " %u " , val ) ;
put_str ( fieldname , _isam_string ) ;
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 )
{
1996-09-02 14:20:24 +00:00
put_str ( fieldname , val . string ( ) ) ;
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 TDate & val )
1995-10-30 10:19:44 +00:00
{
1996-09-26 15:26:47 +00:00
put_str ( fieldname , val . string ( full ) ) ;
1994-08-22 11:10:49 +00:00
setempty ( FALSE ) ;
1994-08-12 10:52:49 +00:00
}
void TRectype : : put ( const char * fieldname , char val )
{
1996-09-26 15:26:47 +00:00
const char w [ 2 ] = { val , ' \0 ' } ;
1994-08-12 10:52:49 +00:00
1996-09-02 14:20:24 +00:00
put_str ( fieldname , w ) ;
1994-08-12 10:52:49 +00:00
setempty ( FALSE ) ;
}
void TRectype : : put ( const char * fieldname , bool val )
{
1997-07-30 17:08:44 +00:00
char s [ 2 ] = { val ? ' X ' : ' ' , ' \0 ' } ;
1996-09-02 14:20:24 +00:00
put_str ( fieldname , s ) ;
1994-08-12 10:52:49 +00:00
setempty ( FALSE ) ;
}
# endif // FOXPRO
1996-09-02 14:20:24 +00:00
void TRectype : : put_str ( const char * fieldname , const char * val )
1996-05-30 13:53:00 +00:00
{
1998-03-30 13:43:36 +00:00
const RecDes * recd = rec_des ( ) ;
const int nf = findfld ( recd , fieldname ) ;
if ( nf = = FIELDERR )
1998-11-03 10:27:35 +00:00
{
1998-03-30 13:43:36 +00:00
unknown_field ( fieldname ) ;
1998-11-03 10:27:35 +00:00
return ;
}
1998-03-30 13:43:36 +00:00
const TFieldtypes ft = ( TFieldtypes ) recd - > Fd [ nf ] . TypeF ;
1996-09-26 15:26:47 +00:00
if ( val = = NULL )
val = " " ;
if ( ft = = _boolfld )
1996-12-13 08:07:49 +00:00
val = ( * val & & strchr ( " 1STXY " , toupper ( * val ) ) ! = NULL ) ? " T " : " F " ;
1996-05-30 13:53:00 +00:00
if ( * val = = ' \0 ' ) // Da provare
1994-08-22 11:10:49 +00:00
{
TRecfield f ( * this , fieldname ) ;
if ( * f . pos ( ) = = ' \0 ' ) return ;
}
1994-08-12 10:52:49 +00:00
1998-03-30 13:43:36 +00:00
if ( ft = = _memofld )
1995-11-22 13:46:11 +00:00
{
1998-03-30 13:43:36 +00:00
_memo_dirty - > set ( nf ) ;
_memo_data - > add ( val , nf ) ;
1996-09-26 15:26:47 +00:00
}
1994-08-22 11:10:49 +00:00
else
1995-07-03 07:49:30 +00:00
{
1998-03-30 13:43:36 +00:00
__putfieldbuff ( recd - > Fd [ nf ] . Len , recd - > Fd [ nf ] . Dec , ft , val ,
1996-09-26 15:26:47 +00:00
_rec + recd - > Fd [ nf ] . RecOff ) ;
1995-07-03 07:49:30 +00:00
}
1994-08-22 11:10:49 +00:00
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-09-27 10:19:36 +00:00
if ( _cod ! = NULL & & strcmp ( fieldname , " COD " ) = = 0 )
* _cod = _tab ;
1996-09-26 15:26:47 +00:00
else
1995-06-15 10:30:27 +00:00
{
1996-09-26 15:26:47 +00:00
const RecDes * recd = rec_des ( ) ;
int nf = findfld ( recd , fieldname ) ;
if ( nf = = FIELDERR )
unknown_field ( fieldname ) ;
else
1995-06-15 10:30:27 +00:00
{
1996-09-26 15:26:47 +00:00
const int recoff = recd - > Fd [ nf ] . RecOff ;
char * p = _rec + recoff ;
const byte len = recd - > Fd [ nf ] . Len ;
const byte dec = recd - > Fd [ nf ] . Dec ;
const TFieldtypes type = ( TFieldtypes ) recd - > Fd [ nf ] . TypeF ;
if ( type = = _datefld )
__putfieldbuff ( len , dec , _datefld , " " , p ) ;
else
{
memset ( p , ' ' , len ) ;
if ( ( type = = _intfld ) | | ( type = = _longfld ) | | ( type = = _wordfld ) )
* ( p + len - 1 ) = ' 0 ' ;
else
if ( type = = _realfld )
{
if ( dec )
{
memset ( p + len - dec - 2 , ' 0 ' , dec + 2 ) ;
* ( p + len - dec - 1 ) = ' . ' ;
}
else
* ( p + len - 1 ) = ' 0 ' ;
}
}
1995-06-15 10:30:27 +00:00
}
1995-11-22 13:46:11 +00:00
}
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
recall ( ) ;
memset ( _rec + 1 , c , len ( ) - 1 ) ;
1994-12-28 15:01:04 +00:00
1994-09-27 10:19:36 +00:00
if ( _cod ! = NULL )
1995-11-22 13:46:11 +00:00
* _cod = _tab ;
1996-09-26 15:26:47 +00:00
if ( has_memo ( ) )
init_memo ( RECORD_NON_FISICO ) ;
1994-08-22 11:10:49 +00:00
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 " ) ;
1996-01-03 15:54:04 +00:00
memcpy ( _rec , rec . _rec , _length ) ; // Copy contents
1996-09-26 15:26:47 +00:00
if ( rec . _memo_data )
{
init_memo ( rec . _memo_recno ) ; // ??
* _memo_data = * rec . _memo_data ;
CHECK ( rec . _memo_dirty , " memo_dirty NULL con memo_data valido " ) ;
* _memo_dirty = * rec . _memo_dirty ;
1996-01-03 15:54:04 +00:00
}
1994-08-12 10:52:49 +00:00
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
}
1998-03-30 13:43:36 +00:00
// Certified 50%
1997-06-02 10:06:58 +00:00
int TRectype : : read ( TBaseisamfile & f , word op , word lockop )
1997-05-23 14:02:46 +00:00
{
1998-08-10 10:20:31 +00:00
int err = f . _read ( * this , op , lockop ) ;
return err ;
1997-05-23 14:02:46 +00:00
}
int TRectype : : readat ( TBaseisamfile & f , TRecnotype nrec , word lockop )
{
1997-06-02 10:06:58 +00:00
return f . _readat ( * this , nrec , lockop ) ;
1997-05-23 14:02:46 +00:00
}
1995-08-09 09:54:36 +00:00
// Certified 100%
1997-05-23 14:02:46 +00:00
int TRectype : : next ( TBaseisamfile & f , word lockop )
1995-08-09 09:54:36 +00:00
{
1997-12-02 12:05:16 +00:00
/* const int err = f._read(*this, _isnext, lockop);
1995-08-09 09:54:36 +00:00
* this = f . curr ( ) ;
1997-12-02 12:05:16 +00:00
return err ; */
return read ( f , _isnext , lockop ) ;
}
// Certified 100%
int TRectype : : prev ( TBaseisamfile & f , word lockop )
{
return read ( f , _isprev , lockop ) ;
}
int TRectype : : first ( TBaseisamfile & f , word lockop )
{
return read ( f , _isfirst , lockop ) ;
}
int TRectype : : last ( TBaseisamfile & f , word lockop )
{
return read ( f , _islast , lockop ) ;
1995-08-09 09:54:36 +00:00
}
1997-05-23 14:02:46 +00:00
// Certified ??%
1997-06-02 10:06:58 +00:00
int TRectype : : write ( TBaseisamfile & f ) const
{ return f . _write ( * this ) ; }
1995-08-09 09:54:36 +00:00
1997-05-23 14:02:46 +00:00
// Certified ??%
1997-06-02 10:06:58 +00:00
int TRectype : : rewrite ( TBaseisamfile & f ) const
1995-08-09 09:54:36 +00:00
{
1997-06-02 10:06:58 +00:00
return f . _rewrite ( * this ) ;
1995-08-09 09:54:36 +00:00
}
1997-05-23 14:02:46 +00:00
// Certified ??%
1997-06-02 10:06:58 +00:00
int TRectype : : remove ( TBaseisamfile & f ) const
1995-08-09 09:54:36 +00:00
{
1997-06-02 10:06:58 +00:00
return f . _remove ( * this ) ;
1995-08-09 09:54:36 +00:00
}
1994-08-12 10:52:49 +00:00
1995-09-19 15:45:42 +00:00
void TRectype : : renum_key ( const char * field , const char * val )
{
put ( field , val ) ;
}
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
{
1996-09-26 15:26:47 +00:00
__build_key ( rec_des ( ) , numkey , _rec , _isam_string , FALSE ) ;
1995-04-10 15:28:03 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
///////////////////////////////////////////////////////////
// TRecfield (campo/sottocampo di un record)
///////////////////////////////////////////////////////////
void TRecfield : : set ( int from , int to )
{
1998-11-03 10:27:35 +00:00
const RecDes * rd = _rec - > rec_des ( ) ;
const int nf = findfld ( rd , _name ) ;
if ( nf = = FIELDERR )
1994-08-22 11:10:49 +00:00
{
1998-11-03 10:27:35 +00:00
NFCHECK ( " File n. %d unknown field %s " , _rec - > num ( ) , _name ) ;
_p = _isam_string ;
_len = 50 ;
1994-08-22 11:10:49 +00:00
_dec = 0 ;
1998-11-03 10:27:35 +00:00
_type = _alfafld ;
1994-08-22 11:10:49 +00:00
}
else
{
1998-11-03 10:27:35 +00:00
if ( from < 0 )
{
NFCHECK ( " Invalid Start %d " , from ) ;
from = 0 ;
}
1995-04-10 15:28:03 +00:00
_p = _rec - > string ( ) + rd - > Fd [ nf ] . RecOff + from ;
_dec = rd - > Fd [ nf ] . Dec ;
1996-05-08 11:09:13 +00:00
_type = ( TFieldtypes ) rd - > Fd [ nf ] . TypeF ;
1994-08-22 11:10:49 +00:00
if ( to > = 0 )
{
1995-08-09 09:54:36 +00:00
CHECK ( from < = to & & to < = rd - > Fd [ nf ] . Len , " Invalid Range " ) ;
1994-08-22 11:10:49 +00:00
_len = to - from + 1 ;
}
1998-11-03 10:27:35 +00:00
else
_len = rd - > Fd [ nf ] . Len - from ;
1994-08-22 11:10:49 +00:00
}
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 ) ;
_rec = & rec ;
set ( from , to ) ;
1994-08-12 10:52:49 +00:00
}
int TRecfield : : operator = ( int i )
{
1998-11-03 10:27:35 +00:00
char buff [ 16 ] ;
sprintf ( buff , " %d " , i ) ;
__putfieldbuff ( _len , _dec , _type , buff , _p ) ;
1994-08-22 11:10:49 +00:00
_rec - > setempty ( FALSE ) ;
return i ;
1994-08-12 10:52:49 +00:00
}
long TRecfield : : operator = ( long l )
{
1998-11-03 10:27:35 +00:00
char buff [ 16 ] ;
sprintf ( buff , " %ld " , l ) ;
__putfieldbuff ( _len , _dec , _type , buff , _p ) ;
1994-08-22 11:10:49 +00:00
_rec - > setempty ( FALSE ) ;
return l ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
1995-05-09 13:33:34 +00:00
1994-08-12 10:52:49 +00:00
const real & TRecfield : : operator = ( const real & r )
{
1998-11-03 10:27:35 +00:00
char buff [ 80 ] ;
strcpy ( buff , r . string ( ) ) ;
__putfieldbuff ( _len , _dec , _type , buff , _p ) ;
1994-08-22 11:10:49 +00:00
_rec - > setempty ( FALSE ) ;
return r ;
1994-08-12 10:52:49 +00:00
}
1995-04-20 14:35:14 +00:00
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
const TDate & TRecfield : : operator = ( const TDate & d )
{
1998-11-03 10:27:35 +00:00
char buff [ 16 ] ;
strcpy ( buff , ( const char * ) d ) ;
__putfieldbuff ( _len , _dec , _type , buff , _p ) ;
1994-08-22 11:10:49 +00:00
_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
{
1996-12-02 11:01:06 +00:00
if ( _type = = _intfld | | _type = = _intzerofld | | _type = = _longfld | | _type = = _longzerofld )
{
strncpy ( _isam_string , _p , _len ) ;
_isam_string [ _len ] = ' \0 ' ;
}
else
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
return atoi ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator long ( ) const
{
1996-12-02 11:01:06 +00:00
if ( _type = = _longfld | | _type = = _longzerofld | | _type = = _intfld | | _type = = _intzerofld )
{
strncpy ( _isam_string , _p , _len ) ;
_isam_string [ _len ] = ' \0 ' ;
}
else
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
return atol ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
# ifndef FOXPRO
1995-05-09 13:33:34 +00:00
TRecfield : : operator const real ( ) const
1994-08-12 10:52:49 +00:00
{
1996-12-02 11:01:06 +00:00
if ( _type = = _realfld )
{
strncpy ( _isam_string , _p , _len ) ;
_isam_string [ _len ] = ' \0 ' ;
}
else
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
real r ( _isam_string ) ;
1994-08-22 11:10:49 +00:00
return r ;
1994-08-12 10:52:49 +00:00
}
1995-05-09 13:33:34 +00:00
1994-08-12 10:52:49 +00:00
# endif // FOXPRO
TRecfield : : operator TDate ( ) const
1996-12-02 11:01:06 +00:00
{
if ( _type = = _datefld )
{
strncpy ( _isam_string , _p , 8 ) ;
_isam_string [ 8 ] = ' \0 ' ;
return TDate ( atol ( _isam_string ) ) ;
}
1995-10-30 10:19:44 +00:00
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1996-12-02 11:01:06 +00:00
return TDate ( _isam_string ) ;
1994-08-12 10:52:49 +00:00
}
TRecfield : : operator const char * ( ) const
1996-05-08 11:09:13 +00:00
{
if ( _type = = _memofld )
return _rec - > get ( _name ) ;
__getfieldbuff ( _len , _type , _p , _isam_string ) ;
1995-04-10 15:28:03 +00:00
return _isam_string ;
1994-08-12 10:52:49 +00:00
}
TRecnotype TRecfield : : ptr ( ) const
{
1995-11-22 13:46:11 +00:00
if ( _p = = NULL ) return ( RECORD_NON_FISICO ) ;
1994-08-22 11:10:49 +00:00
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
}