Esempio n. 1
0
static void hb_getCommand( const char * pszFileName,
                           LPTSTR * lpAppName, LPTSTR * lpParams )
{
   const char * src, * params;
   char cQuote = 0;

   while( HB_ISSPACE( *pszFileName ) )
      ++pszFileName;

   params = NULL;
   src = pszFileName;
   while( *src )
   {
      if( *src == cQuote )
         cQuote = 0;
      else if( cQuote == 0 )
      {
         if( *src == '"' )
            cQuote = *src;
         else if( HB_ISSPACE( *src ) )
         {
            params = src;
            while( HB_ISSPACE( *params ) )
               ++params;
            if( *params == 0 )
               params = NULL;
            break;
         }
      }
      ++src;
   }

   *lpParams = params ? HB_CHARDUP( params ) : NULL;
   *lpAppName = HB_CHARDUPN( pszFileName, src - pszFileName );
}
Esempio n. 2
0
static int hb_gt_gui_optionId( const char * pszOption )
{
   if( pszOption )
   {
      HB_SIZE nSize;
      int i;

      while( HB_ISSPACE( *pszOption ) )
         pszOption++;
      nSize = strlen( pszOption );
      while( nSize > 0 && HB_ISSPACE( pszOption[ nSize - 1 ] ) )
         nSize--;

      if( nSize >= 2 && nSize <= 9 )
      {
         for( i = 0; i < ( int ) _HB_BUTTON_COUNT; ++i )
         {
            if( nSize == s_buttons[ i ].len &&
                hb_strnicmp( s_buttons[ i ].name, pszOption, nSize ) == 0 )
            {
               return s_buttons[ i ].id;
            }
         }
      }
   }
   return 0;
}
Esempio n. 3
0
File: wafunc.c Progetto: CsBela/core
/*
 * Find a field index by name
 */
HB_USHORT hb_rddFieldIndex( AREAP pArea, const char * szName )
{
   HB_USHORT uiCount = 0;
   LPFIELD pField;

   HB_TRACE( HB_TR_DEBUG, ( "hb_rddFieldIndex(%p, %s)", pArea, szName ) );

   while( HB_ISSPACE( *szName ) )
   {
      ++szName;
   }

   if( *szName )
   {
      char szSym[ HB_SYMBOL_NAME_LEN + 1 ];
      hb_strncpyUpperTrim( szSym, szName, sizeof( szSym ) - 1 );

      pField = pArea->lpFields;
      while( pField )
      {
         ++uiCount;
         if( strcmp( szSym, hb_dynsymName( ( PHB_DYNS ) pField->sym ) ) == 0 )
            return uiCount;
         pField = pField->lpfNext;
      }
   }
   return 0;
}
Esempio n. 4
0
/* Escaping delimited strings. Need to be cleaned/optimized/improved */
static char * hb_strescape( const char * szInput, HB_ISIZ nLen, const char * cDelim )
{
   HB_ISIZ      nCnt = 0;
   const char * szChr;
   char *       szEscape;
   char *       szReturn;

   szReturn = szEscape = ( char * ) hb_xgrab( nLen * 2 + 4 );

   while( nLen && HB_ISSPACE( szInput[ nLen - 1 ] ) )
      nLen--;

   szChr = szInput;

   while( *szChr && nCnt++ < nLen )
   {
      if( *szChr == *cDelim )
         *szEscape++ = '\\';

      *szEscape++ = *szChr++;
   }
   *szEscape = '\0';

   return szReturn;
}
Esempio n. 5
0
/*
 * Find a field index by name
 */
HB_USHORT hb_rddFieldIndex( AREAP pArea, const char * szName )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_rddFieldIndex(%p, %s)", pArea, szName ) );

   while( HB_ISSPACE( *szName ) )
      ++szName;

   if( *szName )
   {
      HB_SIZE nLen = strlen( szName );

      while( HB_ISSPACE( szName[ nLen - 1 ] ) )
         --nLen;

      if( nLen <= HB_SYMBOL_NAME_LEN )
      {
         char szFieldName[ HB_SYMBOL_NAME_LEN + 1 ];
         PHB_DYNS pDynSym;

         szFieldName[ nLen ] = '\0';
         while( nLen-- )
            szFieldName[ nLen ] = HB_TOUPPER( szName[ nLen ] );

         pDynSym = hb_dynsymFind( szFieldName );
         if( pDynSym )
         {
            LPFIELD pField = pArea->lpFields;
            HB_USHORT uiCount = 0;

            while( pField )
            {
               ++uiCount;
               if( pDynSym == ( PHB_DYNS ) pField->sym )
                  return uiCount;
               pField = pField->lpfNext;
            }
         }
      }
   }
   return 0;
}
Esempio n. 6
0
BOOL hb_strEmpty( const char * szText, ULONG ulLen )
{
   HB_TRACE(HB_TR_DEBUG, ("hb_strEmpty(%s, %lu)", szText, ulLen));

   while( ulLen-- )
   {
      char c = szText[ ulLen ];

      if( !HB_ISSPACE( c ) )
         return FALSE;
   }

   return TRUE;
}
Esempio n. 7
0
/* Export field value into the buffer in SQL format */
static HB_BOOL hb_exportBufSqlVar( PHB_FILEBUF pFileBuf, PHB_ITEM pValue,
                                   const char * szDelim, const char * szEsc )
{
   switch( hb_itemType( pValue ) )
   {
      case HB_IT_STRING:
      {
         HB_SIZE nLen = hb_itemGetCLen( pValue );
         HB_SIZE nCnt = 0;
         const char *szVal = hb_itemGetCPtr( pValue );

         hb_addStrToFBuffer( pFileBuf, szDelim );
         while( nLen && HB_ISSPACE( szVal[ nLen - 1 ] ) )
            nLen--;

         while( *szVal && nCnt++ < nLen )
         {
            if( *szVal == *szDelim || *szVal == *szEsc )
               hb_addToFBuffer( pFileBuf, *szEsc );
            if( ( HB_UCHAR ) *szVal >= 32 )
               hb_addToFBuffer( pFileBuf, *szVal );
            else
            {
               /* printf( "%d %c", *szVal, *szVal ); */
            }
            szVal++;
         }
         hb_addStrToFBuffer( pFileBuf, szDelim );
         break;
      }

      case HB_IT_DATE:
      {
         char szDate[ 9 ];

         hb_addStrToFBuffer( pFileBuf, szDelim );
         hb_itemGetDS( pValue, szDate );
         if( szDate[ 0 ] == ' ' )
         {
            hb_addStrToFBuffer( pFileBuf, "0100-01-01" );
         }
         else
         {
            hb_addStrnToFBuffer( pFileBuf, &szDate[0], 4 );
            hb_addToFBuffer( pFileBuf, '-' );
            hb_addStrnToFBuffer( pFileBuf, &szDate[4], 2 );
            hb_addToFBuffer( pFileBuf, '-' );
            hb_addStrnToFBuffer( pFileBuf, &szDate[6], 2 );
         }
         hb_addStrToFBuffer( pFileBuf, szDelim );
         break;
      }

      case HB_IT_TIMESTAMP:
      {
         long lDate, lTime;
         char szDateTime[ 24 ];

         hb_itemGetTDT( pValue, &lDate, &lTime );
         hb_timeStampStr( szDateTime, lDate, lTime );
         hb_addStrToFBuffer( pFileBuf, szDelim );
         hb_addStrToFBuffer( pFileBuf, szDateTime );
         hb_addStrToFBuffer( pFileBuf, szDelim );
         break;
      }

      case HB_IT_LOGICAL:
         hb_addStrToFBuffer( pFileBuf, szDelim );
         hb_addToFBuffer( pFileBuf, hb_itemGetL( pValue ) ? 'Y' : 'N' );
         hb_addStrToFBuffer( pFileBuf, szDelim );
         break;

      case HB_IT_INTEGER:
      case HB_IT_LONG:
      case HB_IT_DOUBLE:
      {
         char szResult[ HB_MAX_DOUBLE_LENGTH ];
         int iSize, iWidth, iDec;

         hb_itemGetNLen( pValue, &iWidth, &iDec );
         iSize = ( iDec > 0 ? iWidth + 1 + iDec : iWidth );
         if( hb_itemStrBuf( szResult, pValue, iSize, iDec ) )
         {
            int iPos = 0;
            while( iSize && HB_ISSPACE( szResult[ iPos ] ) )
            {
               iPos++;
               iSize--;
            }
            hb_addStrnToFBuffer( pFileBuf, &szResult[ iPos ], iSize );
         }
         else
            hb_addToFBuffer( pFileBuf, '0' );
         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;
}
Esempio n. 8
0
char * hb_verPlatform( void )
{
   char * pszPlatform;

   HB_TRACE( HB_TR_DEBUG, ( "hb_verPlatform()" ) );

   pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 );

#if defined( HB_OS_DOS )

   {
      union REGS regs;

      regs.h.ah = 0x30;
      HB_DOS_INT86( 0x21, &regs, &regs );

      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah );

      /* Host OS detection: Windows 2.x, 3.x, 95/98 */

      {
         regs.HB_XREGS.ax = 0x1600;
         HB_DOS_INT86( 0x2F, &regs, &regs );

         if( regs.h.al != 0x00 && regs.h.al != 0x80 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 0x01 || regs.h.al == 0xFF )
               hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }

      /* Host OS detection: Windows NT family */

      {
         regs.HB_XREGS.ax = 0x3306;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.HB_XREGS.bx == 0x3205 )
            hb_strncat( pszPlatform, " (Windows NT)", PLATFORM_BUF_SIZE );
      }

      /* Host OS detection: OS/2 */

      {
         regs.h.ah = 0x30;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.h.al >= 10 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 20 && regs.h.ah > 20 )
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }
   }

