Ejemplo n.º 1
0
static void hb_delimInitArea( DELIMAREAP pArea, char * szFileName )
{
   char * szEol;

   /* Allocate only after succesfully open file */
   pArea->szFileName = hb_strdup( szFileName );

   /* set line separator: EOL */
   szEol = hb_setGetEOL();
   if( !szEol || !szEol[ 0 ] )
      szEol = hb_conNewLine();
   pArea->szEol = hb_strdup( szEol );
   pArea->uiEolLen = strlen( pArea->szEol );

   /* allocate record buffer, one additional byte is for deleted flag */
   pArea->pRecord = ( BYTE * ) hb_xgrab( pArea->uiRecordLen + 1 );
   /* pseudo deleted flag */
   *pArea->pRecord++ = ' ';

   /* Allocate IO buffer */
   pArea->ulBufferSize += pArea->uiEolLen;
   pArea->pBuffer = ( BYTE * ) hb_xgrab( pArea->ulBufferSize );

   pArea->ulRecCount = 0;
   pArea->ulFileSize = 0;
   pArea->ulBufferRead = pArea->ulBufferIndex = 0;
}
Ejemplo n.º 2
0
char * hb_jsonEncode( PHB_ITEM pValue, HB_SIZE * pnLen, HB_BOOL fHuman )
{
   PHB_JSON_ENCODE_CTX pCtx;
   char * szRet;
   HB_SIZE nLen;

   pCtx = ( PHB_JSON_ENCODE_CTX ) hb_xgrab( sizeof( HB_JSON_ENCODE_CTX ) );
   pCtx->nAlloc = 16;
   pCtx->pHead = pCtx->pBuffer = ( char * ) hb_xgrab( pCtx->nAlloc );
   pCtx->nAllocId = 8;
   pCtx->pId = ( void ** ) hb_xgrab( sizeof( void * ) * pCtx->nAllocId );
   pCtx->fHuman = fHuman;
   pCtx->szEol = hb_setGetEOL();
   if( ! pCtx->szEol || ! pCtx->szEol[ 0 ] )
      pCtx->szEol = hb_conNewLine();
   pCtx->iEolLen = ( int ) strlen( pCtx->szEol );

   _hb_jsonEncode( pValue, pCtx, 0, HB_FALSE );

   nLen = pCtx->pHead - pCtx->pBuffer;
   szRet = ( char * ) hb_xrealloc( pCtx->pBuffer, nLen + 1 );
   szRet[ nLen ] = '\0';
   hb_xfree( pCtx->pId );
   hb_xfree( pCtx );
   if( pnLen )
      *pnLen = nLen;
   return szRet;
}
Ejemplo n.º 3
0
static void hb_sdfInitArea( SDFAREAP pArea, char * szFileName )
{
   const char * szEol;

   /* Allocate only after succesfully open file */
   pArea->szFileName = hb_strdup( szFileName );

   /* set line separator: EOL */
   szEol = hb_setGetEOL();
   if( ! szEol || ! szEol[ 0 ] )
      szEol = hb_conNewLine();
   pArea->szEol = hb_strdup( szEol );
   pArea->uiEolLen = ( HB_USHORT ) strlen( pArea->szEol );

   /* Alloc buffer */
   pArea->pRecord = ( HB_BYTE * ) hb_xgrab( pArea->uiRecordLen + pArea->uiEolLen + 3 );
   /* pseudo deleted flag */
   *pArea->pRecord++ = ' ';

   pArea->nFileSize = 0;
   pArea->ulRecCount = 0;
}
Ejemplo n.º 4
0
static void hb_sdfInitArea( SDFAREAP pArea, char * szFileName )
{
   const char * szEol;

   /* Allocate only after succesfully open file */
   pArea->szFileName = hb_strdup( szFileName );

   /* set line separator: EOL */
   szEol = hb_setGetEOL();
   if( ! szEol || ! szEol[ 0 ] )
      szEol = hb_conNewLine();
   pArea->szEol = hb_strdup( szEol );
   pArea->uiEolLen = ( HB_USHORT ) strlen( szEol );
   pArea->fAnyEol = ( szEol[ 0 ] == '\n' || szEol[ 0 ] == '\r' ) &&
                    ( pArea->uiEolLen == 1 ||
                      ( pArea->uiEolLen == 2 && szEol[ 0 ] != szEol[ 1 ] &&
                        ( szEol[ 1 ] == '\n' || szEol[ 1 ] == '\r' ) ) );

   /* allocate record buffer, one additional byte is for deleted flag */
   pArea->pRecord = ( HB_BYTE * ) hb_xgrab( pArea->uiRecordLen + pArea->uiEolLen + 1 );
   /* pseudo deleted flag */
   *pArea->pRecord++ = ' ';
   memcpy( pArea->pRecord + pArea->uiRecordLen,
           pArea->szEol, pArea->uiEolLen );

   if( pArea->fReadonly )
   {
      /* allocate IO buffer */
      pArea->nBufferSize += pArea->fAnyEol ? 2 : pArea->uiEolLen;
      if( pArea->nBufferSize < 8192 )
         pArea->nBufferSize = 8192;
      pArea->pBuffer = ( HB_BYTE * ) hb_xgrab( pArea->nBufferSize );
   }
   pArea->ulRecCount = 0;
   pArea->nBufferIndex = pArea->nBufferRead = pArea->nBufferSize;
}
Ejemplo n.º 5
0
static void hb_mlGetEOLs( PHB_MLC_INFO pMLC, int iParam )
{
   int iEOLs = 0;
   HB_SIZE nLen;

   pMLC->pEOLs = pMLC->EOL_buffer;

/* NOTE: This is a parameter extension (HB_EXTENSION) which breaks
         our effort to keep strict parameter compatibility with
         Clipper 5.x. In this case we've resorted to a compromise
         because there was no other idea which seemed natural enough.
         Clipper will ignore these parameters and use CRLF EOL hard
         coded. [vszakats] */
#ifndef HB_CLP_STRICT /* HB_EXTENSION */
   nLen = hb_parclen( iParam );
   if( nLen )
   {
      pMLC->pEOLs[ 0 ].szEOL = hb_parc( iParam );
      pMLC->pEOLs[ 0 ].nLen = nLen;
      iEOLs = 1;
   }
   else if( HB_ISARRAY( iParam ) )
   {
      PHB_ITEM pArray = hb_param( iParam, HB_IT_ARRAY );
      HB_SIZE nSize = hb_arrayLen( pArray ), n;

      for( n = 1; n <= nSize; ++n )
      {
         if( hb_arrayGetCLen( pArray, n ) > 0 )
            ++iEOLs;
      }
      if( iEOLs )
      {
         if( iEOLs > HB_EOL_BUFFER_SIZE )
            pMLC->pEOLs = ( PHB_EOL_INFO ) hb_xgrab( sizeof( HB_EOL_INFO ) * iEOLs );
         iEOLs = 0;
         for( n = 1; n <= nSize; ++n )
         {
            nLen = hb_arrayGetCLen( pArray, n );
            if( nLen > 0 )
            {
               pMLC->pEOLs[ iEOLs ].szEOL = hb_arrayGetCPtr( pArray, n );
               pMLC->pEOLs[ iEOLs ].nLen = nLen;
               ++iEOLs;
            }
         }
      }
   }
#else
   HB_SYMBOL_UNUSED( iParam );
   HB_SYMBOL_UNUSED( nLen );
#endif

   if( iEOLs == 0 )
   {
      pMLC->pEOLs[ 0 ].szEOL = hb_setGetEOL();
      if( ! pMLC->pEOLs[ 0 ].szEOL || ! pMLC->pEOLs[ 0 ].szEOL[ 0 ] )
         pMLC->pEOLs[ 0 ].szEOL = hb_conNewLine();
      pMLC->pEOLs[ 0 ].nLen = strlen( pMLC->pEOLs[ 0 ].szEOL );
      iEOLs = pMLC->pEOLs[ 0 ].nLen ? 1 : 0;
   }

   pMLC->iEOLs = iEOLs;
}