コード例 #1
0
ファイル: win_svc_1.c プロジェクト: tfonrouge/harbour
static VOID WINAPI hbwin_SvcMainFunction( DWORD dwArgc, LPTSTR * lpszArgv )
{
    s_ServiceStatus.dwServiceType             = SERVICE_WIN32;
    s_ServiceStatus.dwCurrentState            = SERVICE_START_PENDING;
    s_ServiceStatus.dwControlsAccepted        = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
    s_ServiceStatus.dwWin32ExitCode           = 0;
    s_ServiceStatus.dwServiceSpecificExitCode = 0;
    s_ServiceStatus.dwCheckPoint              = 0;
    s_ServiceStatus.dwWaitHint                = 0;

    s_hStatus = RegisterServiceCtrlHandler( s_lpServiceName, ( LPHANDLER_FUNCTION ) hbwin_SvcControlHandler );

    if( s_hStatus != ( SERVICE_STATUS_HANDLE ) 0 )
    {
        if( s_pHarbourEntryFunc != NULL )
        {
            if( hb_vmRequestReenterExt() )
            {
                DWORD i;
                int iArgCount = 0;

                if( ! s_pHarbourControlFunc )
                {
                    /* We report the running status to SCM. */
                    s_ServiceStatus.dwCurrentState = SERVICE_RUNNING;
                    SetServiceStatus( s_hStatus, &s_ServiceStatus );
                }

                hb_vmPushEvalSym();
                hb_vmPush( s_pHarbourEntryFunc );

                for( i = 1; i < dwArgc; ++i )
                {
                    PHB_ITEM pItem = hb_stackAllocItem();

                    HB_ITEMPUTSTR( pItem, lpszArgv[ i ] );
                    if( hb_cmdargIsInternal( hb_itemGetCPtr( pItem ), NULL ) )
                        hb_stackPop();
                    else
                        ++iArgCount;
                }

                hb_vmSend( ( HB_USHORT ) iArgCount );

                hb_vmRequestRestore();
            }
            else
                HB_TRACE( HB_TR_DEBUG, ( "HVM stack not available" ) );
        }
        else
            HB_TRACE( HB_TR_DEBUG, ( "Harbour service entry function not found" ) );
    }
    else
        HB_TRACE( HB_TR_DEBUG, ( "Error registering service" ) );
}
コード例 #2
0
ファイル: cmdarg.c プロジェクト: jlsiug/harbour-core
int hb_cmdargPushArgs( void )
{
   int iArgCount = 0, i;

   for( i = 1; i < s_argc; i++ )
   {
      /* Filter out any parameters beginning with //, like //INFO */
      if( ! hb_cmdargIsInternal( s_argv[ i ], NULL ) )
      {
#if defined( HB_OS_WIN )
         if( s_lpArgV )
            HB_ITEMPUTSTR( hb_stackAllocItem(), s_lpArgV[ i ] );
         else
#endif
            hb_vmPushString( s_argv[ i ], strlen( s_argv[ i ] ) );
         iArgCount++;
      }
   }

   return iArgCount;
}
コード例 #3
0
ファイル: cmdarg.c プロジェクト: jlsiug/harbour-core
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;
}