#elif defined( HB_OS_OS2 )

   {
      unsigned long aulQSV[ QSV_MAX ] = { 0 };
      APIRET rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX );

      if( rc == 0 )
      {
         /* is this OS/2 2.x ? */
         if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 )
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld",
                         aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10,
                         aulQSV[ QSV_VERSION_MINOR - 1 ] );
         else
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f",
                         ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 );
      }
      else
         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" );
   }

#elif defined( HB_OS_WIN )

   {
      const char * pszName = "";

      OSVERSIONINFO osvi;

      memset( &osvi, 0, sizeof( osvi ) );

#if defined( HB_OS_WIN_CE )
      pszName = " CE";
      osvi.dwOSVersionInfoSize = sizeof( osvi );
      GetVersionEx( &osvi );
#else
      /* Detection of legacy Windows versions */
      switch( hb_iswin9x() )
      {
         case 5:
            osvi.dwMajorVersion = 4;
            osvi.dwMinorVersion = 0;
            pszName = " 95";
            break;
         case 8:
            osvi.dwMajorVersion = 4;
            osvi.dwMinorVersion = 10;
            pszName = " 98";
            break;
         case 9:
            osvi.dwMajorVersion = 4;
            osvi.dwMinorVersion = 90;
            pszName = " ME";
            break;
      }
#endif

      if( pszName[ 0 ] == '\0' )
      {
#if defined( HB_OS_WIN_CE )
         pszName = " CE";
#else
         if( hb_iswinver( 11, 0, 0, HB_TRUE ) )
         {
            osvi.dwMajorVersion = 11;
            osvi.dwMinorVersion = 0;
            pszName = " 11 or newer";
         }
         else if( hb_iswin10() )
         {
            osvi.dwMajorVersion = 10;
            osvi.dwMinorVersion = 0;
            if( hb_iswinver( 10, 0, VER_NT_WORKSTATION, HB_FALSE ) )
               pszName = " 10";
            else
               pszName = " Server 2016";
         }
         else if( hb_iswin81() )
         {
            osvi.dwMajorVersion = 6;
            osvi.dwMinorVersion = 3;
            if( hb_iswinver( 6, 3, VER_NT_WORKSTATION, HB_FALSE ) )
               pszName = " 8.1";
            else
               pszName = " Server 2012 R2";
         }
         else if( hb_iswinvista() )
         {
            if( hb_iswin8() )
            {
               osvi.dwMajorVersion = 6;
               osvi.dwMinorVersion = 2;
               if( hb_iswinver( 6, 2, VER_NT_WORKSTATION, HB_FALSE ) )
                  pszName = " 8";
               else
                  pszName = " Server 2012";
            }
            else if( hb_iswinver( 6, 1, 0, HB_FALSE ) )
            {
               osvi.dwMajorVersion = 6;
               osvi.dwMinorVersion = 1;
               if( hb_iswinver( 6, 1, VER_NT_WORKSTATION, HB_FALSE ) )
                  pszName = " 7";
               else
                  pszName = " Server 2008 R2";
            }
            else
            {
               osvi.dwMajorVersion = 6;
               osvi.dwMinorVersion = 0;
               if( hb_iswinver( 6, 0, VER_NT_WORKSTATION, HB_FALSE ) )
                  pszName = " Vista";
               else
                  pszName = " Server 2008";
            }
         }
         else if( hb_iswinver( 5, 2, 0, HB_FALSE ) )
         {
            osvi.dwMajorVersion = 5;
            osvi.dwMinorVersion = 2;
            if( hb_iswinver( 5, 2, VER_NT_WORKSTATION, HB_FALSE ) )
               pszName = " XP x64";
            else if( GetSystemMetrics( SM_SERVERR2 ) != 0 )
               pszName = " Server 2003 R2";
            else
               pszName = " Server 2003";
         }
         else if( hb_iswinver( 5, 1, 0, HB_FALSE ) )
         {
            osvi.dwMajorVersion = 5;
            osvi.dwMinorVersion = 1;
            pszName = " XP";
         }
         else if( hb_iswin2k() )
         {
            osvi.dwMajorVersion = 5;
            osvi.dwMinorVersion = 0;
            pszName = " 2000";
         }
         else
            pszName = " NT";
#endif
      }

      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows%s%s %lu.%lu",
                   pszName,
                   s_iWine ? " (Wine)" : "",
                   osvi.dwMajorVersion,
                   osvi.dwMinorVersion );

      /* Add service pack/other info */

      if( hb_iswin2k() )
      {
         int tmp;

         for( tmp = 5; tmp > 0; --tmp )
         {
            if( hb_iswinsp( tmp, HB_TRUE ) )
            {
               char szServicePack[ 8 ];
               hb_snprintf( szServicePack, sizeof( szServicePack ), " SP%u", tmp );
               hb_strncat( pszPlatform, szServicePack, PLATFORM_BUF_SIZE );
               break;
            }
         }
      }
#if defined( HB_OS_WIN_CE )
      else
      {
         /* Also for Win9x and NT, but GetVersionEx() is deprecated
            so we avoid it. */
         if( osvi.szCSDVersion[ 0 ] != TEXT( '\0' ) )
         {
            char * pszCSDVersion = HB_OSSTRDUP( osvi.szCSDVersion );
            int i;

            /* Skip the leading spaces (Win95B, Win98) */
            for( i = 0; pszCSDVersion[ i ] != '\0' && HB_ISSPACE( ( int ) pszCSDVersion[ i ] ); i++ )
               ;

            if( pszCSDVersion[ i ] != '\0' )
            {
               hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE );
               hb_strncat( pszPlatform, pszCSDVersion + i, PLATFORM_BUF_SIZE );
            }
            hb_xfree( pszCSDVersion );
         }
      }
#endif
   }

#elif defined( __CEGCC__ )
   {
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" );
   }
#elif defined( HB_OS_UNIX )

   {
      struct utsname un;

      uname( &un );
#if defined( HB_OS_MINIX )
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s Release %s Version %s %s",
                   un.sysname, un.release, un.version, un.machine );
#else
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine );
#endif
   }

#else

   {
      hb_strncpy( pszPlatform, "(unrecognized)", PLATFORM_BUF_SIZE );
   }

