Beispiel #1
0
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
}
Beispiel #2
0
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
}
Beispiel #3
0
static char * hb_cmdargDup( int argc )
{
#if defined( HB_OS_WIN )
   if( s_lpArgV )
      return argc >= 0 && argc < s_argc ? HB_OSSTRDUP( s_lpArgV[ argc ] ) : NULL;
#endif
   return argc >= 0 && argc < s_argc ? hb_osStrDecode( s_argv[ argc ] ) : NULL;
}
Beispiel #4
0
char * hb_getenv( const char * szName )
{
   char * pszBuffer = NULL;

#if defined( HB_OS_WIN )
   {
      LPTSTR lpName = HB_CHARDUP( szName );
      DWORD size = GetEnvironmentVariable( lpName, NULL, 0 );

      if( size != 0 )
      {
         LPTSTR lpBuffer = ( LPTSTR ) hb_xgrab( size * sizeof( TCHAR ) );
         GetEnvironmentVariable( lpName, lpBuffer, size );
         pszBuffer = HB_OSSTRDUP( lpBuffer );
         hb_xfree( lpBuffer );
      }
      hb_xfree( lpName );
   }
#elif defined( HB_OS_OS2 )
   {
      PSZ EnvValue = ( PSZ ) "";
      char * pszNameFree = NULL;

      szName = hb_osEncodeCP( szName, &pszNameFree, NULL );
      if( DosScanEnv( ( PCSZ ) szName, &EnvValue ) == NO_ERROR )
         pszBuffer = hb_osStrDecode( ( char * ) EnvValue );
      if( pszNameFree )
         hb_xfree( pszNameFree );
   }
#else
   {
      char * pszTemp, * pszNameFree = NULL;

      szName = hb_osEncodeCP( szName, &pszNameFree, NULL );
      pszTemp = getenv( szName );
      if( pszNameFree )
         hb_xfree( pszNameFree );

      if( pszTemp != NULL )
         pszBuffer = hb_osStrDecode( pszTemp );
   }
#endif

   return pszBuffer;
}
Beispiel #5
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;
}