예제 #1
0
HB_SIZE hb_inkeyKeyString( int iKey, char * buffer, HB_SIZE nSize )
{
   HB_SIZE nLen = 0;

   HB_TRACE( HB_TR_DEBUG, ( "hb_inkeyKeyString(%d,%p, %" HB_PFS "u)", iKey, buffer, nSize ) );

   if( HB_INKEY_ISUNICODE( iKey ) )
   {
      nLen = hb_cdpTextPutU16( hb_vmCDP(), buffer, nSize, HB_INKEY_VALUE( iKey ) );
   }
   else
   {
      if( HB_INKEY_ISCHAR( iKey ) )
         iKey = HB_INKEY_VALUE( iKey );
      else if( HB_INKEY_ISKEY( iKey ) )
      {
         int iFlags = HB_INKEY_FLAGS( iKey );

         iKey = HB_INKEY_VALUE( iKey );

         if( iKey > 0 && iKey <= ( int ) HB_SIZEOFARRAY( s_transKeyFun ) )
            iKey = s_inkeyTransChar( iKey, iFlags, &s_transKeyFun[ iKey - 1 ] );
         else if( iKey >= 32 && iKey <= 127 )
            iKey = s_inkeyTransChar( iKey, iFlags, &s_transKeyStd[ iKey - 32 ] );
      }
      if( iKey >= 32 && iKey <= 255 && iKey != 127 )
      {
         PHB_CODEPAGE cdp = hb_vmCDP();
         nLen = hb_cdpTextPutU16( cdp, buffer, nSize,
                                  hb_cdpGetU16( cdp, ( HB_UCHAR ) iKey ) );
      }
   }
   return nLen;
}
예제 #2
0
void hb_dbQSortComplete( LPDBQUICKSORT pQuickSort )
{
   HB_ULONG ulRecCount;
   AREAP pArea;

   ulRecCount = hb_fsSeek( pQuickSort->hFile, 0, FS_END ) / pQuickSort->uiRecordLen;
   if( ulRecCount >= 1 )
   {
      hb_dbQSortDo( pQuickSort, 1, ulRecCount );
      pArea = pQuickSort->pSortInfo->dbtri.lpaDest;
      hb_fsSeek( pQuickSort->hFile, 0, FS_SET );
      while( ulRecCount-- > 0 )
      {
         /* Read sorted record */
         hb_fsRead( pQuickSort->hFile, pQuickSort->pSwapBufferA, pQuickSort->uiRecordLen );

         /* Remove deleted flag */
         pQuickSort->pSwapBufferA[ 0 ] = ' ';

         if( pArea->cdPage != hb_vmCDP() )
         {
            hb_dbfTranslateRec( ( DBFAREAP ) pArea, ( HB_BYTE * ) pQuickSort->pSwapBufferA, hb_vmCDP(), pArea->cdPage );
         }

         /* Append a new record and copy data */
         if( SELF_APPEND( pArea, HB_TRUE ) == HB_FAILURE ||
             SELF_PUTREC( pArea, pQuickSort->pSwapBufferA ) == HB_FAILURE )
            break;
      }
   }
   hb_dbQSortExit( pQuickSort );
}
예제 #3
0
파일: adsx.c 프로젝트: SBCamus/core
static HB_ERRCODE adsxOpen( ADSXAREAP pArea, LPDBOPENINFO pOpenInfo )
{
   if( SUPER_OPEN( ( AREAP ) pArea, pOpenInfo ) == HB_SUCCESS )
   {
      if( pOpenInfo->cdpId )
      {
         pArea->adsarea.area.cdPage = hb_cdpFind( pOpenInfo->cdpId );
         if( ! pArea->adsarea.area.cdPage )
            pArea->adsarea.area.cdPage = hb_vmCDP();
      }
      else
         pArea->adsarea.area.cdPage = hb_vmCDP();
      return HB_SUCCESS;
   }
   return HB_FAILURE;
}
예제 #4
0
파일: inkeyapi.c 프로젝트: ggargano/hbtest2
int hb_inkeyKeyStd( int iKey )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_inkeyKeyStd(%d)", iKey ) );

   if( HB_INKEY_ISEXT( iKey ) )
   {
      if( HB_INKEY_ISUNICODE( iKey ) )
      {
         HB_WCHAR wc = ( HB_WCHAR ) HB_INKEY_VALUE( iKey );
         if( wc )
         {
            HB_UCHAR uc = hb_cdpGetUC( hb_vmCDP(), wc, 0 );
            if( uc != 0 )
               iKey = uc;
         }
         else
            iKey = 0;
      }
      else if( HB_INKEY_ISMOUSEPOS( iKey ) )
         iKey = K_MOUSEMOVE;
      else
         iKey = HB_INKEY_VALUE( iKey );
   }
   return iKey;
}
예제 #5
0
파일: mlcfunc.c 프로젝트: JamesLinus/core
static HB_BOOL hb_mlInit( PHB_MLC_INFO pMLC, int iParAdd )
{
   HB_ISIZ nSize = hb_parnsdef( 2, 79 );

   pMLC->pszString = hb_parc( 1 );
   if( pMLC->pszString && nSize > 0 )
   {
      pMLC->nOffset = pMLC->nMaxCol = pMLC->nMaxPos = pMLC->nCol = 0;

      pMLC->nLineLength = nSize;
      pMLC->nLen = hb_parclen( 1 );

      pMLC->nTabSize = hb_parnsdef( 3 + iParAdd, 4 );
      pMLC->fWordWrap = hb_parldef( 4 + iParAdd, 1 );

#ifdef HB_CLP_STRICT
      if( pMLC->nLineLength > 254 )
         pMLC->nLineLength = 79;
#endif
      if( pMLC->nTabSize >= pMLC->nLineLength )
         pMLC->nTabSize = pMLC->nLineLength - 1;
      if( pMLC->nTabSize == 0 )
         pMLC->nTabSize = 1;

      pMLC->cdp = hb_vmCDP();
      if( ! HB_CDP_ISCHARIDX( pMLC->cdp ) )
         pMLC->cdp = NULL;

      hb_mlGetEOLs( pMLC, 5 + iParAdd );
      return HB_TRUE;
   }

   return HB_FALSE;
}
예제 #6
0
static void hb_inkeySetTextKeys( const char * pszText, HB_SIZE nSize, HB_BOOL fInsert )
{
   PHB_CODEPAGE cdp = hb_vmCDP();
   HB_SIZE nIndex = 0;
   HB_WCHAR wc;

   if( fInsert )
   {
      HB_WCHAR buffer[ 32 ], * keys;
      HB_SIZE n = 0;

      keys = nSize <= HB_SIZEOFARRAY( buffer ) ? buffer :
                        ( HB_WCHAR * ) hb_xgrab( nSize * sizeof( HB_WCHAR ) );
      while( HB_CDPCHAR_GET( cdp, pszText, nSize, &nIndex, &wc ) )
         keys[ n++ ] = wc;

      while( n-- )
      {
         int iKey = keys[ n ] >= 128 ? HB_INKEY_NEW_UNICODE( keys[ n ] ) : keys[ n ];
         hb_inkeyIns( iKey );
      }
      if( nSize > HB_SIZEOFARRAY( buffer ) )
         hb_xfree( keys );
   }
   else
   {
      while( HB_CDPCHAR_GET( cdp, pszText, nSize, &nIndex, &wc ) )
      {
         int iKey = wc >= 128 ? HB_INKEY_NEW_UNICODE( wc ) : wc;
         hb_inkeyPut( iKey );
      }
   }
}
예제 #7
0
파일: fstemp.c 프로젝트: alcz/harbour
static HB_BOOL fsGetTempDirByCase( char * pszName, const char * pszTempDir, HB_BOOL fTrans )
{
   HB_BOOL fOK = HB_FALSE;

   if( pszTempDir && *pszTempDir != '\0' )
   {
      char * pTmp;

      if( fTrans )
         hb_osStrDecode2( pszTempDir, pszName, HB_PATH_MAX - 1 );
      else
         hb_strncpy( pszName, pszTempDir, HB_PATH_MAX - 1 );

      switch( hb_setGetDirCase() )
      {
         case HB_SET_CASE_LOWER:
            pTmp = hb_cdpnDupLower( hb_vmCDP(), pszName, NULL );
            fOK = strcmp( pszName, pTmp ) == 0;
            hb_xfree( pTmp );
            break;
         case HB_SET_CASE_UPPER:
            pTmp = hb_cdpnDupUpper( hb_vmCDP(), pszName, NULL );
            fOK = strcmp( pszName, pTmp ) == 0;
            hb_xfree( pTmp );
            break;
         default:
            fOK = HB_TRUE;
            break;
      }
   }

   if( fOK )
   {
#  if defined( __DJGPP__ ) || defined( HB_OS_OS2 )
      /* convert '/' to '\' */
      char * pszDelim = pszName;
      while( ( pszDelim = strchr( pszDelim, '/' ) ) != NULL )
         *pszDelim = '\\';
#  endif
      if( ! hb_fsDirExists( pszTempDir ) )
         fOK = HB_FALSE;
   }

   return fOK;
}
예제 #8
0
파일: strwild.c 프로젝트: Andygon/core
HB_BOOL hb_strMatchCaseWildExact( const char * szString, const char * szPattern )
{
   PHB_CODEPAGE cdp = hb_vmCDP();

   if( cdp && HB_CDP_ISCHARIDX( cdp ) )
      return hb_strMatchWildCDP( szString, szPattern, HB_TRUE, HB_TRUE, HB_FALSE, cdp );
   else
      return hb_strMatchWildRaw( szString, szPattern, HB_TRUE, HB_TRUE, HB_FALSE );
}
예제 #9
0
파일: hbi18n1.c 프로젝트: JamesLinus/core
PHB_ITEM hb_i18n_gettext( PHB_ITEM pMsgID, PHB_ITEM pContext )
{
   PHB_I18N_TRANS pI18N = hb_i18n_table();
   PHB_CODEPAGE cdpage = NULL;
   PHB_ITEM pMsgDst = pMsgID;

   if( pI18N )
   {
      PHB_ITEM pTable = pContext && pI18N->context_table ?
                        hb_hashGetItemPtr( pI18N->context_table, pContext, 0 ) :
                        pI18N->default_context;

      cdpage = pI18N->base_cdpage;
      if( pTable )
      {
         pTable = hb_hashGetItemPtr( pTable, pMsgID, 0 );
         if( pTable )
         {
            if( HB_IS_ARRAY( pTable ) )
               pTable = hb_arrayGetItemPtr( pTable, 1 );
            if( pTable && HB_IS_STRING( pTable ) )
            {
               pMsgID = pTable;
               cdpage = pI18N->cdpage;
            }
         }
      }
   }

   if( pMsgID )
   {
      if( HB_IS_STRING( pMsgID ) )
      {
         if( cdpage )
         {
            PHB_CODEPAGE cdp = hb_vmCDP();
            if( cdp && cdp != cdpage )
            {
               if( pMsgDst != pMsgID )
               {
                  hb_itemCopy( pMsgDst, pMsgID );
                  pMsgID = pMsgDst;
               }
               hb_i18n_transitm( pMsgID, cdpage, cdp );
            }
         }
      }
      else
         pMsgID = NULL;
   }

   return pMsgID;
}
예제 #10
0
파일: sxsem.c 프로젝트: JamesLinus/core
static HB_BOOL hb_sxSemName( char * szFileName )
{
   const char * szName = hb_parc( 1 );
   HB_BOOL fResult = HB_FALSE;

   if( szName && szName[ 0 ] )
   {
      hb_cdpnDup2Lower( hb_vmCDP(), szName, strlen( szName ),
                        szFileName, HB_PATH_MAX );
      szFileName[ HB_PATH_MAX - 1 ] = '\0';
      fResult = HB_TRUE;
   }
   else
   {
      AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();

      if( pArea )
      {
         DBORDERINFO pOrderInfo;

         memset( &pOrderInfo, 0, sizeof( pOrderInfo ) );
         pOrderInfo.itmOrder = hb_param( 1, HB_IT_NUMERIC );
         if( pOrderInfo.itmOrder && hb_itemGetNI( pOrderInfo.itmOrder ) == 0 )
            pOrderInfo.itmOrder = NULL;
         pOrderInfo.itmResult = hb_itemPutC( NULL, NULL );
         SELF_ORDINFO( pArea, DBOI_NAME, &pOrderInfo );
         szName = hb_itemGetCPtr( pOrderInfo.itmResult );
         if( szName && szName[ 0 ] )
         {
            hb_cdpnDup2Lower( hb_vmCDP(), szName, strlen( szName ),
                              szFileName, HB_PATH_MAX );
            szFileName[ HB_PATH_MAX - 1 ] = '\0';
            fResult = HB_TRUE;
         }
         hb_itemRelease( pOrderInfo.itmResult );
      }
   }

   return fResult;
}
예제 #11
0
파일: inkeyapi.c 프로젝트: Andygon/core
HB_SIZE hb_inkeyKeyString( int iKey, char * buffer, HB_SIZE nSize )
{
   HB_SIZE nLen = 0;

   HB_TRACE( HB_TR_DEBUG, ( "hb_inkeyKeyString(%d,%p, %" HB_PFS "u)", iKey, buffer, nSize ) );

   if( HB_INKEY_ISUNICODE( iKey ) )
   {
      nLen = hb_cdpTextPutU16( hb_vmCDP(), buffer, nSize, HB_INKEY_VALUE( iKey ) );
   }
   else
   {
      if( HB_INKEY_ISCHAR( iKey ) )
         iKey = HB_INKEY_VALUE( iKey );
      if( iKey >= 32 && iKey <= 255 && iKey != 127 )
      {
         PHB_CODEPAGE cdp = hb_vmCDP();
         nLen = hb_cdpTextPutU16( cdp, buffer, nSize,
                                  hb_cdpGetU16( cdp, ( HB_UCHAR ) iKey ) );
      }
   }
   return nLen;
}
예제 #12
0
static PHB_CODEPAGE _hb_jsonCdpPar( int iParam, HB_BOOL lVmCp )
{
   if( hb_pcount() >= iParam )
   {
      const char * szCdp = hb_parc( iParam );

      if( szCdp )
         return hb_cdpFindExt( szCdp );
   }
   else if( lVmCp )
      return hb_vmCDP();

   return NULL;
}
예제 #13
0
파일: inkeyapi.c 프로젝트: Andygon/core
int hb_inkeyKeyStd( int iKey )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_inkeyKeyStd(%d)", iKey ) );

   if( HB_INKEY_ISEXT( iKey ) )
   {
      int iFlags = HB_INKEY_FLAGS( iKey );

      if( HB_INKEY_ISMOUSEPOS( iKey ) )
         iKey = K_MOUSEMOVE;
      else if( HB_INKEY_ISKEY( iKey ) )
      {
         iKey = HB_INKEY_VALUE( iKey );

         if( iKey > 0 && iKey <= ( int ) HB_SIZEOFARRAY( s_transKeyFun ) )
            iKey = s_inkeyTransChar( iKey, iFlags, &s_transKeyFun[ iKey - 1 ] );
         else if( iKey >= 32 && iKey <= 127 )
            iKey = s_inkeyTransChar( iKey, iFlags, &s_transKeyStd[ iKey - 32 ] );
      }
      else if( HB_INKEY_ISCHAR( iKey ) || HB_INKEY_ISUNICODE( iKey ) )
      {
         int iVal = HB_INKEY_VALUE( iKey );

         if( iVal >= 32 && iVal <= 127 &&
             ( iFlags & ( HB_KF_ALT | HB_KF_CTRL ) ) != 0 )
            iKey = s_inkeyTransChar( iVal, iFlags, &s_transKeyStd[ iVal - 32 ] );
         else if( HB_INKEY_ISUNICODE( iKey ) )
         {
            HB_WCHAR wc = ( HB_WCHAR ) iVal;
            if( wc )
            {
               HB_UCHAR uc = hb_cdpGetUC( hb_vmCDP(), wc, 0 );
               if( uc != 0 )
                  iKey = uc;
            }
            else
               iKey = 0;
         }
         else
            iKey = iVal;
      }
      else /* HB_INKEY_ISMOUSEKEY | HB_INKEY_ISEVENT */
         iKey = HB_INKEY_VALUE( iKey );
   }
   return iKey;
}
예제 #14
0
파일: hbxml2.c 프로젝트: emazv72/hbcontrib
static xmlChar * xml_cdpStrToUTF8( const char * szStr, HB_SIZE * pnLen, const char * pszCdpIn )
{

   PHB_CODEPAGE cdpIn  = pszCdpIn ? hb_cdpFindExt( pszCdpIn ) : hb_vmCDP();
   PHB_CODEPAGE cdpOut = hb_cdpFindExt( XML_UTF8_HB_CDP );

   char * szDest = NULL;

   if( cdpIn && cdpOut && szStr )
   {
      int len = strlen( szStr );
      memcpy( pnLen, &len, sizeof( len ) );

      szDest = hb_cdpnDup( szStr, pnLen, cdpIn, cdpOut );
   }

   return ( xmlChar * ) szDest;
}
예제 #15
0
파일: strwild.c 프로젝트: Andygon/core
HB_BOOL hb_strMatchFile( const char * szString, const char * szPattern )
{
#if defined( HB_OS_UNIX )
#  if defined( HB_NO_FNMATCH )
   return hb_strMatchWildExact( szString, szPattern );
#  else
   return fnmatch( szPattern, szString, FNM_PERIOD | FNM_PATHNAME ) == 0;
#  endif
#elif defined( HB_OS_DOS ) || defined( HB_OS_WIN ) || defined( HB_OS_OS2 )
   PHB_CODEPAGE cdp = hb_vmCDP();

   if( cdp && HB_CDP_ISCHARIDX( cdp ) )
      return hb_strMatchWildCDP( szString, szPattern, HB_TRUE, HB_TRUE, HB_TRUE, cdp );
   else
      return hb_strMatchWildRaw( szString, szPattern, HB_TRUE, HB_TRUE, HB_TRUE );
#else
   return hb_strMatchCaseWildExact( szString, szPattern );
#endif
}
예제 #16
0
파일: hardcr.c 프로젝트: AmericoBalboa/core
static char * hb_strHardCR( char * pszString, HB_SIZE nStringLen )
{
   HB_SIZE nStringPos;
   PHB_CODEPAGE cdp;

   HB_TRACE( HB_TR_DEBUG, ( "hb_strHardCR(%s, %" HB_PFS "u)", pszString, nStringLen ) );

   cdp = hb_vmCDP();
   if( HB_CDP_ISCUSTOM( cdp ) )
   {
      HB_WCHAR wc;

      nStringPos = 0;
      while( nStringPos < nStringLen )
      {
         if( pszString[ nStringPos ]     == HB_CHAR_SOFT1 &&
             pszString[ nStringPos + 1 ] == HB_CHAR_SOFT2 )
         {
            pszString[ nStringPos ] = HB_CHAR_HARD1;
            nStringPos += 2;
         }
         else if( ! HB_CDPCHAR_GET( cdp, pszString, nStringLen, &nStringPos, &wc ) )
            break;
      }
   }
   else
   {
      for( nStringPos = 0; nStringPos < nStringLen; nStringPos++ )
      {
         if( pszString[ nStringPos ]     == HB_CHAR_SOFT1 &&
             pszString[ nStringPos + 1 ] == HB_CHAR_SOFT2 )
         {
            pszString[ nStringPos++ ] = HB_CHAR_HARD1;
         }
      }
   }
   return pszString;
}
예제 #17
0
파일: sdf1.c 프로젝트: AmericoBalboa/core
/*
 * Open a data store in the WorkArea.
 */