#endif

   return pszPlatform;
}
Esempio n. 9
0
/* Export field value into the buffer in PG accepted CSV format */
static HB_BOOL exportBufSqlVar( pgCopyContext * context, PHB_ITEM pValue, const char * szQuote, const char * szEsc )
{
   switch( hb_itemType( pValue ) )
   {
      case HB_IT_STRING:
      case HB_IT_MEMO:
      {
         HB_SIZE      nLen  = hb_itemGetCLen( pValue );
         HB_SIZE      nCnt  = 0;
         const char * szVal = hb_itemGetCPtr( pValue );

         if( ! addStrToContext( context, szQuote ) )
            return HB_FALSE;

         if( context->str_trim )
         {
            while( nLen && HB_ISSPACE( szVal[ nLen - 1 ] ) )
               nLen--;
         }

         while( *szVal && nCnt++ < nLen )
         {
            /* if( *szVal == *szDelim || *szVal == *szEsc || *szVal == *szQuote )
               we don't need to escape delim in CSV mode,
               only the quote and the escape itself */

            if( *szVal == *szQuote || *szVal == *szEsc )
               if( ! addToContext( context, *szEsc ) )
                  return HB_FALSE;
            if( ( HB_UCHAR ) *szVal >= 32 )
               if( ! addToContext( context, *szVal ) )
                  return HB_FALSE;
            szVal++;
         }
         if( ! addStrToContext( context, szQuote ) )
            return HB_FALSE;
         break;
      }

      case HB_IT_DATE:
      {
         char szDate[ 9 ];

         if( ! addStrToContext( context, szQuote ) )
            return HB_FALSE;
         hb_itemGetDS( pValue, szDate );
         if( szDate[ 0 ] == ' ' )
         {
            if( ! addStrToContext( context, "0100-01-01" ) )
               return HB_FALSE;
         }
         else
         {
            if( ! addStrnToContext( context, &szDate[ 0 ], 4 ) ||
                ! addToContext( context, '-' ) ||
                ! addStrnToContext( context, &szDate[ 4 ], 2 ) ||
                ! addToContext( context, '-' ) ||
                ! addStrnToContext( context, &szDate[ 6 ], 2 ) )
               return HB_FALSE;
         }
         if( ! addStrToContext( context, szQuote ) )
            return HB_FALSE;
         break;
      }

      case HB_IT_TIMESTAMP:
      {
         long lDate, lTime;
         char szDateTime[ 24 ];

         hb_itemGetTDT( pValue, &lDate, &lTime );
         hb_timeStampStr( szDateTime, lDate, lTime );
         if( ! addStrToContext( context, szQuote ) ||
             ! addStrToContext( context, szDateTime ) ||
             ! addStrToContext( context, szQuote ) )
            return HB_FALSE;
         break;
      }

      case HB_IT_LOGICAL:
#if 0
         if( ! addStrToContext( context, szQuote ) || ! addToContext( context, hb_itemGetL( pValue ) ? 'Y' : 'N' ) || ! addStrToContext( context, szQuote ) )
#endif
         if( ! addToContext( context, hb_itemGetL( pValue ) ? 'Y' : 'N' ) )
            return HB_FALSE;
         break;

      case HB_IT_INTEGER:
      case HB_IT_LONG:
      case HB_IT_DOUBLE:
      {
         char szResult[ HB_MAX_DOUBLE_LENGTH ];
         int  iSize, iWidth, iDec;

         hb_itemGetNLen( pValue, &iWidth, &iDec );
         iSize = ( iDec > 0 ? iWidth + 1 + iDec : iWidth );
         if( hb_itemStrBuf( szResult, pValue, iSize, iDec ) )
         {
            int iPos = 0;
            while( iSize && HB_ISSPACE( szResult[ iPos ] ) )
            {
               iPos++;
               iSize--;
            }
            if( ! addStrnToContext( context, &szResult[ iPos ], iSize ) )
               return HB_FALSE;
         }
         else
         if( ! addToContext( context, '0' ) )
            return HB_FALSE;
         break;
      }
      /* an "M" field or the other, might be a "V" in SixDriver */
      default:
         return HB_FALSE;
   }

   return HB_TRUE;
}
Esempio n. 10
0
static int hb_pp_parseRepoVer( PHB_PP_STATE pState, const char * pszFileName,
                               int iQuiet, char ** pszCommitID, int * piCommitRev, char ** pszCommitInfo )
{
   FILE * file_in;

   char szId[ _VALUE_SIZE ];
   char szDate[ _VALUE_SIZE ];
   char szName[ _VALUE_SIZE ];
   char szMail[ _VALUE_SIZE ];
   char szCommitInfo[ _VALUE_SIZE ];

   int iLen;

   *szId = *szDate = *szName = *szMail = *szCommitInfo = '\0';

   file_in = hb_fopen( pszFileName, "r" );
   if( ! file_in )
   {
      if( iQuiet < 2 )
         fprintf( stderr, "'%s' not found. Skipping.\n", pszFileName );
   }
   else
   {
      char szLine[ 256 ];
      char * pszValue;

      if( iQuiet == 0 )
         fprintf( stdout, "Reading repository revision file: %s\n", pszFileName );

      for( ;; )
      {
         if( ! fgets( szLine, sizeof( szLine ), file_in ) )
            break;

         if( ! *szId )
            pszValue = szId;
         else if( ! *szDate )
            pszValue = szDate;
         else if( ! *szName )
            pszValue = szName;
         else if( ! *szMail )
            pszValue = szMail;
         else
            break;

         {
            hb_strncpy( pszValue, szLine, _VALUE_SIZE - 1 );
            iLen = ( int ) strlen( pszValue );
            while( iLen-- && HB_ISSPACE( pszValue[ iLen ] ) )
               pszValue[ iLen ] = '\0';
         }
      }

      fclose( file_in );
   }

   hb_pp_addDefine( pState, "HB_VER_COMMIT_ID", szId );
#if defined( HB_LEGACY_LEVEL4 )
   hb_pp_addDefine( pState, "HB_VER_CHLID", szId );
#endif

   *pszCommitID = hb_strdup( szId );

   if( szDate[ 0 ] && szName[ 0 ] && szMail[ 0 ] )
   {
      iLen = ( int ) strlen( szMail );
      while( iLen-- )
      {
         if( szMail[ iLen ] == '@' )
            szMail[ iLen ] = ' ';
      }
#if defined( __HB_INCLUDE_MORE_COMMIT_INFO )
      hb_snprintf( szCommitInfo, sizeof( szCommitInfo ), "%s %s (%s)", szDate, szName, szMail );
#else
      hb_snprintf( szCommitInfo, sizeof( szCommitInfo ), "%s", szDate );
      HB_SYMBOL_UNUSED( szName );
      HB_SYMBOL_UNUSED( szMail );
#endif
      if( *pszCommitInfo )
         hb_xfree( *pszCommitInfo );

      hb_pp_delDefine( pState, "HB_VER_COMMIT_INFO" );
      hb_pp_addDefine( pState, "HB_VER_COMMIT_INFO", szCommitInfo );

      *pszCommitInfo = hb_strdup( szCommitInfo );

      *piCommitRev = hb_pp_TimeStampToNum( pState, szCommitInfo );
   }

   return 0;
}
Esempio n. 11
0
/*
 * find a field expression index, this function strips _FIELD->, FIELD->,
 * alias-> prefixes
 */
