Exemple #1
0
static void hb_pp_generateRules( FILE * fout, PHB_PP_STATE pState, const char * szPPRuleFuncName )
{
   int iDefs = 0, iTrans = 0, iCmds = 0;

   fprintf( fout, "/*\n * $" "Id" "$\n */\n\n/*\n"
            " * Harbour Project source code:\n"
            " *    Build in preprocessor rules.\n"
            " *\n"
            " * Copyright 2006-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#define _HB_PP_INTERNAL\n#include \"hbpp.h\"\n\n" );

   if( pState->pDefinitions )
      iDefs = hb_pp_writeRules( fout, pState->pDefinitions, "def" );
   if( pState->pTranslations )
      iTrans = hb_pp_writeRules( fout, pState->pTranslations, "trs" );
   if( pState->pCommands )
      iCmds = hb_pp_writeRules( fout, pState->pCommands, "cmd" );

   fprintf( fout, "\nvoid %s( PHB_PP_STATE pState )\n{\n", szPPRuleFuncName ? szPPRuleFuncName : "hb_pp_setStdRules" );
   hb_pp_generateInitFunc( fout, iDefs,  "Definitions",  "def" );
   hb_pp_generateInitFunc( fout, iTrans, "Translations", "trs" );
   hb_pp_generateInitFunc( fout, iCmds,  "Commands",     "cmd" );
   fprintf( fout, "}\n" );
}
Exemple #2
0
static void hb_pp_generateRules( FILE * fout, FILE * fword, PHB_PP_STATE pState )
{
   PRESERVEDNAME pTemp;
   int  iDefs = 0, iTrans = 0, iCmds = 0;
   UINT wNum = 0;

   fprintf( fout, "/*\n * $Id: ppgen.c 9869 2012-12-08 18:25:43Z andijahja $\n */\n\n/*\n"
            " * Harbour Project source code:\n"
            " *    Build in preprocessor rules.\n"
            " *\n"
            " * Copyright 2006 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#define _HB_PP_INTERNAL\n#include \"hbpp.h\"\n\n" );

   fprintf( fword, "/*\n * $Id: ppgen.c 9869 2012-12-08 18:25:43Z andijahja $\n */\n\n/*\n"
            " * Harbour Project source code:\n"
            " *    Word list which should not be used as variable names.\n"
            " *\n"
            " * Copyright 2012 Andi Jahja <*****@*****.**>\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#include \"hbapi.h\"\n"
            "#include \"hbcomp.h\"\n"
            "\nstatic const char * s_szReservedName[] = {\n" );

   if( pState->pDefinitions )
      iDefs = hb_pp_writeRules( fout, pState->pDefinitions, "def" );
   if( pState->pTranslations )
      iTrans = hb_pp_writeRules( fout, pState->pTranslations, "trs" );
   if( pState->pCommands )
      iCmds = hb_pp_writeRules( fout, pState->pCommands, "cmd" );

   fprintf( fout, "\nvoid hb_pp_setStdRules( PHB_PP_STATE pState )\n{\n" );
   hb_pp_generateInitFunc( fout, iDefs, "Definitions", "def" );
   hb_pp_generateInitFunc( fout, iTrans, "Translations", "trs" );
   hb_pp_generateInitFunc( fout, iCmds, "Commands", "cmd" );
   fprintf( fout, "}\n" );

   do
   {
      if ( ! hb_pp_NameFound( ( char * ) s_otherReservedName[ wNum ] ) )
         fprintf( fword, "   \"%s\",\n", ( char* ) s_otherReservedName[ wNum ] );

      ++ wNum;
   } while( wNum < sizeof( s_otherReservedName ) / sizeof( char * ) );

   pTemp = s_PPReservedName;

   do
   {
      fprintf( fword, "   \"%s\"", pTemp->szName );
      hb_xfree( pTemp->szName );
      pTemp = pTemp->pNext;
      hb_xfree( ( void * ) s_PPReservedName );
      s_PPReservedName = pTemp;
      fprintf( fword, s_PPReservedName ? ",\n" : "\n" );
   } while( pTemp );

   fprintf( fword, "};\n\n"
            "#define RESERVED_NAMES sizeof( s_szReservedName ) / sizeof( char * )\n\n"
            "BOOL hb_compReservedPPName( char * szName )\n"
            "{\n"
            "   UINT  wNum   = 0;\n"
            "   int   iFound = 1;\n"
            "   int   iLen   = ( int ) strlen( szName );\n\n"
            "   while( wNum < RESERVED_NAMES && iFound )\n"
            "   {\n"
            "      int u = ( int ) strlen( s_szReservedName[ wNum ] ) ;\n\n"
            "      if ( iLen == u )\n"
            "      {\n"
            "         int i, j = 0;\n\n"
            "         for ( i = 0; i < u; i ++ )\n"
            "         {\n"
            "            if ( szName[ i ] == s_szReservedName[ wNum ] [ i ] )\n"
            "               j ++;\n"
            "            else\n"
            "               break;\n"
            "         }\n\n"
            "         if ( j == u )\n"
            "            iFound = 0;\n"
            "      }\n\n"
            "      ++wNum;\n"
            "   }\n\n"
            "   return ( iFound == 0 );\n"
            "}\n" );
}