static HB_ERRCODE hb_sdfOpen( SDFAREAP pArea, LPDBOPENINFO pOpenInfo )
{
   PHB_ITEM pError = NULL;
   PHB_FNAME pFileName;
   HB_ERRCODE errCode;
   HB_USHORT uiFlags;
   HB_BOOL fRetry;
   char szFileName[ HB_PATH_MAX ];
   char szAlias[ HB_RDD_MAX_ALIAS_LEN + 1 ];

   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfOpen(%p,%p)", pArea, pOpenInfo ) );

   pArea->fShared = HB_TRUE;     /* pOpenInfo->fShared; */
   pArea->fReadonly = HB_TRUE;   /* pOpenInfo->fReadonly; */

   if( pOpenInfo->cdpId )
   {
      pArea->area.cdPage = hb_cdpFindExt( pOpenInfo->cdpId );
      if( ! pArea->area.cdPage )
         pArea->area.cdPage = hb_vmCDP();
   }
   else
      pArea->area.cdPage = hb_vmCDP();

   uiFlags = ( pArea->fReadonly ? FO_READ : FO_READWRITE ) |
             ( pArea->fShared ? FO_DENYNONE : FO_EXCLUSIVE );

   pFileName = hb_fsFNameSplit( pOpenInfo->abName );
   /* Add default file name extension if necessary */
   if( hb_setGetDefExtension() && ! pFileName->szExtension )
   {
      PHB_ITEM pFileExt = hb_itemPutC( NULL, NULL );
      SELF_INFO( &pArea->area, DBI_TABLEEXT, pFileExt );
      pFileName->szExtension = hb_itemGetCPtr( pFileExt );
      hb_fsFNameMerge( szFileName, pFileName );
      hb_itemRelease( pFileExt );
   }
   else
   {
      hb_strncpy( szFileName, pOpenInfo->abName, sizeof( szFileName ) - 1 );
   }

   /* Create default alias if necessary */
   if( ! pOpenInfo->atomAlias && pFileName->szName )
   {
      const char * szName = strrchr( pFileName->szName, ':' );
      if( szName == NULL )
         szName = pFileName->szName;
      else
         ++szName;
      hb_strncpyUpperTrim( szAlias, szName, sizeof( szAlias ) - 1 );
      pOpenInfo->atomAlias = szAlias;
   }
   hb_xfree( pFileName );

   /* Try open */
   do
   {
      pArea->pFile = hb_fileExtOpen( szFileName, NULL, uiFlags |
                                     FXO_DEFAULTS | FXO_SHARELOCK |
                                     FXO_COPYNAME | FXO_NOSEEKPOS,
                                     NULL, pError );
      if( ! pArea->pFile )
      {
         if( ! pError )
         {
            pError = hb_errNew();
            hb_errPutGenCode( pError, EG_OPEN );
            hb_errPutSubCode( pError, EDBF_OPEN_DBF );
            hb_errPutOsCode( pError, hb_fsError() );
            hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_OPEN ) );
            hb_errPutFileName( pError, szFileName );
            hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT );
         }
         fRetry = ( SELF_ERROR( &pArea->area, pError ) == E_RETRY );
      }
      else
         fRetry = HB_FALSE;
   }
   while( fRetry );

   if( pError )
      hb_itemRelease( pError );

   if( ! pArea->pFile )
      return HB_FAILURE;

   errCode = SUPER_OPEN( &pArea->area, pOpenInfo );
   if( errCode != HB_SUCCESS )
   {
      SELF_CLOSE( &pArea->area );
      return HB_FAILURE;
   }

   hb_sdfInitArea( pArea, szFileName );

   /* Position cursor at the first record */
   return SELF_GOTOP( &pArea->area );
}
예제 #18
0
파일: hbi18n1.c 프로젝트: JamesLinus/core
PHB_ITEM hb_i18n_ngettext( PHB_ITEM pNum, PHB_ITEM pMsgID, PHB_ITEM pContext )
{
   PHB_I18N_TRANS pI18N = hb_i18n_table();
   PHB_CODEPAGE cdpage = NULL;
   PHB_ITEM pMsgDst = pMsgID;
   PHB_ITEM pBlock = NULL;
   int iPluralForm = 0;

   if( pI18N )
   {
      PHB_ITEM pTable = pContext && pI18N->context_table ?
                        hb_hashGetItemPtr( pI18N->context_table, pContext, 0 ) :
                        pI18N->default_context;

      cdpage = pI18N->base_cdpage;
      pBlock = pI18N->base_plural_block;
      iPluralForm = pI18N->base_plural_form;

      if( pTable )
      {
         PHB_ITEM pMsg = HB_IS_ARRAY( pMsgID ) ?
                         hb_arrayGetItemPtr( pMsgID, 1 ) : pMsgID;
         pTable = pMsg && HB_IS_STRING( pMsg ) ?
                  hb_hashGetItemPtr( pTable, pMsg, 0 ) : NULL;
         if( pTable )
         {
            if( HB_IS_STRING( pTable ) ||
                ( HB_IS_ARRAY( pTable ) &&
                  ( hb_arrayGetType( pTable, 1 ) & HB_IT_STRING ) != 0 ) )
            {
               pMsgID = pTable;
               cdpage = pI18N->cdpage;
               pBlock = pI18N->plural_block;
               iPluralForm = pI18N->plural_form;
            }
         }
      }
   }

   if( pMsgID && HB_IS_ARRAY( pMsgID ) )
   {
      long lIndex;

      if( ! pNum )
         lIndex = 1;
      else if( pBlock )
      {
         hb_evalBlock1( pBlock, pNum );
         lIndex = hb_parnl( -1 );
      }
      else
         lIndex = hb_i18n_pluralindex( iPluralForm, pNum );

      if( lIndex < 1 || ( lIndex != 1 &&
            ( hb_arrayGetType( pMsgID, lIndex ) & HB_IT_STRING ) == 0 ) )
         lIndex = 1;

      pMsgID = hb_arrayGetItemPtr( pMsgID, lIndex );
   }

   if( pMsgID )
   {
      if( HB_IS_STRING( pMsgID ) )
      {
         if( cdpage )
         {
            PHB_CODEPAGE cdp = hb_vmCDP();
            if( cdp && cdp != cdpage )
            {
               if( pMsgDst != pMsgID )
               {
                  hb_itemCopy( pMsgDst, pMsgID );
                  pMsgID = pMsgDst;
               }
               hb_i18n_transitm( pMsgID, cdpage, cdp );
            }
         }
      }
      else
         pMsgID = NULL;
   }

   return pMsgID;
}
예제 #19
0
HB_SIZE hb_jsonDecode( const char * szSource, PHB_ITEM pValue )
{
   return hb_jsonDecodeCP( szSource, pValue, hb_vmCDP() );
}
예제 #20
0
파일: dbf2txt.c 프로젝트: NaldoDj/core
/* Export field values to text file */
static HB_BOOL hb_ExportVar( HB_FHANDLE handle, PHB_ITEM pValue, const char * cDelim, PHB_CODEPAGE cdp )
{
   switch( hb_itemType( pValue ) )
   {
      /* a "C" field */
      case HB_IT_STRING:
      {
         char * szStrEsc;
         char * szString;

         szStrEsc = hb_strescape( hb_itemGetCPtr( pValue ),
                                  hb_itemGetCLen( pValue ), cDelim );
         if( cdp )
            hb_cdpnDupLen( szStrEsc, strlen( szStrEsc ), hb_vmCDP(), cdp );

         szString = hb_xstrcpy( NULL, cDelim, szStrEsc, cDelim, NULL );

         /* FWrite( handle, szString ) */
         hb_fsWriteLarge( handle, szString, strlen( szString ) );

         /* Orphaned, get rif off it */
         hb_xfree( szStrEsc );
         hb_xfree( szString );
         break;
      }
      /* a "D" field */
      case HB_IT_DATE:
      {
         char * szDate = ( char * ) hb_xgrab( 9 );

         hb_itemGetDS( pValue, szDate );
         hb_fsWriteLarge( handle, szDate, strlen( szDate ) );
         hb_xfree( szDate );
         break;
      }
      /* an "L" field */
      case HB_IT_LOGICAL:
         hb_fsWriteLarge( handle, ( hb_itemGetL( pValue ) ? "T" : "F" ), 1 );
         break;
      /* an "N" field */
      case HB_IT_INTEGER:
      case HB_IT_LONG:
      case HB_IT_DOUBLE:
      {
         char * szResult = hb_itemStr( pValue, NULL, NULL );

         if( szResult )
         {
            HB_SIZE      nLen      = strlen( szResult );
            const char * szTrimmed = hb_strLTrim( szResult, &nLen );

            hb_fsWriteLarge( handle, szTrimmed, strlen( szTrimmed ) );
            hb_xfree( szResult );
         }
         break;
      }
      /* an "M" field or the other, might be a "V" in SixDriver */
      default:
         /* We do not want MEMO contents */
         return HB_FALSE;
   }
   return HB_TRUE;
}
예제 #21
0
파일: hbjson.c 프로젝트: AugustoAbacus/core
static const char * _hb_jsonDecode( const char * szSource, PHB_ITEM pValue )
{
   if( *szSource == '\"' )
   {
      char * szDest, * szHead;
      HB_SIZE nAlloc = 16;

      szHead = szDest = ( char * ) hb_xgrab( nAlloc );
      szSource++;
      while( *szSource != '\"' )
      {
         if( szHead + 6 >= szDest + nAlloc )
         {
            HB_SIZE nLen = szHead - szDest;
            nAlloc += nAlloc << 1;
            szDest = ( char * ) hb_xrealloc( szDest, nAlloc );
            szHead = szDest + nLen;
         }
         if( *szSource == '\\' )
         {
            szSource++;
            switch( *szSource )
            {
               case '\"':
                  *szHead++ = '\"';
                  break;
               case '\\':
                  *szHead++ = '\\';
                  break;
               case '/':
                  *szHead++ = '/';
                  break;
               case 'b':
                  *szHead++ = '\b';
                  break;
               case 'f':
                  *szHead++ = '\f';
                  break;
               case 'n':
                  *szHead++ = '\n';
                  break;
               case 'r':
                  *szHead++ = '\r';
                  break;
               case 't':
                  *szHead++ = '\t';
                  break;
               case 'u':
               {
                  HB_WCHAR wc = 0;
                  int i;

                  for( i = 0; i < 4; i++ )
                  {
                     char c = *++szSource;
                     wc <<= 4;
                     if( c >= '0' && c <= '9' )
                        wc += c - '0';
                     else if( c >= 'A' && c <= 'F' )
                        wc += c - 'A' + 10;
                     else if( c >= 'a' && c <= 'f' )
                        wc += c - 'a' + 10;
                     else
                     {
                        hb_xfree( szDest );
                        return NULL;
                     }
                  }
                  szHead += hb_cdpU16ToStr( hb_vmCDP(), HB_CDP_ENDIAN_NATIVE,
                                            &wc, 1,
                                            szHead, szDest + nAlloc - szHead );
                  break;
               }
               default:
                  hb_xfree( szDest );
                  return NULL;
            }
            szSource++;
         }
         else if( *( const unsigned char * ) szSource >= ' ' )
            *szHead++ = *szSource++;
         else
         {
            hb_xfree( szDest );
            return NULL;
         }
      }
      hb_itemPutCL( pValue, szDest, szHead - szDest );
      hb_xfree( szDest );
      return szSource + 1;
   }
   else if( *szSource == '-' || ( *szSource >= '0' && *szSource <= '9' ) )
   {
      /* NOTE: this function is much less strict to number format than
               JSON syntax definition. This is allowed behaviour [Mindaugas] */
      HB_MAXINT nValue = 0;
      double dblValue = 0;
      HB_BOOL fNeg, fDbl = HB_FALSE;
      int iDec = 0;

      fNeg = *szSource == '-';
      if( fNeg )
         szSource++;

      while( *szSource >= '0' && *szSource <= '9' )
      {
         nValue = nValue * 10 + *szSource - '0';
         szSource++;
      }
      if( *szSource == '.' )
      {
         double mult = 1;

         dblValue = ( double ) nValue;
         fDbl = HB_TRUE;
         szSource++;
         while( *szSource >= '0' && *szSource <= '9' )
         {
            mult /= 10;
            dblValue += ( ( double ) ( *szSource - '0' ) ) * mult;
            szSource++;
            iDec++;
         }
      }
      if( *szSource == 'e' || *szSource == 'E' )
      {
         HB_BOOL fNegExp;
         int iExp = 0;

         szSource++;
         fNegExp = *szSource == '-';
         if( fNegExp )
            szSource++;

         while( *szSource >= '0' && *szSource <= '9' )
         {
            iExp = iExp * 10 + *szSource - '0';
            szSource++;
         }
         if( ! fDbl )
         {
            dblValue = ( double ) nValue;
            fDbl = HB_TRUE;
         }
         if( fNegExp )
            iDec += iExp;
         dblValue = hb_numExpConv( dblValue, fNegExp ? iExp : -iExp );
      }

      if( fDbl )
         hb_itemPutNDDec( pValue, hb_numRound( fNeg ? -dblValue : dblValue, iDec ), iDec );
      else
         hb_itemPutNInt( pValue, fNeg ? -nValue : nValue );
      return szSource;
   }
   else if( ! strncmp( szSource, "null", 4 ) )
   {
      hb_itemClear( pValue );
      return szSource + 4;
   }
   else if( ! strncmp( szSource, "true", 4 ) )
   {
      hb_itemPutL( pValue, HB_TRUE );
      return szSource + 4;
   }
   else if( ! strncmp( szSource, "false", 5 ) )
   {
      hb_itemPutL( pValue, HB_FALSE );
      return szSource + 5;
   }
   else if( *szSource == '[' )
   {
      hb_arrayNew( pValue, 0 );
      szSource = _skipws( szSource + 1 );
      if( *szSource != ']' )
      {
         PHB_ITEM pItem = hb_itemNew( NULL );

         for( ;; )
         {
            szSource = _hb_jsonDecode( szSource, pItem );
            if( ! szSource )
            {
               hb_itemRelease( pItem );
               return NULL;
            }
            hb_arrayAddForward( pValue, pItem );

            szSource = _skipws( szSource );
            if( *szSource == ',' )
            {
               szSource = _skipws( szSource + 1 );
               continue;
            }
            else if( *szSource == ']' )
               break;
            else
            {
               hb_itemRelease( pItem );
               return NULL;
            }
         }
         hb_itemRelease( pItem );
      }
      return szSource + 1;
   }
   else if( *szSource == '{' )
   {
      hb_hashNew( pValue );
      szSource = _skipws( szSource + 1 );
      if( *szSource != '}' )
      {
         PHB_ITEM pItemKey = hb_itemNew( NULL );
         PHB_ITEM pItemValue = hb_itemNew( NULL );

         for( ;; )
         {
            /* Do we need to check if key does not exist yet? */
            if( ( szSource = _hb_jsonDecode( szSource, pItemKey ) ) == NULL ||
                ! HB_IS_STRING( pItemKey ) ||
                * ( szSource = _skipws( szSource ) ) != ':' ||
                ( szSource = _hb_jsonDecode( _skipws( szSource + 1 ), pItemValue ) ) == NULL)
            {
               hb_itemRelease( pItemKey );
               hb_itemRelease( pItemValue );
               return NULL;
            }

            hb_hashAdd( pValue, pItemKey, pItemValue );
            szSource = _skipws( szSource );
            if( *szSource == ',' )
            {
               szSource = _skipws( szSource + 1 );
               continue;
            }
            else if( *szSource == '}' )
               break;
            else
            {
               hb_itemRelease( pItemKey );
               hb_itemRelease( pItemValue );
               return NULL;
            }
         }
         hb_itemRelease( pItemKey );
         hb_itemRelease( pItemValue );
      }
      return szSource + 1;
   }
   return NULL;
}
예제 #22
0
파일: sdf1.c 프로젝트: AmericoBalboa/core
/*
 * Create a data store in the specified WorkArea.
 */