HB_USHORT hb_rddFieldExpIndex( AREAP pArea, const char * szField )
{
   int n;

   while( HB_ISSPACE( *szField ) )
      ++szField;

   if( strchr( szField, '>' ) != NULL )
   {
      char szAlias[ HB_RDD_MAX_ALIAS_LEN + 1 ];
      int i, j, l;

      n = 0;
      if( SELF_ALIAS( pArea, szAlias ) == HB_SUCCESS )
         l = ( int ) strlen( szAlias );
      else
         l = 0;

      /*
       * strip the _FIELD-> and FIELD-> prefix, it could be nested
       * so repeat this process until all prefixes will be removed
       */
      do
      {
         j = n;
         i = 0;
         if( HB_ISFIRSTIDCHAR( szField[ n ] ) )
         {
            ++i;
            while( HB_ISNEXTIDCHAR( szField[ n + i ] ) )
               ++i;

            if( ! ( ( i == l &&
                      hb_strnicmp( &szField[ n ], szAlias, l ) == 0 ) ) &&
                ! ( i >= 4 && i <= 5 &&
                    hb_strnicmp( &szField[ n ], "FIELD", i ) == 0 ) &&
                ! ( i >= 4 && i <= 6 &&
                    hb_strnicmp( &szField[ n ], "_FIELD", i ) == 0 ) )
            {
               i = 0;
            }
         }

         if( i > 0 )
         {
            i += n;
            while( HB_ISSPACE( szField[ i ] ) )
               i++;
            if( szField[ i ] == '-' && szField[ i + 1 ] == '>' )
            {
               n = i + 2;
               while( szField[ n ] == ' ' )
                  n++;
            }
         }
      }
      while( n != j );
      szField = &szField[ n ];
   }
   return hb_rddFieldIndex( pArea, szField );
}
Esempio n. 12
0
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName,
                                 BOOL fQuiet, char * piSVNID, char * piSVNDateID,
                                 char ** pszChangeLogID, char ** pszLastEntry )
{
   int            iResult = 0;
   const char *   pszFile;
   FILE *         file_in;

   pszFile = pszFileName ? pszFileName : "../../../../ChangeLog";

   do
   {
      if( hb_fsFileExists( pszFile ) )
         break;
      pszFile += 3;
   }
   while( ! pszFileName && ( *pszFile == '.' || *pszFile == 'C' ) );

   file_in = hb_fopen( pszFile, "r" );
   if( ! file_in )
   {
      if( ! fQuiet )
      {
#if ! defined( __MINGW32CE__ ) && ! defined( HB_OS_WIN_CE )
         perror( pszFile );
#else
         fprintf( stderr, "Cannot open the %s file.\n", pszFile );
#endif
      }
      iResult = 1;
   }
   else
   {
      char     szLine[ 256 ];
      char     szLine1[ 256 ];
      char     szId[ 128 ];
      char     szLog[ 128 ];
      char *   szFrom, * szTo;
      int      iLen;

      *szId = *szLog = *szLine1 = '\0';

      do
      {
         if( ! fgets( szLine, sizeof( szLine ), file_in ) )
            break;

         if( ! *szId )
         {
            szFrom = strstr( szLine, "$Id: " );
            if( szFrom )
            {
               szFrom   += 5;
               szTo     = strstr( szFrom, " $" );

               if( szTo )
               {
                  *szTo = 0;
               }

               hb_strncpy( szId, szFrom, sizeof( szId ) - 1 );
               hb_strncpy( szLine1, szLine + 1, sizeof( szLine1 ) - 1 );
            }
         }
         else if( ! *szLog )
         {
            if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' &&
                szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' )
            {
               int iLen;
               hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 );
               iLen = strlen( szLog );
               while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) )
                  szLog[ iLen ] = '\0';
            }
         }
      }
      while( ! *szLog );

      fclose( file_in );

      if( ! *szLog )
      {
         if( ! fQuiet )
            fprintf( stderr, "Cannot find valid $Id end log entry in the %s file.\n", pszFile );
         iResult = 1;
      }
      else
      {
         char  _szId[ 6 ];
         int   u = 0;

         hb_xmemset( _szId, 0, 6 );
         *szLine           = '"';
         hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 );
         iLen              = strlen( szLine );
         szLine[ iLen ]    = '"';
         szLine[ ++iLen ]  = '\0';
         hb_pp_addDefine( pState, "HB_VER_LENTRY", szLine );
         *pszLastEntry     = hb_strdup( szLog );

         hb_strncpy( szLine + 1, szId, sizeof( szLine ) - 3 );
         iLen              = strlen( szLine );
         szLine[ iLen ]    = '"';
         szLine[ ++iLen ]  = '\0';
         hb_pp_addDefine( pState, "HB_VER_CHLCVS", szLine );
         *pszChangeLogID   = hb_strdup( szId );

         szFrom            = strchr( szLine, ' ' );

         if( szFrom )
         {
            while( *szFrom == ' ' )
               ++szFrom;
            iLen = 0;
            while( ! HB_ISSPACE( szFrom[ iLen ] ) )
            {
               _szId[ u++ ] = szFrom[ iLen ];
               ++iLen;
            }
            /*
               Latest CVS version before migration to SVN:
               ChangeLog,v 1.6768 2011/01/25 18:50:35 guerra000
             */
            if( iLen )
            {
#if 0
               int iCurrentVersion = atoi( _szId ) + 6768;
               sprintf( _szId, "%i", iCurrentVersion );
               hb_strncpy( piSVNID, _szId, strlen( _szId ) );
#else
               hb_strncpy( piSVNID, _szId, u );
#endif
            }
            else
               _szId[ 0 ] = 0;
         }

         if( _szId[ 0 ] )
         {
            char szSVNDateID[ 10 ];
            int iLen     = 0, u = 0, wLen = ( int ) strlen( szLine1 );
            char *szDate = NULL;

            *szSVNDateID ='\0';

            do
            {
               if ( szLine1[ u ] == ' ' )
                  iLen ++;

               if ( iLen == 4 )
               {
                  iLen = u;
                  szDate = szLine1 + iLen + 1;
                  break;
               }

               ++u;
            } while ( u < wLen );

            iLen = 0;
            u    = 0;

            do
            {
               if (! ( szDate[ iLen ] == '-' ) )
                  szSVNDateID[ u++ ] = szDate[ iLen ];

               if ( szDate[ iLen ] == ' ' )
                  break;

               ++iLen;
            } while( szDate [ iLen ] );

            szSVNDateID[ u ] = 0;
            hb_strncpy( piSVNDateID, szSVNDateID, u );

            hb_pp_addDefine( pState, "HB_VER_BUILDDATE", szSVNDateID );
            hb_pp_addDefine( pState, "HB_VER_CVSID", _szId );
         }
         else
         {
            if( ! fQuiet )
               fprintf( stderr, "Unrecognized Id entry in the %s file.\n", pszFile );
            iResult = 1;
         }
      }
   }

   return iResult;
}
Esempio n. 13
0
static void hb_ParseLine( PHB_ITEM pReturn, const char * szText, int iDelimiter, int * iWord )
{
   if( szText )
   {
      HB_ISIZ nLen = strlen( szText );

      if( nLen > 0 )
      {
         PHB_ITEM pTemp      = hb_itemNew( NULL );
         HB_ISIZ  i          = 0;
         int      word_count = 0;
         /* booked enough memory */
         char * szResult = ( char * ) hb_xgrab( nLen + 1 );

#if 0
         while( nLen )
         {
            if( szText[ nLen - 1 ] && ! HB_ISSPACE( szText[ nLen - 1 ] ) )
               break;

            nLen--;
         }

         szText[ nLen ] = 0;

         nLen = strlen( szText );
#endif

         while( i < nLen )
         {
            HB_ISIZ ui = 0;

            hb_xmemset( szResult, ' ', nLen + 1 );

            /* an '"' found, loop until the next one is found */
            if( szText[ i ] == '"' )
            {
               /* an '"' after '"' ? */
               if( szText[ i + 1 ] != '"' )
                  szResult[ ui ] = szText[ i + 1 ];
               else
                  szResult[ ui ] = '\0';

               ++i;

               while( ++i < nLen )
               {
                  if( szText[ i - 1 ] == '"' )
                  {
                     szResult[ ui + 1 ] = '\0';
                     break;
                  }
                  else
                  {
                     if( szText[ i ] == '"' )
                        szResult[ ui + 1 ] = '\0';
                     else
                        szResult[ ++ui ] = szText[ i ];
                  }
               }
               word_count++;
               hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, szResult ) );
            }
            /* delimiter found */
            else if( szText[ i ] == iDelimiter )
            {
               /* first delimiter found but no word yet */
               if( word_count == 0 )
               {
                  /* add an empty string */
                  szResult[ ui ] = '\0';
               }
               else
               {
                  /* we have already have the first word */
                  /* check next character */
                  if( szText[ i - 1 ] == iDelimiter )
                  {
                     /* delimiter after delimiter */
                     /* just add an empty string */
                     szResult[ ui ] = '\0';
                  }
                  else
                  {
                     /* ",,0" */
                     /* it is not a delimiter */
                     /* move to next character */
                     ++i;
                     szResult[ ui ] = szText[ i ];

                     while( ++i < nLen )
                     {
                        if( szText[ i ] == iDelimiter )
                           break;
                        else
                           szResult[ ++ui ] = szText[ i ];
                     }
                  }
               }
               word_count++;
               szResult[ ui + 1 ] = '\0';
               hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, szResult ) );
            }
            else
            {
               szResult[ ui ] = szText[ i ];

               while( ++i < nLen )
               {
                  if( szText[ i ] == iDelimiter )
                  {
                     szResult[ ui + 1 ] = '\0';
                     break;
                  }
                  else if( szText[ i ] == '"' )
                  {
                     szResult[ ui ] = szText[ i + 1 ];
                     ++i;

                     while( ++i < nLen )
                     {
                        if( szText[ i - 1 ] == '"' )
                        {
                           szResult[ ui + 1 ] = '\0';
                           break;
                        }
                        else
                        {
                           if( szText[ i ] == '"' )
                           {
                              szResult[ ui + 1 ] = '\0';
                              break;
                           }
                           else
                              szResult[ ++ui ] = szText[ i ];
                        }
                     }
                  }
                  else
                     szResult[ ++ui ] = szText[ i ];
               }
               word_count++;
               szResult[ ui + 1 ] = '\0';
               hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, szResult ) );
            }

            i++;
         }

         /* last character in passed string is a delimiter */
         /* just add an empty string */
         if( szText[ nLen - 1 ] == iDelimiter )
         {
            word_count++;
            hb_arrayAddForward( pReturn, hb_itemPutC( pTemp, NULL ) );
         }

         /* store number of words */
         *iWord = word_count;

         /* clean up */
         hb_xfree( szResult );

         hb_itemRelease( pTemp );
      }
   }
}
Esempio n. 14
0
static char * hb_buildArgsOS2( const char *pszFileName, APIRET * ret )
{
   PHB_FNAME pFilepath;
   char szFileBuf[ HB_PATH_MAX ];
   char * pArgs = NULL, * pszFree = NULL, cQuote = 0, c;
   HB_SIZE nLen = 0, nLen2;
   void * pMem;

   while( HB_ISSPACE( *pszFileName ) )
      ++pszFileName;

   pszFileName = hb_osEncodeCP( pszFileName, &pszFree, NULL );

   while( ( c = *pszFileName ) != '\0' )
   {
      ++pszFileName;
      if( c == '"' )
         cQuote = cQuote ? 0 : c;
      else
      {
         if( cQuote == 0 && HB_ISSPACE( c ) )
            break;
         if( nLen < sizeof( szFileBuf ) - 1 )
            szFileBuf[ nLen++ ] = c;
      }
   }
   szFileBuf[ nLen ] = '\0';

   while( HB_ISSPACE( *pszFileName ) )
      ++pszFileName;
   nLen2 = strlen( pszFileName );

   pFilepath = hb_fsFNameSplit( szFileBuf );
   if( pFilepath->szPath && ! pFilepath->szExtension )
   {
      pFilepath->szExtension = ".com";
      if( ! hb_fsFileExists( hb_fsFNameMerge( szFileBuf, pFilepath ) ) )
      {
         pFilepath->szExtension = ".exe";
         if( ! hb_fsFileExists( hb_fsFNameMerge( szFileBuf, pFilepath ) ) )
         {
            pFilepath->szExtension = NULL;
            hb_fsFNameMerge( szFileBuf, pFilepath );
         }
      }
      nLen = strlen( szFileBuf );
   }
   hb_xfree( pFilepath );

   *ret = DosAllocMem( &pMem, nLen + nLen2 + 3,
                       PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE );
   if( *ret == NO_ERROR )
   {
      pArgs = ( char * ) pMem;
      memcpy( pArgs, szFileBuf, nLen + 1 );
      memcpy( pArgs + nLen + 1, pszFileName, nLen2 + 1 );
      pArgs[ nLen + nLen2 + 2 ] = '\0';
   }

   if( pszFree )
      hb_xfree( pszFree );

   return pArgs;
}
Esempio n. 15
0
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName,
                                 int iQuiet, int * piRevID,
                                 char ** pszChangeLogID, char ** pszLastEntry )
{
   char * pszFree = NULL;
   int iResult = 0;
   FILE * file_in;

   char szToCheck[ HB_PATH_MAX ];
   PHB_FNAME pFileName = hb_fsFNameSplit( pszFileName );

   if( ! pFileName->szName )
   {
      static const char * s_szNames[] = {
         "ChangeLog.txt",
         "CHANGES.txt",
#if defined( HB_OS_DOS )
         "ChangeLo.txt",
         "Change~1.txt",
         "Change~?.txt",
         "Chang~??.txt",
#endif
         NULL
      };
      int i = 0;

      if( ! pFileName->szPath )
         pFileName->szPath = "../../../../..";

      pszFileName = s_szNames[ i++ ];
      while( pszFileName )
      {
         pFileName->szName = pszFileName;
         hb_fsFNameMerge( szToCheck, pFileName );

         if( hb_fsFileExists( szToCheck ) )
         {
            pszFileName = szToCheck;
            break;
         }

         if( strchr( szToCheck, '?' ) != NULL )
         {
            pszFree = hb_fsFileFind( szToCheck );
            if( pszFree )
            {
               pszFileName = pszFree;
               break;
            }
         }

         pszFileName = s_szNames[ i++ ];
      }

      if( ! pszFileName )
         pszFileName = s_szNames[ 0 ];
   }

   hb_xfree( pFileName );

   file_in = hb_fopen( pszFileName, "r" );
   if( ! file_in )
   {
      if( iQuiet < 2 )
      {
#if ! defined( HB_OS_WIN_CE )
         perror( pszFileName );
#else
         fprintf( stderr, "Cannot open the %s file.\n", pszFileName );
#endif
      }
      iResult = 1;
   }
   else
   {
      char szLine[ 256 ];
      char szId[ 128 ];
      char szLog[ 128 ];
      char * szFrom, * szTo;
      int iLen;

      if( iQuiet == 0 )
         fprintf( stdout, "Reading ChangeLog file: %s\n", pszFileName );

      *szId = *szLog = '\0';

      do
      {
         if( ! fgets( szLine, sizeof( szLine ), file_in ) )
            break;

         if( ! *szId )
         {
            szFrom = strstr( szLine, "$" "Id" );
            if( szFrom )
            {
               szFrom += 3;
               szTo = strchr( szFrom, '$' );
               if( szTo )
               {
                  /* Is it tarball source package? */
                  if( szTo == szFrom )
                  {
                     /* we do not have revision number :-( */
                     hb_strncpy( szId, "unknown -1 (source tarball without keyword expanding)", sizeof( szId ) - 1 );
                  }
                  else if( szTo - szFrom > 3 && szTo[ -1 ] == ' ' &&
                           szFrom[ 0 ] == ':' && szFrom[ 1 ] == ' ' )
                  {
                     szTo[ -1 ] = '\0';
                     hb_strncpy( szId, szFrom + 2, sizeof( szId ) - 1 );
                  }
               }
            }
         }
         else if( ! *szLog )
         {
            if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' &&
                szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' )
            {
               hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 );
               iLen = ( int ) strlen( szLog );
               while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) )
                  szLog[ iLen ] = '\0';
            }
         }
      }
      while( ! *szLog );

      fclose( file_in );

      if( ! *szLog )
      {
         if( iQuiet < 2 )
            fprintf( stderr, "Cannot find valid $" "Id entry in the %s file.\n", pszFileName );
         iResult = 1;
      }
      else
      {
         char szRevID[ 18 ];

         *szLine = '"';
         hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 );
         iLen = ( int ) strlen( szLine );
         szLine[ iLen ] = '"';
         szLine[ ++iLen ] = '\0';
         hb_pp_addDefine( pState, "HB_VER_LENTRY", szLine );
         *pszLastEntry = hb_strdup( szLog );

         hb_strncpy( szLine + 1, szId, sizeof( szLine ) - 3 );
         iLen = ( int ) strlen( szLine );
         szLine[ iLen ] = '"';
         szLine[ ++iLen ] = '\0';
         hb_pp_addDefine( pState, "HB_VER_CHLID", szLine );
         *pszChangeLogID = hb_strdup( szId );

         if( strlen( szLog ) >= 16 )
         {
            long lJulian = 0, lMilliSec = 0;
            int iUTC = 0;

            if( strlen( szLog ) >= 25 && szLog[ 17 ] == 'U' &&
                szLog[ 18 ] == 'T' && szLog[ 19 ] == 'C' &&
                ( szLog[ 20 ] == '+' || szLog[ 20 ] == '-' ) &&
                HB_ISDIGIT( szLog[ 21 ] ) && HB_ISDIGIT( szLog[ 22 ] ) &&
                HB_ISDIGIT( szLog[ 23 ] ) && HB_ISDIGIT( szLog[ 24 ] ) )
            {
               iUTC = ( ( int ) ( szLog[ 21 ] - '0' ) * 10 +
                        ( int ) ( szLog[ 22 ] - '0' ) ) * 60 +
                        ( int ) ( szLog[ 23 ] - '0' ) * 10 +
                        ( int ) ( szLog[ 24 ] - '0' );
            }
            szLog[ 16 ] = '\0';
            if( iUTC != 0 && hb_timeStampStrGetDT( szLog, &lJulian, &lMilliSec ) )
            {
               hb_timeStampUnpackDT( hb_timeStampPackDT( lJulian, lMilliSec ) -
                                     ( double ) iUTC / ( 24 * 60 ),
                                     &lJulian, &lMilliSec );
            }
            if( lJulian && lMilliSec )
            {
               hb_timeStampStrRawPut( szRevID, lJulian, lMilliSec );
               memmove( szRevID, szRevID + 2, 10 );
            }
            else
            {
               szRevID[ 0 ] = szLog[ 2 ];
               szRevID[ 1 ] = szLog[ 3 ];
               szRevID[ 2 ] = szLog[ 5 ];
               szRevID[ 3 ] = szLog[ 6 ];
               szRevID[ 4 ] = szLog[ 8 ];
               szRevID[ 5 ] = szLog[ 9 ];
               szRevID[ 6 ] = szLog[ 11 ];
               szRevID[ 7 ] = szLog[ 12 ];
               szRevID[ 8 ] = szLog[ 14 ];
               szRevID[ 9 ] = szLog[ 15 ];
            }
            szRevID[ 10 ] = '\0';

         }
         else
            szRevID[ 0 ] = '\0';

         *piRevID = ( int ) hb_strValInt( szRevID, &iLen );

         hb_pp_addDefine( pState, "HB_VER_REVID", szRevID );
