Extend system

Post Reply
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Extend system

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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 ) );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply