Page 1 of 1
Extend system
Posted: Tue Mar 20, 2007 9:14 am
by byte-one
Hello all,
is there an way to give back a array with nested arrays from a C-routine to Harbour? hb_reta() produces only one array.
Greetings
Posted: Tue Mar 20, 2007 9:45 am
by Antonio Linares
From Harbour Directory() source code:
Code: Select all
HB_FUNC( DIRECTORY )
{
PHB_ITEM pDirSpec = hb_param( 1, HB_IT_STRING );
PHB_ITEM pAttributes = hb_param( 2, HB_IT_STRING );
USHORT uiMask;
PHB_ITEM pDir = hb_itemArrayNew( 0 );
PHB_FFIND ffind;
/* Get the passed attributes and convert them to Harbour Flags */
uiMask = HB_FA_ARCHIVE
| HB_FA_READONLY
| HB_FA_DEVICE
| HB_FA_TEMPORARY
| HB_FA_SPARSE
| HB_FA_REPARSE
| HB_FA_COMPRESSED
| HB_FA_OFFLINE
| HB_FA_NOTINDEXED
| HB_FA_ENCRYPTED
| HB_FA_VOLCOMP;
if( pAttributes && hb_itemGetCLen( pAttributes ) > 0 )
{
if ( ( uiMask |= hb_fsAttrEncode( hb_itemGetCPtr( pAttributes ) ) ) & HB_FA_LABEL )
{
/* NOTE: This is Clipper Doc compatible. (not operationally) */
uiMask = HB_FA_LABEL;
}
}
/* Get the file list */
if( ( ffind = hb_fsFindFirst( pDirSpec ? hb_itemGetCPtr( pDirSpec ) : HB_DIR_ALL_FILES_MASK, uiMask ) ) != NULL )
{
PHB_ITEM pFilename = hb_itemNew( NULL );
PHB_ITEM pSize = hb_itemNew( NULL );
PHB_ITEM pDate = hb_itemNew( NULL );
PHB_ITEM pTime = hb_itemNew( NULL );
PHB_ITEM pAttr = hb_itemNew( NULL );
do
{
PHB_ITEM pSubarray = hb_itemArrayNew( F_LEN );
char buffer[ 32 ];
hb_arraySet( pSubarray, F_NAME, hb_itemPutC( pFilename, ffind->szName ) );
hb_arraySet( pSubarray, F_SIZE, hb_itemPutNL( pSize, ffind->size ) );
hb_arraySet( pSubarray, F_DATE, hb_itemPutDL( pDate, ffind->lDate ) );
hb_arraySet( pSubarray, F_TIME, hb_itemPutC( pTime, ffind->szTime ) );
hb_arraySet( pSubarray, F_ATTR, hb_itemPutC( pAttr, hb_fsAttrDecode( ffind->attr, buffer ) ) );
/* Don't exit when array limit is reached */
hb_arrayAdd( pDir, pSubarray );
hb_itemRelease( pSubarray );
}
while( hb_fsFindNext( ffind ) );
hb_itemRelease( pFilename );
hb_itemRelease( pSize );
hb_itemRelease( pDate );
hb_itemRelease( pTime );
hb_itemRelease( pAttr );
hb_fsFindClose( ffind );
}
hb_itemRelease( hb_itemReturn( pDir ) );
}