diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 61266f4f35..e585d557c6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,13 @@ +19990820-19:42 GMT+1 Bruno Cantero + * filelist.txt + include/rddapi.h + source/rdd/dbcmd.c + source/rdd/dbf1.c + source/rdd/sdf1.c + source/rdd/delim1.c + source/rdd/dbfntx/dbfntx1.c + dbUseArea() and dbCreate() add a default extension to filename if not provided. + 19990820-11:50 EDT Paul Tucker * source/rtl/dir.c * corrected case of iDirnameLen diff --git a/harbour/funclist.txt b/harbour/funclist.txt index 87d1796740..cc3f663974 100644 --- a/harbour/funclist.txt +++ b/harbour/funclist.txt @@ -114,7 +114,7 @@ FERROR ;R; FIELDBLOCK ;N; FIELDGET ;R; FIELDNAME ;R; -FIELDPOS ;S; +FIELDPOS ;R; FIELDPUT ;S; FIELDWBLOCK ;N; FILE ;R; diff --git a/harbour/include/rddapi.h b/harbour/include/rddapi.h index e7c8c78f05..cf841266e5 100644 --- a/harbour/include/rddapi.h +++ b/harbour/include/rddapi.h @@ -633,8 +633,8 @@ typedef struct _RDDFUNCS DBENTRYP_V goCold; DBENTRYP_V goHot; DBENTRYP_VP putRec; - DBENTRYP_SI putValue; #endif + DBENTRYP_SI putValue; DBENTRYP_V recall; DBENTRYP_LP reccount; #if 0 diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index cd0a9656b1..3fa1f7f417 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -83,6 +83,8 @@ HARBOUR HB_EOF( void ); HARBOUR HB_FCOUNT( void ); HARBOUR HB_FIELDGET( void ); HARBOUR HB_FIELDNAME( void ); +HARBOUR HB_FIELDPOS( void ); +HARBOUR HB_FIELDPUT( void ); HARBOUR HB_FOUND( void ); HARBOUR HB_LASTREC( void ); HARBOUR HB_RDDLIST( void ); @@ -117,6 +119,8 @@ HB_INIT_SYMBOLS_BEGIN( dbCmd__InitSymbols ) { "FCOUNT", FS_PUBLIC, HB_FCOUNT, 0 }, { "FIELDGET", FS_PUBLIC, HB_FIELDGET, 0 }, { "FIELDNAME", FS_PUBLIC, HB_FIELDNAME, 0 }, +{ "FIELDPOS", FS_PUBLIC, HB_FIELDPOS, 0 }, +{ "FIELDPUT", FS_PUBLIC, HB_FIELDPUT, 0 }, { "FOUND", FS_PUBLIC, HB_FOUND, 0 }, { "LASTREC", FS_PUBLIC, HB_LASTREC, 0 }, { "RDDLIST", FS_PUBLIC, HB_RDDLIST, 0 }, @@ -407,6 +411,15 @@ static ERRCODE GetValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) return SUCCESS; } +static ERRCODE PutValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +{ + HB_SYMBOL_UNUSED( pArea ); + HB_SYMBOL_UNUSED( uiIndex ); + HB_SYMBOL_UNUSED( pItem ); + printf( "Calling default: PutValue()\n" ); + return SUCCESS; +} + static ERRCODE Recall( AREAP pArea ) { HB_SYMBOL_UNUSED( pArea ); @@ -503,12 +516,16 @@ static ERRCODE Open( AREAP pArea, LPDBOPENINFO pOpenInfo ) pArea->lpFileInfo->hFile = hb_fsOpen( pOpenInfo->abName, uiFlags ); if( pArea->lpFileInfo->hFile == FS_ERROR ) + { + ( ( PHB_DYNS ) pArea->atomAlias )->hArea = 0; return FAILURE; + } if( SELF_READDBHEADER( pArea ) == FAILURE ) { hb_fsClose( pArea->lpFileInfo->hFile ); pArea->lpFileInfo->hFile = FS_ERROR; + ( ( PHB_DYNS ) pArea->atomAlias )->hArea = 0; return FAILURE; } @@ -588,6 +605,7 @@ static RDDFUNCS defTable = { Bof, FieldName, Flush, GetValue, + PutValue, Recall, RecCount, RecNo, @@ -753,6 +771,7 @@ HARBOUR HB_DBCREATE( void ) USHORT uiSize, uiRddID; DBOPENINFO pInfo; WORD wLen; + PHB_FNAME pFileName; szFileName = hb_parc( 1 ); pStruct = hb_param( 2 , IT_ARRAY ); @@ -810,13 +829,20 @@ HARBOUR HB_DBCREATE( void ) SELF_NEW( ( AREAP ) pTempArea ); SELF_CREATEFIELDS( ( AREAP ) pTempArea, pStruct ); - pInfo.abName = ( BYTE * ) szFileName; + pFileName = hb_fsFNameSplit( szFileName ); - /* TODO: append default extension to szFileName if necessary */ - /* SELF_INFO( ( AREAP ) pTempArea, DBI_TABLEEXT, pItem ) */ + szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 3 ); + strcpy( szFileName, hb_parc( 1 ) ); + if( !pFileName->szExtension ) + { + HB_DBTABLEEXT(); + strcat( szFileName, hb_parc( -1 ) ); + } + pInfo.abName = ( BYTE * ) szFileName; SELF_CREATE( ( AREAP ) pTempArea, &pInfo ); SELF_RELEASE( ( AREAP ) pTempArea ); + hb_xfree( szFileName ); hb_xfree( pTempArea ); } @@ -992,6 +1018,7 @@ HARBOUR HB_DBUSEAREA( void ) LPAREANODE pAreaNode; USHORT uiSize, uiRddID; DBOPENINFO pInfo; + PHB_FNAME pFileName; uiNetError = 0; @@ -1039,10 +1066,10 @@ HARBOUR HB_DBUSEAREA( void ) return; } - /* TODO: Implement szAlias from szFilename */ + pFileName = hb_fsFNameSplit( szFileName ); szAlias = hb_parc( 4 ); if( strlen( szAlias ) == 0 ) - szAlias = szFileName; + szAlias = pFileName->szName; /* Create a new WorkArea node */ @@ -1075,21 +1102,33 @@ HARBOUR HB_DBUSEAREA( void ) 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 */ @@ -1184,6 +1223,50 @@ HARBOUR HB_FIELDNAME( void ) hb_retc( "" ); } +HARBOUR HB_FIELDPOS( void ) +{ + USHORT uiCount; + char * szName; + LPFIELD pField; + + if( pCurrArea && ( ( AREAP ) pCurrArea->pArea )->lprfsHost ) + { + szName = hb_parc( 1 ); + szName = hb_strUpper( szName, strlen( szName ) ); + uiCount = 0; + pField = ( ( AREAP ) pCurrArea->pArea )->lpFields; + while( pField ) + { + if( strcmp( szName, ( char * ) pField->sym ) == 0 ) + { + hb_retni( uiCount + 1 ); + return; + } + pField = pField->lpfNext; + uiCount++; + } + } + hb_retni( 0 ); +} + +HARBOUR HB_FIELDPUT( void ) +{ + USHORT uiIndex; + PHB_ITEM pItem; + + uiIndex = hb_parni( 1 ); + if( pCurrArea && ( ( AREAP ) pCurrArea->pArea )->lprfsHost && uiIndex ) + { + pItem = hb_param( 2, IT_ANY ); + if( SELF_PUTVALUE( ( AREAP ) pCurrArea->pArea, uiIndex, pItem ) == SUCCESS ) + { + hb_itemReturn( pItem ); + return; + } + } + hb_ret(); +} + HARBOUR HB_FOUND( void ) { BOOL bFound = FALSE; diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index dea0565d38..a78bbaf951 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -29,6 +29,8 @@ #include "init.h" #include "rddapi.h" #include "rddsys.ch" +#include "errorapi.h" +#include "dates.h" typedef struct { @@ -257,6 +259,84 @@ static ERRCODE GetValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) return SUCCESS; } +static ERRCODE PutValue( AREAP pArea, USHORT uiIndex, PHB_ITEM pItem ) +{ + LPFIELD pField; + USHORT uiCount, uiOffset; + BYTE * szText, * szOldChar, szEndChar; + BOOL bError; + long lDay, lMonth, lYear; + + 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; + bError = TRUE; + szOldChar = szText + pField->uiLen; + switch( pField->uiType ) + { + case 'C': + if( pItem->type & IT_STRING ) + { + szOldChar = szText + pField->uiLen + ( ( USHORT ) pField->uiDec << 8 ); + szEndChar = * szOldChar; + sprintf( szText, "%-*s", pField->uiLen, pItem->item.asString.value ); + bError = FALSE; + } + break; + + case 'N': + if( pItem->type & IT_NUMERIC ) + { + if( pField->uiDec ) + sprintf( szText, "%*.*f", pField->uiLen, pField->uiDec, pItem->item.asDouble.value ); + else + sprintf( szText, "%*ld", pField->uiLen, pItem->item.asInteger.value ); + bError = FALSE; + } + break; + + case 'D': + if( pItem->type & IT_DATE ) + { + hb_dateDecode( pItem->item.asDate.value, &lDay, &lMonth, &lYear ); + hb_dateStrPut( szText, lDay, lMonth, lYear ); + bError = FALSE; + } + break; + + case 'L': + if( pItem->type & IT_LOGICAL ) + { + if( pItem->item.asLogical.value ) + *szText = 'T'; + else + *szText = 'F'; + bError = FALSE; + } + break; + } + * szOldChar = szEndChar; + + if( bError ) + { + printf( "Error 1020 EG_DATATYPE\n" ); + return FAILURE; + } + return SUCCESS; +} + static ERRCODE RecCount( AREAP pArea, LONG * pRecCount ) { DBFHEADER pHeader; @@ -472,6 +552,7 @@ static RDDFUNCS dbfTable = { 0, /* Super Bof */ 0, /* Super FieldName */ 0, /* Super Flush */ GetValue, + PutValue, 0, /* Super Recall */ RecCount, 0, /* Super RecNo */ diff --git a/harbour/source/rdd/dbfntx/dbfntx1.c b/harbour/source/rdd/dbfntx/dbfntx1.c index 1a9109e590..80cb7e551e 100644 --- a/harbour/source/rdd/dbfntx/dbfntx1.c +++ b/harbour/source/rdd/dbfntx/dbfntx1.c @@ -69,6 +69,7 @@ static RDDFUNCS ntxTable = { 0, /* Super Bof */ 0, /* Super FieldName */ 0, /* Super Flush */ 0, /* Super GetValue */ + 0, /* Super PutValue */ 0, /* Super Recall */ 0, /* Super RecCount */ 0, /* Super SetFieldExtent */ diff --git a/harbour/source/rdd/delim1.c b/harbour/source/rdd/delim1.c index 825e0895c5..3450ac0fb5 100644 --- a/harbour/source/rdd/delim1.c +++ b/harbour/source/rdd/delim1.c @@ -79,6 +79,7 @@ static RDDFUNCS delimTable = { 0, /* Super Bof */ 0, /* Super FieldName */ 0, /* Super Flush */ 0, /* Super GetValue */ + 0, /* Super PutValue */ 0, /* Super Recall */ 0, /* Super RecCount */ 0, /* Super RecNo */ diff --git a/harbour/source/rdd/sdf1.c b/harbour/source/rdd/sdf1.c index 60e628e348..a3dd4a954c 100644 --- a/harbour/source/rdd/sdf1.c +++ b/harbour/source/rdd/sdf1.c @@ -79,6 +79,7 @@ static RDDFUNCS sdfTable = { 0, /* Super Bof */ 0, /* Super FieldName */ 0, /* Super Flush */ 0, /* Super GetValue */ + 0, /* Super PutValue */ 0, /* Super Recall */ 0, /* Super RecCount */ 0, /* Super RecNo */