Files
harbour-core/harbour/examples/pp/hbpragma.c
Viktor Szakats 45a114e471 2010-06-03 18:17 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* tests/testsha1.prg
  * tests/longdev.prg
  * tests/clsccast.prg
  * tests/cmphello.prg
  * tests/clsicast.prg
  * tests/testop.prg
  * tests/clsscast.prg
  * tests/objarr.prg
  * tests/rddtest/rddmktst.prg
  * tests/rddtest/adscl52.prg
  * tests/rddtest/adscl53.prg
  * tests/rddtest/ntxcl52.prg
  * tests/rddtest/ntxcl53.prg
  * tests/rddtest/cdxcl52.prg
  * tests/rddtest/rddtst.prg
  * tests/rddtest/cdxcl53.prg
  * tests/transtst.prg
  * tests/output.prg
  * tests/ac_test2.prg
  * tests/clsscope.prg
  * tests/dosshell.prg
  * tests/sbartest.prg
  * tests/speedold.prg
  * tests/sdf_test.prg
  * tests/wcecon.prg
  * tests/debugtst.prg
  * tests/testdyn.c
  * tests/multiarg.prg
  * tests/fornext.prg
  * tests/hbinline.prg
  * tests/foreach2.prg
  * tests/objasign.prg
  * tests/scroll.prg
  * tests/inherit.prg
  * tests/rto_get.prg
  * tests/boxtst2.prg
  * tests/inkeytst.prg
  * tests/overload.prg
  * tests/cpinfo.prg
  * tests/gtwin.prg
  * tests/mt/mttest08.prg
  * tests/mt/mttest09.prg
  * tests/mt/mttest01.prg
  * tests/mt/mttest10.prg
  * tests/mt/mttest02.prg
  * tests/mt/mttest11.prg
  * tests/mt/mttest03.prg
  * tests/mt/mttest12.prg
  * tests/mt/mttest04.prg
  * tests/mt/mttest05.prg
  * tests/mt/mttest06.prg
  * tests/mt/mttest07.prg
  * tests/speedtst.prg
  * tests/testsha2.prg
  * tests/hsxtest.prg
  * tests/arrayidx.prg
  * tests/clsnv.prg
  * tests/rto_tb.prg
  * tests/gtchars.prg
  * tests/disptest.prg
  * tests/funcarr.prg
  * tests/testhtml.prg
  * tests/readhrb.prg
  * tests/tstcolor.prg
  * tests/gtxfnt.prg
  * tests/devtest.prg
  * tests/aliaslck.prg
  * tests/stripem.prg
  * tests/dynobj.prg
  * tests/tb1.prg
  * tests/round.prg
  * tests/longstr.prg
  * tests/testdyn.prg
  * tests/testdyn1.prg
  * tests/delimtst.prg
  * tests/tstdspac.prg
  * tests/version.prg
  * tests/setkeys.prg
  * tests/gtcolors.prg
  * tests/destruct.prg
  * tests/seconds.prg
  * tests/gtkeys.prg
  * tests/usrrdd/exarr.prg
  * doc/en/diskspac.txt
  * doc/en/string.txt
  * doc/en/rdd.txt
  * doc/en/hashes.txt
  * doc/en/hb_apigt.txt
  * doc/en/rddord.txt
  * doc/en/hb_api.txt
  * doc/en/hb_date.txt
  * doc/en/math.txt
  * doc/en/hb_vm.txt
  * doc/en/treport.txt
  * doc/en/terminal.txt
  * doc/en/hb_apiln.txt
  * doc/en/dir.txt
  * doc/en/command.txt
  * doc/en/rddmisc.txt
  * doc/en/errsys.txt
  * doc/en/nation.txt
  * doc/en/var.txt
  * doc/en/dbstrux.txt
  * doc/en/datetime.txt
  * doc/en/memo.txt
  * doc/en/tgetlist.txt
  * doc/en/tlabel.txt
  * doc/en/1stread.txt
  * doc/en/hb_set.txt
  * doc/en/hb_compa.txt
  * doc/en/hb_apier.txt
  * doc/en/hbinet.txt
  * doc/en/hb_macro.txt
  * doc/en/array.txt
  * doc/en/hb_apiit.txt
  * doc/en/rdddb.txt
  * doc/en/dbsdf.txt
  * doc/en/hvm.txt
  * doc/en/input.txt
  * doc/en/dbdelim.txt
  * doc/en/browse.txt
  * doc/en/menu.txt
  * doc/en/hb_apird.txt
  * doc/en/hb_apifs.txt
  * doc/en/file.txt
  * doc/en/lang.txt
  * doc/en/objfunc.txt
  * doc/en/eval.txt
  * doc/en/binnum.txt
  * doc/en/tclass.txt
  * doc/en/misc.txt
  * doc/en/set.txt
  * doc/en/readme.txt
  * doc/man/harbour.1
  * doc/man/hbmk2.1
  * doc/man/hbpp.1
  * doc/man/hbtest.1
  * doc/man/hbrun.1
  * examples/hbextern/hbextern.prg
  * examples/pp/pp.c
  * examples/pp/hbpragma.c
  * examples/pp/hbppcore.c
  * examples/pp/hbppcomp.c
  * examples/pp/hbpptbl.c
  * examples/pp/hbppdef.h
  * examples/superlib/hbsuper.prg
  * examples/hbsqlit2/hbsqlit2.ch
  * examples/misc/mankala.prg
  * examples/misc/guess.prg
  * examples/rddado/adordd.prg
  * examples/rddado/adordd.ch
  * examples/hbapollo/apollo.ch
  * examples/hbapollo/apollo.c
  * examples/hbapollo/apollo1.prg
  * examples/hbdoc2/gentpl.prg
  * examples/hbdoc2/gentxt.prg
  * examples/hbdoc2/tmplates.prg
  * examples/hbdoc2/genxml.prg
  * examples/hbdoc2/genhtml.prg
  * examples/hbdoc2/hbdoc2.prg
  * examples/hbdoc2/hbdoc2.ch
  * examples/guestbk/guestbk.prg
  * examples/httpsrv/uhttpd.ini
  * examples/httpsrv/uhttpd.prg
  * examples/httpsrv/cookie.prg
  * examples/httpsrv/cgifunc.prg
  * examples/httpsrv/session.prg
  * examples/terminal/trm_cli.prg
  * examples/terminal/terminal.prg
  * examples/terminal/trm_srv.prg
  * examples/terminal/trm_app.prg
  * examples/hbbtree/hb_btree.h
  * examples/hbbtree/hb_btree.ch
  * examples/hbbtree/hb_btree.c
  * examples/hbbtree/tbtree.prg
  * examples/hscript/hscript.prg
  * examples/hscript/dir.hs
  * examples/hscript/multiply.hs
  * examples/hscript/ugly.hs
  * examples/hscript/hello.hs
  * examples/gtwvw/hbole.h
  * examples/gtwvw/wvwdraw.c
  * examples/gtwvw/wvwmenu.c
  * examples/gtwvw/gtwvw.c
  * examples/gtwvw/wvwstbar.c
  * examples/gtwvw/wvwcheck.c
  * examples/gtwvw/wvwfuncs.c
  * examples/gtwvw/wvwpush.c
  * examples/gtwvw/wvwedit.c
  * examples/gtwvw/wvwtbar.c
  * examples/gtwvw/hbgtwvw.h
    * Deleted 'www.' from harbour-project.org website name.
      (www.harbour-project.org -> harbour-project.org)