static HB_ERRCODE hb_sdfCreate( SDFAREAP pArea, LPDBOPENINFO pCreateInfo )
{
   HB_ERRCODE errCode;
   PHB_FNAME pFileName;
   PHB_ITEM pError = NULL;
   HB_BOOL fRetry;
   char szFileName[ HB_PATH_MAX ];

   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfCreate(%p,%p)", pArea, pCreateInfo ) );

   pArea->fShared = HB_FALSE;    /* pCreateInfo->fShared; */
   pArea->fReadonly = HB_FALSE;  /* pCreateInfo->fReadonly */

   if( pCreateInfo->cdpId )
   {
      pArea->area.cdPage = hb_cdpFindExt( pCreateInfo->cdpId );
      if( ! pArea->area.cdPage )
         pArea->area.cdPage = hb_vmCDP();
   }
   else
      pArea->area.cdPage = hb_vmCDP();

   pFileName = hb_fsFNameSplit( pCreateInfo->abName );
   if( hb_setGetDefExtension() && ! pFileName->szExtension )
   {
      PHB_ITEM pItem = hb_itemPutC( NULL, NULL );
      SELF_INFO( &pArea->area, DBI_TABLEEXT, pItem );
      pFileName->szExtension = hb_itemGetCPtr( pItem );
      hb_fsFNameMerge( szFileName, pFileName );
      hb_itemRelease( pItem );
   }
   else
   {
      hb_strncpy( szFileName, pCreateInfo->abName, sizeof( szFileName ) - 1 );
   }
   hb_xfree( pFileName );

   /* Try create */
   do
   {
      pArea->pFile = hb_fileExtOpen( szFileName, NULL,
                                     FO_READWRITE | FO_EXCLUSIVE | FXO_TRUNCATE |
                                     FXO_DEFAULTS | FXO_SHARELOCK | FXO_COPYNAME |
                                     FXO_NOSEEKPOS,
                                     NULL, pError );
      if( ! pArea->pFile )
      {
         if( ! pError )
         {
            pError = hb_errNew();
            hb_errPutGenCode( pError, EG_CREATE );
            hb_errPutSubCode( pError, EDBF_CREATE_DBF );
            hb_errPutOsCode( pError, hb_fsError() );
            hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_CREATE ) );
            hb_errPutFileName( pError, szFileName );
            hb_errPutFlags( pError, EF_CANRETRY | EF_CANDEFAULT );
         }
         fRetry = ( SELF_ERROR( &pArea->area, pError ) == E_RETRY );
      }
      else
         fRetry = HB_FALSE;
   }
   while( fRetry );

   if( pError )
      hb_itemRelease( pError );

   if( ! pArea->pFile )
      return HB_FAILURE;

   errCode = SUPER_CREATE( &pArea->area, pCreateInfo );
   if( errCode != HB_SUCCESS )
   {
      SELF_CLOSE( &pArea->area );
      return errCode;
   }

   hb_sdfInitArea( pArea, szFileName );

   /* Position cursor at the first record */
   return SELF_GOTOP( &pArea->area );
}
예제 #23
0
파일: sdf1.c 프로젝트: AmericoBalboa/core
/*
 * Obtain the current value of a field.
 */
