Пример #1
0
Файл: net.c Проект: Andygon/core
char * hb_username( void )
{
#if defined( HB_OS_UNIX ) || ( defined( HB_OS_OS2 ) && defined( __GNUC__ ) )

#  if defined( __WATCOMC__ ) || defined( HB_OS_VXWORKS )
      return hb_getenv( "USER" );
#  else
      struct passwd * pwd = getpwuid( getuid() );
      return pwd && pwd->pw_name ? hb_osStrDecode( pwd->pw_name ) : hb_getenv( "USER" );
#  endif

#elif defined( HB_OS_WIN )

   DWORD ulLen = 256;
   TCHAR lpValue[ 256 ];

   lpValue[ 0 ] = TEXT( '\0' );
   GetUserName( lpValue, &ulLen );
   lpValue[ 255 ] = TEXT( '\0' );

   return lpValue[ 0 ] ? HB_OSSTRDUP( lpValue ) : NULL;

#else

   return NULL;

#endif
}
Пример #2
0
/* check environment parameters */
void hb_compChkEnvironment( HB_COMP_DECL )
{
   /* NOTE: if HARBOURCMD envvar exists then it's used instead of CLIPPERCMD */
   char * szEnvCMD = hb_getenv( "HARBOURCMD" );

   if( ! szEnvCMD || szEnvCMD[ 0 ] == '\0' )
   {
      if( szEnvCMD )
         hb_xfree( szEnvCMD );
      szEnvCMD = hb_getenv( "CLIPPERCMD" );
   }

   if( szEnvCMD )
   {
      const char * szSwitch = szEnvCMD;

      while( *szSwitch )
      {
         while( *szSwitch == ' ' )
            ++szSwitch;
         if( *szSwitch )
            szSwitch = hb_compChkParseSwitch( HB_COMP_PARAM, szSwitch, HB_TRUE );
      }
      hb_xfree( szEnvCMD );
   }
}
Пример #3
0
int hb_gt_chrmapinit( int * piTransTbl, const char * pszTerm, HB_BOOL fSetACSC )
{
    char * pszFree = NULL;
    int nRet = -1;

    chrmap_init( piTransTbl );

    if( pszTerm == NULL || *pszTerm == '\0' )
        pszTerm = pszFree = hb_getenv( "HB_TERM" );
    if( pszTerm == NULL || *pszTerm == '\0' )
    {
        if( pszFree )
            hb_xfree( pszFree );
        pszTerm = pszFree = hb_getenv( "TERM" );
    }

    if( pszTerm != NULL && *pszTerm != '\0' )
    {
        char * pszFile = hb_getenv( "HB_CHARMAP" );

        if( pszFile != NULL && *pszFile != '\0' )
            nRet = hb_gt_chrmapread( pszFile, pszTerm, piTransTbl );
        if( nRet == -1 )
        {
            char szFile[ HB_PATH_MAX ];
            if( pszFile )
                hb_xfree( pszFile );
            pszFile = hb_getenv( "HB_ROOT" );
            if( pszFile != NULL && sizeof( szFile ) >
                    strlen( pszFile ) + strlen( s_szCharMapFileDefault ) )
            {
                hb_strncpy( szFile, pszFile, sizeof( szFile ) - 1 );
                hb_strncat( szFile, s_szCharMapFileDefault, sizeof( szFile ) - 1 );
                nRet = hb_gt_chrmapread( szFile, pszTerm, piTransTbl );
            }
        }
        if( pszFile )
            hb_xfree( pszFile );
        if( nRet == -1 )
            nRet = hb_gt_chrmapread( s_szCharMapFileDefault, pszTerm, piTransTbl );
    }

    if( pszFree )
        hb_xfree( pszFree );

    if( nRet == -1 )
    {
        chrmap_dotctrl( piTransTbl );
        if( fSetACSC )
            chrmap_acscbox( piTransTbl );
        else
            chrmap_ascictrl( piTransTbl );
    }

    return nRet;
}
Пример #4
0
void hb_compChkDefines( HB_COMP_DECL, int iArg, const char * const Args[] )
{
   /* 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_compChkDefineSwitch( HB_COMP_PARAM, szSwitch );
            }
         }
         hb_xfree( szStrEnv );
      }
   }

   /* Check the command line options */
   {
      int i;

      /* Check all switches in command line They start with an OS_OPT_DELIMITER
         char */
      for( i = 1; i < iArg; i++ )
         hb_compChkDefineSwitch( HB_COMP_PARAM, Args[ i ] );
   }
}
Пример #5
0
Файл: net.c Проект: Andygon/core
char * hb_netname( void )
{
#if defined( HB_OS_UNIX ) || ( defined( HB_OS_OS2 ) && defined( __GNUC__ ) )

#  if defined( __WATCOMC__ )
      return hb_getenv( "HOSTNAME" );
#  else
      char szValue[ MAXGETHOSTNAME + 1 ];
      szValue[ 0 ] = szValue[ MAXGETHOSTNAME ] = '\0';
      gethostname( szValue, MAXGETHOSTNAME );
      return szValue[ 0 ] ? hb_osStrDecode( szValue ) : NULL;
#  endif

#elif defined( HB_OS_DOS )

#  if defined( __DJGPP__ ) || defined( __RSX32__ ) || defined( __GNUC__ )
      char szValue[ MAXGETHOSTNAME + 1 ];
      szValue[ 0 ] = szValue[ MAXGETHOSTNAME ] = '\0';
      gethostname( szValue, MAXGETHOSTNAME );
      return szValue[ 0 ] ? hb_osStrDecode( szValue ) : NULL;
#  else
      union REGS regs;
      struct SREGS sregs;
      char * pszValue = ( char * ) hb_xgrab( 16 );
      pszValue[ 0 ] = '\0';

      regs.HB_XREGS.ax = 0x5E00;
      regs.HB_XREGS.dx = FP_OFF( pszValue );
      sregs.ds = FP_SEG( pszValue );

      HB_DOS_INT86X( 0x21, &regs, &regs, &sregs );

      if( regs.h.ch == 0 )
         pszValue = '\0';

      return pszValue;
#  endif

#elif defined( HB_OS_WIN )

   DWORD ulLen = MAX_COMPUTERNAME_LENGTH + 1;
   TCHAR lpValue[ MAX_COMPUTERNAME_LENGTH + 1 ];

   lpValue[ 0 ] = TEXT( '\0' );
   GetComputerName( lpValue, &ulLen );
   lpValue[ MAX_COMPUTERNAME_LENGTH ] = TEXT( '\0' );

   return lpValue[ 0 ] ? HB_OSSTRDUP( lpValue ) : NULL;

#else

   return NULL;

#endif
}
Пример #6
0
void hb_compChkAddIncPaths( HB_COMP_DECL )
{
   char * szInclude = hb_getenv( "INCLUDE" );

   if( szInclude )
   {
      if( szInclude[ 0 ] != '\0' )
         hb_pp_addSearchPath( HB_COMP_PARAM->pLex->pPP, szInclude, HB_FALSE );
      hb_xfree( szInclude );
   }
}
Пример #7
0
static int hb_pp_generateVerInfo( char * szVerFile, char * szCVSID, char * szCVSDateID, char * szChangeLogID, char * szLastEntry )
{
   int      iResult = 0;
   char *   pszEnv;
   FILE *   fout;

   fout = hb_fopen( szVerFile, "w" );
   if( ! fout )
   {
#if ! defined( __MINGW32CE__ ) && ! defined( HB_OS_WIN_CE )
      perror( szVerFile );
#endif
      iResult = 1;
   }
   else
   {
      fprintf( fout, "/*\n * $Id: ppgen.c 9869 2012-12-08 18:25:43Z andijahja $\n */\n\n/*\n"
               " * Harbour Project source code:\n"
               " *    Version information and build time switches.\n"
               " *\n"
               " * Copyright 2008 Przemyslaw Czerpak <druzus / at / priv.onet.pl>\n"
               " * www - http://www.harbour-project.org\n"
               " *\n"
               " * This file is generated automatically by Harbour preprocessor\n"
               " * and is covered by the same license as Harbour PP\n"
               " */\n\n" );

      fprintf( fout, "\n#ifndef __HBVERBLD_INCLUDED" );
      fprintf( fout, "\n#define __HBVERBLD_INCLUDED\n" );

      if( szCVSID )
         fprintf( fout, "\n#define HB_VER_CVSID\t\t%s\n", szCVSID );

      if( szCVSDateID )
      {
         fprintf( fout, "\n#if defined(HB_VER_BUILDDATE)" );
         fprintf( fout, "\n#undef HB_VER_BUILDDATE" );
         fprintf( fout, "\n#endif\n" );
         fprintf( fout, "#define HB_VER_BUILDDATE\t%s\n", szCVSDateID );
      }

      if( szChangeLogID )
      {
         fprintf( fout, "\n#if defined(HB_VER_CHLCVS)" );
         fprintf( fout, "\n#undef HB_VER_CHLCVS" );
         fprintf( fout, "\n#endif\n" );
         fprintf( fout, "\n#define HB_VER_CHLCVS\t\"%s\"\n", szChangeLogID );
      }

      if( szLastEntry )
      {
         fprintf( fout, "\n#if defined(HB_VER_LENTRY)" );
         fprintf( fout, "\n#undef HB_VER_LENTRY" );
         fprintf( fout, "\n#endif\n" );
         fprintf( fout, "\n#define HB_VER_LENTRY\t\"%s\"\n", szLastEntry );
      }

      pszEnv = hb_getenv( "C_USR" );
      if( pszEnv )
      {
         fprintf( fout, "\n#undef  HB_VER_C_USR" );
         fprintf( fout, "\n#define HB_VER_C_USR\t\"%s\"\n", pszEnv );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "L_USR" );
      if( pszEnv )
      {
         fprintf( fout, "\n#undef  HB_VER_L_USR" );
         fprintf( fout, "\n#define HB_VER_L_USR\t\"%s\"\n", pszEnv );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "PRG_USR" );
      if( pszEnv )
      {
         fprintf( fout, "\n#undef  HB_VER_PRG_USR" );
         fprintf( fout, "\n#define HB_VER_PRG_USR\t\"%s\"\n", pszEnv );
         hb_xfree( pszEnv );
      }

      fprintf( fout, "\n#endif /* __HBVERBLD_INCLUDED */\n" );

      fclose( fout );
   }

   return iResult;
}
Пример #8
0
/* NOTE: pszTempDir must be at least HB_PATH_MAX long. */
HB_ERRCODE hb_fsTempDir( char * pszTempDir )
{
   HB_ERRCODE nResult = ( HB_ERRCODE ) FS_ERROR;

   pszTempDir[ 0 ] = '\0';

#if defined( HB_OS_UNIX )
   {
      char * pszTempDirEnv = hb_getenv( "TMPDIR" );

      if( fsGetTempDirByCase( pszTempDir, pszTempDirEnv, HB_FALSE ) )
         nResult = 0;
#ifdef P_tmpdir
      else if( fsGetTempDirByCase( pszTempDir, P_tmpdir, HB_TRUE ) )
         nResult = 0;
#endif
      else if( fsGetTempDirByCase( pszTempDir, "/tmp", HB_TRUE ) )
         nResult = 0;

      if( pszTempDirEnv )
         hb_xfree( pszTempDirEnv );
   }
#elif defined( HB_OS_WIN )
   {
      TCHAR lpDir[ HB_PATH_MAX ];

      if( GetTempPath( HB_PATH_MAX, lpDir ) )
      {
         nResult = 0;
         lpDir[ HB_PATH_MAX - 1 ] = TEXT( '\0' );
         HB_OSSTRDUP2( lpDir, pszTempDir, HB_PATH_MAX - 1 );
      }
   }
#else
   {
#if ! defined( HB_OS_OS2 )
      char szBuffer[ L_tmpnam ];

      if( tmpnam( szBuffer ) != NULL )
      {
         PHB_FNAME pTempName = hb_fsFNameSplit( szBuffer );
         if( fsGetTempDirByCase( pszTempDir, pTempName->szPath, HB_TRUE ) )
            nResult = 0;
         hb_xfree( pTempName );
      }
      if( nResult != 0 )
#endif
      {
         static const char * env_tmp[] = { "TEMP", "TMP", "TMPDIR", NULL };

         const char ** tmp = env_tmp;

         while( *tmp && nResult != 0 )
         {
            char * pszTempDirEnv = hb_getenv( *tmp++ );

            if( pszTempDirEnv )
            {
               if( fsGetTempDirByCase( pszTempDir, pszTempDirEnv, HB_FALSE ) )
                  nResult = 0;
               hb_xfree( pszTempDirEnv );
            }
         }
      }
   }
#endif

   if( nResult == 0 && pszTempDir[ 0 ] != '\0' )
   {
      int len = ( int ) strlen( pszTempDir );
      if( pszTempDir[ len - 1 ] != HB_OS_PATH_DELIM_CHR &&
          len < HB_PATH_MAX - 1 )
      {
         pszTempDir[ len ] = HB_OS_PATH_DELIM_CHR;
         pszTempDir[ len + 1 ] = '\0';
      }
   }
   else
   {
      pszTempDir[ 0 ] = '.';
      pszTempDir[ 1 ] = HB_OS_PATH_DELIM_CHR;
      pszTempDir[ 2 ] = '\0';
   }

   return nResult;
}
Пример #9
0
int main( int argc, char * argv[] )
{
  FILE * handl_o;
  char szFileName[ _POSIX_PATH_MAX + 1 ];
  char szPpoName[ _POSIX_PATH_MAX + 1 ];
  int iArg = 1;
  BOOL bOutTable = FALSE;
  BOOL bOutNew = FALSE;
  DEFINES * stdef;
  COMMANDS * stcmd;

  HB_TRACE(HB_TR_DEBUG, ("main(%d, %p)", argc, argv));

  printf( "Harbour Preprocessor (old revision) %d.%d.%d\n",
     HB_VER_MAJOR, HB_VER_MINOR, HB_VER_REVISION );
  printf( "Copyright (c) 1999-2008, http://www.harbour-project.org/\n" );

  hb_pp_Table();
  stdef = hb_pp_topDefine;
  stcmd = hb_pp_topCommand;
  hb_pp_Init();

  while( iArg < argc )
    {
      if( HB_ISOPTSEP(argv[ iArg ][ 0 ]))
        {
          switch( argv[ iArg ][ 1 ] )
            {
            case 'd':
            case 'D':   /* defines a #define from the command line */
              {
                 char *szDefText = hb_strdup( argv[iArg] + 2 ), *pAssign, *sDefLine;
                 unsigned int i = 0;

                 while( i < strlen( szDefText ) && ! HB_ISOPTSEP( szDefText[ i ] ) )
                    i++;

                 szDefText[ i ] = '\0';
                 if( szDefText )
                 {
                    if( ( pAssign = strchr( szDefText, '=' ) ) == NULL )
                    {
                       hb_pp_AddDefine_( szDefText, 0 );
                    }
                    else
                    {
                       szDefText[ pAssign - szDefText ] = '\0';

                       /* hb_pp_AddDefine_( szDefText,  pAssign + 1 ); */
                       sDefLine = hb_xstrcpy( NULL, szDefText, " ", pAssign + 1, NULL );
                       hb_pp_ParseDefine_( sDefLine );
                       hb_xfree( sDefLine );
                    }
                 }

                 hb_xfree( szDefText );
              }
              break;
            case 'i':
            case 'I':
              AddSearchPath( argv[ iArg ]+2, &hb_comp_pIncludePath );
              break;
            case 'o':
            case 'O':
              bOutTable = TRUE;
              break;
            case 'n':
            case 'N':
              bOutNew = TRUE;
              break;
            case 'w':
            case 'W':
              s_iWarnings = 1;
              if( argv[ iArg ][ 2 ] )
                {  /*there is -w<0,1,2,3> probably */
                  s_iWarnings = argv[ iArg ][ 2 ] - '0';
                  if( s_iWarnings < 0 || s_iWarnings > 3 )
                    printf( "\nInvalid command line option: %s\n", argv[ iArg ] );
                }
              break;
            default:
              printf( "\nInvalid command line option: %s\n", &argv[ iArg ][ 1 ] );
              break;
            }
        }
      else  hb_comp_pFileName = hb_fsFNameSplit( argv[ iArg ] );
      iArg++;
    }

  if( hb_comp_pFileName )
    {
      if( ! hb_comp_pFileName->szExtension )
        hb_comp_pFileName->szExtension =".prg";

      hb_fsFNameMerge( szFileName, hb_comp_pFileName );

      if( !hb_pp_fopen( szFileName ) )
        {
          printf("\nCan't open %s\n", szFileName );
          return 1;
        }

      printf( "\nParsing file %s\n", szFileName );
    }
  else
    {
      printf( "\nSyntax:  %s <file[.prg]> [options]"
              "\n"
              "\nOptions:  /d<id>[=<val>]   #define <id>"
              "\n          /i<path>         add #include file search path"
              "\n          /o               creates hbpp.out with all tables"
              "\n          /n               with those only, which defined in your file"
              "\n          /w               enable warnings"
              "\n"
              , argv[ 0 ] );

      if( bOutTable )
        OutTable( NULL, NULL );

      return 1;
    }

  hb_comp_pFileName->szExtension = ".ppo";
  hb_fsFNameMerge( szPpoName, hb_comp_pFileName );

  if( ( handl_o = fopen( szPpoName, "wt" ) ) == NULL )
    {
      printf("\nCan't open %s\n", szPpoName );
      return 1;
    }

  {
    char * szInclude = hb_getenv( "INCLUDE" );

    if( szInclude )
      {
        char * pPath;
        char * pDelim;

        pPath = szInclude;
        while( ( pDelim = strchr( pPath, HB_OS_PATH_LIST_SEP_CHR ) ) != NULL )
          {
            *pDelim = '\0';
            AddSearchPath( pPath, &hb_comp_pIncludePath );
            pPath = pDelim + 1;
          }
        AddSearchPath( pPath, &hb_comp_pIncludePath );
        hb_xfree( szInclude );
      }
  }

  hb_buffer = ( char* ) hb_xgrab( HB_PP_STR_SIZE );
  while( hb_pp_Internal_( handl_o,hb_buffer ) > 0 );
  fclose( hb_comp_files.pLast->handle );
  hb_xfree( hb_comp_files.pLast->pBuffer );
  hb_xfree( hb_comp_files.pLast );
  hb_xfree( hb_buffer );
  fclose( handl_o );

  if( bOutTable )
    OutTable( NULL, NULL );
  else if( bOutNew )
    OutTable( stdef, stcmd );

  printf( "\nOk" );

  return 0;
}
Пример #10
0
static char * hb_cmdargGet( const char * pszName, HB_BOOL bRetValue )
{
   char * pszRetVal = NULL;
   char * pszEnvVar;
   int i;
   int iPrefixLen;

   HB_TRACE( HB_TR_DEBUG, ( "hb_cmdargGet(%s, %d)", pszName, ( int ) bRetValue ) );

   /* Check the command-line first */

   for( i = 1; i < s_argc; i++ )
   {
      if( hb_cmdargIsInternal( s_argv[ i ], &iPrefixLen ) &&
          hb_strnicmp( s_argv[ i ] + iPrefixLen, pszName, strlen( pszName ) ) == 0 )
      {
         if( bRetValue )
         {
#if defined( HB_OS_WIN )
            if( s_lpArgV )
            {
               LPCTSTR lpPos = s_lpArgV[ i ] + iPrefixLen + strlen( pszName );

               if( *lpPos == TEXT( ':' ) )
                  lpPos++;
               return HB_OSSTRDUP( lpPos );
            }
            else
#endif
            {
               char * pszPos = s_argv[ i ] + iPrefixLen + strlen( pszName );

               if( *pszPos == ':' )
                  pszPos++;

               return hb_osStrDecode( pszPos );
            }
         }
         else
            return ( char * ) "";
      }
   }

   /* Check the environment variable */
   pszEnvVar = hb_getenv( "HARBOUR" );
   if( ! pszEnvVar || pszEnvVar[ 0 ] == '\0' )
   {
      if( pszEnvVar )
         hb_xfree( pszEnvVar );

#ifdef HB_CLP_STRICT
      pszEnvVar = hb_getenv( "CLIPPER" );
#else
      pszEnvVar = NULL;
#endif
   }

   if( pszEnvVar && pszEnvVar[ 0 ] != '\0' )
   {
      char * pszNext = pszEnvVar;

      /* Step through all envvar switches. */

      /* NOTE: CA-Cl*pper doesn't need the switches to be separated by any
               chars at all, Harbour is more strict/standard in this respect,
               it requires the switches to be separated. */

      i = ( int ) strlen( pszName );
      while( *pszNext )
      {
         static const char * s_szSeparator = " ;,\t";
         char * pszEnd;

         /* Skip the separators */
         while( *pszNext && strchr( s_szSeparator, *pszNext ) )
            pszNext++;

         /* The // is optional in the envvar */
         if( hb_cmdargIsInternal( pszNext, &iPrefixLen ) )
            pszNext += iPrefixLen;

         pszEnd = pszNext;
         /* Search for the end of this switch */
         while( *pszEnd && strchr( s_szSeparator, *pszEnd ) == NULL )
            pszEnd++;

         /* Check the switch */
         if( hb_strnicmp( pszNext, pszName, i ) == 0 )
         {
            if( bRetValue )
            {
               HB_SIZE nLen;
               pszNext += i;

               /* Skip value separator colon. */
               if( *pszNext == ':' )
                  pszNext++;

               nLen = pszEnd > pszNext ? pszEnd - pszNext : 0;
               pszRetVal = ( char * ) hb_xgrab( nLen + 1 );
               hb_strncpy( pszRetVal, pszNext, nLen );
            }
            else
               pszRetVal = ( char * ) "";
            break;
         }

         /* Step to the next switch */
         pszNext = pszEnd;
      }
   }

   if( pszEnvVar )
      hb_xfree( pszEnvVar );

   return pszRetVal;
}
Пример #11
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
}
Пример #12
0
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
static HB_FHANDLE hb_fsCreateTempLow( const BYTE * pszDir, const BYTE * pszPrefix, ULONG ulAttr, BYTE * pszName, const UCHAR * pszExt )
{
   /* less attemps */
   int iAttemptLeft = 99, iLen;
   HB_FHANDLE fd;

   do
   {
      pszName[ 0 ] = '\0';

      if( pszDir && pszDir[ 0 ] != '\0' )
      {
         strncpy( ( char * ) pszName, ( char * ) pszDir, _POSIX_PATH_MAX );
      }
      else
      {
#if defined(HB_WIN32_IO)
         if( ! GetTempPathA( ( DWORD ) _POSIX_PATH_MAX, ( LPSTR ) pszName ) )
         {
            pszName[ 0 ] = '.';
            pszName[ 1 ] = '\0';
         }
#else
         char * pszTmpDir = hb_getenv( "TMPDIR" );

         if( !fsGetTempDirByCase( pszName, pszTmpDir ) )
         {
#ifdef P_tmpdir
            if( !fsGetTempDirByCase( pszName, P_tmpdir ) )
#endif
            {
               pszName[ 0 ] = '.';
               pszName[ 1 ] = '\0';
            }
         }
         if( pszTmpDir )
            hb_xfree( pszTmpDir );
#endif
      }

      if( pszName[0] != '\0' )
      {
         int len = strlen( ( char * ) pszName );
         if( pszName[ len - 1 ] != ( BYTE ) hb_set.HB_SET_DIRSEPARATOR )
         {
            pszName[ len ] = ( BYTE ) hb_set.HB_SET_DIRSEPARATOR;
            pszName[ len + 1 ] = '\0';
         }
      }

      if( pszPrefix )
         strncat( ( char * ) pszName, ( char * ) pszPrefix, _POSIX_PATH_MAX );

      iLen = ( int ) strlen( ( char * ) pszName );
      if( iLen > _POSIX_PATH_MAX - 6 )
         return FS_ERROR;

#if !defined(__WATCOMC__) && ( defined( HB_OS_LINUX ) || defined( HB_OS_BSD ) )
      if( hb_set.HB_SET_FILECASE != HB_SET_CASE_LOWER &&
          hb_set.HB_SET_FILECASE != HB_SET_CASE_UPPER &&
          hb_set.HB_SET_DIRCASE != HB_SET_CASE_LOWER &&
          hb_set.HB_SET_DIRCASE != HB_SET_CASE_UPPER &&
          pszExt == NULL )
      {
         strncat( ( char * ) pszName, "XXXXXX", _POSIX_PATH_MAX );
         fd = ( HB_FHANDLE ) mkstemp( ( char * ) pszName );
         hb_fsSetIOError( fd != ( HB_FHANDLE ) -1, 0 );
      }
      else
#endif
      {
         int i, n;
         double d = hb_random_num(), x;

         for( i = 0; i < 6; i++ )
         {
            d = d * 36;
            n = ( int ) d;
            d = modf( d, &x );
            pszName[ iLen++ ] = ( BYTE ) ( n + ( n > 9 ? 'a' - 10 : '0' ) );
         }
         pszName[ iLen ] = '\0';
         if( pszExt )
            strncat( ( char * ) pszName, ( char * ) pszExt, _POSIX_PATH_MAX );
         hb_fsNameConv( pszName, NULL );
         fd = hb_fsCreateEx( pszName, ulAttr, FO_EXCLUSIVE | FO_EXCL );
      }

      if( fd != ( HB_FHANDLE ) FS_ERROR )
         return fd;
   }
   while( --iAttemptLeft );

   return FS_ERROR;
}
Пример #14
0
int main( int argc, char * argv[] )
{
   char * szFile = NULL, * szRuleFile = NULL, * szVerFile = NULL;
   char * szStdCh = NULL, * szLogFile = NULL, * szInclude;
   HB_BOOL fWrite = HB_FALSE, fChgLog = HB_FALSE;
   char * szChangeLogID = NULL, * szLastEntry = NULL;
   int iRevID = 0, iResult = 0, iQuiet = 0, i;
   char * szPPRuleFuncName = NULL;
   PHB_PP_STATE pState;

   pState = hb_pp_new();

   if( argc >= 2 )
   {
      szFile = argv[ 1 ];
      for( i = 2; szFile && i < argc; i++ )
      {
         if( ! HB_ISOPTSEP( argv[ i ][ 0 ] ) )
            szFile = NULL;
         else
         {
            switch( argv[ i ][ 1 ] )
            {
               case 'q':
               case 'Q':
                  if( ! argv[ i ][ 2 ] )
                     iQuiet = 1;
                  else if( argv[ i ][ 2 ] == '-' && ! argv[ i ][ 3 ] )
                     iQuiet = 0;
                  else if( argv[ i ][ 2 ] >= '0' && argv[ i ][ 2 ] <= '2' && ! argv[ i ][ 3 ] )
                     iQuiet = argv[ i ][ 2 ] - '0';
                  else
                     szFile = NULL;
                  break;

               case 'd':
               case 'D':
                  if( ! argv[ i ][ 2 ] )
                     szFile = NULL;
                  else
                  {
                     char * szDefText = hb_strdup( argv[ i ] + 2 ), * szAssign;

                     szAssign = strchr( szDefText, '=' );
                     if( szAssign )
                        *szAssign++ = '\0';
                     hb_pp_addDefine( pState, szDefText, szAssign );
                     hb_xfree( szDefText );
                  }
                  break;

               case 'e':
               case 'E':
                  if( argv[ i ][ 2 ] )
                     szPPRuleFuncName = argv[ i ] + 2;
                  else
                     szPPRuleFuncName = NULL;
                  break;

               case 'w':
               case 'W':
                  if( argv[ i ][ 2 ] )
                     szFile = NULL;
                  else
                     fWrite = HB_TRUE;
                  break;

               case 'c':
               case 'C':
                  fChgLog = HB_TRUE;
                  if( argv[ i ][ 2 ] )
                     szLogFile = argv[ i ] + 2;
                  break;

               case 'i':
               case 'I':
                  if( argv[ i ][ 2 ] )
                     hb_pp_addSearchPath( pState, argv[ i ] + 2, HB_FALSE );
                  else
                     szFile = NULL;
                  break;

               case 'o':
               case 'O':
                  if( argv[ i ][ 2 ] )
                     szRuleFile = argv[ i ] + 2;
                  else
                     szFile = NULL;
                  break;

               case 'v':
               case 'V':
                  if( argv[ i ][ 2 ] )
                     szVerFile = argv[ i ] + 2;
                  else
                     szFile = NULL;
                  break;

               case 'u':
               case 'U':
                  if( argv[ i ][ 2 ] )
                     szStdCh = argv[ i ] + 2;
                  else
                     szStdCh = NULL;
                  break;

               default:
                  szFile = NULL;
                  break;
            }
         }
      }
   }

   if( iQuiet < 2 )
   {
      printf( "Harbour Preprocessor %d.%d.%d%s\n",
              HB_VER_MAJOR, HB_VER_MINOR, HB_VER_RELEASE, HB_VER_STATUS );
      printf( "Copyright (c) 1999-2014, http://harbour-project.org/\n" );
   }

   if( szFile )
   {
      if( ! szRuleFile && ! szVerFile )
         fWrite = HB_TRUE;

      hb_pp_init( pState, iQuiet != 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );

      szInclude = hb_getenv( "INCLUDE" );
      if( szInclude )
      {
         if( szInclude[ 0 ] )
            hb_pp_addSearchPath( pState, szInclude, HB_FALSE );
         hb_xfree( szInclude );
      }

      if( szStdCh )
         hb_pp_readRules( pState, szStdCh );

      if( hb_pp_inFile( pState, szFile, HB_TRUE, NULL, HB_TRUE ) )
      {
         if( fWrite )
         {
            char szFileName[ HB_PATH_MAX ];
            PHB_FNAME pFileName;

            pFileName = hb_fsFNameSplit( szFile );
            pFileName->szExtension = ".ppo";
            hb_fsFNameMerge( szFileName, pFileName );
            hb_xfree( pFileName );

            hb_pp_outFile( pState, szFileName, NULL );
         }

         if( fChgLog )
            iResult = hb_pp_parseChangelog( pState, szLogFile, iQuiet,
                                            &iRevID, &szChangeLogID, &szLastEntry );

         if( iResult == 0 )
            iResult = hb_pp_preprocesfile( pState, szRuleFile, szPPRuleFuncName );

         if( iResult == 0 && szVerFile )
            iResult = hb_pp_generateVerInfo( szVerFile, iRevID,
                                             szChangeLogID, szLastEntry );
         if( iResult == 0 && hb_pp_errorCount( pState ) > 0 )
            iResult = 1;
      }
      else
         iResult = 1;
   }
   else
   {
      hb_pp_usage( argv[ 0 ] );
      iResult = 1;
   }

   if( szChangeLogID )
      hb_xfree( szChangeLogID );
   if( szLastEntry )
      hb_xfree( szLastEntry );

   hb_pp_free( pState );

   return iResult;
}
Пример #15
0
static int hb_pp_generateVerInfo( char * szVerFile, int iRevID, char * szChangeLogID, char * szLastEntry )
{
   int iResult = 0;
   char * pszEnv;
   FILE * fout;

   fout = hb_fopen( szVerFile, "w" );
   if( ! fout )
   {
#if ! defined( HB_OS_WIN_CE )
      perror( szVerFile );
#endif
      iResult = 1;
   }
   else
   {
      char * pszEscaped;

      fprintf( fout, "/*\n"
               " * Harbour Project source code:\n"
               " *    Version information and build time switches.\n"
               " *\n"
               " * Copyright 2008-2014 Przemyslaw Czerpak <druzus / at / priv.onet.pl>\n"
               " * www - http://harbour-project.org\n"
               " *\n"
               " * This file is generated automatically by Harbour preprocessor\n"
               " * and is covered by the same license as Harbour PP\n"
               " */\n\n" );

      fprintf( fout, "#define HB_VER_REVID             %d\n", iRevID );

      if( szChangeLogID )
      {
         pszEscaped = hb_pp_escapeString( szChangeLogID );
         fprintf( fout, "#define HB_VER_CHLID             \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
      }

      if( szLastEntry )
      {
         pszEscaped = hb_pp_escapeString( szLastEntry );
         fprintf( fout, "#define HB_VER_LENTRY            \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
      }

      pszEnv = hb_getenv( "HB_USER_CFLAGS" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_VER_HB_USER_CFLAGS    \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_USER_LDFLAGS" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_VER_HB_USER_LDFLAGS   \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_USER_PRGFLAGS" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_VER_HB_USER_PRGFLAGS  \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_PLATFORM" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_PLATFORM              \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_COMPILER" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_COMPILER              \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      fclose( fout );
   }

   return iResult;
}
Пример #16
0
static int hb_pp_generateVerInfo( char * szVerFile, int iCommitRev, char * szCommitInfo, char * szCommitID )
{
   int iResult = 0;
   FILE * fout;

   fout = hb_fopen( szVerFile, "w" );
   if( ! fout )
   {
#if ! defined( HB_OS_WIN_CE )
      perror( szVerFile );
#endif
      iResult = 1;
   }
   else
   {
      char * pszEnv;
      char * pszEscaped;

      fprintf( fout, "/*\n"
               " * Version information and build time switches.\n"
               " *\n"
               " * Copyright 2008-2016 Przemyslaw Czerpak <druzus / at / priv.onet.pl>\n"
               " *\n"
               " * This file is generated automatically by Harbour preprocessor\n"
               " * and is covered by the same license as Harbour PP\n"
               " */\n\n" );

      if( szCommitID )
      {
         pszEscaped = hb_pp_escapeString( szCommitID );
         fprintf( fout, "#define HB_VER_COMMIT_ID         \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
      }

      fprintf( fout, "#define HB_VER_COMMIT_REV        %d\n", iCommitRev );

      if( szCommitInfo )
      {
         pszEscaped = hb_pp_escapeString( szCommitInfo );
         fprintf( fout, "#define HB_VER_COMMIT_INFO       \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
      }

      pszEnv = hb_getenv( "HB_USER_CFLAGS" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_VER_HB_USER_CFLAGS    \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_USER_LDFLAGS" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_VER_HB_USER_LDFLAGS   \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_USER_PRGFLAGS" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_VER_HB_USER_PRGFLAGS  \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_PLATFORM" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_PLATFORM              \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

      pszEnv = hb_getenv( "HB_COMPILER" );
      if( pszEnv )
      {
         pszEscaped = hb_pp_escapeString( pszEnv );
         fprintf( fout, "#define HB_COMPILER              \"%s\"\n", pszEscaped );
         hb_xfree( pszEscaped );
         hb_xfree( pszEnv );
      }

#if defined( HB_LEGACY_LEVEL4 )
      fprintf( fout, "\n#define HB_VER_CHLID            HB_VER_COMMIT_ID\n" );
      fprintf( fout, "\n#define HB_VER_LENTRY           HB_VER_COMMIT_INFO\n" );
#endif

      fclose( fout );
   }

   return iResult;
}