diff --git a/harbour/ChangeLog b/harbour/ChangeLog index be06426b9c..dcbea34e28 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,9 @@ +19990829-11:21 GMT+1 Bruno Cantero + * include/rddapi.h + source/rdd/dbcmd.c + source/rdd/dbf1.c + * Beginning with memos. + 19990829-01:20 EDT Paul Tucker * source/debug/debugger.prg * ::Activate - call restoreAppStatus() since code was the same. diff --git a/harbour/include/rddapi.h b/harbour/include/rddapi.h index c78dfe3c9b..656d4b7dad 100644 --- a/harbour/include/rddapi.h +++ b/harbour/include/rddapi.h @@ -85,7 +85,7 @@ extern void hb_rddPutFieldValue( HB_ITEM_PTR pItem, PHB_SYMB pFieldSymbol ); #define DBI_LOCKOFFSET 35 /* New locking offset */ #define DBI_SHARED 36 /* Gets/Sets the shared flag */ -#define DBI_MEMOEXT 37 /* Gets/Sets the shared flag */ +#define DBI_MEMOEXT 37 /* String: Get memo file extension */ #define DBI_MEMOHANDLE 38 /* Dos handle for memo file */ #define DBI_MEMOBLOCKSIZE 39 /* Blocksize in memo files */ @@ -708,7 +708,9 @@ typedef struct _RDDFUNCS #if 0 DBENTRYP_V closeMemFile; +#endif DBENTRYP_VP createMemFile; +#if 0 DBENTRYP_SVPB getValueFile; DBENTRYP_VP openMemFile; DBENTRYP_SVP putValueFile; diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index 5859b45164..9f17b69905 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -436,6 +436,8 @@ static RDDFUNCS defTable = { Bof, ( DBENTRYP_VSP ) UnSupported, ( DBENTRYP_VL ) UnSupported, ( DBENTRYP_UL ) UnSupported, + ( DBENTRYP_VP ) UnSupported, + /*( DBENTRYP_VP ) UnSupported,*/ UnSupported, UnSupported }; @@ -897,7 +899,7 @@ HARBOUR HB_DBCOMMITALL( void ) HARBOUR HB_DBCREATE( void ) { char * szFileName, * szDriver; - PHB_ITEM pStruct, pFieldDesc; + PHB_ITEM pStruct, pFieldDesc, pFileExt; LPRDDNODE pRddNode; AREAP pTempArea; USHORT uiSize, uiRddID; @@ -962,17 +964,32 @@ HARBOUR HB_DBCREATE( void ) SELF_CREATEFIELDS( ( AREAP ) pTempArea, pStruct ); pFileName = hb_fsFNameSplit( szFileName ); - szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); strcpy( szFileName, hb_parc( 1 ) ); if( !pFileName->szExtension ) { - HB_DBTABLEEXT(); - strcat( szFileName, hb_parc( -1 ) ); + pFileExt = hb_itemPutC( 0, "" ); + SELF_INFO( ( AREAP ) pTempArea, DBI_TABLEEXT, pFileExt ); + strcat( szFileName, pFileExt->item.asString.value ); + hb_itemRelease( pFileExt ); } pInfo.abName = ( BYTE * ) szFileName; - SELF_CREATE( ( AREAP ) pTempArea, &pInfo ); + if( SELF_CREATE( ( AREAP ) pTempArea, &pInfo ) == SUCCESS && + pTempArea->lpExtendInfo->fHasMemo ) + { + pFileExt = hb_itemPutC( 0, "" ); + SELF_INFO( ( AREAP ) pTempArea, DBI_MEMOEXT, pFileExt ); + szFileName[ 0 ] = 0; + if( pFileName->szPath ) + strcat( szFileName, pFileName->szPath ); + strcat( szFileName, pFileName->szName ); + strcat( szFileName, pFileExt->item.asString.value ); + pInfo.abName = ( BYTE * ) szFileName; + SELF_CREATEMEMFILE( ( AREAP ) pTempArea, &pInfo ); + hb_itemRelease( pFileExt ); + } + SELF_RELEASE( ( AREAP ) pTempArea ); hb_xfree( szFileName ); hb_xfree( pFileName ); @@ -1228,149 +1245,176 @@ HARBOUR HB_DBUNLOCKALL( void ) HARBOUR HB_DBUSEAREA( void ) { - char * szDriver, * szFileName, * szAlias; - WORD wLen; - LPRDDNODE pRddNode; - LPAREANODE pAreaNode; - USHORT uiSize, uiRddID; - DBOPENINFO pInfo; - PHB_FNAME pFileName; - - bNetError = FALSE; - - if( hb_parl( 1 ) ) - hb_rddSelectFirstAvailable(); - else if( pCurrArea ) /* If current WorkArea is in use then close it */ - { - SELF_CLOSE( ( AREAP ) pCurrArea->pArea ); - SELF_RELEASE( ( AREAP ) pCurrArea->pArea ); - - if( pWorkAreas == pCurrArea ) /* Empty list */ - pWorkAreas = 0; - else - { - if( pCurrArea->pPrev ) - pCurrArea->pPrev->pNext = pCurrArea->pNext; - if( pCurrArea->pNext ) - pCurrArea->pNext->pPrev = pCurrArea->pPrev; - } - - hb_xfree( pCurrArea->pArea ); - hb_xfree( pCurrArea ); - pCurrArea = 0; - } - - hb_rddCheck(); - szDriver = hb_parc( 2 ); - if( ( wLen = strlen( szDriver ) ) > 0 ) - hb_strUpper( szDriver, wLen ); - else - szDriver = szDefDriver; - - uiRddID = 0; - pRddNode = hb_rddFindNode( szDriver, &uiRddID ); - if( !pRddNode ) - { - hb_errRT_DBCMD( EG_ARG, 1015, 0, "DBUSEAREA" ); - return; - } - - szFileName = hb_parc( 3 ); - if( strlen( szFileName ) == 0 ) - { - hb_errRT_DBCMD( EG_ARG, 1005, 0, "DBUSEAREA" ); - return; - } - - pFileName = hb_fsFNameSplit( szFileName ); - szAlias = hb_parc( 4 ); - if( strlen( szAlias ) == 0 ) - szAlias = pFileName->szName; - - /* Create a new WorkArea node */ - - pCurrArea = ( LPAREANODE ) hb_xgrab( sizeof( AREANODE ) ); - - if( pRddNode->uiAreaSize == 0 ) /* Calculate the size of WorkArea */ - { - uiSize = sizeof( AREA ); /* Default Size Area */ - pCurrArea->pArea = ( AREAP ) hb_xgrab( uiSize ); - memset( pCurrArea->pArea, 0, uiSize ); - ( ( AREAP ) pCurrArea->pArea )->lprfsHost = &pRddNode->pTable; - - /* Need more space? */ - SELF_STRUCTSIZE( ( AREAP ) pCurrArea->pArea, &uiSize ); - if( uiSize > sizeof( AREA ) ) /* Size of Area changed */ - pCurrArea->pArea = ( AREAP ) hb_xrealloc( pCurrArea->pArea, uiSize ); - - pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ - } - else - { - pCurrArea->pArea = ( AREAP ) hb_xgrab( pRddNode->uiAreaSize ); - memset( pCurrArea->pArea, 0, pRddNode->uiAreaSize ); - ( ( AREAP ) pCurrArea->pArea )->lprfsHost = &pRddNode->pTable; - } - - ( ( AREAP ) pCurrArea->pArea )->rddID = uiRddID; - - pCurrArea->pPrev = 0; - pCurrArea->pNext = 0; - - SELF_NEW( ( AREAP ) pCurrArea->pArea ); - - szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); - strcpy( szFileName, hb_parc( 3 ) ); - if( !pFileName->szExtension ) - { - HB_DBTABLEEXT(); - strcat( szFileName, hb_parc( -1 ) ); - } - pInfo.uiArea = uiCurrArea; - pInfo.abName = ( BYTE * ) szFileName; - pInfo.atomAlias = ( BYTE * ) szAlias; - pInfo.fShared = ISLOG( 5 ) ? hb_parl( 5 ) : !hb_set.HB_SET_EXCLUSIVE; - pInfo.fReadonly = ISLOG( 6 ) ? hb_parl( 6 ) : FALSE; - - if( SELF_OPEN( ( AREAP ) pCurrArea->pArea, &pInfo ) == FAILURE ) - { - SELF_RELEASE( ( AREAP ) pCurrArea->pArea ); - hb_xfree( pCurrArea->pArea ); - hb_xfree( pCurrArea ); - hb_xfree( szFileName ); - hb_xfree( pFileName ); - pCurrArea = 0; - return; - } - - hb_xfree( szFileName ); - hb_xfree( pFileName ); - ( ( AREAP ) pCurrArea->pArea )->uiArea = uiCurrArea; - - /* Insert the new WorkArea node */ - - if( !pWorkAreas ) - { - pWorkAreas = pCurrArea; /* The new WorkArea node is the first */ - return; - } - - pAreaNode = pWorkAreas; - while( pAreaNode->pNext ) - { - if( ( ( AREAP ) pAreaNode->pArea )->uiArea > uiCurrArea ) - { - /* Insert the new WorkArea node */ - pCurrArea->pPrev = pAreaNode->pPrev; - pCurrArea->pNext = pAreaNode; - pAreaNode->pPrev = pCurrArea; - if( pCurrArea->pPrev ) - pCurrArea->pPrev->pNext = pCurrArea; - } - pAreaNode = pAreaNode->pNext; - } - pAreaNode->pNext = pCurrArea; /* Append the new WorkArea node */ - pCurrArea->pPrev = pAreaNode; +// char * szDriver, * szFileName, * szAlias; +// WORD wLen; +// LPRDDNODE pRddNode; +// LPAREANODE pAreaNode; +// USHORT uiSize, uiRddID; +// DBOPENINFO pInfo; +// PHB_FNAME pFileName; +// PHB_ITEM pFileExt; +// +// bNetError = FALSE; +// +// if( hb_parl( 1 ) ) +// hb_rddSelectFirstAvailable(); +// else if( pCurrArea ) /* If current WorkArea is in use then close it */ +// { +// SELF_CLOSE( ( AREAP ) pCurrArea->pArea ); +// SELF_RELEASE( ( AREAP ) pCurrArea->pArea ); +// +// if( pWorkAreas == pCurrArea ) /* Empty list */ +// pWorkAreas = 0; +// else +// { +// if( pCurrArea->pPrev ) +// pCurrArea->pPrev->pNext = pCurrArea->pNext; +// if( pCurrArea->pNext ) +// pCurrArea->pNext->pPrev = pCurrArea->pPrev; +// } +// +// hb_xfree( pCurrArea->pArea ); +// hb_xfree( pCurrArea ); +// pCurrArea = 0; +// } +// +// hb_rddCheck(); +// szDriver = hb_parc( 2 ); +// if( ( wLen = strlen( szDriver ) ) > 0 ) +// hb_strUpper( szDriver, wLen ); +// else +// szDriver = szDefDriver; +// +// uiRddID = 0; +// pRddNode = hb_rddFindNode( szDriver, &uiRddID ); +// if( !pRddNode ) +// { +// hb_errRT_DBCMD( EG_ARG, 1015, 0, "DBUSEAREA" ); +// return; +// } +// +// szFileName = hb_parc( 3 ); +// if( strlen( szFileName ) == 0 ) +// { +// hb_errRT_DBCMD( EG_ARG, 1005, 0, "DBUSEAREA" ); +// return; +// } +// +// pFileName = hb_fsFNameSplit( szFileName ); +// szAlias = hb_parc( 4 ); +// if( strlen( szAlias ) == 0 ) +// szAlias = pFileName->szName; +// +// /* Create a new WorkArea node */ +// +// pCurrArea = ( LPAREANODE ) hb_xgrab( sizeof( AREANODE ) ); +// +// if( pRddNode->uiAreaSize == 0 ) /* Calculate the size of WorkArea */ +// { +// uiSize = sizeof( AREA ); /* Default Size Area */ +// pCurrArea->pArea = ( AREAP ) hb_xgrab( uiSize ); +// memset( pCurrArea->pArea, 0, uiSize ); +// ( ( AREAP ) pCurrArea->pArea )->lprfsHost = &pRddNode->pTable; +// +// /* Need more space? */ +// SELF_STRUCTSIZE( ( AREAP ) pCurrArea->pArea, &uiSize ); +// if( uiSize > sizeof( AREA ) ) /* Size of Area changed */ +// pCurrArea->pArea = ( AREAP ) hb_xrealloc( pCurrArea->pArea, uiSize ); +// +// pRddNode->uiAreaSize = uiSize; /* Update the size of WorkArea */ +// } +// else +// { +// pCurrArea->pArea = ( AREAP ) hb_xgrab( pRddNode->uiAreaSize ); +// memset( pCurrArea->pArea, 0, pRddNode->uiAreaSize ); +// ( ( AREAP ) pCurrArea->pArea )->lprfsHost = &pRddNode->pTable; +// } +// +// ( ( AREAP ) pCurrArea->pArea )->rddID = uiRddID; +// +// pCurrArea->pPrev = 0; +// pCurrArea->pNext = 0; +// +// SELF_NEW( ( AREAP ) pCurrArea->pArea ); +// +// szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); +// strcpy( szFileName, hb_parc( 3 ) ); +// if( !pFileName->szExtension ) +// { +// pFileExt = hb_itemPutC( 0, "" ); +// SELF_INFO( ( AREAP ) pCurrArea->pArea, DBI_TABLEEXT, pFileExt ); +// strcat( szFileName, pFileExt->item.asString.value ); +// hb_itemRelease( pFileExt ); +// } +// pInfo.uiArea = uiCurrArea; +// pInfo.abName = ( BYTE * ) szFileName; +// pInfo.atomAlias = ( BYTE * ) szAlias; +// pInfo.fShared = ISLOG( 5 ) ? hb_parl( 5 ) : !hb_set.HB_SET_EXCLUSIVE; +// pInfo.fReadonly = ISLOG( 6 ) ? hb_parl( 6 ) : FALSE; +// +// if( SELF_OPEN( ( AREAP ) pCurrArea->pArea, &pInfo ) == FAILURE ) +// { +// SELF_RELEASE( ( AREAP ) pCurrArea->pArea ); +// hb_xfree( pCurrArea->pArea ); +// hb_xfree( pCurrArea ); +// hb_xfree( szFileName ); +// hb_xfree( pFileName ); +// pCurrArea = 0; +// return; +// } +// +// if( ( ( AREAP ) pCurrArea->pArea )->lpExtendInfo->fHasMemo ) +// { +// pFileExt = hb_itemPutC( 0, "" ); +// SELF_INFO( ( AREAP ) pCurrArea->pArea, DBI_MEMOEXT, pFileExt ); +// szFileName[ 0 ] = 0; +// if( pFileName->szPath ) +// strcat( szFileName, pFileName->szPath ); +// strcat( szFileName, pFileName->szName ); +// strcat( szFileName, pFileExt->item.asString.value ); +// pInfo.abName = ( BYTE * ) szFileName; +// hb_itemRelease( pFileExt ); +// if( SELF_OPENMEMFILE( ( AREAP ) pCurrArea->pArea, &pInfo ) == FAILURE ) +// { +// SELF_CLOSE( ( AREAP ) pCurrArea->pArea ); +// SELF_RELEASE( ( AREAP ) pCurrArea->pArea ); +// hb_xfree( pCurrArea->pArea ); +// hb_xfree( pCurrArea ); +// hb_xfree( szFileName ); +// hb_xfree( pFileName ); +// pCurrArea = 0; +// return; +// } +// } +// +// hb_xfree( szFileName ); +// hb_xfree( pFileName ); +// ( ( AREAP ) pCurrArea->pArea )->uiArea = uiCurrArea; +// +// /* Insert the new WorkArea node */ +// +// if( !pWorkAreas ) +// { +// pWorkAreas = pCurrArea; /* The new WorkArea node is the first */ +// return; +// } +// +// pAreaNode = pWorkAreas; +// while( pAreaNode->pNext ) +// { +// if( ( ( AREAP ) pAreaNode->pArea )->uiArea > uiCurrArea ) +// { +// /* Insert the new WorkArea node */ +// pCurrArea->pPrev = pAreaNode->pPrev; +// pCurrArea->pNext = pAreaNode; +// pAreaNode->pPrev = pCurrArea; +// if( pCurrArea->pPrev ) +// pCurrArea->pPrev->pNext = pCurrArea; +// } +// pAreaNode = pAreaNode->pNext; +// } +// pAreaNode->pNext = pCurrArea; /* Append the new WorkArea node */ +// pCurrArea->pPrev = pAreaNode; } HARBOUR HB_DELETED( void ) diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index 82caea8ee2..77ac7cab91 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -51,6 +51,13 @@ typedef struct typedef DBFHEADER * LPDBFHEADER; +typedef struct +{ + LONG lNextBlock; +} MEMOHEADER; + +typedef MEMOHEADER * LPMEMOHEADER; + typedef struct { @@ -79,6 +86,7 @@ HB_INIT_SYMBOLS_END( dbf1__InitSymbols ) #define LOCK_START 0x40000000L #define LOCK_FILE 0x3FFFFFFFL +#define MEMO_BLOCK 512 static BOOL hb_nltoa( LONG lValue, char * szBuffer, USHORT uiLen ) { @@ -466,6 +474,34 @@ static ERRCODE Create( AREAP pArea, LPDBOPENINFO pCreateInfo ) return SUCCESS; } +static ERRCODE CreateMemFile( AREAP pArea, LPDBOPENINFO pCreateInfo ) +{ + LPFILEINFO lpMemInfo; + LPMEMOHEADER pMemoHeader; + BOOL bError = FALSE; + + lpMemInfo = ( LPFILEINFO ) hb_xgrab( sizeof( FILEINFO ) ); + memset( lpMemInfo, 0, sizeof( FILEINFO ) ); + lpMemInfo->hFile = FS_ERROR; + pArea->lpFileInfo->pNext = lpMemInfo; + lpMemInfo->hFile = hb_fsCreate( pCreateInfo->abName, FC_NORMAL ); + if( lpMemInfo->hFile == FS_ERROR ) + return FAILURE; + + pMemoHeader = ( LPMEMOHEADER ) hb_xgrab( MEMO_BLOCK + 1 ); + memset( pMemoHeader, 0, MEMO_BLOCK + 1 ); + pMemoHeader->lNextBlock = 1; + bError = ( hb_fsWrite( lpMemInfo->hFile, ( BYTE * ) pMemoHeader, + MEMO_BLOCK + 1 ) != MEMO_BLOCK + 1 ); + hb_xfree( pMemoHeader ); + hb_fsClose( lpMemInfo->hFile ); + lpMemInfo->hFile = FS_ERROR; + if( bError ) + return FAILURE; + else + return SUCCESS; +} + static ERRCODE Deleted( AREAP pArea, BOOL * pDeleted ) { * pDeleted = ( pArea->lpExtendInfo->bRecord[ 0 ] == '*' ); @@ -652,6 +688,10 @@ static ERRCODE Info( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) hb_itemPutC( pItem, ".DBF" ); break; + case DBI_MEMOEXT: + hb_itemPutC( pItem, ".DBT" ); + break; + case DBI_GETLOCKARRAY: hb_dbfGetLockArray( pArea, pItem ); break; @@ -920,7 +960,7 @@ static ERRCODE ReadDBHeader( AREAP pArea ) { pFieldInfo.uiLen = ( USHORT ) pDBField->bLen; if( pFieldInfo.uiType == 'M' ) - pArea->lpExtendInfo->fHasMemo = 1; + pArea->lpExtendInfo->fHasMemo = TRUE; } else if( pFieldInfo.uiType == 'C' ) { @@ -1024,6 +1064,7 @@ static ERRCODE WriteDBHeader( AREAP pArea ) case 'M': pHeader.uiRecordLen += 10; pHeader.bVersion = 0x83; + pArea->lpExtendInfo->fHasMemo = TRUE; break; case 'D': @@ -1133,6 +1174,8 @@ static RDDFUNCS dbfTable = { 0, /* Super Bof */ RawLock, Lock, UnLock, + CreateMemFile, + /*0, */ /* Super OpenMemFile */ ReadDBHeader, WriteDBHeader };