static HB_ERRCODE hb_sdfGetValue( SDFAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem )
{
   LPFIELD pField;

   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfGetValue(%p, %hu, %p)", pArea, uiIndex, pItem ) );

   if( --uiIndex >= pArea->area.uiFieldCount )
      return HB_FAILURE;

   pField = pArea->area.lpFields + uiIndex;
   switch( pField->uiType )
   {
      case HB_FT_STRING:
         if( ( pField->uiFlags & HB_FF_BINARY ) == 0 )
         {
            HB_SIZE nLen = pField->uiLen;
            char * pszVal = hb_cdpnDup( ( const char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                                        &nLen, pArea->area.cdPage, hb_vmCDP() );
            hb_itemPutCLPtr( pItem, pszVal, nLen );
         }
         else
         {
            hb_itemPutCL( pItem, ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                          pField->uiLen );
         }
         break;

      case HB_FT_LOGICAL:
         switch( pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] )
         {
            case 'T':
            case 't':
            case 'Y':
            case 'y':
               hb_itemPutL( pItem, HB_TRUE );
               break;
            default:
               hb_itemPutL( pItem, HB_FALSE );
               break;
         }
         break;

      case HB_FT_DATE:
         hb_itemPutDS( pItem, ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ] );
         break;

      case HB_FT_TIMESTAMP:
      {
         long lJulian, lMilliSec;
         HB_BYTE * pFieldPtr = pArea->pRecord + pArea->pFieldOffset[ uiIndex ], bChar;

         bChar = pFieldPtr[ pField->uiLen ];
         pFieldPtr[ pField->uiLen ] = 0;
         hb_timeStampStrGetDT( ( const char * ) pFieldPtr, &lJulian, &lMilliSec );
         pFieldPtr[ pField->uiLen ] = bChar;
         hb_itemPutTDT( pItem, lJulian, lMilliSec );
         break;
      }

      case HB_FT_LONG:
      {
         HB_MAXINT lVal;
         double    dVal;
         HB_BOOL   fDbl;

         fDbl = hb_strnToNum( ( const char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                              pField->uiLen, &lVal, &dVal );

         if( pField->uiDec )
         {
            hb_itemPutNDLen( pItem, fDbl ? dVal : ( double ) lVal,
                             ( int ) ( pField->uiLen - pField->uiDec - 1 ),
                             ( int ) pField->uiDec );
         }
         else if( fDbl )
         {
            hb_itemPutNDLen( pItem, dVal, ( int ) pField->uiLen, 0 );
         }
         else
         {
            hb_itemPutNIntLen( pItem, lVal, ( int ) pField->uiLen );
         }
      }
      break;

      case HB_FT_MEMO:
         hb_itemPutC( pItem, NULL );
         break;

      case HB_FT_NONE:
         hb_itemClear( pItem );
         break;

      default:
      {
         PHB_ITEM pError;
         pError = hb_errNew();
         hb_errPutGenCode( pError, EG_DATATYPE );
         hb_errPutDescription( pError, hb_langDGetErrorDesc( EG_DATATYPE ) );
         hb_errPutOperation( pError, hb_dynsymName( ( PHB_DYNS ) pField->sym ) );
         hb_errPutSubCode( pError, EDBF_DATATYPE );
         SELF_ERROR( &pArea->area, pError );
         hb_itemRelease( pError );
         return HB_FAILURE;
      }
   }

   return HB_SUCCESS;
}
예제 #24
0
파일: sdf1.c 프로젝트: AmericoBalboa/core
/*
 * Assign a value to a field.
 */
