示例#1
0
PHB_COMP hb_comp_new( void )
{
   PHB_COMP pComp = NULL;
   PHB_PP_STATE pPP = hb_pp_new();

   if( pPP )
   {
      pComp = ( PHB_COMP ) hb_xgrab( sizeof( HB_COMP ) );
      memset( pComp, 0, sizeof( HB_COMP ) );
      pComp->pLex = ( PHB_COMP_LEX ) hb_xgrab( sizeof( HB_COMP_LEX ) );
      memset( pComp->pLex, 0, sizeof( HB_COMP_LEX ) );

      /* initialize default settings */
      pComp->mode = HB_MODE_COMPILER;
      pComp->funcs = &s_comp_funcs;

      pComp->pLex->pPP = pPP;

      /* various compatibility flags (-k switch)
         activate Harbour extensions by default. */
      pComp->supported = HB_COMPFLAG_HARBOUR   |
                         HB_COMPFLAG_XBASE     |
                         HB_COMPFLAG_HB_INLINE |
                         HB_COMPFLAG_OPTJUMP   |
                         HB_COMPFLAG_MACROTEXT |
                         HB_COMPFLAG_SHORTCUTS;

      pComp->fSwitchCase       = HB_FALSE;
      pComp->fPPO              = HB_FALSE;   /* flag indicating, is ppo output needed */
      pComp->fLineNumbers      = HB_TRUE;    /* holds if we need pcodes with line numbers */
      pComp->fAnyWarning       = HB_FALSE;   /* holds if there was any warning during the compilation process */
      pComp->fAutoMemvarAssume = HB_FALSE;   /* holds if undeclared variables are automatically assumed MEMVAR (-a)*/
      pComp->fForceMemvars     = HB_FALSE;   /* holds if memvars are assumed when accesing undeclared variable (-v)*/
      pComp->fDebugInfo        = HB_FALSE;   /* holds if generate debugger required info */
      pComp->fNoStartUp        = HB_FALSE;   /* C code generation embed HB_FS_FIRST or not */
      pComp->fCredits          = HB_FALSE;   /* print credits */
      pComp->fBuildInfo        = HB_FALSE;   /* print build info */
      pComp->fLogo             = HB_TRUE;    /* print logo */
      pComp->fSingleModule     = HB_FALSE;
      pComp->fError            = HB_FALSE;
      pComp->fINCLUDE          = HB_TRUE;

      pComp->iSyntaxCheckOnly = 0;               /* syntax check only */
      pComp->iStartProc       = 0;               /* no implicit starting procedure */
      pComp->iWarnings        = 0;               /* enable parse warnings */
      pComp->iErrorCount      = 0;               /* number of compile errors */

      pComp->iGenCOutput = HB_COMPGENC_COMPACT;  /* C code generation default mode */
      pComp->iExitLevel  = HB_EXITLEVEL_DEFAULT; /* holds if there was any warning during the compilation process */
      pComp->iLanguage   = HB_LANG_C;            /* default Harbour generated output language */
      pComp->iErrorFmt   = HB_ERRORFMT_CLIPPER;  /* default Harbour generated output language */

      pComp->outMsgFunc  = hb_compOutMsg;
   }

   return pComp;
}
示例#2
0
文件: ppgen.c 项目: xharbour/core
int main( int argc, char * argv[] )
{
   char *         szFile         = NULL, * szRuleFile = NULL, * szWordFile = NULL, * szVerFile = NULL;
   char *         szLogFile      = NULL;
   BOOL           fQuiet         = FALSE, fWrite = FALSE, fChgLog = FALSE;
   char *         szChangeLogID  = NULL, * szLastEntry = NULL;
   int            iResult        = 0, i;
   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 ] )
                     szFile = NULL;
                  else
                     fQuiet = TRUE;
                  break;

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

               case 'c':
               case 'C':
                  fChgLog = 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, FALSE );
                  else
                     szFile = NULL;
                  break;

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

               case 'x':
               case 'X':
                  if( argv[ i ][ 2 ] )
                     szWordFile = argv[ i ] + 2;
                  else
                     szWordFile = NULL;
                  break;

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

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

   if( szFile )
   {
      hb_pp_init( pState, fQuiet, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
      if( hb_pp_inFile( pState, szFile, TRUE, NULL, TRUE ) )
      {
         char * szSVNID = ( char * ) hb_xgrab( 10 );
         char * szSVNDateID = ( char * ) hb_xgrab( 10 );
         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, fQuiet,
                                            szSVNID, szSVNDateID, &szChangeLogID, &szLastEntry );

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

         if( iResult == 0 && szVerFile )
            iResult = hb_pp_generateVerInfo( szVerFile, szSVNID, szSVNDateID,
                                             szChangeLogID, szLastEntry );

         hb_xfree( szSVNID );
         hb_xfree( szSVNDateID );
      }
      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;
}
示例#3
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;
}