diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 0315353660..d613f37918 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,12 @@ +19990818-14:13 GMT+1 Bruno Cantero + * include/rddapi.h + source/rdd/dbcmd.c + source/rdd/dbf1.c + source/rdd/sdf1.c + source/rdd/delim1.c + source/rdd/dbfntx/dbfntx1.c + Added new functions + 19990818-03:00 GMT+1 Victor Szel * source/compiler/harbour.y diff --git a/harbour/include/rddapi.h b/harbour/include/rddapi.h index 15abdd0de6..e5382bb919 100644 --- a/harbour/include/rddapi.h +++ b/harbour/include/rddapi.h @@ -156,6 +156,25 @@ typedef struct typedef DBOPENINFO * LPDBOPENINFO; +/* +* DBEXTENDINFO +* ------------ +* Additional properties +*/ + +typedef struct +{ + USHORT uiHeaderLen; /* Size of header */ + USHORT uiRecordLen; /* Size of record */ + BYTE * bRecord; /* Buffer of the data */ + BYTE * bOldRecord; /* Buffer of the data for undelete */ + BOOL fHasMemo; /* Work Area with Memo fields */ + PHB_ITEM pRecNo; /* Current record */ +} DBEXTENDINFO; + +typedef DBEXTENDINFO * LPDBEXTENDINFO; + + /* * DBORDERCONDINFO * --------------- @@ -509,10 +528,12 @@ typedef struct _AREA BOOL fTop; /* TRUE if "top" */ BOOL fBottom; /* TRUE if "bottom" */ +#endif BOOL fBof; /* TRUE if "bof" */ BOOL fEof; /* TRUE if "eof" */ BOOL fFound; /* TRUE if "found" */ +#if 0 DBSCOPEINFO dbsi; /* Info regarding last LOCATE */ DBFILTERINFO dbfi; /* Filter in effect */ @@ -528,6 +549,7 @@ typedef struct _AREA USHORT rddID; LPFILEINFO lpFileInfo; /* Files used by this workarea */ + LPDBEXTENDINFO lpExtendInfo; /* Additional properties */ } AREA; @@ -549,11 +571,11 @@ typedef USHORT ( * DBENTRYP_VF )( AREAP area, LPDBFIELDINFO param ); typedef USHORT ( * DBENTRYP_SP )( AREAP area, USHORT * param ); typedef USHORT ( * DBENTRYP_P )( AREAP area, BYTE * param ); typedef USHORT ( * DBENTRYP_S )( AREAP area, USHORT param ); +typedef USHORT ( * DBENTRYP_LP )( AREAP area, LONG * param ); +typedef USHORT ( * DBENTRYP_SVP )( AREAP area, USHORT index, void * param ); #if 0 -typedef USHORT ( * DBENTRYP_LP )( AREAP area, LONGP param); typedef USHORT ( * DBENTRYP_PP )( AREAP area, void ** param); -typedef USHORT ( * DBENTRYP_SVP )( AREAP area, USHORT index, void * param); typedef USHORT ( * DBENTRYP_SVPB )( AREAP area, USHORT index, void * param, USHORT mode); typedef USHORT ( * DBENTRYP_VPL )( AREAP area, void * p1, LONG p2); typedef USHORT ( * DBENTRYP_VPLP )( AREAP area, void * p1, LONGP p2); @@ -600,23 +622,31 @@ typedef struct _RDDFUNCS #if 0 DBENTRYP_V deleterec; DBENTRYP_SP deleted; +#endif DBENTRYP_SP fieldCount; +#if 0 DBENTRYP_VP fieldDisplay; DBENTRYP_SSI fieldInfo; +#endif DBENTRYP_SVP fieldName; +#if 0 DBENTRYP_V flush; DBENTRYP_PP getRec; +#endif DBENTRYP_SI getValue; +#if 0 DBENTRYP_SVP getVarLen; DBENTRYP_V goCold; DBENTRYP_V goHot; DBENTRYP_VP putRec; DBENTRYP_SI putValue; DBENTRYP_V recall; - DBENTRYP_LP reccount; - DBENTRYP_ISI recInfo; - DBENTRYP_I recno; #endif + DBENTRYP_LP reccount; +#if 0 + DBENTRYP_ISI recInfo; +#endif + DBENTRYP_I recno; DBENTRYP_S setFieldExtent; /* WorkArea/Database management */ @@ -703,12 +733,12 @@ typedef struct _RDDFUNCS DBENTRYP_SVPB getValueFile; DBENTRYP_VP openMemFile; DBENTRYP_SVP putValueFile; +#endif /* Database file header handling */ DBENTRYP_V readDBHeader; -#endif DBENTRYP_V writeDBHeader; diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index 471c7ad8e1..f493a3e160 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -24,8 +24,8 @@ #include #include "extend.h" -#include "init.h" #include "itemapi.h" +#include "init.h" #include "errorapi.h" #include "rddapi.h" #include "set.h" @@ -34,6 +34,7 @@ #include "set.ch" #define HARBOUR_MAX_RDD_DRIVERNAME_LENGTH 32 +#define HARBOUR_MAX_RDD_FIELDNAME_LENGTH 32 typedef struct _RDDNODE { @@ -77,13 +78,19 @@ HARBOUR HB_DBSKIP( void ); HARBOUR HB_DBUSEAREA( void ); HARBOUR HB_DELIM( void ); HARBOUR HB_EOF( void ); +HARBOUR HB_FIELDCOUNT( void ); +HARBOUR HB_FIELDGET( void ); +HARBOUR HB_FIELDNAME( void ); HARBOUR HB_FOUND( void ); +HARBOUR HB_LASTREC( void ); HARBOUR HB_RDDLIST( void ); HARBOUR HB_RDDNAME( void ); HARBOUR HB_RDDREGISTER( void ); HARBOUR HB_RDDSETDEFAULT( void ); HARBOUR HB_RDDSHUTDOWN( void ); HARBOUR HB_RDDSYS( void ); +HARBOUR HB_RECCOUNT( void ); +HARBOUR HB_RECNO( void ); HARBOUR HB_SDF( void ); HB_INIT_SYMBOLS_BEGIN( dbCmd__InitSymbols ) @@ -100,12 +107,18 @@ HB_INIT_SYMBOLS_BEGIN( dbCmd__InitSymbols ) { "DBSKIP", FS_PUBLIC, HB_DBSKIP, 0 }, { "DBUSEAREA", FS_PUBLIC, HB_DBUSEAREA, 0 }, { "EOF", FS_PUBLIC, HB_EOF, 0 }, +{ "FIELDCOUNT", FS_PUBLIC, HB_FIELDCOUNT, 0 }, +{ "FIELDGET", FS_PUBLIC, HB_FIELDGET, 0 }, +{ "FIELDNAME", FS_PUBLIC, HB_FIELDNAME, 0 }, { "FOUND", FS_PUBLIC, HB_FOUND, 0 }, +{ "LASTREC", FS_PUBLIC, HB_LASTREC, 0 }, { "RDDLIST", FS_PUBLIC, HB_RDDLIST, 0 }, { "RDDNAME", FS_PUBLIC, HB_RDDNAME, 0 }, { "RDDREGISTER", FS_PUBLIC, HB_RDDREGISTER, 0 }, { "RDDSETDEFAULT", FS_PUBLIC, HB_RDDSETDEFAULT, 0 }, -{ "RDDSHUTDOWN", FS_PUBLIC, HB_RDDSHUTDOWN, 0 } +{ "RDDSHUTDOWN", FS_PUBLIC, HB_RDDSHUTDOWN, 0 }, +{ "RECCOUNT", FS_PUBLIC, HB_RECCOUNT, 0 }, +{ "RECNO", FS_PUBLIC, HB_RECNO, 0 } HB_INIT_SYMBOLS_END( dbCmd__InitSymbols ) #if ! defined(__GNUC__) #pragma startup dbCmd__InitSymbols @@ -212,10 +225,10 @@ static int hb_rddRegister( char * szDriver, USHORT uiType ) if ( hb_parni( -1 ) != SUCCESS ) { hb_xfree( pRddNewNode ); /* Delete de new RDD node */ - return 3; /* Invalid FUNCTABLE */ + return 3; /* Invalid FUNCTABLE */ } - if( !pRddList ) /* First RDD node */ + if( !pRddList ) /* First RDD node */ pRddList = pRddNewNode; else { @@ -263,19 +276,19 @@ static ERRCODE UnSupported_L( AREAP pArea, LONG lLong ) static ERRCODE Bof( AREAP pArea, BOOL * pBof ) { - printf( "Calling default: Bof()\n" ); + * pBof = pArea->fBof; return SUCCESS; } static ERRCODE Eof( AREAP pArea, BOOL * pEof ) { - printf( "Calling default: Eof()\n" ); + * pEof = pArea->fEof; return SUCCESS; } static ERRCODE Found( AREAP pArea, BOOL * pFound ) { - printf( "Calling default: Found()\n" ); + * pFound = pArea->fFound; return SUCCESS; } @@ -292,7 +305,10 @@ static ERRCODE AddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) pField = pArea->lpFields + pArea->uiFieldCount; if( pArea->uiFieldCount > 0 ) ( ( LPFIELD ) ( pField - 1 ) )->lpfNext = pField; - pField->sym = ( void * ) pFieldInfo->atomName; + pField->sym = ( void * ) hb_xgrab( HARBOUR_MAX_RDD_FIELDNAME_LENGTH + 1 ); + memset( pField->sym, 0, HARBOUR_MAX_RDD_FIELDNAME_LENGTH + 1 ); + strncpy( ( char * ) pField->sym, ( char * ) pFieldInfo->atomName, + HARBOUR_MAX_RDD_FIELDNAME_LENGTH ); pField->uiType = pFieldInfo->uiType; pField->uiTypeExtended = pFieldInfo->typeExtended; pField->uiLen = pFieldInfo->uiLen; @@ -302,12 +318,55 @@ static ERRCODE AddField( AREAP pArea, LPDBFIELDINFO pFieldInfo ) return SUCCESS; } +static ERRCODE FieldCount( AREAP pArea, USHORT * uiFields ) +{ + * uiFields = pArea->uiFieldCount; + return SUCCESS; +} + +static ERRCODE FieldName( AREAP pArea, USHORT uiIndex, void * szName ) +{ + LPFIELD pField; + + pField = pArea->lpFields; + while( pField && uiIndex > 1 ) + { + pField = pField->lpfNext; + uiIndex--; + } + if( pField ) + { + strncpy( ( char * ) szName, ( char * ) pField->sym, + HARBOUR_MAX_RDD_FIELDNAME_LENGTH ); + return SUCCESS; + } + else + return FAILURE; +} + static ERRCODE CreateFields( AREAP pArea, PHB_ITEM pStruct ) { printf( "Calling default: CreateFields()\n" ); return SUCCESS; } +static ERRCODE GetValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +{ + printf( "Calling default: GetValue()\n" ); + return SUCCESS; +} + +static ERRCODE RecCount( AREAP pArea, LONG * pRecCount ) +{ + printf( "Calling default: RecCount()\n" ); + return SUCCESS; +} + +static ERRCODE RecNo( AREAP pArea, PHB_ITEM pRecNo ) +{ + return SUCCESS; +} + static ERRCODE SetFieldExtent( AREAP pArea, USHORT uiFieldExtent ) { pArea->uiFieldCount = 0; @@ -319,7 +378,9 @@ static ERRCODE SetFieldExtent( AREAP pArea, USHORT uiFieldExtent ) static ERRCODE Close( AREAP pArea ) { - printf( "Calling default: Close()\n" ); + if( pArea->lpFileInfo->hFile != FS_ERROR ) + hb_fsClose( pArea->lpFileInfo->hFile ); + pArea->lpFileInfo->hFile = FS_ERROR; return SUCCESS; } @@ -332,11 +393,12 @@ static ERRCODE Create( AREAP pArea, LPDBOPENINFO pCreateInfo ) if( SELF_WRITEDBHEADER( pArea ) == FAILURE ) { hb_fsClose( pArea->lpFileInfo->hFile ); + pArea->lpFileInfo->hFile = FS_ERROR; return FAILURE; } hb_fsClose( pArea->lpFileInfo->hFile ); - pArea->lpFileInfo->hFile = 0; + pArea->lpFileInfo->hFile = FS_ERROR; return SUCCESS; } @@ -349,29 +411,70 @@ static ERRCODE Info( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) static ERRCODE NewArea( AREAP pArea ) { pArea->lpFileInfo = ( LPFILEINFO ) hb_xgrab( sizeof( FILEINFO ) ); - pArea->lpFileInfo->hFile = 0; + pArea->lpFileInfo->hFile = FS_ERROR; pArea->lpFileInfo->pNext = 0; + pArea->lpExtendInfo = ( LPDBEXTENDINFO ) hb_xgrab( sizeof( DBEXTENDINFO ) ); + memset( pArea->lpExtendInfo, 0, sizeof( DBEXTENDINFO ) ); + pArea->lpExtendInfo->pRecNo = hb_itemNew( NULL ); return SUCCESS; } static ERRCODE Open( AREAP pArea, LPDBOPENINFO pOpenInfo ) { - printf( "Calling default: Open()\n" ); - return SUCCESS; + USHORT uiFlags; + + uiFlags = pOpenInfo->fReadonly ? FO_READ : FO_READWRITE; + uiFlags |= pOpenInfo->fShared ? FO_DENYNONE : FO_EXCLUSIVE; + pArea->lpFileInfo->hFile = hb_fsOpen( pOpenInfo->abName, uiFlags ); + + + if( pArea->lpFileInfo->hFile == FS_ERROR ) + return FAILURE; + + if( SELF_READDBHEADER( pArea ) == FAILURE ) + { + hb_fsClose( pArea->lpFileInfo->hFile ); + pArea->lpFileInfo->hFile = FS_ERROR; + return FAILURE; + } + + return SELF_GOTOP( pArea ); } static ERRCODE Release( AREAP pArea ) { LPFILEINFO pFileInfo; + LPFIELD pField; if( pArea->lpFields ) + { + pField = pArea->lpFields; + while( pField ) + { + if( pField->sym ) + hb_xfree( pField->sym ); + pField = pField->lpfNext; + } hb_xfree( pArea->lpFields ); + } + while( pArea->lpFileInfo ) { pFileInfo = pArea->lpFileInfo; pArea->lpFileInfo = pArea->lpFileInfo->pNext; hb_xfree( pFileInfo ); } + + if( pArea->lpExtendInfo ) + { + if( pArea->lpExtendInfo->bRecord ) + hb_xfree( pArea->lpExtendInfo->bRecord ); + if( pArea->lpExtendInfo->bOldRecord ) + hb_xfree( pArea->lpExtendInfo->bOldRecord ); + hb_itemRelease( pArea->lpExtendInfo->pRecNo ); + hb_xfree( pArea->lpExtendInfo ); + } + return SUCCESS; } @@ -404,6 +507,11 @@ static RDDFUNCS defTable = { Bof, Skip, AddField, CreateFields, + FieldCount, + FieldName, + GetValue, + RecCount, + RecNo, SetFieldExtent, Close, Create, @@ -413,6 +521,7 @@ static RDDFUNCS defTable = { Bof, Release, StructSize, SysName, + UnSupported_V, UnSupported_V }; @@ -788,7 +897,7 @@ HARBOUR HB_DBUSEAREA( void ) uiRddID = 0; if( !( pRddNode = hb_FindRddNode( szDriver, &uiRddID ) ) ) { - MyError( "DBCMD/1015 Argument error", "DBCREATE" ); + MyError( "DBCMD/1015 Argument error", "DBUSEAREA" ); return; } @@ -908,6 +1017,64 @@ HARBOUR HB_EOF( void ) hb_retl( bEof ); } +HARBOUR HB_FIELDCOUNT( void ) +{ + USHORT uiFields; + + if( pCurrArea ) + { + if( !( ( AREAP ) pCurrArea->pArea )->lprfsHost ) + MyError( "No table error ", "9xxxx" ); + else + SELF_FIELDCOUNT( ( AREAP ) pCurrArea->pArea, &uiFields ); + } + hb_retni( uiFields ); +} + +HARBOUR HB_FIELDGET( void ) +{ + PHB_ITEM pItem; + USHORT uiField; + + pItem = hb_itemNew( 0 ); + uiField = hb_parni( 1 ); + + if( pCurrArea && uiField ) + SELF_GETVALUE( ( AREAP ) pCurrArea->pArea, uiField, pItem ); + + hb_itemReturn( pItem ); + hb_itemRelease( pItem ); +} + +HARBOUR HB_FIELDNAME( void ) +{ + USHORT uiFields, uiIndex; + char * szName; + + if( pCurrArea ) + { + if( !( ( AREAP ) pCurrArea->pArea )->lprfsHost ) + MyError( "No table error ", "9xxxx" ); + else + { + uiIndex = hb_parni( 1 ); + if( SELF_FIELDCOUNT( ( AREAP ) pCurrArea->pArea, &uiFields ) != SUCCESS ) + hb_retc( "" ); + if( uiIndex > 0 && uiIndex <= uiFields ) + { + szName = ( char * ) hb_xgrab( HARBOUR_MAX_RDD_FIELDNAME_LENGTH + 1 ); + + SELF_FIELDNAME( ( AREAP ) pCurrArea->pArea, hb_parni( 1 ), szName ); + + hb_retc( szName ); + hb_xfree( szName ); + return; + } + } + } + hb_retc( "" ); +} + HARBOUR HB_FOUND( void ) { BOOL bFound = FALSE; @@ -922,6 +1089,11 @@ HARBOUR HB_FOUND( void ) hb_retl( bFound ); } +HARBOUR HB_LASTREC( void ) +{ + HB_RECCOUNT(); +} + HARBOUR HB_RDDLIST( void ) { USHORT uiType; @@ -1018,3 +1190,33 @@ HARBOUR HB_RDDSHUTDOWN( void ) hb_xfree( pRddNode ); } } + +HARBOUR HB_RECNO( void ) +{ + if( pCurrArea ) + { + if( !( ( AREAP ) pCurrArea->pArea )->lprfsHost ) + MyError( "No table error ", "9xxxx" ); + else + { + SELF_RECNO( ( AREAP ) pCurrArea->pArea, + ( ( AREAP ) pCurrArea->pArea )->lpExtendInfo->pRecNo ); + hb_itemReturn( ( ( AREAP ) pCurrArea->pArea )->lpExtendInfo->pRecNo ); + } + } +} + +HARBOUR HB_RECCOUNT( void ) +{ + LONG ulRecCount = 0; + + if( pCurrArea ) + { + if( !( ( AREAP ) pCurrArea->pArea )->lprfsHost ) + MyError( "No table error ", "9xxxx" ); + else + SELF_RECCOUNT( ( AREAP ) pCurrArea->pArea, &ulRecCount ); + } + hb_retnl( ulRecCount ); +} + diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index b2f42dc830..38203260ba 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -72,46 +72,71 @@ HB_INIT_SYMBOLS_END( dbf1__InitSymbols ) #pragma startup dbf1__InitSymbols #endif -static ERRCODE Bof( AREAP pArea, BOOL * pBof ) +static ERRCODE ReadBuffer( AREAP pArea, LONG lRecNo ) { - printf( "Calling DBF: Bof()\n" ); - return SUCCESS; -} - -static ERRCODE Eof( AREAP pArea, BOOL * pEof ) -{ - printf( "Calling DBF: Eof()\n" ); - return SUCCESS; -} - -static ERRCODE Found( AREAP pArea, BOOL * pFound ) -{ - printf( "Calling DBF: Found()\n" ); + hb_fsSeek( pArea->lpFileInfo->hFile, pArea->lpExtendInfo->uiHeaderLen + + ( lRecNo - 1 ) * pArea->lpExtendInfo->uiRecordLen, FS_SET ); + if( hb_fsRead( pArea->lpFileInfo->hFile, pArea->lpExtendInfo->bRecord, + pArea->lpExtendInfo->uiRecordLen ) != pArea->lpExtendInfo->uiRecordLen ) + { + memset( pArea->lpExtendInfo->bRecord, ' ', pArea->lpExtendInfo->uiRecordLen ); + pArea->lpExtendInfo->bRecord[ pArea->lpExtendInfo->uiRecordLen ] = 0; + return FAILURE; + } return SUCCESS; } static ERRCODE GoBottom( AREAP pArea ) { - printf( "Calling DBF: GoBottom()\n" ); - return SUCCESS; + LONG lRecCount; + + if( SELF_RECCOUNT( pArea, &lRecCount ) == FAILURE ) + return FAILURE; + + return SELF_GOTO( pArea, lRecCount ); } static ERRCODE GoTo( AREAP pArea, LONG lRecNo ) { - printf( "Calling DBF: GoTo()\n" ); - return SUCCESS; + LONG lRecCount; + + if( SELF_RECCOUNT( pArea, &lRecCount ) == FAILURE ) + return FAILURE; + + if( lRecCount < 1 ) + { + pArea->fBof = 1; + pArea->fEof = 1; + lRecNo = 1; + } + else + { + if( lRecNo > lRecCount + 1 ) + lRecNo = lRecCount + 1; + if( lRecNo == 1 ) + pArea->fBof = 1; + else + pArea->fBof = 0; + if( lRecNo == lRecCount + 1 ) + pArea->fEof = 1; + else + pArea->fEof = 0; + } + hb_itemPutNL( pArea->lpExtendInfo->pRecNo, lRecNo ); + if( lRecCount > 0 ) + return ReadBuffer( pArea, lRecNo ); + else + return SUCCESS; } static ERRCODE GoTop( AREAP pArea ) { - printf( "Calling DBF: GoTop()\n" ); - return SUCCESS; + return SELF_GOTO( pArea, 1 ); } static ERRCODE Skip( AREAP pArea, LONG lToSkip ) { - printf( "Calling DBF: Skip()\n" ); - return SUCCESS; + return SELF_GOTO( pArea, hb_itemGetNL( pArea->lpExtendInfo->pRecNo ) + lToSkip ); } static ERRCODE CreateFields( AREAP pArea, PHB_ITEM pStruct ) @@ -150,9 +175,73 @@ static ERRCODE CreateFields( AREAP pArea, PHB_ITEM pStruct ) return SUCCESS; } -static ERRCODE Close( AREAP pArea ) +static ERRCODE GetValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { - printf( "Calling DBF: Close()\n" ); + LPFIELD pField; + USHORT uiCount, uiOffset; + BYTE * szText, * szOldChar, szEndChar; + + if( uiIndex > pArea->uiFieldCount ) + return FAILURE; + + pField = pArea->lpFields; + uiOffset = 1; + for( uiCount = 1; uiCount < uiIndex; uiCount++ ) + { + if( pField->uiType == 'C' ) + uiOffset += pField->uiLen + ( ( USHORT ) pField->uiDec << 8 ); + else + uiOffset += pField->uiLen; + pField = pField->lpfNext; + } + + szText = pArea->lpExtendInfo->bRecord + uiOffset; + switch( pField->uiType ) + { + case 'C': + hb_itemPutCL( pItem, ( char * ) szText, + pField->uiLen + ( ( USHORT ) pField->uiDec << 8 ) ); + break; + + case 'N': + szOldChar = szText + pField->uiLen; + szEndChar = * szOldChar; + * szOldChar = 0; + if( pField->uiDec ) + hb_itemPutND( pItem, atof( ( char * ) szText ) ); + else + hb_itemPutNL( pItem, atof( ( char * ) szText ) ); + * szOldChar = szEndChar; + break; + + case 'D': + szOldChar = szText + pField->uiLen; + szEndChar = * szOldChar; + * szOldChar = 0; + hb_itemPutDS( pItem, ( char * ) szText ); + * szOldChar = szEndChar; + break; + + case 'L': + if( * szText == 'T' ) + hb_itemPutL( pItem, 1 ); + else + hb_itemPutL( pItem, 0 ); + break; + } + + return SUCCESS; +} + +static ERRCODE RecCount( AREAP pArea, LONG * pRecCount ) +{ + DBFHEADER pHeader; + + hb_fsSeek( pArea->lpFileInfo->hFile, 0, FS_SET ); + if( hb_fsRead( pArea->lpFileInfo->hFile, ( BYTE * ) &pHeader, + sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) ) + return FAILURE; + * pRecCount = pHeader.ulRecords; return SUCCESS; } @@ -167,9 +256,82 @@ static ERRCODE Info( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) return SUCCESS; } -static ERRCODE Open( AREAP pArea, LPDBOPENINFO pOpenInfo ) +static ERRCODE ReadDBHeader( AREAP pArea ) { - printf( "Calling DBF: Open()\n" ); + DBFHEADER pHeader; + DBFIELDINFO pFieldInfo; + LPDBFFIELD pDBField; + USHORT uiDataLen; + char * szBuffer; + USHORT uiFields, uiCount; + + hb_fsSeek( pArea->lpFileInfo->hFile, 0, FS_SET ); + if( hb_fsRead( pArea->lpFileInfo->hFile, ( BYTE * ) &pHeader, + sizeof( DBFHEADER ) ) != sizeof( DBFHEADER ) ) + return FAILURE; + + pArea->lpExtendInfo->uiHeaderLen = pHeader.uiHeaderLen; + uiDataLen = pHeader.uiHeaderLen - sizeof( DBFHEADER ); + szBuffer = ( char * ) hb_xgrab( uiDataLen ); + if( hb_fsRead( pArea->lpFileInfo->hFile, ( BYTE * ) szBuffer, + uiDataLen ) != uiDataLen ) + { + hb_xfree( szBuffer ); + return FAILURE; + } + + for( uiFields = 0; uiFields < uiDataLen; uiFields += 32 ) + if( szBuffer[ uiFields ] == 0xD ) + break; + + uiFields /= 32; + if( ( uiDataLen / 32 ) < uiFields ) + { + hb_xfree( szBuffer ); + return FAILURE; + } + + pArea->lpExtendInfo->uiRecordLen = 1; + SELF_SETFIELDEXTENT( pArea, uiFields ); + pFieldInfo.typeExtended = 0; + pDBField = ( LPDBFFIELD ) szBuffer; + for( uiCount = 0; uiCount < uiFields; uiCount++ ) + { + pFieldInfo.atomName = ( BYTE * ) pDBField->bName; + pFieldInfo.uiType = toupper( pDBField->bType ); + + if( pFieldInfo.uiType == 'N' ) + { + pFieldInfo.uiLen = ( USHORT ) pDBField->bLen; + pFieldInfo.uiDec = ( USHORT ) pDBField->bDec; + } + else + { + if( pFieldInfo.uiType == 'L' || pFieldInfo.uiType == 'D' || + pFieldInfo.uiType == 'M' ) + { + pFieldInfo.uiLen = ( USHORT ) pDBField->bLen; + if( pFieldInfo.uiType == 'M' ) + pArea->lpExtendInfo->fHasMemo = 1; + } + else if( pFieldInfo.uiType == 'C' ) + { + pFieldInfo.uiLen = ( USHORT ) pDBField->bLen + + ( ( USHORT ) pDBField->bDec << 8 ); + } + pFieldInfo.uiDec = 0; + } + pArea->lpExtendInfo->uiRecordLen += pFieldInfo.uiLen; + SELF_ADDFIELD( pArea, &pFieldInfo ); + pDBField++; + } + hb_xfree( szBuffer ); + pArea->lpExtendInfo->bRecord = ( BYTE * ) hb_xgrab( pArea->lpExtendInfo->uiRecordLen + 1 ); + memset( pArea->lpExtendInfo->bRecord, ' ', pArea->lpExtendInfo->uiRecordLen ); + pArea->lpExtendInfo->bRecord[ pArea->lpExtendInfo->uiRecordLen ] = 0; + pArea->lpExtendInfo->bOldRecord = ( BYTE * ) hb_xgrab( pArea->lpExtendInfo->uiRecordLen + 1 ); + memset( pArea->lpExtendInfo->bOldRecord, ' ', pArea->lpExtendInfo->uiRecordLen ); + pArea->lpExtendInfo->bOldRecord[ pArea->lpExtendInfo->uiRecordLen ] = 0; return SUCCESS; } @@ -269,24 +431,30 @@ static ERRCODE WriteDBHeader( AREAP pArea ) static RDDFUNCS dbfSuper = { 0 }; -static RDDFUNCS dbfTable = { Bof, - Eof, - Found, +static RDDFUNCS dbfTable = { 0, /* Super Bof */ + 0, /* Super Eof */ + 0, /* Super Found */ GoBottom, GoTo, GoTop, Skip, 0, /* Super AddField */ CreateFields, + 0, /* Super FieldCount */ + 0, /* Super FieldName */ + GetValue, + RecCount, + 0, /* Super RecNo */ 0, /* Super SetFieldsExtent */ - Close, + 0, /* Super Close */ 0, /* Super Create */ Info, 0, /* Super NewArea */ - Open, + 0, /* Super Open */ 0, /* Super Release */ 0, /* Super StructSize */ 0, /* Super SysName */ + ReadDBHeader, WriteDBHeader }; diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index 0676918ea7..468d5cb4c0 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -39,54 +39,6 @@ HB_INIT_SYMBOLS_END( dbfntx1__InitSymbols ) #pragma startup dbfntx1__InitSymbols #endif -static ERRCODE Bof( AREAP pArea, BOOL * pBof ) -{ - printf( "Calling DBFNTX: Bof()\n" ); - return SUCCESS; -} - -static ERRCODE Eof( AREAP pArea, BOOL * pEof ) -{ - printf( "Calling DBFNTX: Eof()\n" ); - return SUCCESS; -} - -static ERRCODE Found( AREAP pArea, BOOL * pFound ) -{ - printf( "Calling DBFNTX: Found()\n" ); - return SUCCESS; -} - -static ERRCODE GoBottom( AREAP pArea ) -{ - printf( "Calling DBFNTX: GoBottom()\n" ); - return SUCCESS; -} - -static ERRCODE GoTo( AREAP pArea, LONG lRecNo ) -{ - printf( "Calling DBFNTX: GoTo()\n" ); - return SUCCESS; -} - -static ERRCODE GoTop( AREAP pArea ) -{ - printf( "Calling DBFNTX: GoTop()\n" ); - return SUCCESS; -} - -static ERRCODE Skip( AREAP pArea, LONG lToSkip ) -{ - printf( "Calling DBFNTX: Skip()\n" ); - return SUCCESS; -} - -static ERRCODE Close( AREAP pArea ) -{ - printf( "Calling DBFNTX: Close()\n" ); - return SUCCESS; -} - static ERRCODE Info( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { switch( uiIndex ) @@ -98,29 +50,28 @@ static ERRCODE Info( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) return SUCCESS; } -static ERRCODE Open( AREAP pArea, LPDBOPENINFO pOpenInfo ) -{ - printf( "Calling DBFNTX: Open()\n" ); - return SUCCESS; -} - static RDDFUNCS ntxSuper = { 0 }; -static RDDFUNCS ntxTable = { Bof, - Eof, - Found, - GoBottom, - GoTo, - GoTop, - Skip, +static RDDFUNCS ntxTable = { 0, /* Super Bof */ + 0, /* Super Eof */ + 0, /* Super Found */ + 0, /* Super GoBottom */ + 0, /* Super GoTo */ + 0, /* Super GoTop */ + 0, /* Super Skip */ 0, /* Super AddField */ 0, /* Super CreateFields */ + 0, /* Super FieldCount */ + 0, /* Super FieldName */ + 0, /* Super GetValue */ + 0, /* Super RecCount */ 0, /* Super SetFieldExtent */ - Close, + 0, /* Super RecNo */ + 0, /* Super Close */ 0, /* Super Create */ Info, 0, /* Super NewArea */ - Open, + 0, /* Super Open */ 0, /* Super Release */ 0, /* Super StructSize */ 0, /* Super SysName */ diff --git a/harbour/source/rdd/delim1.c b/harbour/source/rdd/delim1.c index 833902bddb..fd6e05d2ba 100644 --- a/harbour/source/rdd/delim1.c +++ b/harbour/source/rdd/delim1.c @@ -38,63 +38,15 @@ HB_INIT_SYMBOLS_END( delim1__InitSymbols ) #pragma startup delim1__InitSymbols #endif -static ERRCODE Bof( AREAP pArea, BOOL * pBof ) -{ - printf( "Calling DELIM: Bof()\n" ); - return SUCCESS; -} - -static ERRCODE Eof( AREAP pArea, BOOL * pEof ) -{ - printf( "Calling DELIM: Eof()\n" ); - return SUCCESS; -} - -static ERRCODE Found( AREAP pArea, BOOL * pFound ) -{ - printf( "Calling DELIM: Found()\n" ); - return SUCCESS; -} - -static ERRCODE GoBottom( AREAP pArea ) -{ - printf( "Calling DELIM: GoBottom()\n" ); - return SUCCESS; -} - -static ERRCODE GoTo( AREAP pArea, LONG lRecNo ) -{ - printf( "Calling DELIM: GoTo()\n" ); - return SUCCESS; -} - -static ERRCODE GoTop( AREAP pArea ) -{ - printf( "Calling DELIM: GoTop()\n" ); - return SUCCESS; -} - -static ERRCODE Skip( AREAP pArea, LONG lToSkip ) -{ - printf( "Calling DELIM: Skip()\n" ); - return SUCCESS; -} - -static ERRCODE Close( AREAP pArea ) -{ - printf( "Calling DELIM: Close()\n" ); - return SUCCESS; -} - static ERRCODE Info( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { printf( "Calling DELIM: Info()\n" ); return SUCCESS; } -static ERRCODE Open( AREAP pArea, LPDBOPENINFO pOpenInfo ) +static ERRCODE ReadDBHeader( AREAP pArea ) { - printf( "Calling DELIM: Open()\n" ); + printf( "Calling DELIM: ReadDBHeader()\n" ); return SUCCESS; } @@ -106,26 +58,32 @@ static ERRCODE WriteDBHeader( AREAP pArea ) static RDDFUNCS delimSuper = { 0 }; -static RDDFUNCS delimTable = { Bof, - Eof, - Found, - GoBottom, - GoTo, - GoTop, - Skip, +static RDDFUNCS delimTable = { 0, /* Super Bof */ + 0, /* Super Eof */ + 0, /* Super Found */ + 0, /* Super GoBottom */ + 0, /* Super GoTo */ + 0, /* Super GoTop */ + 0, /* Super Skip */ 0, /* Super AddField */ 0, /* Super CreateFields */ + 0, /* Super FieldCount */ + 0, /* Super FieldName */ + 0, /* Super GetValue */ + 0, /* Super RecCount */ + 0, /* Super RecNo */ 0, /* Super SetFieldExtent */ - Close, + 0, /* Super Close */ 0, /* Super Create */ Info, 0, /* Super NewArea */ - Open, + 0, /* Super Open */ 0, /* Super Release */ 0, /* Super StructSize */ 0, /* Super SysName */ + ReadDBHeader, WriteDBHeader - }; + }; HARBOUR HB__DELIM( void ) { diff --git a/harbour/source/rdd/sdf1.c b/harbour/source/rdd/sdf1.c index 01c406a90e..ea5c577e5e 100644 --- a/harbour/source/rdd/sdf1.c +++ b/harbour/source/rdd/sdf1.c @@ -38,63 +38,15 @@ HB_INIT_SYMBOLS_END( sdf1__InitSymbols ) #pragma startup sdf1__InitSymbols #endif -static ERRCODE Bof( AREAP pArea, BOOL * pBof ) -{ - printf( "Calling SDF: Bof()\n" ); - return SUCCESS; -} - -static ERRCODE Eof( AREAP pArea, BOOL * pEof ) -{ - printf( "Calling SDF: Eof()\n" ); - return SUCCESS; -} - -static ERRCODE Found( AREAP pArea, BOOL * pFound ) -{ - printf( "Calling SDF: Found()\n" ); - return SUCCESS; -} - -static ERRCODE GoBottom( AREAP pArea ) -{ - printf( "Calling SDF: GoBottom()\n" ); - return SUCCESS; -} - -static ERRCODE GoTo( AREAP pArea, LONG lRecNo ) -{ - printf( "Calling SDF: GoTo()\n" ); - return SUCCESS; -} - -static ERRCODE GoTop( AREAP pArea ) -{ - printf( "Calling SDF: GoTop()\n" ); - return SUCCESS; -} - -static ERRCODE Skip( AREAP pArea, LONG lToSkip ) -{ - printf( "Calling SDF: Skip()\n" ); - return SUCCESS; -} - -static ERRCODE Close( AREAP pArea ) -{ - printf( "Calling SDF: Close()\n" ); - return SUCCESS; -} - static ERRCODE Info( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) { printf( "Calling SDF: Info()\n" ); return SUCCESS; } -static ERRCODE Open( AREAP pArea, LPDBOPENINFO pOpenInfo ) +static ERRCODE ReadDBHeader( AREAP pArea ) { - printf( "Calling SDF: Open()\n" ); + printf( "Calling SDF: ReadDBHeader()\n" ); return SUCCESS; } @@ -106,26 +58,32 @@ static ERRCODE WriteDBHeader( AREAP pArea ) static RDDFUNCS sdfSuper = { 0 }; -static RDDFUNCS sdfTable = { Bof, - Eof, - Found, - GoBottom, - GoTo, - GoTop, - Skip, +static RDDFUNCS sdfTable = { 0, /* Super Bof */ + 0, /* Super Eof */ + 0, /* Super Found */ + 0, /* Super GoBottom */ + 0, /* Super GoTo */ + 0, /* Super GoTop */ + 0, /* Super Skip */ 0, /* Super AddField */ 0, /* Super CreateFields */ + 0, /* Super FieldCount */ + 0, /* Super FieldName */ + 0, /* Super GetValue */ + 0, /* Super RecCount */ + 0, /* Super RecNo */ 0, /* Super SetFieldExtent */ - Close, + 0, /* Super Close */ 0, /* Super Create */ Info, 0, /* Super NewArea */ - Open, + 0, /* Super Open */ 0, /* Super Release */ 0, /* Super StructSize */ 0, /* Super SysName */ + ReadDBHeader, WriteDBHeader - }; + }; HARBOUR HB__SDF( void ) {