コード例 #1
0
ファイル: hbdate.c プロジェクト: ggargano/hbtest2
void hb_timeStampStrRawGet( const char * szDateTime, long * plJulian, long * plMilliSec )
{
   int iYear, iMonth, iDay, iHour, iMinutes, iSeconds, iMSec, iLen;

   HB_TRACE( HB_TR_DEBUG, ( "hb_timeStampStrRawGet(%s, %p, %p)", szDateTime, plJulian, plMilliSec ) );

   *plJulian = *plMilliSec = 0;

   iLen = 0;
   while( iLen < 10 && HB_ISDIGIT( szDateTime[ iLen ] ) )
      ++iLen;

   if( iLen == 8 || iLen >= 10 )
   {
      hb_dateStrGet( szDateTime, &iYear, &iMonth, &iDay );
      *plJulian = hb_dateEncode( iYear, iMonth, iDay );
      szDateTime += 8;
      iLen -= 8;
   }

   if( iLen >= 2 )
   {
      hb_timeStrRawGet( szDateTime, &iHour, &iMinutes, &iSeconds, &iMSec );
      *plMilliSec = hb_timeEncode( iHour, iMinutes, iSeconds, iMSec );
   }
}
コード例 #2
0
ファイル: cp_utf8.c プロジェクト: NaldoDj/core
static void hb_cp_init( PHB_CODEPAGE cdp )
{
   HB_UCHAR * flags, * upper, * lower;
   int i;

   cdp->buffer = ( HB_UCHAR * ) hb_xgrab( 0x300 );
   cdp->flags = flags = ( HB_UCHAR * ) cdp->buffer;
   cdp->upper = upper = ( HB_UCHAR * ) cdp->buffer + 0x100;
   cdp->lower = lower = ( HB_UCHAR * ) cdp->buffer + 0x200;

   for( i = 0; i < 0x100; ++i )
   {
      flags[ i ] = 0;
      if( HB_ISDIGIT( i ) )
         flags[ i ] |= HB_CDP_DIGIT;
      if( HB_ISALPHA( i ) )
         flags[ i ] |= HB_CDP_ALPHA;
      if( HB_ISUPPER( i ) )
         flags[ i ] |= HB_CDP_UPPER;
      if( HB_ISLOWER( i ) )
         flags[ i ] |= HB_CDP_LOWER;
      upper[ i ] = ( HB_UCHAR ) HB_TOUPPER( i );
      lower[ i ] = ( HB_UCHAR ) HB_TOLOWER( i );
   }
}
コード例 #3
0
ファイル: comio.c プロジェクト: jmptrader/core
static int s_fileGetValue( const char * pszName, int * piLen )
{
   int iLen = 0, iValue = 0;

   while( HB_ISDIGIT( pszName[ iLen ] ) )
      iValue = iValue * 10 + ( pszName[ iLen++ ] - '0' );

   *piLen = iLen;
   return iValue;
}
コード例 #4
0
ファイル: hbdate.c プロジェクト: ggargano/hbtest2
void hb_timeStrRawGet( const char * szTime,
                       int * piHour, int * piMinutes,
                       int * piSeconds, int * piMSec )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_timeStrRawGet(%.10s, %p, %p, %p, %p)", szTime, piHour, piMinutes, piSeconds, piMSec ) );

   *piHour = *piMinutes = *piSeconds = *piMSec = 0;

   if( szTime )
   {
      int iLen = 0;

      while( iLen < 10 && HB_ISDIGIT( szTime[ iLen ] ) )
         ++iLen;

      if( iLen >= 2 && ( ( iLen & 1 ) == 0 || iLen == 7 || iLen == 9 ) )
      {
         *piHour = ( szTime[ 0 ] - '0' ) * 10 + ( szTime[ 1 ] - '0' );
         szTime += 2;
         iLen -= 2;
         if( iLen >= 2 )
         {
            *piMinutes = ( szTime[ 0 ] - '0' ) * 10 + ( szTime[ 1 ] - '0' );
            szTime += 2;
            iLen -= 2;
            if( iLen >= 2 )
            {
               *piSeconds = ( szTime[ 0 ] - '0' ) * 10 + ( szTime[ 1 ] - '0' );
               szTime += 2;
               iLen -= 2;
               switch( iLen )
               {
                  case 4:
                  case 3:
                     *piMSec = ( ( int ) ( szTime[ 0 ] - '0' )   * 10 +
                                 ( int ) ( szTime[ 1 ] - '0' ) ) * 10 +
                                 ( int ) ( szTime[ 2 ] - '0' );
                     break;
                  case 2:
                     *piMSec = ( ( int ) ( szTime[ 0 ] - '0' )   * 10 +
                                 ( int ) ( szTime[ 1 ] - '0' ) ) * 10;
                     break;
                  case 1:
                     *piMSec = ( int ) ( szTime[ 0 ] - '0' ) * 100;
                     break;
               }
            }
         }
      }
   }
}
コード例 #5
0
ファイル: strasint.c プロジェクト: NaldoDj/core
int _GT_Internal_StringAsInt( char * String, HB_ISIZ Start, HB_ISIZ End )
{
   int     Decimal = 1;
   int     Value   = 0;
   HB_ISIZ Digit;

   HB_TRACE( HB_TR_DEBUG, ( "_GT_Internal_StringAsInt(%s, %" HB_PFS "d, %" HB_PFS "d)", String, Start, End ) );

   for( Digit = End; Digit >= Start; Digit-- )
   {
      if( HB_ISDIGIT( String[ Digit ] ) )
      {
         Value   += ( String[ Digit ] - '0' ) * Decimal;
         Decimal *= 10;
      }
   }

   return Value;
}
コード例 #6
0
ファイル: comio.c プロジェクト: jmptrader/core
static HB_BOOL s_fileAccept( PHB_FILE_FUNCS pFuncs, const char * pszFileName )
{
   HB_SYMBOL_UNUSED( pFuncs );

   if( HB_TOUPPER( pszFileName[ 0 ] ) == 'C' &&
       HB_TOUPPER( pszFileName[ 1 ] ) == 'O' &&
       HB_TOUPPER( pszFileName[ 2 ] ) == 'M' )
   {
      if( pszFileName[ 3 ] == '$' )
         return strchr( pszFileName + 4, ':' ) != NULL;
      else if( pszFileName[ 3 ] >= '1' && pszFileName[ 3 ] <= '9' )
      {
         pszFileName += 4;
         while( HB_ISDIGIT( *pszFileName ) )
            ++pszFileName;
         return *pszFileName == ':';
      }
   }
   return HB_FALSE;
}
コード例 #7
0
ファイル: ascpos.c プロジェクト: ggargano/hbtest2
/* helper function */
static void do_ascpos( int iSwitch )
{
   if( HB_ISCHAR( 1 ) )
   {
      HB_SIZE sStrSize = hb_parclen( 1 );
      const HB_BYTE * pcString = ( const HB_BYTE * ) hb_parc( 1 );
      HB_SIZE sPos = hb_parnsdef( 2, sStrSize );

      if( sPos == 0 || sPos > sStrSize )
         hb_retni( 0 );
      else
      {
         if( iSwitch == DO_ASCPOS_VALPOS )
         {
            if( HB_ISDIGIT( ( HB_UCHAR ) pcString[ sPos - 1 ] ) )
               hb_retni( pcString[ sPos - 1 ] - '0' );
            else
               hb_retni( 0 );
         }
         else
            hb_retni( pcString[ sPos - 1 ] );
      }
   }
   else
   {
      PHB_ITEM pSubst = NULL;
      int iArgErrorMode = ct_getargerrormode();

      if( iArgErrorMode != CT_ARGERR_IGNORE )
         pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                  iSwitch == DO_ASCPOS_VALPOS ?
                                  CT_ERROR_VALPOS : CT_ERROR_ASCPOS, NULL,
                                  HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE,
                                  HB_ERR_ARGS_BASEPARAMS );

      if( pSubst != NULL )
         hb_itemReturnRelease( pSubst );
      else
         hb_retni( 0 );
   }
}
コード例 #8
0
ファイル: hbdate.c プロジェクト: ggargano/hbtest2
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;
}
コード例 #9
0
ファイル: xhbat.c プロジェクト: AmericoBalboa/core
static HB_SIZE hb_AtSkipStrings( const char * szSub, HB_SIZE nSubLen, const char * szText, HB_SIZE nLen )
{
   char cLastChar = ' ';

   HB_TRACE( HB_TR_DEBUG, ( "hb_AtSkipStrings(%s, %" HB_PFS "u, %s, %" HB_PFS "u)", szSub, nSubLen, szText, nLen ) );

   if( nSubLen > 0 && nLen >= nSubLen )
   {
      HB_SIZE nPos    = 0;
      HB_SIZE nSubPos = 0;

      while( nPos < nLen && nSubPos < nSubLen )
      {
         if( szText[ nPos + 1 ] == '"' && ( szText[ nPos ] == 'e' || szText[ nPos ] == 'E' ) )
         {
            nPos++;

            while( ++nPos < nLen && ( szText[ nPos ] != '"' || szText[ nPos - 1 ] == '\\' ) )
            {
               /* Skip. */
            }

            nPos++;
            nSubPos = 0;
            continue;
         }

         if( szText[ nPos ] == '"' && szSub[ 0 ] != '"' )
         {
            while( ++nPos < nLen && szText[ nPos ] != '"' )
            {
               /* Skip. */
            }

            nPos++;
            nSubPos = 0;
            continue;
         }

         if( szText[ nPos ] == '\'' && szSub[ 0 ] != '\'' )
         {
            while( ++nPos < nLen && szText[ nPos ] != '\'' )
            {
               /* Skip. */
            }

            nPos++;
            nSubPos = 0;
            continue;
         }

         if( szText[ nPos ] == '[' && szSub[ 0 ] != '[' )
         {
            if( ! ( HB_ISALPHA( ( HB_BYTE ) cLastChar ) || HB_ISDIGIT( ( HB_BYTE ) cLastChar ) || strchr( "])}_.", cLastChar ) ) )
            {
               while( ++nPos < nLen && szText[ nPos ] != ']' )
               {
                  /* Skip. */
               }

               nPos++;
               nSubPos = 0;
               continue;
            }
         }

         if( szText[ nPos ] == szSub[ nSubPos ] )
         {
            nSubPos++;
            nPos++;
         }
         else if( nSubPos )
         {
            /* Go back to the first character after the first match,
               or else tests like "22345" $ "012223456789" will fail. */
            nPos   -= ( nSubPos - 1 );
            nSubPos = 0;
         }
         else
         {
            cLastChar = szText[ nPos ];
            nPos++;
         }
      }

      return ( nSubPos < nSubLen ) ? 0 : ( nPos - nSubLen + 1 );
   }
   else
      return 0;
}
コード例 #10
0
ファイル: hbpp.c プロジェクト: ItamarLins/harbour-core
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;
}
コード例 #11
0
ファイル: hbdate.c プロジェクト: ggargano/hbtest2
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;
}
コード例 #12
0
ファイル: cmdcheck.c プロジェクト: CsBela/core
void hb_compChkCompilerSwitch( HB_COMP_DECL, int iArg, const char * const Args[] )
{
   /* If iArg is passed check the command line options */
   if( iArg )
   {
      int i;

      /* Check all switches in command line
         They start with an OS_OPT_DELIMITER char
       */
      for( i = 1; i < iArg && ! HB_COMP_PARAM->fExit; i++ )
      {
         const char * szSwitch = Args[ i ];

         if( ! HB_ISOPTSEP( szSwitch[ 0 ] ) )
            continue;

         if( szSwitch[ 0 ] == '-' )
         {
            int  j = 1;
            char Switch[ 7 ];

            Switch[ 0 ] = '-';

            while( szSwitch[ j ] && ! HB_COMP_PARAM->fExit )
            {
               Switch[ 1 ] = szSwitch[ j ];

               if( szSwitch[ j + 1 ] == '-' )
               {
                  Switch[ 2 ] = '-';
                  Switch[ 3 ] = '\0';

                  hb_compChkEnvironVar( HB_COMP_PARAM, Switch );

                  j += 2;
                  continue;
               }
               else
               {
                  switch( Switch[ 1 ] )
                  {
                     case 'b':
                     case 'B':
                        if( ( szSwitch[ j + 1 ] == 'U' || szSwitch[ j + 1 ] == 'u' ) &&
                            ( szSwitch[ j + 2 ] == 'I' || szSwitch[ j + 2 ] == 'i' ) &&
                            ( szSwitch[ j + 3 ] == 'L' || szSwitch[ j + 3 ] == 'l' ) &&
                            ( szSwitch[ j + 4 ] == 'D' || szSwitch[ j + 4 ] == 'd' ) )
                        {
                           Switch[ 2 ] = 'U';
                           Switch[ 3 ] = 'I';
                           Switch[ 4 ] = 'L';
                           Switch[ 5 ] = 'D';
                           Switch[ 6 ] = '\0';

                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );

                           j += 5;
                           continue;
                        }
                        else if( ! szSwitch[ j + 1 ] )
                        {
                           Switch[ 2 ] = '\0';
                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                           j += 1;
                           continue;
                        }
                        break;

                     case 'c':
                     case 'C':
                        if( ( szSwitch[ j + 1 ] == 'R' || szSwitch[ j + 1 ] == 'r' ) &&
                            ( szSwitch[ j + 2 ] == 'E' || szSwitch[ j + 2 ] == 'e' ) &&
                            ( szSwitch[ j + 3 ] == 'D' || szSwitch[ j + 3 ] == 'd' ) )
                        {
                           Switch[ 2 ] = 'R';
                           Switch[ 3 ] = 'E';
                           Switch[ 4 ] = 'D';
                           Switch[ 5 ] = '\0';

                           j += 4;

                           if( szSwitch[ j ] == 'I' || szSwitch[ j ] == 'i' )
                           {
                              j++;
                              if( szSwitch[ j ] == 'T' || szSwitch[ j ] == 't' )
                              {
                                 j++;
                                 if( szSwitch[ j ] == 'S' || szSwitch[ j ] == 's' )
                                 {
                                    j++;
                                 }
                              }
                           }
                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                        }
                        else
                        {
                           Switch[ 2 ] = '\0';
                           hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, Switch, NULL );
                        }
                        continue;

                     case 'd':
                     case 'D':
                        szSwitch += ( j - 1 );
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );

                        /* Accept rest as part of #define and continue with next Args[]. */
                        j = ( int ) strlen( szSwitch );
                        continue;

                     case 'e':
                     case 'E':
                        if( ( szSwitch[ j + 1 ] == 'S' || szSwitch[ j + 1 ] == 's' ) &&
                            HB_ISDIGIT( szSwitch[ j + 2 ] ) )
                        {
                           Switch[ 2 ] = 'S';
                           Switch[ 3 ] = szSwitch[ j + 2 ];
                           Switch[ 4 ] = '\0';

                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                           j += 3;
                        }
                        else
                        {
                           Switch[ 2 ] = '\0';
                           hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, Switch, NULL );
                        }
                        continue;

                     case 'g':
                     case 'G':
                        if( szSwitch[ j + 1 ] == 'd' || szSwitch[ j + 1 ] == 'D' )
                        {
                           szSwitch += ( j - 1 );
                           hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
                           j = ( int ) strlen( szSwitch );
                        }
                        else
                        {
                           /* Required argument */
                           Switch[ 2 ] = szSwitch[ j + 1 ];
                           if( Switch[ 2 ] )
                           {
                              if( HB_ISDIGIT( szSwitch[ j + 2 ] ) )
                              {
                                 /* Optional argument */
                                 Switch[ 3 ] = szSwitch[ j + 2 ];
                                 Switch[ 4 ] = '\0';
                                 j += 3;
                              }
                              else
                              {
                                 /* No optional argument */
                                 Switch[ 3 ] = '\0';
                                 j += 2;
                              }
                              hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                           }
                           else
                              hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, Switch, NULL );
                        }
                        continue;

                     case 'i':
                     case 'I':
                        szSwitch += ( j - 1 );
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );

                        /* Accept rest as IncludePath and continue with next Args[]. */
                        j = ( int ) strlen( szSwitch );
                        continue;

                     case 'j':
                     case 'J':
                        szSwitch += ( j - 1 );
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
                        j = ( int ) strlen( szSwitch );
                        continue;

                     case 'k':
                     case 'K':
                        szSwitch += ( j - 1 );
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );

                        /* Accept rest as part of #define and continue with next Args[]. */
                        j = ( int ) strlen( szSwitch );
                        continue;

                     case 'n':
                     case 'N':
                        /* Required argument */
                        if( szSwitch[ j + 1 ] )
                        {
                           /* Optional argument */
                           Switch[ 2 ] = szSwitch[ j + 1 ];
                           Switch[ 3 ] = '\0';
                           j += 2;
                        }
                        else
                        {
                           /* No optional argument */
                           Switch[ 2 ] = '\0';
                           j += 1;
                        }
                        hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                        continue;

                     case 'o':
                     case 'O':
                        szSwitch += ( j - 1 );
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );

                        /* Accept rest as OutputPath and continue with next Args[]. */
                        j = ( int ) strlen( szSwitch );
                        continue;

                     case 'p':
                     case 'P':
                        if( szSwitch[ j + 1 ] )
                        {
                           szSwitch += ( j - 1 );
                           hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );

                           /* Accept rest as PPOPath and continue with next Args[]. */
                           j += ( int ) strlen( szSwitch ) - 1;
                        }
                        else
                        {
                           Switch[ 2 ] = '\0';
                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                           j++;
                        }
                        continue;

                     case 'q':
                     case 'Q':
                        if( HB_ISDIGIT( szSwitch[ j + 1 ] ) )
                        {
                           Switch[ 2 ] = szSwitch[ j + 1 ];
                           Switch[ 3 ] = '\0';

                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );

                           j += 2;
                           continue;
                        }
                        else
                        {
                           Switch[ 2 ] = '\0';
                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                        }

                        break;

                     case 'r':
                     case 'R':
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
                        j = ( int ) strlen( szSwitch ) - 1;
                        break;

                     case 's':
                     case 'S':
                        ++j;
                        Switch[ 2 ] = Switch[ 3 ] = Switch[ 4 ] = '\0';
                        if( szSwitch[ j ] == 'm' || szSwitch[ j ] == 'M' )
                        {
                           Switch[ 2 ] = szSwitch[ j++ ];
                           if( HB_ISDIGIT( szSwitch[ j ] ) || szSwitch[ j ] == '-' )
                              Switch[ 3 ] = szSwitch[ j++ ];
                        }
                        hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                        continue;

                     case 'u':
                     case 'U':
                        szSwitch += ( j - 1 );
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );

                        /* Accept rest as part of .ch Path or "undef:<id>" and continue with next Args[]. */
                        j = ( int ) strlen( szSwitch );
                        continue;

                     case 'w':
                     case 'W':
                        if( HB_ISDIGIT( szSwitch[ j + 1 ] ) )
                        {
                           Switch[ 2 ] = szSwitch[ j + 1 ];
                           Switch[ 3 ] = '\0';

                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );

                           j += 2;
                           continue;
                        }
                        else
                        {
                           Switch[ 2 ] = '\0';
                           hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                        }

                        break;

                     case 'x':
                     case 'X':
                        szSwitch += ( j - 1 );
                        hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );

                        /* Accept rest as INIT Symbol and continue with next Args[]. */
                        j = ( int ) strlen( szSwitch );
                        continue;

                     case '-':
                     {
                        int l = ++j;
                        while( szSwitch[ j ] && ! HB_ISOPTSEP( szSwitch[ j ] ) )
                           j++;
                        if( szSwitch[ l - 1 ] == '-' && j - l == 7 &&
                            memcmp( &szSwitch[ l ], "version", 7 ) == 0 )
                        {
                           HB_COMP_PARAM->fLogo = HB_TRUE;
                           HB_COMP_PARAM->fQuiet = HB_TRUE;
                        }
                        else if( szSwitch[ l - 1 ] == '-' && j - l == 4 &&
                                 memcmp( &szSwitch[ l ], "help", 4 ) == 0 )
                        {
                           HB_COMP_PARAM->fLogo = HB_TRUE;
                           HB_COMP_PARAM->fQuiet = HB_FALSE;
                           HB_COMP_PARAM->fExit = HB_FALSE;
                        }
                        else
                           hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_BADOPTION, &szSwitch[ l ], NULL );
                        if( szSwitch[ j ] )
                           ++j;
                        continue;
                     }
                     default:
                        Switch[ 2 ] = '\0';
                        hb_compChkEnvironVar( HB_COMP_PARAM, Switch );
                  }
               }

               j++;
            }
            continue;
         }

         while( ! HB_COMP_PARAM->fExit )
         {
            int j = 1;
            const char * szSwitch1 = szSwitch + j; /* hack to avoid what is seems a bug in 'Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)' / XCode 4.1 [vszakats] */

            while( *szSwitch1 && ! HB_ISOPTSEP( *szSwitch1 ) )
            {
               j++;
               szSwitch1++;
            }

            if( szSwitch[ j ] == '/' )
            {
               char * szTmp = hb_strndup( szSwitch, j );
               hb_compChkEnvironVar( HB_COMP_PARAM, szTmp );
               hb_xfree( szTmp );
               szSwitch += j;
            }
            else
            {
               hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
               break;
            }
         }
      }
   }
   else /* Check the environment variables */
   {
      /* NOTE: CLIPPERCMD enviroment variable
         is overriden if HARBOURCMD exists
       */
      char * szStrEnv = hb_getenv( "HARBOURCMD" );

      if( ! szStrEnv || szStrEnv[ 0 ] == '\0' )
      {
         if( szStrEnv )
            hb_xfree( szStrEnv );

         szStrEnv = hb_getenv( "CLIPPERCMD" );
      }

      if( szStrEnv )
      {
         char * szSwitch, * szPtr;

         szPtr = szStrEnv;
         while( *szPtr && ! HB_COMP_PARAM->fExit )
         {
            while( *szPtr == ' ' )
               ++szPtr;
            szSwitch = szPtr;
            if( *szSwitch )
            {
               while( *++szPtr )
               {
                  if( *szPtr == ' ' )
                  {
                     *szPtr++ = '\0';
                     break;
                  }
               }
               hb_compChkEnvironVar( HB_COMP_PARAM, szSwitch );
            }
         }
         hb_xfree( szStrEnv );
      }
   }
}
コード例 #13
0
ファイル: comio.c プロジェクト: jmptrader/core
static int s_filePortParams( const char * pszName, int * piTimeout,
                             int * piBaud, int * piParity,
                             int * piSize, int * piStop,
                             int * piFlow )
{
   int iPort = 0, iLen, iValue;

   *piTimeout = -1;
   *piBaud = *piParity = *piSize = *piStop = *piFlow = 0;

   pszName += 3;
   if( *pszName == '$' )
   {
      const char * pszParams = strchr( pszName, ':' );

      if( pszParams != NULL && pszParams - pszName > 1 )
      {
         char * pszPort = hb_strndup( pszName + 1, pszParams - pszName - 1 );

         iPort = hb_comFindPort( pszPort, HB_TRUE );
         hb_xfree( pszPort );
         pszName = pszParams;
      }
   }
   else
   {
      while( HB_ISDIGIT( *pszName ) )
         iPort = iPort * 10 + ( *pszName++ - '0' );
   }

   while( iPort > 0 && *pszName )
   {
      if( HB_ISDIGIT( *pszName ) )
      {
         iValue = s_fileGetValue( pszName, &iLen );
         if( iLen == 1 )
         {
            if( iValue >= 1 && iValue <= 2 && *piStop == 0 )
               *piStop = iValue;
            else if( iValue >= 5 && iValue <= 8 && *piSize == 0 )
               *piSize = iValue;
            else
               iPort = -1;
         }
         else if( iLen == 2 && *piStop == 0 && *piSize == 0 )
         {
            if( pszName[ 0 ] >= '1' && pszName[ 0 ] <= '2' &&
                pszName[ 1 ] >= '5' && pszName[ 1 ] <= '8' )
            {
               *piStop = pszName[ 0 ] - '0';
               *piSize = pszName[ 1 ] - '0';
            }
            else if( pszName[ 0 ] >= '5' && pszName[ 0 ] <= '8' &&
                     pszName[ 1 ] >= '1' && pszName[ 1 ] <= '2' )
            {
               *piStop = pszName[ 1 ] - '0';
               *piSize = pszName[ 0 ] - '0';
            }
            else if( *piBaud )
               iPort = -1;
            else
               *piBaud = iValue;
         }
         else if( *piBaud )
            iPort = -1;
         else
            *piBaud = iValue;
         pszName += iLen;
      }
      else if( HB_ISALPHA( *pszName ) )
      {
         if( hb_strnicmp( pszName, "RTS", 3 ) == 0 )
         {
            *piFlow |= HB_COM_FLOW_IRTSCTS;
            pszName += 3;
         }
         else if( hb_strnicmp( pszName, "CTS", 3 ) == 0 )
         {
            *piFlow |= HB_COM_FLOW_ORTSCTS;
            pszName += 3;
         }
         else if( hb_strnicmp( pszName, "DTR", 3 ) == 0 )
         {
            *piFlow |= HB_COM_FLOW_IDTRDSR;
            pszName += 3;
         }
         else if( hb_strnicmp( pszName, "DSR", 3 ) == 0 )
         {
            *piFlow |= HB_COM_FLOW_ODTRDSR;
            pszName += 3;
         }
         else if( hb_strnicmp( pszName, "DCD", 3 ) == 0 )
         {
            *piFlow |= HB_COM_FLOW_DCD;
            pszName += 3;
         }
         else if( hb_strnicmp( pszName, "XOFF", 4 ) == 0 )
         {
            *piFlow |= HB_COM_FLOW_XOFF;
            pszName += 4;
         }
         else if( hb_strnicmp( pszName, "XON", 3 ) == 0 )
         {
            *piFlow |= HB_COM_FLOW_XON;
            pszName += 3;
         }
         else if( *piParity == 0 && ! HB_ISALPHA( pszName[ 1 ] ) )
         {
            switch( *pszName )
            {
               case 'N':
               case 'n':
               case 'E':
               case 'e':
               case 'O':
               case 'o':
               case 'S':
               case 's':
               case 'M':
               case 'm':
                  *piParity = HB_TOUPPER( *pszName );
                  pszName++;
                  break;
               default:
                  iPort = -1;
                  break;
            }
         }
         else
            iPort = -1;
      }
      else if( *pszName == ':' || *pszName == ',' || *pszName == ' ' )
         pszName++;
      else
         iPort = -1;
   }

   if( *piBaud == 0 )
      *piBaud = 9600;
   if( *piParity == 0 )
      *piParity = 'N';
   if( *piSize == 0 )
      *piSize = 8;
   if( *piStop == 0 )
      *piStop = 1;

   return iPort;
}
コード例 #14
0
ファイル: cmdcheck.c プロジェクト: JamesLinus/core
static const char * hb_compChkParseSwitch( HB_COMP_DECL, const char * szSwitch,
                                           HB_BOOL fEnv )
{
   const char * szSwPtr = szSwitch;

   if( szSwPtr[ 0 ] == '-' && szSwPtr[ 1 ] == '-' )
   {
      if( strncmp( szSwPtr + 2, "version", 7 ) == 0 )
      {
         szSwPtr += 9;
         HB_COMP_PARAM->fLogo = HB_TRUE;
         HB_COMP_PARAM->fQuiet = HB_TRUE;
      }
      else if( strncmp( szSwPtr + 2, "help", 4 ) == 0 )
      {
         szSwPtr += 6;
         HB_COMP_PARAM->fLogo = HB_TRUE;
         HB_COMP_PARAM->fQuiet = HB_FALSE;
         HB_COMP_PARAM->fExit = HB_FALSE;
      }
   }
   else if( HB_ISOPTSEP( *szSwPtr ) )
   {
      ++szSwPtr;
      switch( HB_TOUPPER( *szSwPtr ) )
      {
         case 'A':
            ++szSwPtr;
            if( *szSwPtr == '-' )
            {
               ++szSwPtr;
               HB_COMP_PARAM->fAutoMemvarAssume = HB_FALSE;
            }
            else
               HB_COMP_PARAM->fAutoMemvarAssume = HB_TRUE;
            break;

         case 'B':
         {
            char *szOption = hb_compChkOptionDup( szSwPtr );

            if( strcmp( szOption, "BUILD" ) == 0 )
            {
               HB_COMP_PARAM->fBuildInfo = HB_TRUE;
               szSwPtr += 5;
            }
            else if( szSwPtr[ 1 ] == '-' )
            {
               HB_COMP_PARAM->fDebugInfo = HB_FALSE;
               szSwPtr += 2;
            }
            else
            {
               HB_COMP_PARAM->fDebugInfo = HB_TRUE;
               HB_COMP_PARAM->fLineNumbers = HB_TRUE;
               ++szSwPtr;
            }
            hb_xfree( szOption );
            break;
         }

         case 'C':
         {
            char *szOption = hb_compChkOptionDup( szSwPtr );

            if( strlen( szOption ) >= 4 &&
                strncmp( "CREDITS", szOption, strlen( szOption ) ) == 0 )
            {
               HB_COMP_PARAM->fCredits = HB_TRUE;
               szSwPtr += strlen( szOption );
            }
            hb_xfree( szOption );
            break;
         }

         case 'D':
            szSwPtr = hb_compChkAddDefine( HB_COMP_PARAM, szSwPtr + 1, HB_TRUE, fEnv );
            break;

         case 'E':
            if( HB_TOUPPER( szSwPtr[ 1 ] ) == 'S' )
            {
               switch( szSwPtr[ 2 ] )
               {
                  case '1':
                     szSwPtr += 3;
                     HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_SETEXIT;
                     break;
                  case '2':
                     szSwPtr += 3;
                     HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_DELTARGET;
                     break;
                  case '0':
                     ++szSwPtr;
                     /* no break; */
                  default:
                     szSwPtr += 2;
                     HB_COMP_PARAM->iExitLevel = HB_EXITLEVEL_DEFAULT;
                     break;
               }
            }
            break;

         case 'F':
            switch( HB_TOUPPER( szSwPtr[ 1 ] ) )
            {
               case 'N':
                  if( szSwPtr[ 2 ] == ':' )
                  {
                     if( HB_TOUPPER( szSwPtr[ 3 ] ) == 'U' )
                     {
                        szSwPtr += 4;
                        hb_setSetFileCase( HB_SET_CASE_UPPER );
                     }
                     else if( HB_TOUPPER( szSwPtr[ 3 ] ) == 'L' )
                     {
                        szSwPtr += 4;
                        hb_setSetFileCase( HB_SET_CASE_LOWER );
                     }
                  }
                  else
                  {
                     szSwPtr += 2;
                     if( *szSwPtr == '-' )
                        ++szSwPtr;
                     hb_setSetFileCase( HB_SET_CASE_MIXED );
                  }
                  break;
               case 'D':
                  if( szSwPtr[ 2 ] == ':' )
                  {
                     if( HB_TOUPPER( szSwPtr[ 3 ] ) == 'U' )
                     {
                        szSwPtr += 4;
                        hb_setSetDirCase( HB_SET_CASE_UPPER );
                     }
                     else if( HB_TOUPPER( szSwPtr[ 3 ] ) == 'L' )
                     {
                        szSwPtr += 4;
                        hb_setSetDirCase( HB_SET_CASE_LOWER );
                     }
                  }
                  else
                  {
                     szSwPtr += 2;
                     if( *szSwPtr == '-' )
                        ++szSwPtr;
                     hb_setSetDirCase( HB_SET_CASE_MIXED );
                  }
                  break;
               case 'P':
                  szSwPtr += 2;
                  if( *szSwPtr == ':' )
                  {
                     if( szSwPtr[ 1 ] && szSwPtr[ 1 ] != ' ' )
                     {
                        hb_setSetDirSeparator( szSwPtr[ 1 ] );
                        szSwPtr += 2;
                     }
                  }
                  else
                  {
                     if( *szSwPtr == '-' )
                        ++szSwPtr;
                     hb_setSetDirSeparator( HB_OS_PATH_DELIM_CHR );
                  }
                  break;
               case 'S':
                  szSwPtr += 2;
                  if( *szSwPtr == '-' )
                  {
                     ++szSwPtr;
                     hb_setSetTrimFileName( HB_FALSE );
                  }
                  else
                     hb_setSetTrimFileName( HB_TRUE );
            }
            break;

         case 'G':
            switch( HB_TOUPPER( szSwPtr[ 1 ] ) )
            {
               case 'C':
                  HB_COMP_PARAM->iLanguage = HB_LANG_C;
                  szSwPtr += 2;
                  switch( *szSwPtr )
                  {
                     case '1':
                        ++szSwPtr;
                        HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_NORMAL;
                        break;
                     case '2':
                        ++szSwPtr;
                        HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_VERBOSE;
                        break;
                     case '3':
                        ++szSwPtr;
                        HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_REALCODE;
                        break;
                     case '0':
                        ++szSwPtr;
                        /* no break; */
                     default:
                        HB_COMP_PARAM->iGenCOutput = HB_COMPGENC_COMPACT;
                        break;
                  }
                  break;

               case 'H':
                  HB_COMP_PARAM->iLanguage = HB_LANG_PORT_OBJ;
                  szSwPtr += 2;
                  break;

               case 'D':
                  if( HB_COMP_PARAM->szDepExt )
                  {
                     hb_xfree( HB_COMP_PARAM->szDepExt );
                     HB_COMP_PARAM->szDepExt = NULL;
                  }
                  szSwPtr += 2;
                  if( *szSwPtr == '-' )
                  {
                     HB_COMP_PARAM->iTraceInclude = 0;
                     ++szSwPtr;
                  }
                  else
                  {
                     HB_COMP_PARAM->iTraceInclude = 2;
                     if( *szSwPtr == '.' )
                        szSwPtr = hb_compChkOptionGet( szSwPtr, &HB_COMP_PARAM->szDepExt, fEnv );
                  }
                  break;

               case 'E':
                  szSwPtr += 2;
                  switch( *szSwPtr )
                  {
                     case '1':
                        ++szSwPtr;
                        HB_COMP_PARAM->iErrorFmt = HB_ERRORFMT_IDE;
                        break;
                     case '0':
                        ++szSwPtr;
                        /* no break; */
                     default:
                        HB_COMP_PARAM->iErrorFmt = HB_ERRORFMT_CLIPPER;
                        break;
                  }
                  break;

               default:
                  hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F', HB_COMP_ERR_UNSUPPORTED_LANG, NULL, NULL );
                  break;
            }
            break;

         case 'H':
         case '?':
            /* HELP message */
            break;

         case 'I':
            ++szSwPtr;
            switch( *szSwPtr )
            {
               case '-':
                  HB_COMP_PARAM->fINCLUDE = HB_FALSE;
                  ++szSwPtr;
                  break;
               case '+':
                  HB_COMP_PARAM->fINCLUDE = HB_TRUE;
                  ++szSwPtr;
                  break;
               default:
                  szSwPtr = hb_compChkOptionAddPath( HB_COMP_PARAM, szSwPtr, fEnv );
            }
            break;

         case 'J':
            ++szSwPtr;
            HB_COMP_PARAM->fI18n = HB_TRUE;
            if( *szSwPtr )
               szSwPtr = hb_compChkOptionFName( szSwPtr, &HB_COMP_PARAM->pI18nFileName, fEnv );
            break;

         case 'K':
            ++szSwPtr;
            while( *szSwPtr && ! HB_COMP_PARAM->fExit )
            {
               int ch = HB_TOUPPER( *szSwPtr );

               ++szSwPtr;
               switch( ch )
               {
                  case '?':
                     hb_compPrintLogo( HB_COMP_PARAM );
                     hb_compPrintModes( HB_COMP_PARAM );
                     HB_COMP_PARAM->fLogo = HB_FALSE;
                     HB_COMP_PARAM->fQuiet = HB_TRUE;
                     break;

                  case 'H':
                     /* default Harbour mode */
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_HARBOUR;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_HARBOUR;
                     break;

                  case 'C':
                     /* clear all flags - minimal set of features */
                     HB_COMP_PARAM->supported &= HB_COMPFLAG_SHORTCUTS;
                     HB_COMP_PARAM->supported |= HB_COMPFLAG_OPTJUMP |
                                                 HB_COMPFLAG_MACROTEXT;
                     break;

                  case 'X':
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_XBASE;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_XBASE;
                     break;

                  case 'I':
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_HB_INLINE;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_HB_INLINE;
                     break;

                  case 'J':
                     if( *szSwPtr == '+' )
                     {
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_OPTJUMP;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_OPTJUMP;
                     break;

                  case 'M':
                     if( *szSwPtr == '+' )
                     {
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_MACROTEXT;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_MACROTEXT;
                     break;

                  case 'D':
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_MACRODECL;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_MACRODECL;
                     break;

                  case 'R':
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_RT_MACRO;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_RT_MACRO;
                     break;

                  case 'S':
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_ARRSTR;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_ARRSTR;
                     break;

                  case 'O':
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_EXTOPT;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_EXTOPT;
                     break;

                  case 'U':
                     if( *szSwPtr == '-' )
                     {
                        HB_COMP_PARAM->supported &= ~HB_COMPFLAG_USERCP;
                        ++szSwPtr;
                     }
                     else
                        HB_COMP_PARAM->supported |= HB_COMPFLAG_USERCP;
                     break;

                  default:
                     ch = -1;
                     --szSwPtr;
               }
               if( ch == -1 )
                  break;
            }
            break;

         case 'L':
            ++szSwPtr;
            if( *szSwPtr == '-' )
            {
               HB_COMP_PARAM->fLineNumbers = HB_TRUE;
               ++szSwPtr;
            }
            else
               HB_COMP_PARAM->fLineNumbers = HB_FALSE;
            break;

         case 'M':
            ++szSwPtr;
            if( *szSwPtr == '-' )
            {
               HB_COMP_PARAM->fSingleModule = HB_FALSE;
               ++szSwPtr;
            }
            else
               HB_COMP_PARAM->fSingleModule = HB_TRUE;
            break;

         case 'N':
            ++szSwPtr;
            HB_COMP_PARAM->fNoStartUp = *szSwPtr == '1';
            switch( *szSwPtr )
            {
               case '-':
                  HB_COMP_PARAM->iStartProc = 0;
                  ++szSwPtr;
                  break;
               case '2':
                  HB_COMP_PARAM->iStartProc = 2;
                  ++szSwPtr;
                  break;
               case '0':
               case '1':
                  ++szSwPtr;
                  /* no break; */
               default:
                  HB_COMP_PARAM->iStartProc = 1;
                  break;
            }
            break;

         case 'O':
            szSwPtr = hb_compChkOptionFName( szSwPtr + 1, &HB_COMP_PARAM->pOutPath, fEnv );
            break;

         case 'P':
            ++szSwPtr;
            if( *szSwPtr == '+' )
            {
               HB_COMP_PARAM->fPPT = HB_TRUE;
               ++szSwPtr;
            }
            else
            {
               if( HB_COMP_PARAM->pPpoPath )
               {
                  hb_xfree( HB_COMP_PARAM->pPpoPath );
                  HB_COMP_PARAM->pPpoPath = NULL;
               }
               if( *szSwPtr == '-' )
               {
                  HB_COMP_PARAM->fPPT = HB_COMP_PARAM->fPPO = HB_FALSE;
                  ++szSwPtr;
               }
               else
               {
                  if( *szSwPtr )
                     szSwPtr = hb_compChkOptionFName( szSwPtr, &HB_COMP_PARAM->pPpoPath, fEnv );
                  HB_COMP_PARAM->fPPO = HB_TRUE;
               }
            }
            break;

         case 'Q':
            ++szSwPtr;
            switch( *szSwPtr )
            {
               case 'l':
               case 'L':
                  HB_COMP_PARAM->fGauge = HB_FALSE;
                  ++szSwPtr;
                  break;
               case '2':
                  HB_COMP_PARAM->fFullQuiet = HB_TRUE;
                  /* no break */
               case '0':
                  HB_COMP_PARAM->fLogo = HB_FALSE;
                  ++szSwPtr;
                  /* no break */
               default:
                  HB_COMP_PARAM->fQuiet = HB_TRUE;
            }
            break;

         case 'R':
            ++szSwPtr;
            if( szSwPtr[ 0 ] == ':' )
            {
               if( HB_ISDIGIT( szSwPtr[ 1 ] ) )
               {
                  int iCycles = 0;
                  ++szSwPtr;
                  while( HB_ISDIGIT( *szSwPtr ) )
                     iCycles = iCycles * 10 + *szSwPtr++ - '0';
                  if( iCycles > 0 )
                     HB_COMP_PARAM->iMaxTransCycles = iCycles;
               }
            }
            else
            {
               /* NOTE: ignored for Cl*pper compatibility:
                        /r[<lib>] request linker to search <lib> (or none) */
               hb_compChkIgnoredInfo( HB_COMP_PARAM, "-r[<lib>]" );
               szSwPtr = hb_compChkOptionGet( szSwPtr, NULL, fEnv );
            }
            break;

         case 'S':
            ++szSwPtr;
            switch( *szSwPtr )
            {
               case '-':
                  HB_COMP_PARAM->iSyntaxCheckOnly = 0;
                  ++szSwPtr;
                  break;
               case 'm':
               case 'M':
                  HB_COMP_PARAM->iSyntaxCheckOnly = 2;
                  ++szSwPtr;
                  break;
               default:
                  HB_COMP_PARAM->iSyntaxCheckOnly = 1;
                  break;
            }
            break;

         case 'T':
            /* NOTE: ignored for Cl*pper compatibility:
                     /t<path> path for temp file creation */
            hb_compChkIgnoredInfo( HB_COMP_PARAM, "-t<path>" );
            szSwPtr = hb_compChkOptionGet( szSwPtr + 1, NULL, fEnv );
            break;

         case 'U':
            if( hb_strnicmp( szSwPtr, "UNDEF:", 6 ) == 0 )
            {
               if( hb_strnicmp( szSwPtr + 6, ".ARCH.", 6 ) == 0 )
               {
                  HB_COMP_PARAM->fNoArchDefs = HB_TRUE;
                  szSwPtr += 12;
               }
               else
                  szSwPtr = hb_compChkAddDefine( HB_COMP_PARAM, szSwPtr + 6, HB_FALSE, fEnv );
               break;
            }
            ++szSwPtr;
            /* extended definitions file: -u+<file> */
            if( *szSwPtr == '+' )
            {
               if( szSwPtr[ 1 ] && hb_compChkOptionLen( szSwPtr + 1, fEnv ) > 0 )
               {
                  HB_COMP_PARAM->szStdChExt = ( char ** )
                     ( HB_COMP_PARAM->iStdChExt == 0 ?
                        hb_xgrab( sizeof( char * ) ) :
                        hb_xrealloc( HB_COMP_PARAM->szStdChExt,
                                     ( HB_COMP_PARAM->iStdChExt + 1 ) *
                                     sizeof( char * ) ) );
                  szSwPtr = hb_compChkOptionGet( szSwPtr + 1,
                                                 &HB_COMP_PARAM->szStdChExt[ HB_COMP_PARAM->iStdChExt++ ],
                                                 fEnv );
               }
            }
            else
            {
               if( HB_COMP_PARAM->szStdCh )
                  hb_xfree( HB_COMP_PARAM->szStdCh );
               szSwPtr = hb_compChkOptionGet( szSwPtr, &HB_COMP_PARAM->szStdCh, fEnv );
            }
            break;

         case 'V':
            ++szSwPtr;
            if( *szSwPtr == '-' )
            {
               HB_COMP_PARAM->fForceMemvars = HB_FALSE;
               ++szSwPtr;
            }
            else
               HB_COMP_PARAM->fForceMemvars = HB_TRUE;
            break;

         case 'W':
            ++szSwPtr;
            HB_COMP_PARAM->iWarnings = 1;
            if( *szSwPtr >= '0' && *szSwPtr <= '3' )
            {
               HB_COMP_PARAM->iWarnings = *szSwPtr - '0';
               ++szSwPtr;
            }
            break;

#ifdef YYDEBUG
         case 'Y':
            ++szSwPtr;
            extern int hb_comp_yydebug;
            hb_comp_yydebug = HB_TRUE;
            break;
#endif

         case 'Z':
            ++szSwPtr;
            if( *szSwPtr == '-' )
            {
               HB_COMP_PARAM->supported |= HB_COMPFLAG_SHORTCUTS;
               ++szSwPtr;
            }
            else
               HB_COMP_PARAM->supported &= ~HB_COMPFLAG_SHORTCUTS;
            break;
      }
   }

   if( ! HB_COMP_PARAM->fExit )
   {
      if( szSwPtr - szSwitch <= 1 ||
          ( *szSwPtr != '\0' && *szSwPtr != ' ' && ! HB_ISOPTSEP( *szSwPtr ) ) )
         hb_compGenError( HB_COMP_PARAM, hb_comp_szErrors, 'F',
                          fEnv ? HB_COMP_ERR_BADOPTION : HB_COMP_ERR_BADPARAM,
                          szSwitch, NULL );
      else
         return szSwPtr;
   }

   return "";
}
コード例 #15
0
ファイル: macrolex.c プロジェクト: ggargano/hbtest2
int hb_macro_yylex( YYSTYPE * yylval_ptr, HB_MACRO_PTR pMacro )
{
   PHB_MACRO_LEX pLex = ( PHB_MACRO_LEX ) pMacro->pLex;

   while( pLex->nSrc < pLex->nLen )
   {
      unsigned char ch = ( unsigned char ) pLex->pString[ pLex->nSrc++ ];
      switch( ch )
      {
         case ' ':
         case '\t':
            break;

         case '$':
         case ',':
         case '|':
         case '@':
         case '(':
         case '{':
            pLex->quote = HB_TRUE;
            return ch;

         case ')':
         case '}':
         case ']':
            pLex->quote = HB_FALSE;
            return ch;

         case '#':
            pLex->quote = HB_TRUE;
            return NE1;

         case '!':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return NE2;
            }
            return NOT;

         case '<':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '>' )
            {
               pLex->nSrc++;
               return NE2;
            }
            else if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return LE;
            }
            return '<';

         case '>':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return GE;
            }
            return '>';

         case '=':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return EQ;
            }
            else if( pLex->pString[ pLex->nSrc ] == '>' && HB_SUPPORT_HARBOUR )
            {
               pLex->nSrc++;
               return HASHOP;
            }
            return '=';

         case '+':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '+' )
            {
               pLex->nSrc++;
               return INC;
            }
            else if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return PLUSEQ;
            }
            return '+';

         case '-':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '-' )
            {
               pLex->nSrc++;
               return DEC;
            }
            else if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return MINUSEQ;
            }
            else if( pLex->pString[ pLex->nSrc ] == '>' )
            {
               pLex->nSrc++;
               return ALIASOP;
            }
            return '-';

         case '*':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '*' )
            {
               pLex->nSrc++;
               if( pLex->pString[ pLex->nSrc ] == '=' )
               {
                  pLex->nSrc++;
                  return EXPEQ;
               }
               return POWER;
            }
            else if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return MULTEQ;
            }
            return '*';

         case '/':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return DIVEQ;
            }
            return '/';

         case '%':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return MODEQ;
            }
            return '%';

         case '^':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return EXPEQ;
            }
            return POWER;

         case ':':
            pLex->quote = HB_TRUE;
            if( pLex->pString[ pLex->nSrc ] == '=' )
            {
               pLex->nSrc++;
               return INASSIGN;
            }
            else if( pLex->pString[ pLex->nSrc ] == ':' )
            {
               yylval_ptr->string = "SELF";
               return IDENTIFIER;
            }
            return ':';

         case '.':
            pLex->quote = HB_TRUE;
            if( pLex->nSrc < pLex->nLen &&
                HB_ISDIGIT( pLex->pString[ pLex->nSrc ] ) )
            {
               HB_SIZE ul = pLex->nSrc;
               while( ++ul < pLex->nLen &&
                      HB_ISDIGIT( pLex->pString[ ul ] ) ) {};
               ul -= --pLex->nSrc;
               return hb_lexNumConv( yylval_ptr, pLex, ul );
            }
            if( pLex->nLen - pLex->nSrc >= 4 &&
                pLex->pString[ pLex->nSrc + 3 ] == '.' )
            {
               if( ( pLex->pString[ pLex->nSrc + 0 ] | ( 'a' - 'A' ) ) == 'a' &&
                   ( pLex->pString[ pLex->nSrc + 1 ] | ( 'a' - 'A' ) ) == 'n' &&
                   ( pLex->pString[ pLex->nSrc + 2 ] | ( 'a' - 'A' ) ) == 'd' )
               {
                  pLex->nSrc += 4;
                  return AND;
               }
               if( ( pLex->pString[ pLex->nSrc + 0 ] | ( 'a' - 'A' ) ) == 'n' &&
                   ( pLex->pString[ pLex->nSrc + 1 ] | ( 'a' - 'A' ) ) == 'o' &&
                   ( pLex->pString[ pLex->nSrc + 2 ] | ( 'a' - 'A' ) ) == 't' )
               {
                  pLex->nSrc += 4;
                  return NOT;
               }
            }
            if( pLex->nLen - pLex->nSrc >= 3 &&
                pLex->pString[ pLex->nSrc + 2 ] == '.' )
            {
               if( ( pLex->pString[ pLex->nSrc + 0 ] | ( 'a' - 'A' ) ) == 'o' &&
                   ( pLex->pString[ pLex->nSrc + 1 ] | ( 'a' - 'A' ) ) == 'r' )
               {
                  pLex->nSrc += 3;
                  return OR;
               }
            }
            if( pLex->nLen - pLex->nSrc >= 2 &&
                pLex->pString[ pLex->nSrc + 1 ] == '.' )
            {
               if( ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 't' ||
                   ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 'y' )
               {
                  pLex->quote = HB_FALSE;
                  pLex->nSrc += 2;
                  return TRUEVALUE;
               }
               if( ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 'f' ||
                   ( pLex->pString[ pLex->nSrc ] | ( 'a' - 'A' ) ) == 'n' )
               {
                  pLex->quote = HB_FALSE;
                  pLex->nSrc += 2;
                  return FALSEVALUE;
               }
               if( pLex->pString[ pLex->nSrc ] == '.' )
               {
                  pLex->nSrc += 2;
                  return EPSILON;
               }
            }
            return '.';

         case '[':
            if( pLex->quote )
               return hb_lexStringCopy( yylval_ptr, pMacro, pLex, ']' );
            pLex->quote = HB_TRUE;
            return '[';

         case '`':
         case '\'':
            return hb_lexStringCopy( yylval_ptr, pMacro, pLex, '\'' );

         case '"':
            return hb_lexStringCopy( yylval_ptr, pMacro, pLex, '"' );

         case '&':
            if( pLex->nSrc < pLex->nLen )
            {
               if( HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc ] ) )
               {
                  /* [&<keyword>[.[<nextidchars>]]]+ */
                  int iParts = 0;
                  pLex->quote = HB_FALSE;
                  yylval_ptr->string = pLex->pDst;
                  pLex->nSrc--;
                  do
                  {
                     ++iParts;
                     *pLex->pDst++ = '&';
                     pLex->nSrc++;
                     hb_lexIdentCopy( pLex );
                     if( pLex->pString[ pLex->nSrc ] == '.' )
                     {
                        ++iParts;
                        *pLex->pDst++ = '.';
                        pLex->nSrc++;
                        hb_lexIdentCopy( pLex );
                     }
                  }
                  while( pLex->nLen - pLex->nSrc > 1 &&
                         pLex->pString[ pLex->nSrc ] == '&' &&
                         HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc + 1 ] ) );
                  if( iParts == 2 && *( pLex->pDst - 1 ) == '.' )
                  {
                     pLex->pDst--;
                     iParts = 1;
                  }
                  *pLex->pDst++ = '\0';
                  if( iParts == 1 )
                  {
                     yylval_ptr->string++;
                     if( pLex->pDst - yylval_ptr->string > HB_SYMBOL_NAME_LEN + 1 )
                        ( ( char * ) yylval_ptr->string )[ HB_SYMBOL_NAME_LEN ] = '\0';
                     return MACROVAR;
                  }
                  return MACROTEXT;
               }
               else if( pLex->pString[ pLex->nSrc ] == '\'' ||
                        pLex->pString[ pLex->nSrc ] == '"' ||
                        pLex->pString[ pLex->nSrc ] == '[' )
                  hb_macroError( EG_SYNTAX, pMacro );
            }
            pLex->quote = HB_TRUE;
            return '&';

         default:
            if( HB_ISDIGIT( ch ) )
            {
               HB_SIZE n = pLex->nSrc;

               pLex->quote = HB_FALSE;
               if( ch == '0' && n < pLex->nLen )
               {
                  if( pLex->pString[ n ] == 'd' || pLex->pString[ n ] == 'D' )
                  {
                     while( ++n < pLex->nLen &&
                            HB_ISDIGIT( pLex->pString[ n ] ) ) {};
                     if( n - pLex->nSrc == 9 )
                     {
                        int year, month, day;
                        hb_dateStrGet( pLex->pString + pLex->nSrc + 1,
                                       &year, &month, &day );
                        yylval_ptr->valLong.lNumber =
                                       hb_dateEncode( year, month, day );
                        pLex->nSrc = n;
                        if( yylval_ptr->valLong.lNumber == 0 &&
                            ( year != 0 || month != 0 || day != 0 ) )
                        {
                           hb_macroError( EG_SYNTAX, pMacro );
                        }
                        return NUM_DATE;
                     }
                     else if( n - pLex->nSrc == 2 &&
                              pLex->pString[ pLex->nSrc + 1 ] == '0' )
                     {
                        yylval_ptr->valLong.lNumber = 0;
                        return NUM_DATE;
                     }
                     n = pLex->nSrc;
                  }
                  else if( pLex->pString[ n ] == 'x' ||
                           pLex->pString[ n ] == 'X' )
                  {
                     while( ++n < pLex->nLen &&
                            HB_ISXDIGIT( pLex->pString[ n ] ) ) {};
                     if( n == pLex->nSrc + 1 )
                        --n;
                  }
                  else
                  {
                     while( n < pLex->nLen &&
                            HB_ISDIGIT( pLex->pString[ n ] ) )
                        ++n;
                     if( pLex->nLen - n > 1 && pLex->pString[ n ] == '.' &&
                         HB_ISDIGIT( pLex->pString[ n + 1 ] ) )
                     {
                        while( ++n < pLex->nLen &&
                               HB_ISDIGIT( pLex->pString[ n ] ) ) {};
                     }
                  }
               }
               else
               {
                  while( n < pLex->nLen &&
                         HB_ISDIGIT( pLex->pString[ n ] ) )
                     ++n;
                  if( pLex->nLen - n > 1 && pLex->pString[ n ] == '.' &&
                      HB_ISDIGIT( pLex->pString[ n + 1 ] ) )
                  {
                     while( ++n < pLex->nLen &&
                            HB_ISDIGIT( pLex->pString[ n ] ) ) {};
                  }
               }
               n -= --pLex->nSrc;
               return hb_lexNumConv( yylval_ptr, pLex, n );
            }
            else if( HB_ISFIRSTIDCHAR( ch ) )
            {
               HB_SIZE nLen;
               pLex->quote = HB_FALSE;
               yylval_ptr->string = pLex->pDst;
               *pLex->pDst++ = ch - ( ( ch >= 'a' && ch <= 'z' ) ? 'a' - 'A' : 0 );
               hb_lexIdentCopy( pLex );
               if( pLex->nLen - pLex->nSrc > 1 &&
                   pLex->pString[ pLex->nSrc ] == '&' &&
                   HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc + 1 ] ) )
               {
                  /* [<keyword>][&<keyword>[.[<nextidchars>]]]+ */
                  do
                  {
                     *pLex->pDst++ = '&';
                     pLex->nSrc++;
                     hb_lexIdentCopy( pLex );
                     if( pLex->pString[ pLex->nSrc ] == '.' )
                     {
                        *pLex->pDst++ = '.';
                        pLex->nSrc++;
                        hb_lexIdentCopy( pLex );
                     }
                  }
                  while( pLex->nLen - pLex->nSrc > 1 &&
                         pLex->pString[ pLex->nSrc ] == '&' &&
                         HB_ISFIRSTIDCHAR( pLex->pString[ pLex->nSrc + 1 ] ) );
                  *pLex->pDst++ = '\0';
                  return MACROTEXT;
               }
               nLen = pLex->pDst - yylval_ptr->string;
               *pLex->pDst++ = '\0';
               if( nLen == 1 )
               {
                  if( pLex->nLen > pLex->nSrc &&
                      pLex->pString[ pLex->nSrc ] == '"' )
                  {
                     switch( yylval_ptr->string[ 0 ] )
                     {
                        case 'E':
                           pLex->nSrc++;
                           return hb_lexStringExtCopy( yylval_ptr, pMacro, pLex );
                        case 'T':
                           pLex->nSrc++;
                           return hb_lexTimestampGet( yylval_ptr, pMacro, pLex );
                        case 'D':
                           pLex->nSrc++;
                           return hb_lexDateGet( yylval_ptr, pMacro, pLex );
                     }
                  }
               }
               else if( nLen == 2 )
               {
                  if( yylval_ptr->string[ 0 ] == 'I' &&
                      yylval_ptr->string[ 1 ] == 'F' )
                  {
                     hb_lexSkipBlank( pLex );
                     if( pLex->nSrc < pLex->nLen &&
                         pLex->pString[ pLex->nSrc ] == '(' )
                        return IIF;
                  }
               }
               else if( nLen == 3 )
               {
                  if( yylval_ptr->string[ 0 ] == 'I' &&
                      yylval_ptr->string[ 1 ] == 'I' &&
                      yylval_ptr->string[ 2 ] == 'F' )
                  {
                     hb_lexSkipBlank( pLex );
                     if( pLex->nSrc < pLex->nLen &&
                         pLex->pString[ pLex->nSrc ] == '(' )
                        return IIF;
                  }
                  else if( yylval_ptr->string[ 0 ] == 'N' &&
                           yylval_ptr->string[ 1 ] == 'I' &&
                           yylval_ptr->string[ 2 ] == 'L' )
                     return NIL;
               }
               else /* nLen >= 4 */
               {
                  switch( yylval_ptr->string[ 0 ] )
                  {
                     case '_':
                        if( nLen <= 6 && memcmp( "FIELD", yylval_ptr->string + 1,
                                                 nLen - 1 ) == 0 )
                        {
                           hb_lexSkipBlank( pLex );
                           if( pLex->nSrc + 1 < pLex->nLen &&
                               pLex->pString[ pLex->nSrc ] == '-' &&
                               pLex->pString[ pLex->nSrc + 1 ] == '>' )
                              return FIELD;
                        }
                        break;
                     case 'F':
                        if( nLen <= 5 && memcmp( "IELD", yylval_ptr->string + 1,
                                                 nLen - 1 ) == 0 )
                        {
                           hb_lexSkipBlank( pLex );
                           if( pLex->nSrc + 1 < pLex->nLen &&
                               pLex->pString[ pLex->nSrc ] == '-' &&
                               pLex->pString[ pLex->nSrc + 1 ] == '>' )
                              return FIELD;
                        }
                        break;
                     case 'Q':
                        if( nLen == 5 && memcmp( "SELF", yylval_ptr->string + 1,
                                                 4 ) == 0 )
                        {
                           hb_lexSkipBlank( pLex );
                           if( pLex->nSrc < pLex->nLen &&
                               pLex->pString[ pLex->nSrc ] == '(' )
                           {
                              HB_SIZE n = pLex->nSrc;
                              while( ++n < pLex->nLen )
                              {
                                 if( pLex->pString[ n ] == ')' )
                                 {
                                    pLex->nSrc = n + 1;
                                    return SELF;
                                 }
                                 else if( pLex->pString[ n ] != ' ' &&
                                          pLex->pString[ n ] != '\t' )
                                    break;
                              }
                           }
                        }
                        break;
                  }
                  if( pLex->pDst - yylval_ptr->string > HB_SYMBOL_NAME_LEN + 1 )
                     ( ( char * ) yylval_ptr->string )[ HB_SYMBOL_NAME_LEN ] = '\0';
               }
               return IDENTIFIER;
            }
            return ch;
      }
   }

   return 0;
}
コード例 #16
0
ファイル: dates.c プロジェクト: Petewg/V-harbour-core
long hb_timeUnformat( const char * szTime, const char * szTimeFormat )
{
   int iHour, iMinutes, iSeconds, iMSec, iPM;
   int size, i, count, prec, * pValue;

   HB_TRACE( HB_TR_DEBUG, ( "hb_timeUnformat(%s, %s)", szTime, szTimeFormat ) );

   if( ! szTime )
      return 0;

   if( ! szTimeFormat )
      szTimeFormat = hb_setGetTimeFormat();

   size = ( int ) hb_strnlen( szTime, hb_strnlen( szTimeFormat, 16 ) );
   iHour = iMinutes = iSeconds = iMSec = iPM = -1;
   prec = 0;
   for( i = count = 0; i < size && szTime[ count ]; ++i )
   {
      switch( szTimeFormat[ i ] )
      {
         case 'H':
         case 'h':
            pValue = &iHour;
            break;
         case 'M':
         case 'm':
            pValue = &iMinutes;
            break;
         case 'S':
         case 's':
            pValue = &iSeconds;
            break;
         case 'F':
         case 'f':
            pValue = &iMSec;
            break;
         case 'P':
         case 'p':
            if( iPM < 0 )
            {
               while( szTime[ count ] && ! HB_ISDIGIT( szTime[ count ] ) &&
                      szTime[ count ] != 'P' && szTime[ count ] != 'p' &&
                      szTime[ count ] != 'A' && szTime[ count ] != 'a' )
                  ++count;
               if     ( szTime[ count ] == 'P' || szTime[ count ] == 'p' )
                  iPM = 1;
               else if( szTime[ count ] == 'A' || szTime[ count ] == 'a' )
                  iPM = 0;
            }
         default:
            pValue = NULL;
      }
      if( pValue && *pValue < 0 )
      {
         *pValue = 0;
         while( szTime[ count ] && ! HB_ISDIGIT( szTime[ count ] ) )
            ++count;
         while( HB_ISDIGIT( szTime[ count ] ) )
         {
            *pValue = *pValue * 10 + ( szTime[ count ] - '0' );
            ++count;
            if( pValue == &iMSec )
               ++prec;
         }
      }
   }
   if( iHour < 0 )
      iHour = 0;
   if( iMinutes < 0 )
      iMinutes = 0;
   if( iSeconds < 0 )
      iSeconds = 0;
   if( iMSec < 0 )
      iMSec = 0;
   else if( iMSec > 0 )
   {
      if( prec > 3 )
      {
         do
         {
            iMSec /= 10;
         }
         while( --prec > 3 );
      }
      else
      {
         while( prec++ < 3 )
            iMSec *= 10;
      }
   }
   if( iPM > 0 )
   {
      if( iHour == 0 )
         iHour = 24;    /* wrong time */
      else if( iHour != 12 )
         iHour += 12;
   }
   else if( iPM == 0 )
   {
      if( iHour == 0 )
         iHour = 24;    /* wrong time */
      else if( iHour == 12 )
         iHour = 0;
   }

   return hb_timeEncode( iHour, iMinutes, iSeconds, iMSec );
}
コード例 #17
0
ファイル: dates.c プロジェクト: Petewg/V-harbour-core
static int hb_dateUnformatRaw( const char * szDate, const char * szDateFormat, long * plDate )
{
   int d_value = 0, m_value = 0, y_value = 0;
   int iSize = 0;

   HB_TRACE( HB_TR_DEBUG, ( "hb_dateUnformatRaw(%s, %s, %p)", szDate, szDateFormat, plDate ) );

   if( szDate )
   {
      int d_pos = 0, m_pos = 0, y_pos = 0;
      int count, digit, non_digit, size, used;

      if( ! szDateFormat )
         szDateFormat = hb_setGetDateFormat();
      size = ( int ) strlen( szDateFormat );

      for( count = used = 0; count < size && used < 3; count++ )
      {
         switch( szDateFormat[ count ] )
         {
            case 'D':
            case 'd':
               if( d_pos == 0 )
               {
                  ++used;
                  if( m_pos == 0 && y_pos == 0 )
                     d_pos = 1;
                  else if( m_pos == 0 || y_pos == 0 )
                     d_pos = 2;
                  else
                     d_pos = 3;
               }
               break;
            case 'M':
            case 'm':
               if( m_pos == 0 )
               {
                  ++used;
                  if( d_pos == 0 && y_pos == 0 )
                     m_pos = 1;
                  else if( d_pos == 0 || y_pos == 0 )
                     m_pos = 2;
                  else
                     m_pos = 3;
               }
               break;
            case 'Y':
            case 'y':
               if( y_pos == 0 )
               {
                  ++used;
                  if( m_pos == 0 && d_pos == 0 )
                     y_pos = 1;
                  else if( m_pos == 0 || d_pos == 0 )
                     y_pos = 2;
                  else
                     y_pos = 3;
               }
         }
      }

      /* If there are non-digits at the start of the date field,
         they are not to be treated as date field separators */
      non_digit = 1;
      size = ( int ) strlen( szDate );
      for( count = used = 0; count < size; count++ )
      {
         digit = szDate[ count ];
         if( HB_ISDIGIT( digit ) )
         {
            /* Process the digit for the current date field */
            if( d_pos == 1 )
               d_value = ( d_value * 10 ) + digit - '0';
            else if( m_pos == 1 )
               m_value = ( m_value * 10 ) + digit - '0';
            else if( y_pos == 1 )
               y_value = ( y_value * 10 ) + digit - '0';
            /* Treat the next non-digit as a date field separator */
            non_digit = 0;
         }
         else
         {
            /* Process the non-digit */
            if( non_digit == 0 )
            {
               /* Only move to the next date field on the first
                  consecutive non-digit that is encountered */
               non_digit = 1;
               d_pos--;
               m_pos--;
               y_pos--;
               if( ++used >= 3 )
                  break;
            }
         }
      }
      iSize = count;

      y_value = hb_setUpdateEpoch( y_value );
   }

   *plDate = hb_dateEncode( y_value, m_value, d_value );

   return iSize;
}
コード例 #18
0
ファイル: tcpio.c プロジェクト: jiangxilong/core
static PHB_FILE s_fileOpen( PHB_FILE_FUNCS pFuncs, const char * pszName,
                            const char * pszDefExt, HB_FATTR nExFlags,
                            const char * pPaths, PHB_ITEM pError )
{
   const char * pszHost = pszName + FILE_PREFIX_LEN, * ptr;
   PHB_FILE pFile = NULL;
   HB_ERRCODE errcode = 0;
   HB_SIZE nLen = 0;
   int iPort = 0;
   HB_MAXINT timeout = -1;

   HB_SYMBOL_UNUSED( pFuncs );
   HB_SYMBOL_UNUSED( pszDefExt );
   HB_SYMBOL_UNUSED( pPaths );

   if( ( ptr = strchr( pszHost, ':' ) ) != NULL && ptr != pszHost )
   {
      nLen = ptr - pszHost;
      ++ptr;
      while( HB_ISDIGIT( * ptr ) )
         iPort = iPort * 10 + ( * ptr++ - '0' );

      if( * ptr == ':' )
      {
         ++ptr;
         while( HB_ISDIGIT( * ptr ) )
            timeout = HB_MAX( timeout, 0 ) * 10 + ( * ptr++ - '0' );
      }

      if( * ptr != 0 && * ptr != ':' )
         iPort = 0;
   }

   if( iPort > 0 )
   {
      char * pszAddr, * pszIpAddr;

      hb_socketAutoInit();

      pszAddr = hb_strndup( pszHost, nLen );
      pszIpAddr = hb_socketResolveAddr( pszAddr, HB_SOCKET_AF_INET );
      hb_xfree( pszAddr );

      if( pszIpAddr )
      {
         HB_SOCKET sd = hb_socketOpen( HB_SOCKET_PF_INET, HB_SOCKET_PT_STREAM, 0 );
         if( sd != HB_NO_SOCKET )
         {
            void * pSockAddr;
            unsigned uiLen;

            if( hb_socketInetAddr( &pSockAddr, &uiLen, pszIpAddr, iPort ) )
            {
               hb_socketSetKeepAlive( sd, HB_TRUE );
               if( hb_socketConnect( sd, pSockAddr, uiLen, timeout ) == 0 )
               {
                  PHB_SOCKEX sock;

                  switch( nExFlags & ( FO_READ | FO_WRITE | FO_READWRITE ) )
                  {
                     case FO_READ:
                        hb_socketShutdown( sd, HB_SOCKET_SHUT_WR );
                        break;
                     case FO_WRITE:
                        hb_socketShutdown( sd, HB_SOCKET_SHUT_RD );
                        break;
                  }
                  sock = hb_sockexNew( sd, NULL, NULL );
                  if( sock )
                  {
                     hb_sockexSetShutDown( sock, HB_TRUE );
                     hb_sockexSetAutoFlush( sock, HB_TRUE );
                     pFile = s_fileNew( sock, timeout );
                     sd = HB_NO_SOCKET;
                  }
               }
               hb_xfree( pSockAddr );
            }
            if( sd != HB_NO_SOCKET )
            {
               errcode = hb_socketGetError();
               hb_socketClose( sd );
            }
         }
         hb_xfree( pszIpAddr );
      }
      if( errcode == 0 && pFile == NULL )
         errcode = hb_socketGetError();
   }
   else
      errcode = HB_SOCKET_ERR_WRONGADDR;

   hb_fsSetError( errcode );

   if( pError )
   {
      hb_errPutFileName( pError, pszName );
      if( pFile == NULL )
      {
         hb_errPutOsCode( pError, errcode );
         hb_errPutGenCode( pError, ( HB_ERRCODE ) EG_OPEN );
      }
   }

   return pFile;
}
コード例 #19
0
ファイル: hbpp.c プロジェクト: Petewg/V-harbour-core
static int hb_pp_TimeStampToNum( PHB_PP_STATE pState, char * pszLog )
{
   char szRevID[ 18 ];
   int iLen;

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

      if( strlen( pszLog ) >= 25 &&
          ( pszLog[ 20 ] == '+' || pszLog[ 20 ] == '-' ) &&
          HB_ISDIGIT( pszLog[ 21 ] ) && HB_ISDIGIT( pszLog[ 22 ] ) &&
          HB_ISDIGIT( pszLog[ 23 ] ) && HB_ISDIGIT( pszLog[ 24 ] ) )
      {
         iUTC = ( ( int ) ( pszLog[ 21 ] - '0' ) * 10 +
                  ( int ) ( pszLog[ 22 ] - '0' ) ) * 60 +
                  ( int ) ( pszLog[ 23 ] - '0' ) * 10 +
                  ( int ) ( pszLog[ 24 ] - '0' );
         if( pszLog[ 20 ] == '-' )
            iUTC *= -1;
      }
      pszLog[ 16 ] = '\0';
      if( iUTC != 0 && hb_timeStampStrGetDT( pszLog, &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 ] = pszLog[ 2 ];
         szRevID[ 1 ] = pszLog[ 3 ];
         szRevID[ 2 ] = pszLog[ 5 ];
         szRevID[ 3 ] = pszLog[ 6 ];
         szRevID[ 4 ] = pszLog[ 8 ];
         szRevID[ 5 ] = pszLog[ 9 ];
         szRevID[ 6 ] = pszLog[ 11 ];
         szRevID[ 7 ] = pszLog[ 12 ];
         szRevID[ 8 ] = pszLog[ 14 ];
         szRevID[ 9 ] = pszLog[ 15 ];
      }
      szRevID[ 10 ] = '\0';
   }
   else
      szRevID[ 0 ] = '\0';

   hb_pp_delDefine( pState, "HB_VER_COMMIT_REV" );
   hb_pp_addDefine( pState, "HB_VER_COMMIT_REV", szRevID );
#if defined( HB_LEGACY_LEVEL4 )
   hb_pp_delDefine( pState, "HB_VER_SVNID" );
   hb_pp_addDefine( pState, "HB_VER_SVNID", szRevID );
#endif

   return ( int ) hb_strValInt( szRevID, &iLen );
}