#ifdef HB_LEGACY_LEVEL4
         hb_pp_addDefine( pState, "HB_VER_SVNID", szRevID );
#endif
      }
   }

   if( pszFree )
      hb_xfree( pszFree );

   return iResult;
}
Esempio n. 16
0
static int hb_pp_parseChangelog( PHB_PP_STATE pState, const char * pszFileName,
                                 int iQuiet, int * piCommitRev, char ** pszCommitInfo )
{
   char * pszFree = NULL;
   int iResult = 0;
   FILE * file_in;

   char szToCheck[ HB_PATH_MAX ];
   PHB_FNAME pFileName = hb_fsFNameSplit( pszFileName );

   if( ! pFileName->szName )
   {
      static const char * s_szNames[] = {
         "ChangeLog.txt",
         "CHANGES.txt",
#if defined( HB_OS_DOS )
         "ChangeLo.txt",
         "Change~1.txt",
         "Change~?.txt",
         "Chang~??.txt",
#endif
         NULL
      };
      int i = 0;

      if( ! pFileName->szPath )
         pFileName->szPath = "../../../../..";

      pszFileName = s_szNames[ i++ ];
      while( pszFileName )
      {
         pFileName->szName = pszFileName;
         hb_fsFNameMerge( szToCheck, pFileName );

         if( hb_fsFileExists( szToCheck ) )
         {
            pszFileName = szToCheck;
            break;
         }

         if( strchr( szToCheck, '?' ) != NULL )
         {
            pszFree = hb_fsFileFind( szToCheck );
            if( pszFree )
            {
               pszFileName = pszFree;
               break;
            }
         }

         pszFileName = s_szNames[ i++ ];
      }

      if( ! pszFileName )
         pszFileName = s_szNames[ 0 ];
   }

   hb_xfree( pFileName );

   file_in = hb_fopen( pszFileName, "r" );
   if( ! file_in )
   {
      if( iQuiet < 2 )
      {
#if ! defined( HB_OS_WIN_CE )
         perror( pszFileName );
#else
         fprintf( stderr, "Cannot open the %s file.\n", pszFileName );
#endif
      }
      iResult = 1;
   }
   else
   {
      char szLine[ 256 ];
      char szLog[ 128 ];
      int iLen;

      if( iQuiet == 0 )
         fprintf( stdout, "Reading ChangeLog file: %s\n", pszFileName );

      *szLog = '\0';

      do
      {
         if( ! fgets( szLine, sizeof( szLine ), file_in ) )
            break;

         if( ! *szLog )
         {
            if( szLine[ 4 ] == '-' && szLine[ 7 ] == '-' &&
                szLine[ 10 ] == ' ' && szLine[ 13 ] == ':' )
            {
               hb_strncpy( szLog, szLine, sizeof( szLog ) - 1 );
               iLen = ( int ) strlen( szLog );
               while( iLen-- && HB_ISSPACE( szLog[ iLen ] ) )
                  szLog[ iLen ] = '\0';
            }
         }
      }
      while( ! *szLog );

      fclose( file_in );

      if( ! *szLog )
      {
         if( iQuiet < 2 )
            fprintf( stderr, "Cannot find valid $" "Id entry in the %s file.\n", pszFileName );
         iResult = 1;
      }
      else
      {
         *szLine = '"';
         hb_strncpy( szLine + 1, szLog, sizeof( szLine ) - 3 );
         iLen = ( int ) strlen( szLine );
         szLine[ iLen ] = '"';
         szLine[ ++iLen ] = '\0';
         hb_pp_addDefine( pState, "HB_VER_COMMIT_INFO", szLine );
         *pszCommitInfo = hb_strdup( szLog );

         *piCommitRev = hb_pp_TimeStampToNum( pState, szLog );
      }
   }

   if( pszFree )
      hb_xfree( pszFree );

   return iResult;
}
Esempio n. 17
0
HB_BOOL hb_timeStampStrGet( const char * szDateTime,
                            int * piYear, int * piMonth, int * piDay,
                            int * piHour, int * piMinutes, int * piSeconds,
                            int * piMSec )
{
   int iYear, iMonth, iDay;
   HB_BOOL fValid;

   HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampStrGet(%s, %p, %p, %p, %p, %p, %p, %p)", szDateTime, piYear, piMonth, piDay, piHour, piMinutes, piSeconds, piMSec ) );

   iYear = iMonth = iDay = 0;
   fValid = HB_FALSE;

   if( szDateTime )
   {
      while( HB_ISSPACE( *szDateTime ) )
         ++szDateTime;
      if( HB_ISDIGIT( szDateTime[ 0 ] ) && HB_ISDIGIT( szDateTime[ 1 ] ) &&
          HB_ISDIGIT( szDateTime[ 2 ] ) && HB_ISDIGIT( szDateTime[ 3 ] ) &&
          ( szDateTime[ 4 ] == '-' || szDateTime[ 4 ] == '/' || szDateTime[ 4 ] == '.' ) &&
          HB_ISDIGIT( szDateTime[ 5 ] ) && HB_ISDIGIT( szDateTime[ 6 ] ) &&
          szDateTime[ 7 ] == szDateTime[ 4 ] &&
          HB_ISDIGIT( szDateTime[ 9 ] ) && HB_ISDIGIT( szDateTime[ 9 ] ) &&
          ! HB_ISDIGIT( szDateTime[ 10 ] ) )
      {
         iYear  = ( ( ( int ) ( szDateTime[ 0 ] - '0' )   * 10 +
                      ( int ) ( szDateTime[ 1 ] - '0' ) ) * 10 +
                      ( int ) ( szDateTime[ 2 ] - '0' ) ) * 10 +
                      ( int ) ( szDateTime[ 3 ] - '0' );
         iMonth = ( szDateTime[ 5 ] - '0' ) * 10 + ( szDateTime[ 6 ] - '0' );
         iDay   = ( szDateTime[ 8 ] - '0' ) * 10 + ( szDateTime[ 9 ] - '0' );
         if( hb_dateEncode( iYear, iMonth, iDay ) != 0 ||
             ( iYear == 0 && iMonth == 0 && iDay == 0 ) )
         {
            szDateTime += 10;
            if( *szDateTime == 'T' || *szDateTime == 't' )
            {
               if( HB_ISDIGIT( szDateTime[ 1 ] ) )
                  ++szDateTime;
            }
            else
            {
               if( *szDateTime == ',' )
                  ++szDateTime;
               while( HB_ISSPACE( *szDateTime ) )
                  ++szDateTime;
               if( *szDateTime == '\0' )
                  szDateTime = NULL;
               fValid = HB_TRUE;
            }
         }
         else
         {
            iYear = iMonth = iDay = 0;
            szDateTime = NULL;
         }
      }
   }

   if( piHour || piMinutes || piSeconds || piMSec )
   {
      if( ! hb_timeStrGet( szDateTime, piHour, piMinutes, piSeconds, piMSec ) )
      {
         if( szDateTime )
            fValid = HB_FALSE;
      }
      else
         fValid = HB_TRUE;
   }
   else if( szDateTime )
      fValid = HB_FALSE;

   if( piYear )
      *piYear = iYear;
   if( piMonth )
      *piMonth = iMonth;
   if( piDay )
      *piDay = iDay;

   return fValid;
}
Esempio n. 18
0
HB_BOOL hb_timeStrGet( const char * szTime,
                       int * piHour, int * piMinutes,
                       int * piSeconds, int * piMSec )
{
   int iHour, iMinutes, iSeconds, iMSec, iBlocks;
   HB_BOOL fValid;

   HB_TRACE( HB_TR_DEBUG, ( "hb_timeStrGet(%s, %p, %p, %p, %p)", szTime, piHour, piMinutes, piSeconds, piMSec ) );

   iHour = iMinutes = iSeconds = iMSec = iBlocks = 0;
   fValid = HB_FALSE;

   if( szTime )
   {
      while( HB_ISSPACE( *szTime ) )
         ++szTime;

      if( HB_ISDIGIT( *szTime ) )
      {
         iHour = ( *szTime++ - '0' );
         if( HB_ISDIGIT( *szTime ) )
            iHour = iHour * 10 + ( *szTime++ - '0' );
         if( *szTime == ':' && HB_ISDIGIT( szTime[ 1 ] ) )
         {
            ++iBlocks;
            ++szTime;
            iMinutes = ( *szTime++ - '0' );
            if( HB_ISDIGIT( *szTime ) )
               iMinutes = iMinutes * 10 + ( *szTime++ - '0' );
            if( *szTime == ':' && HB_ISDIGIT( szTime[ 1 ] ) )
            {
               ++iBlocks;
               ++szTime;
               iSeconds = ( *szTime++ - '0' );
               if( HB_ISDIGIT( *szTime ) )
                  iSeconds = iSeconds * 10 + ( *szTime++ - '0' );
               if( *szTime == '.' && HB_ISDIGIT( szTime[ 1 ] ) )
               {
                  ++iBlocks;
                  ++szTime;
                  iMSec = ( *szTime++ - '0' ) * 100;
                  if( HB_ISDIGIT( *szTime ) )
                  {
                     iMSec += ( *szTime++ - '0' ) * 10;
                     if( HB_ISDIGIT( *szTime ) )
                        iMSec += ( *szTime++ - '0' );
                  }
                  if( HB_ISDIGIT( *szTime ) )
                     ++szTime;
               }
            }
         }
         while( HB_ISSPACE( *szTime ) )
            ++szTime;
         if( ( szTime[ 0 ] == 'p' || szTime[ 0 ] == 'P' ) &&
             ( szTime[ 1 ] == 'm' || szTime[ 1 ] == 'M' ) )
         {
            ++iBlocks;
            szTime += 2;
            if( iHour == 0 )
               iHour = 24;    /* wrong time */
            else if( iHour != 12 )
               iHour += 12;
         }
         else if( ( szTime[ 0 ] == 'a' || szTime[ 0 ] == 'A' ) &&
                  ( szTime[ 1 ] == 'm' || szTime[ 1 ] == 'M' ) )
         {
            ++iBlocks;
            szTime += 2;
            if( iHour == 0 )
               iHour = 24;    /* wrong time */
            else if( iHour == 12 )
               iHour = 0;
         }
         while( HB_ISSPACE( *szTime ) )
            ++szTime;
         if( *szTime == 0 && iBlocks > 0 &&
             iHour < 24 && iMinutes < 60 && iSeconds < 60 )
            fValid = HB_TRUE;
         else
            iHour = iMinutes = iSeconds = iMSec = 0;
      }
   }

   if( piHour )
      *piHour = iHour;
   if( piMinutes )
      *piMinutes = iMinutes;
   if( piSeconds )
      *piSeconds = iSeconds;
   if( piMSec )
      *piMSec = iMSec;

   return fValid;
}
Esempio n. 19
0
void hb_winmainArgVBuild( void )
{
   LPCTSTR lpCmdLine;
   LPTSTR * lpArgV;
   LPTSTR lpDst, lpArg, lpModuleName;
   HB_SIZE nSize, nModuleName;
   int iArgC;

   /* NOTE: MAX_PATH used intentionally instead of HB_MAX_PATH */
   lpModuleName = ( LPTSTR ) HB_WINARG_ALLOC( ( MAX_PATH + 1 ) * sizeof( TCHAR ) );
   nModuleName = GetModuleFileName( NULL, lpModuleName, MAX_PATH + 1 );
   if( nModuleName )
      nModuleName++;
   HB_WINARG_FREE( lpModuleName );

   lpCmdLine = GetCommandLine();
   lpArgV = NULL;
   nSize = 0;
   iArgC = -1;

   while( lpCmdLine && ! lpArgV && iArgC != 0 )
   {
      HB_BOOL fQuoted;
      LPCTSTR lpSrc;

      if( nSize != 0 )
      {
         lpArgV = ( LPTSTR * ) HB_WINARG_ALLOC( iArgC * sizeof( LPTSTR ) +
                                                nSize * sizeof( TCHAR ) );
         lpDst = ( LPTSTR ) ( lpArgV + iArgC );
         lpArgV[ 0 ] = lpDst;
         lpDst += nModuleName;
      }
      else
      {
         lpDst = ( LPTSTR ) lpCmdLine;
         nSize = nModuleName;
      }

      lpSrc = lpCmdLine;
      lpArg = NULL;
      iArgC = 0;
      fQuoted = HB_FALSE;

      while( *lpSrc != 0 )
      {
         if( *lpSrc == TEXT( '"' ) )
         {
            if( lpArg == NULL )
               lpArg = lpDst;
            fQuoted = ! fQuoted;
         }
         else if( fQuoted || ! HB_ISSPACE( *lpSrc ) )
         {
            if( lpArg == NULL )
               lpArg = lpDst;
            if( iArgC > 0 || nModuleName == 0 )
            {
               if( lpArgV )
                  *lpDst++ = *lpSrc;
               else
                  nSize++;
            }
         }
         else
         {
            if( lpArg )
            {
               if( iArgC > 0 || nModuleName == 0 )
               {
                  if( lpArgV )
                  {
                     *lpDst++ = '\0';
                     lpArgV[ iArgC ] = lpArg;
                  }
                  else
                     nSize++;
               }
               iArgC++;
               lpArg = NULL;
            }
         }
         ++lpSrc;
      }
      if( lpArg )
      {
         if( iArgC > 0 || nModuleName == 0 )
         {
            if( lpArgV )
            {
               *lpDst = '\0';
               lpArgV[ iArgC ] = lpArg;
            }
            else
               nSize++;
         }
         iArgC++;
      }
   }

   if( iArgC <= 0 )
   {
      if( nModuleName != 0 )
      {
         iArgC = 1;
         lpArgV = ( LPTSTR * ) HB_WINARG_ALLOC( iArgC * sizeof( LPTSTR ) +
                                                nModuleName * sizeof( TCHAR ) );
         lpArgV[ 0 ] = ( LPTSTR ) ( lpArgV + iArgC );
      }
      else
         iArgC = 0;
   }
   if( iArgC > 0 && nModuleName != 0 )
   {
      /* NOTE: Manually setup the executable name in Windows,
               because in console apps the name may be truncated
               in some cases, and in GUI apps it's not filled
               at all. [vszakats] */
      if( GetModuleFileName( NULL, lpArgV[ 0 ], ( DWORD ) nModuleName ) != 0 )
      {
         /* Windows XP does not set trailing 0 if buffer is not large enough [druzus] */
         lpArgV[ 0 ][ nModuleName - 1 ] = 0;
      }
   }

   hb_winmainArgVFree();

   if( iArgC > 0 )
   {
      s_lpArgV = lpArgV;
      s_argc = iArgC;
#if defined( UNICODE )
      {
         LPSTR lpStr;

         nSize = 0;
         for( iArgC = 0; iArgC < s_argc; ++iArgC )
            nSize += hb_wctomblen( s_lpArgV[ iArgC ] ) + 1;

         s_lpArgVStr = ( LPSTR * ) HB_WINARG_ALLOC( s_argc * sizeof( LPSTR ) +
                                                    nSize * sizeof( char ) );
         lpStr = ( LPSTR ) ( s_lpArgVStr + s_argc );
         for( iArgC = 0; iArgC < s_argc; ++iArgC )
         {
            nSize = hb_wctomblen( s_lpArgV[ iArgC ] ) + 1;
            hb_wcntombcpy( lpStr, s_lpArgV[ iArgC ], nSize - 1 );
            s_lpArgVStr[ iArgC ] = lpStr;
            lpStr += nSize;
         }
         s_argv = s_lpArgVStr;
      }
#else
      s_argv = s_lpArgV;
#endif
   }
}
Esempio n. 20
0
char * hb_verPlatform( void )
{
   char * pszPlatform;

   HB_TRACE( HB_TR_DEBUG, ( "hb_verPlatform()" ) );

   pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 );

