Exemplo n.º 1
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;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
void hb_cmdargUpdate( void )
{
   HB_TRACE( HB_TR_DEBUG, ( "hb_cmdargUpdate()" ) );

#if ! defined( HB_OS_WIN )
   if( s_argc > 0 )
   {
   #if defined( HB_OS_OS2 )
      {
         PPIB ppib = NULL;
         APIRET ulrc;

         ulrc = DosGetInfoBlocks( NULL, &ppib );
         if( ulrc == NO_ERROR )
         {
            ulrc = DosQueryModuleName( ppib->pib_hmte,
                                       HB_SIZEOFARRAY( s_szAppName ),
                                       s_szAppName );
            if( ulrc == NO_ERROR )
               s_argv[ 0 ] = s_szAppName;
         }
      }
   #else
      /* NOTE: try to create absolute path from s_argv[ 0 ] if necessary */
      {
         PHB_FNAME pFName = hb_fsFNameSplit( s_argv[ 0 ] );
         HB_BOOL fInPath = HB_FALSE;

         if( ! pFName->szPath )
         {
            char * pszPATH = hb_getenv( "PATH" );

            if( pszPATH && *pszPATH )
            {
               HB_PATHNAMES * pSearchPath = NULL, * pNextPath;
               hb_fsAddSearchPath( pszPATH, &pSearchPath );
               pNextPath = pSearchPath;

               while( pNextPath )
               {
                  pFName->szPath = pNextPath->szPath;
                  hb_fsFNameMerge( s_szAppName, pFName );
                  if( hb_fsFileExists( s_szAppName ) )
                  {
                     /* even if the file is located using PATH then it does
                      * not mean we will have absolute path here. It's not
                      * good idea but PATH envvar can also contain relative
                      * directories, f.e. "." or "bin" so we should add
                      * current directory if necessary in code below.
                      */
                     hb_xfree( pFName );
                     pFName = hb_fsFNameSplit( s_szAppName );
                     fInPath = HB_TRUE;
                     break;
                  }
                  pNextPath = pNextPath->pNext;
               }
               hb_fsFreeSearchPath( pSearchPath );
               if( ! fInPath )
                  pFName->szPath = NULL;
            }
            if( pszPATH )
               hb_xfree( pszPATH );
         }
         if( pFName->szPath )
         {
      #if defined( HB_OS_HAS_DRIVE_LETTER )
            if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR && ! pFName->szDrive )
      #else
            if( pFName->szPath[ 0 ] != HB_OS_PATH_DELIM_CHR )
      #endif
            {
               if( pFName->szPath[ 0 ] == '.' &&
                   pFName->szPath[ 1 ] == HB_OS_PATH_DELIM_CHR )
                  pFName->szPath += 2;
               s_szAppName[ 0 ] = HB_OS_PATH_DELIM_CHR;
               hb_fsCurDirBuff( 0, s_szAppName + 1, HB_PATH_MAX - 1 );
               if( s_szAppName[ 1 ] != 0 )
               {
                  hb_strncat( s_szAppName, HB_OS_PATH_DELIM_CHR_STRING, HB_PATH_MAX - 1 );
                  hb_strncat( s_szAppName, pFName->szPath, HB_PATH_MAX - 1 );
                  pFName->szPath = hb_strdup( s_szAppName );
                  hb_fsFNameMerge( s_szAppName, pFName );
                  hb_xfree( ( void * ) pFName->szPath );
                  s_argv[ 0 ] = s_szAppName;
               }
            }
            else if( fInPath )
               s_argv[ 0 ] = s_szAppName;
         }
         hb_xfree( pFName );
      }
   #endif
   }
#endif
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
HB_BOOL hb_spFileExists( const char * pszFileName, char * pszRetPath )
{
   char * pszPath;
   HB_BOOL bIsFile = HB_FALSE;
   PHB_FNAME pFilepath;

   HB_TRACE( HB_TR_DEBUG, ( "hb_spFileExists(%s, %p)", pszFileName, pszRetPath ) );

   if( pszRetPath )
      pszPath = pszRetPath;
   else
      pszPath = ( char * ) hb_xgrab( HB_PATH_MAX );

   pFilepath = hb_fsFNameSplit( pszFileName );

   if( pFilepath->szPath )
   {
      hb_fsFNameMerge( pszPath, pFilepath );
      bIsFile = hb_fsFileExists( pszPath );
   }
   else
   {
      const char * szDefault = hb_setGetDefault();
      if( szDefault )
      {
         pFilepath->szPath = szDefault;
         hb_fsFNameMerge( pszPath, pFilepath );
         bIsFile = hb_fsFileExists( pszPath );
      }

      if( ! bIsFile && hb_setGetPath() )
      {
         HB_PATHNAMES * pNextPath = hb_setGetFirstSetPath();

         while( bIsFile == HB_FALSE && pNextPath )
         {
            pFilepath->szPath = pNextPath->szPath;
            hb_fsFNameMerge( pszPath, pFilepath );
            bIsFile = hb_fsFileExists( pszPath );
            pNextPath = pNextPath->pNext;
         }
      }

      /*
       * This code is intentional. To eliminate race condition,
       * in pending hb_spCreate()/hb_spOpen() call when we have to know
       * real path and file name we have to set its deterministic value
       * here. If it's not necessary the caller may drop this value.
       */
      if( ! bIsFile )
      {
         pFilepath->szPath = szDefault ? szDefault : ".";
         hb_fsFNameMerge( pszPath, pFilepath );
      }
   }

   hb_xfree( pFilepath );

   if( pszRetPath == NULL )
      hb_xfree( pszPath );

   return bIsFile;
}