static HB_ERRCODE hb_sdfPutValue( SDFAREAP pArea, HB_USHORT uiIndex, PHB_ITEM pItem )
{
   char szBuffer[ 256 ];
   HB_ERRCODE errCode;
   LPFIELD pField;
   HB_SIZE nSize;

   HB_TRACE( HB_TR_DEBUG, ( "hb_sdfPutValue(%p,%hu,%p)", pArea, uiIndex, pItem ) );

   if( ! pArea->fPositioned )
      return HB_SUCCESS;

   if( ! pArea->fRecordChanged )
      return HB_FAILURE;

   if( --uiIndex >= pArea->area.uiFieldCount )
      return HB_FAILURE;

   errCode = HB_SUCCESS;
   pField = pArea->area.lpFields + uiIndex;
   if( pField->uiType != HB_FT_MEMO && pField->uiType != HB_FT_NONE )
   {
      if( HB_IS_MEMO( pItem ) || HB_IS_STRING( pItem ) )
      {
         if( pField->uiType == HB_FT_STRING )
         {
            if( ( pField->uiFlags & HB_FF_BINARY ) == 0 )
            {
               nSize = pField->uiLen;
               hb_cdpnDup2( hb_itemGetCPtr( pItem ), hb_itemGetCLen( pItem ),
                            ( char * ) pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                            &nSize, hb_vmCDP(), pArea->area.cdPage );
            }
            else
            {
               nSize = hb_itemGetCLen( pItem );
               if( nSize > ( HB_SIZE ) pField->uiLen )
                  nSize = pField->uiLen;
               memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                       hb_itemGetCPtr( pItem ), nSize );
            }
            if( nSize < ( HB_SIZE ) pField->uiLen )
               memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ] + nSize,
                       ' ', pField->uiLen - nSize );
         }
         else
            errCode = EDBF_DATATYPE;
      }
      else if( HB_IS_DATETIME( pItem ) )
      {
         if( pField->uiType == HB_FT_DATE )
         {
            hb_itemGetDS( pItem, szBuffer );
            memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, 8 );
         }
         else if( pField->uiType == HB_FT_TIMESTAMP &&
                  ( pField->uiLen == 12 || pField->uiLen == 23 ) )
         {
            long lDate, lTime;
            hb_itemGetTDT( pItem, &lDate, &lTime );
            if( pField->uiLen == 12 )
               hb_timeStr( szBuffer, lTime );
            else
               hb_timeStampStr( szBuffer, lDate, lTime );
            memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ], szBuffer, pField->uiLen );
         }
         else
            errCode = EDBF_DATATYPE;
      }
      else if( HB_IS_NUMBER( pItem ) )
      {
         if( pField->uiType == HB_FT_LONG )
         {
            if( hb_itemStrBuf( szBuffer, pItem, pField->uiLen, pField->uiDec ) )
            {
               memcpy( pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                       szBuffer, pField->uiLen );
            }
            else
            {
               errCode = EDBF_DATAWIDTH;
               memset( pArea->pRecord + pArea->pFieldOffset[ uiIndex ],
                       '*', pField->uiLen );
            }
         }
         else
            errCode = EDBF_DATATYPE;
      }
      else if( HB_IS_LOGICAL( pItem ) )
      {
         if( pField->uiType == HB_FT_LOGICAL )
            pArea->pRecord[ pArea->pFieldOffset[ uiIndex ] ] = hb_itemGetL( pItem ) ? 'T' : 'F';
         else
            errCode = EDBF_DATATYPE;
      }
      else
         errCode = EDBF_DATATYPE;
   }

   if( errCode != HB_SUCCESS )
   {
      PHB_ITEM pError = hb_errNew();
      HB_ERRCODE errGenCode = errCode == EDBF_DATAWIDTH ? EG_DATAWIDTH : EDBF_DATATYPE;

      hb_errPutGenCode( pError, errGenCode );
      hb_errPutDescription( pError, hb_langDGetErrorDesc( errGenCode ) );
      hb_errPutOperation( pError, hb_dynsymName( ( PHB_DYNS ) pField->sym ) );
      hb_errPutSubCode( pError, errCode );
      hb_errPutFlags( pError, EF_CANDEFAULT );
      errCode = SELF_ERROR( &pArea->area, pError );
      hb_itemRelease( pError );
      return errCode == E_DEFAULT ? HB_SUCCESS : HB_FAILURE;
   }

   return HB_SUCCESS;
}