#if defined( HB_OS_DOS )

   {
      union REGS regs;

      regs.h.ah = 0x30;
      HB_DOS_INT86( 0x21, &regs, &regs );

      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah );

      /* Host OS detection: Windows 2.x, 3.x, 95/98 */

      {
         regs.HB_XREGS.ax = 0x1600;
         HB_DOS_INT86( 0x2F, &regs, &regs );

         if( regs.h.al != 0x00 && regs.h.al != 0x80 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 0x01 || regs.h.al == 0xFF )
               hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }

      /* Host OS detection: Windows NT family */

      {
         regs.HB_XREGS.ax = 0x3306;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.HB_XREGS.bx == 0x3205 )
            hb_strncat( pszPlatform, " (Windows NT)", PLATFORM_BUF_SIZE );
      }

      /* Host OS detection: OS/2 */

      {
         regs.h.ah = 0x30;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.h.al >= 10 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 20 && regs.h.ah > 20 )
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }
   }

#elif defined( HB_OS_OS2 )

   {
      unsigned long aulQSV[ QSV_MAX ] = { 0 };
      APIRET rc;

      rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX );

      if( rc == 0 )
      {
         /* is this OS/2 2.x ? */
         if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 )
         {
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld",
                         aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10,
                         aulQSV[ QSV_VERSION_MINOR - 1 ] );
         }
         else
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f",
                         ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 );
      }
      else
         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" );
   }