2010-06-03 16:23:36 +00:00

425 lines
13 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* Support for #pragma directive and related functions
*
* Copyright 2000 Jose Lalin <dezac@corevia.com>
* www - http://harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/*
* See doc/pragma.txt to learn more about Harbour pragmas.
*/
#include "hbppdef.h"
#include "hbcomp.h"
static HB_BOOL StringToBool( char *, HB_BOOL );
static int StringToInt( char *, int );
static HB_BOOL IsOnOffSwitch( char *, HB_BOOL );
static void DebugPragma( char *, int, HB_BOOL );
static HB_BOOL s_bTracePragma = HB_FALSE;
/* Size of abreviated pragma commands */
#define PRAGMAS_LEN 8
/* TODO: Add support for:
RequestLib /R
*/
static PINLINE hb_compInlineAdd_( char * szFunName )
{
HB_SYMBOL_UNUSED( szFunName );
return NULL;
}
HB_BOOL hb_pp_ParsePragma( char * szLine )
{
HB_BOOL bIgnore = HB_TRUE;
HB_TRACE(HB_TR_DEBUG, ("hb_pp_ParsePragma(%s)", szLine));
HB_SKIPTABSPACES( szLine );
if( HB_ISOPTSEP( szLine[ 0 ] ) )
{
switch( szLine[ 1 ] )
{
case 'a':
case 'A':
hb_comp_bAutoMemvarAssume = IsOnOffSwitch( szLine, hb_comp_bAutoMemvarAssume );
DebugPragma( szLine, -1, hb_comp_bAutoMemvarAssume );
break;
case 'b':
case 'B':
hb_comp_bDebugInfo = IsOnOffSwitch( szLine, hb_comp_bDebugInfo );
hb_comp_bLineNumbers = hb_comp_bDebugInfo;
DebugPragma( szLine, -1, hb_comp_bDebugInfo );
break;
case 'e':
case 'E':
if( szLine[ 2 ] == 's' ||
szLine[ 2 ] == 'S' )
{
switch( szLine[ 3 ] )
{
case '\0':
case '0':
hb_comp_iExitLevel = HB_EXITLEVEL_DEFAULT;
break;
case '1':
hb_comp_iExitLevel = HB_EXITLEVEL_SETEXIT;
break;
case '2':
hb_comp_iExitLevel = HB_EXITLEVEL_DELTARGET;
break;
default:
hb_compGenError( NULL, hb_pp_szErrors, 'F', HB_PP_ERR_PRAGMA_BAD_VALUE, NULL, NULL );
}
DebugPragma( szLine, hb_comp_iExitLevel, HB_FALSE );
}
break;
case 'l':
case 'L':
hb_comp_bLineNumbers = IsOnOffSwitch( szLine, hb_comp_bLineNumbers );
DebugPragma( szLine, -1, hb_comp_bLineNumbers );
break;
case 'n':
case 'N':
hb_comp_bStartProc = IsOnOffSwitch( szLine, hb_comp_bStartProc );
DebugPragma( szLine, -1, hb_comp_bStartProc );
break;
case 'p':
case 'P':
hb_comp_bPPO = IsOnOffSwitch( szLine, hb_comp_bPPO );
DebugPragma( szLine, -1, hb_comp_bPPO );
break;
case 'v':
case 'V':
hb_comp_bForceMemvars = IsOnOffSwitch( szLine, hb_comp_bForceMemvars );
DebugPragma( szLine, -1, hb_comp_bForceMemvars );
break;
case 'w':
case 'W':
if( szLine[ 2 ] != '\0' )
{
/* Check for +/- */
if( szLine[ strlen( szLine ) - 1 ] == '+' ||
szLine[ strlen( szLine ) - 1 ] == '-' )
hb_comp_iWarnings = IsOnOffSwitch( szLine, hb_comp_iWarnings != 0 ) ? 1 : 0;
else
{
/* There is -w<0,1,2,3> probably */
hb_comp_iWarnings = szLine[ 2 ] - '0';
if( hb_comp_iWarnings < 0 || hb_comp_iWarnings > 3 )
hb_compGenError( NULL, hb_pp_szErrors, 'F', HB_PP_ERR_PRAGMA_BAD_VALUE, NULL, NULL );
DebugPragma( szLine, -1, hb_comp_iWarnings );
}
}
break;
case 'z':
case 'Z':
hb_comp_bShortCuts = IsOnOffSwitch( szLine, hb_comp_bShortCuts );
DebugPragma( szLine, -1, hb_comp_bShortCuts );
break;
default:
break;
}
}
else
{
if( hb_strnicmp( szLine, "AUTOMEMVAR", PRAGMAS_LEN ) == 0 )
{
hb_comp_bAutoMemvarAssume = StringToBool( szLine, hb_comp_bAutoMemvarAssume );
DebugPragma( szLine, -1, hb_comp_bAutoMemvarAssume );
}
else if( hb_strnicmp( szLine, "BEGINDUMP", PRAGMAS_LEN ) == 0 )
{
char sBuffer[ HB_PP_STR_SIZE ], *pBuffer, sDirective[9] ;
int iSize;
PINLINE pInline;
if( hb_comp_bPPO )
{
hb_pp_WrStr( hb_comp_yyppo, "#pragma BEGINDUMP" );
}
hb_pp_StreamBlock = HB_PP_STREAM_DUMP_C;
pInline = hb_compInlineAdd_( NULL );
DigestInline :
iSize = hb_pp_Internal_( hb_comp_bPPO ? hb_comp_yyppo : NULL, sBuffer );
if( iSize == 0 )
{
hb_pp_StreamBlock = 0;
return bIgnore;
}
pBuffer = (char*) sBuffer;
while( *pBuffer == ' ' || *pBuffer == '\t' )
{
pBuffer++;
}
if( *pBuffer == '#' )
{
pBuffer++;
while( *pBuffer == ' ' || *pBuffer == '\t' )
{
pBuffer++;
}
hb_strncpyUpper( sDirective, pBuffer, 6 );
if( memcmp( sDirective, "PRAGMA", 6 ) == 0 )
{
pBuffer += 6;
}
while( *pBuffer == ' ' || *pBuffer == '\t' )
{
pBuffer++;
}
hb_strncpyUpper( sDirective, pBuffer, 7 );
if( memcmp( sDirective, "ENDDUMP", 7 ) == 0 )
{
hb_pp_StreamBlock = 0;
return bIgnore;
}
}
iSize = strlen( (char*) sBuffer );
if( pInline->pCode == NULL )
{
pInline->pCode = (BYTE *) hb_xgrab( iSize + 1 );
}
else
{
pInline->pCode = (BYTE *) hb_xrealloc( pInline->pCode, pInline->lPCodeSize + iSize + 1 );
}
memcpy( pInline->pCode + pInline->lPCodeSize, sBuffer, iSize + 1 );
pInline->lPCodeSize += iSize;
goto DigestInline;
}
else if( hb_strnicmp( szLine, "DEBUGINFO", PRAGMAS_LEN ) == 0 )
{
hb_comp_bDebugInfo = StringToBool( szLine, hb_comp_bDebugInfo );
hb_comp_bLineNumbers = hb_comp_bDebugInfo;
DebugPragma( szLine, -1, hb_comp_bDebugInfo );
}
else if( hb_strnicmp( szLine, "ENABLEWARNINGS", PRAGMAS_LEN ) == 0 )
{
hb_comp_iWarnings = StringToBool( szLine, hb_comp_iWarnings != 0 ) ? 1 : 0;
DebugPragma( szLine, hb_comp_iWarnings, HB_FALSE );
}
else if( hb_strnicmp( szLine, "EXITSEVERITY", PRAGMAS_LEN ) == 0 )
{
hb_comp_iExitLevel = StringToInt( szLine, hb_comp_iExitLevel );
if( hb_comp_iExitLevel != HB_EXITLEVEL_DEFAULT &&
hb_comp_iExitLevel != HB_EXITLEVEL_SETEXIT &&
hb_comp_iExitLevel != HB_EXITLEVEL_DELTARGET )
hb_compGenError( NULL, hb_pp_szErrors, 'F', HB_PP_ERR_PRAGMA_BAD_VALUE, NULL, NULL );
DebugPragma( szLine, hb_comp_iExitLevel, HB_FALSE );
}
else if( hb_strnicmp( szLine, "DYNAMICMEMVAR", PRAGMAS_LEN ) == 0 )
{
hb_comp_bForceMemvars = StringToBool( szLine, hb_comp_bForceMemvars );
DebugPragma( szLine, -1, hb_comp_bForceMemvars );
}
else if( hb_strnicmp( szLine, "LINENUMBER", PRAGMAS_LEN ) == 0 )
{
hb_comp_bLineNumbers = StringToBool( szLine, hb_comp_bLineNumbers );
DebugPragma( szLine, -1, hb_comp_bLineNumbers );
}
else if( hb_strnicmp( szLine, "NOSTARTPROC", PRAGMAS_LEN ) == 0 )
{
hb_comp_bStartProc = StringToBool( szLine, hb_comp_bStartProc );
DebugPragma( szLine, -1, hb_comp_bStartProc );
}
else if( hb_strnicmp( szLine, "PREPROCESSING", PRAGMAS_LEN ) == 0 )
{
hb_comp_bPPO = StringToBool( szLine, hb_comp_bPPO );
DebugPragma( szLine, -1, hb_comp_bPPO );
}
else if( hb_strnicmp( szLine, "SHORTCUT", PRAGMAS_LEN ) == 0 )
{
hb_comp_bShortCuts = StringToBool( szLine, hb_comp_bShortCuts );
DebugPragma( szLine, -1, hb_comp_bShortCuts );
}
else if( hb_strnicmp( szLine, "WARNINGLEVEL", PRAGMAS_LEN ) == 0 )
{
hb_comp_iWarnings = StringToInt( szLine, hb_comp_iWarnings );
if( hb_comp_iWarnings < 0 || hb_comp_iWarnings > 3 )
hb_compGenError( NULL, hb_pp_szErrors, 'F', HB_PP_ERR_PRAGMA_BAD_VALUE, NULL, NULL );
DebugPragma( szLine, hb_comp_iWarnings, HB_FALSE );
}
else if( hb_strnicmp( szLine, "TRACEPRAGMAS", PRAGMAS_LEN ) == 0 )
{
s_bTracePragma = StringToBool( szLine, s_bTracePragma );
DebugPragma( szLine, -1, s_bTracePragma );
}
else if( hb_strnicmp( szLine, "__text", 6 ) == 0 )
{
bIgnore = hb_pp_StreamBlockBegin( szLine, HB_PP_STREAM_CLIPPER );
DebugPragma( szLine, -1, s_bTracePragma );
}
else if( hb_strnicmp( szLine, "__stream", 8 ) == 0 )
{
bIgnore = hb_pp_StreamBlockBegin( szLine, HB_PP_STREAM_PRG );
DebugPragma( szLine, -1, s_bTracePragma );
}
else if( hb_strnicmp( szLine, "__cstream", 8 ) == 0 )
{
bIgnore = hb_pp_StreamBlockBegin( szLine, HB_PP_STREAM_C );
DebugPragma( szLine, -1, s_bTracePragma );
}
else if( hb_strnicmp( szLine, "__endtext", 9 ) == 0 )
{
hb_pp_BlockEnd( );
DebugPragma( szLine, -1, s_bTracePragma );
}
else if( hb_strnicmp( szLine, "RECURSELEVEL", PRAGMAS_LEN ) == 0 )
{
int iOverflow;
int iMax;
iMax = ( int ) hb_strValInt( szLine, &iOverflow );
if( iOverflow || iMax < 1 )
hb_pp_MaxTranslateCycles = 1024;
else
hb_pp_MaxTranslateCycles = ( unsigned int ) iMax;
DebugPragma( szLine, hb_pp_MaxTranslateCycles, HB_FALSE );
}
}
return bIgnore;
}
/* Checks for +/- within the string, sets bDefault if not found */
static HB_BOOL IsOnOffSwitch( char * pszStr, HB_BOOL bValue )
{
int iPos = strlen( pszStr ) - 1;
if( pszStr[ iPos ] == '+' )
bValue = HB_TRUE;
else if( pszStr[ iPos ] == '-' )
bValue = HB_FALSE;
return bValue;
}
/* Checks for ON/OFF within the string, sets bDefault if not found */
static HB_BOOL StringToBool( char * pszStr, HB_BOOL bValue )
{
char * pos = strchr( pszStr, '=' );
if( ! pos )
pos = strchr( pszStr, '(' );
if( pos )
{
pos++;
HB_SKIPTABSPACES( pos );
if( hb_strnicmp( pos, "ON", 2 ) == 0 )
bValue = HB_TRUE;
else if( hb_strnicmp( pos, "OFF", 3 ) == 0 )
bValue = HB_FALSE;
}
return bValue;
}
/* Returns value after =, sets iDefault if not found */
static int StringToInt( char * pszStr, int iValue )
{
char * pos = strchr( pszStr, '=' );
if( ! pos )
pos = strchr( pszStr, '(' );
if( pos )
{
pos++;
HB_SKIPTABSPACES( pos );
if( *pos >= '0' && *pos <= '9' )
iValue = *pos - '0';
}
return iValue;
}
/* This is only to debug pragmas now */
static void DebugPragma( char * pszStr, int iValue, HB_BOOL bValue )
{
if( s_bTracePragma )
{
if( iValue >= 0 )
printf( "#pragma set to %i \'%s\'\n", iValue, pszStr );
else
printf( "#pragma set to %s \'%s\'\n", bValue ? "ON" : "OFF", pszStr );
}
}