#elif defined( HB_OS_WIN )

   {
      OSVERSIONINFO osVer;

      osVer.dwOSVersionInfoSize = sizeof( osVer );

      if( GetVersionEx( &osVer ) )
      {
         /* NOTE: Unofficial Wine detection.
                  http://www.mail-archive.com/[email protected]/msg48659.html */
         HMODULE hntdll = GetModuleHandle( TEXT( "ntdll.dll" ) );
         const char * pszWine = "";
         const char * pszName = "";

         if( hntdll && GetProcAddress( hntdll, "wine_get_version" ) )
            pszWine = " (Wine)";

         switch( osVer.dwPlatformId )
         {
            case VER_PLATFORM_WIN32_WINDOWS:

               if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion < 10 )
                  pszName = " 95";
               else if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion == 10 )
                  pszName = " 98";
               else
                  pszName = " ME";

               break;

            case VER_PLATFORM_WIN32_NT:

               #ifndef VER_NT_WORKSTATION
               #define VER_NT_WORKSTATION  0x0000001
               #endif

               if( osVer.dwMajorVersion == 6 )
               {
#if !defined( HB_OS_WIN_CE ) && !defined( __DMC__ ) && \
    ( !defined( _MSC_VER ) || _MSC_VER >= 1400 )
                  OSVERSIONINFOEX osVerEx;

                  osVerEx.dwOSVersionInfoSize = sizeof( osVerEx );

                  if( GetVersionEx( ( OSVERSIONINFO * ) &osVerEx ) )
                  {
                     if( osVer.dwMinorVersion == 2 )
                     {
                        if( osVerEx.wProductType == VER_NT_WORKSTATION )
                           pszName = " 8";
                        else
                           pszName = " Server 2012";
                     }
                     else if( osVer.dwMinorVersion == 1 )
                     {
                        if( osVerEx.wProductType == VER_NT_WORKSTATION )
                           pszName = " 7";
                        else
                           pszName = " Server 2008 R2";
                     }
                     else if( osVer.dwMinorVersion == 0 )
                     {
                        if( osVerEx.wProductType == VER_NT_WORKSTATION )
                           pszName = " Vista";
                        else
                           pszName = " Server 2008";
                     }
                     else
                        pszName = "";
                  }
                  else
#endif
                     pszName = "";
               }
               else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion >= 2 )
               {
#if !defined( HB_OS_WIN_CE ) && !defined( __DMC__ ) && \
    ( !defined( _MSC_VER ) || _MSC_VER >= 1400 )
                  OSVERSIONINFOEX osVerEx;

                  osVerEx.dwOSVersionInfoSize = sizeof( osVerEx );

                  if( GetVersionEx( ( OSVERSIONINFO * ) &osVerEx ) )
                  {
                     if( osVerEx.wProductType == VER_NT_WORKSTATION )
                        pszName = " XP x64";
                     else
                     {
                        #ifndef SM_SERVERR2
                        #define SM_SERVERR2 89
                        #endif

                        if( GetSystemMetrics( SM_SERVERR2 ) != 0 )
                           pszName = " Server 2003 R2";
                        else
                           pszName = " Server 2003";
                     }
                  }
                  else
                     pszName = "";
#else
                  pszName = " Server 2003 / XP x64";
#endif
               }
               else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion == 1 )
                  pszName = " XP";
               else if( osVer.dwMajorVersion == 5 )
                  pszName = " 2000";
               else
                  pszName = " NT";

               break;

            case VER_PLATFORM_WIN32s:
               pszName = " 32s";
               break;

            case VER_PLATFORM_WIN32_CE:
               pszName = " CE";
               break;
         }

         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows%s%s %lu.%lu.%04u",
                      pszName,
                      pszWine,
                      osVer.dwMajorVersion,
                      osVer.dwMinorVersion,
                      LOWORD( osVer.dwBuildNumber ) );

         /* Add service pack/other info */

         if( osVer.szCSDVersion )
         {
            char * pszCSDVersion = HB_OSSTRDUP( osVer.szCSDVersion );
            int i;

            /* Skip the leading spaces (Win95B, Win98) */
            for( i = 0; pszCSDVersion[ i ] != '\0' && HB_ISSPACE( ( int ) pszCSDVersion[ i ] ); i++ )
               ;

            if( pszCSDVersion[ i ] != '\0' )
            {
               hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE );
               hb_strncat( pszPlatform, pszCSDVersion + i, PLATFORM_BUF_SIZE );
            }
            hb_xfree( pszCSDVersion );
         }
      }
      else
         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows" );
   }

#elif defined( __CEGCC__ )
   {
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" );
   }
#elif defined( HB_OS_UNIX )

   {
      struct utsname un;

      uname( &un );
#if defined( HB_OS_MINIX )
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s Release %s Version %s %s",
                   un.sysname, un.release, un.version, un.machine );
#else
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine );
#endif
   }

#else

   {
      hb_strncpy( pszPlatform, "(unknown)", PLATFORM_BUF_SIZE );
   }

#endif

   return pszPlatform;
}