2011-01-27 20:54 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)

* contrib/hbnetio/utils/hbnetio/netiosrv.prg
  * contrib/hbnetio/utils/hbnetio/netiocon.prg
  * contrib/hbnetio/utils/hbnetio/netiocmd.prg
    * Minor cleanups.

  * examples/pp/pp.c
  * examples/pp/hbpragma.c
  * examples/pp/hbppcore.c
  * examples/pp/hbppcomp.c
  * examples/pp/hbppdef.h
    * Reformatted with uncrustify. Still an amazing tool.
This commit is contained in:
Viktor Szakats
2011-01-27 19:54:35 +00:00
parent 6ad722ca12
commit 7a46f701c1
9 changed files with 1623 additions and 1605 deletions

View File

@@ -16,6 +16,19 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-01-27 20:54 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* contrib/hbnetio/utils/hbnetio/netiosrv.prg
* contrib/hbnetio/utils/hbnetio/netiocon.prg
* contrib/hbnetio/utils/hbnetio/netiocmd.prg
* Minor cleanups.
* examples/pp/pp.c
* examples/pp/hbpragma.c
* examples/pp/hbppcore.c
* examples/pp/hbppcomp.c
* examples/pp/hbppdef.h
* Reformatted with uncrustify. Still an amazing tool.
2011-01-27 20:46 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/examples/pp/hbppdef.h
* harbour/examples/pp/hbpragma.c

View File

@@ -36,11 +36,6 @@ PROCEDURE Main( ... )
LOCAL nPort := _NETIOMGM_PORT_DEF
LOCAL cPassword := ""
SET DATE ANSI
SET CENTURY ON
SET CONFIRM ON
SET SCOREBOARD OFF
HB_Logo()
FOR EACH cParam IN { ... }

View File

@@ -38,6 +38,13 @@ PROCEDURE hbnetiocon_cmdUI( cIP, nPort, cPassword )
LOCAL pConnection
SET DATE ANSI
SET CENTURY ON
SET CONFIRM ON
SET SCOREBOARD OFF
SetCancel( .F. )
IF ! Empty( cPassword )
pConnection := ConnectLow( cIP, nPort, cPassword )
QQOut( hb_eol() )

View File

@@ -170,8 +170,6 @@ PROCEDURE Main( ... )
ENDCASE
NEXT
SetCancel( .F. )
netiosrv[ _NETIOSRV_pListenSocket ] := ;
netio_mtserver( netiosrv[ _NETIOSRV_nPort ],;
netiosrv[ _NETIOSRV_cIFAddr ],;
@@ -188,8 +186,10 @@ PROCEDURE Main( ... )
IF Empty( netiosrv[ _NETIOSRV_pListenSocket ] )
OutStd( "Cannot start server." + hb_eol() )
ELSE
OutStd( "Ready to accept connections.", hb_eol() )
IF ! Empty( cPasswordManagement )
netiomgm[ _NETIOSRV_pListenSocket ] := ;
netio_mtserver( netiomgm[ _NETIOSRV_nPort ],;
netiomgm[ _NETIOSRV_cIFAddr ],;
@@ -223,9 +223,11 @@ PROCEDURE Main( ... )
ShowConfig( netiosrv, netiomgm )
hb_idleSleep( 2 )
netiomgm[ _NETIOSRV_lShowConn ] := .T.
/* Wait until embedded management console connects */
IF ! Empty( netiomgm[ _NETIOSRV_pListenSocket ] )
hb_idleSleep( 2 )
netiomgm[ _NETIOSRV_lShowConn ] := .T.
ENDIF
/* Command prompt */
DO WHILE ! netiosrv[ _NETIOSRV_lQuit ]

View File

@@ -53,8 +53,8 @@
/*
* Avoid tracing in preprocessor/compiler.
*/
#if ! defined(HB_TRACE_UTILS)
#if defined(HB_TRACE_LEVEL)
#if ! defined( HB_TRACE_UTILS )
#if defined( HB_TRACE_LEVEL )
#undef HB_TRACE_LEVEL
#endif
#endif
@@ -67,29 +67,29 @@
#include "hbcomp.h"
static void pp_ParseBuffer( PFILE, int * );
static char *pp_TextCommand( char * ptr, int *pLen );
static char * pp_TextCommand( char * ptr, int * pLen );
static void pp_TextBlockFinish( void );
static void pp_StreamBlockFinish( void );
#if !defined(HB_PP_DEBUG_MEMORY)
static char s_szLine[ HB_PP_STR_SIZE ];
static char s_szOutLine[ HB_PP_STR_SIZE ];
#if ! defined( HB_PP_DEBUG_MEMORY )
static char s_szLine[ HB_PP_STR_SIZE ];
static char s_szOutLine[ HB_PP_STR_SIZE ];
#else
static char *s_szLine = NULL;
static char *s_szOutLine = NULL;
static char * s_szLine = NULL;
static char * s_szOutLine = NULL;
#endif
int hb_pp_LastOutLine = 1;
static char *s_TextOutFunc = NULL;
static char *s_TextEndFunc = NULL;
static char *s_TextStartFunc = NULL;
int hb_pp_LastOutLine = 1;
static char * s_TextOutFunc = NULL;
static char * s_TextEndFunc = NULL;
static char * s_TextStartFunc = NULL;
/*
HB_BOOL bDebug = HB_FALSE;
*/
HB_BOOL bDebug = HB_FALSE;
*/
void hb_pp_InternalFree( void )
{
#if defined(HB_PP_DEBUG_MEMORY)
#if defined( HB_PP_DEBUG_MEMORY )
if( s_szLine )
{
hb_xfree( s_szLine );
@@ -120,217 +120,220 @@ void hb_pp_InternalFree( void )
int hb_pp_Internal_( FILE * handl_o, char * sOut )
{
PFILE pFile;
char * ptr, * ptrOut, * tmpPtr;
int lContinue;
int rdlen;
ULONG lens;
int lLine = 0;
PFILE pFile;
char * ptr, * ptrOut, * tmpPtr;
int lContinue;
int rdlen;
ULONG lens;
int lLine = 0;
HB_TRACE(HB_TR_DEBUG, ("hb_pp_Internal_(%p, %s)", handl_o, sOut));
HB_TRACE( HB_TR_DEBUG, ( "hb_pp_Internal_(%p, %s)", handl_o, sOut ) );
#if defined(HB_PP_DEBUG_MEMORY)
if( ! s_szLine )
s_szLine = (char *) hb_xgrab( HB_PP_STR_SIZE );
if( ! s_szOutLine )
s_szOutLine = (char *) hb_xgrab( HB_PP_STR_SIZE );
#if defined( HB_PP_DEBUG_MEMORY )
if( ! s_szLine )
s_szLine = ( char * ) hb_xgrab( HB_PP_STR_SIZE );
if( ! s_szOutLine )
s_szOutLine = ( char * ) hb_xgrab( HB_PP_STR_SIZE );
#endif
hb_pp_NestedLiteralString = HB_FALSE;
hb_pp_LiteralEscSeq = HB_FALSE;
for( ;; )
{
pFile = hb_comp_files.pLast;
lens = 0;
lContinue = 0;
ptrOut = sOut;
while( ( rdlen = hb_pp_RdStr( pFile->handle, s_szLine + lens, HB_PP_STR_SIZE -
lens, lContinue, ( char * ) pFile->pBuffer, &( pFile->lenBuffer ),
&( pFile->iBuffer ) ) ) >= 0 )
{
lens += rdlen;
hb_comp_iLine ++;
if( lens >= HB_PP_STR_SIZE-2 )
hb_pp_NestedLiteralString = HB_FALSE;
hb_pp_LiteralEscSeq = HB_FALSE;
for(;; )
{
pFile = hb_comp_files.pLast;
lens = 0;
lContinue = 0;
ptrOut = sOut;
while( ( rdlen = hb_pp_RdStr( pFile->handle, s_szLine + lens, HB_PP_STR_SIZE -
lens, lContinue, ( char * ) pFile->pBuffer, &( pFile->lenBuffer ),
&( pFile->iBuffer ) ) ) >= 0 )
{
hb_compGenError( NULL, hb_pp_szErrors, 'F', HB_PP_ERR_BUFFER_OVERFLOW, NULL, NULL );
}
lens += rdlen;
hb_comp_iLine++;
if( hb_pp_StreamBlock )
{
if( hb_pp_StreamBlock == HB_PP_STREAM_DUMP_C )
break;
else if( hb_pp_StreamBlock == HB_PP_STREAM_CLIPPER )
{
/* Clipper compatible TEXT/ENDTEXT handling */
ptr = s_szLine;
HB_SKIPTABSPACES( ptr );
if( hb_stricmp( ptr, "ENDTEXT" ) == 0 ||
hb_stricmp( ptr, "#pragma __endtext" ) == 0 )
{
pp_TextBlockFinish();
if( lens >= HB_PP_STR_SIZE - 2 )
{
hb_compGenError( NULL, hb_pp_szErrors, 'F', HB_PP_ERR_BUFFER_OVERFLOW, NULL, NULL );
}
if( hb_pp_StreamBlock )
{
if( hb_pp_StreamBlock == HB_PP_STREAM_DUMP_C )
break;
else if( hb_pp_StreamBlock == HB_PP_STREAM_CLIPPER )
{
/* Clipper compatible TEXT/ENDTEXT handling */
ptr = s_szLine;
HB_SKIPTABSPACES( ptr );
if( hb_stricmp( ptr, "ENDTEXT" ) == 0 ||
hb_stricmp( ptr, "#pragma __endtext" ) == 0 )
{
pp_TextBlockFinish();
break;
}
if( s_TextOutFunc )
{
memmove( s_szLine + 1, s_szLine, lens++ );
s_szLine[ 0 ] = '[';
s_szLine[ lens++ ] = ']';
s_szLine[ lens ] = '\0';
lens = hb_snprintf( s_szOutLine, HB_PP_STR_SIZE, s_TextOutFunc, s_szLine );
memcpy( s_szLine, s_szOutLine, lens + 1 );
hb_pp_NestedLiteralString = HB_TRUE;
break;
}
else
{
s_szLine[ 0 ] = '\0'; /* discard text */
}
}
else if( hb_pp_StreamBlock == HB_PP_STREAM_PRG )
{
ptr = s_szLine + lens - rdlen;
HB_SKIPTABSPACES( ptr );
if( hb_stricmp( ptr, "ENDTEXT" ) == 0 ||
hb_stricmp( ptr, "#pragma __endtext" ) == 0 )
{
lens -= rdlen;
s_szLine[ lens ] = '\0';
pp_StreamBlockFinish();
break;
}
else
{
lContinue = 1;
continue;
}
}
else if( hb_pp_StreamBlock == HB_PP_STREAM_C )
{
ptr = s_szLine + lens - rdlen;
HB_SKIPTABSPACES( ptr );
if( hb_stricmp( ptr, "ENDTEXT" ) == 0 ||
hb_stricmp( ptr, "#pragma __endtext" ) == 0 )
{
lens -= rdlen;
s_szLine[ lens ] = '\0';
pp_StreamBlockFinish();
hb_pp_LiteralEscSeq = HB_TRUE;
break;
}
else
{
lContinue = 1;
continue;
}
}
}
if( s_szLine[ lens - 1 ] == ';' )
{
lContinue = pFile->lenBuffer ? 1 : 0;
lens--;
lens--;
while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' )
lens--;
s_szLine[ ++lens ] = ' ';
s_szLine[ ++lens ] = '\0';
}
else
{
lContinue = 0;
lens = 0;
}
if( ! lContinue )
{
pp_ParseBuffer( pFile, &lLine );
break;
}
if( s_TextOutFunc )
{
memmove( s_szLine+1, s_szLine, lens++ );
s_szLine[ 0 ] = '[';
s_szLine[ lens++ ] = ']';
s_szLine[ lens ] = '\0';
lens = hb_snprintf( s_szOutLine, HB_PP_STR_SIZE, s_TextOutFunc, s_szLine );
memcpy( s_szLine, s_szOutLine, lens+1 );
hb_pp_NestedLiteralString = HB_TRUE;
break;
}
else
{
s_szLine[ 0 ] = '\0'; /* discard text */
}
}
else if( hb_pp_StreamBlock == HB_PP_STREAM_PRG )
{
ptr = s_szLine + lens - rdlen;
HB_SKIPTABSPACES( ptr );
if( hb_stricmp( ptr, "ENDTEXT" ) == 0 ||
hb_stricmp( ptr, "#pragma __endtext" ) == 0 )
{
lens -= rdlen;
s_szLine[ lens ] = '\0';
pp_StreamBlockFinish( );
break;
}
else
{
lContinue = 1;
continue;
}
}
else if( hb_pp_StreamBlock == HB_PP_STREAM_C )
{
ptr = s_szLine + lens - rdlen;
HB_SKIPTABSPACES( ptr );
if( hb_stricmp( ptr, "ENDTEXT" ) == 0 ||
hb_stricmp( ptr, "#pragma __endtext" ) == 0 )
{
lens -= rdlen;
s_szLine[ lens ] = '\0';
pp_StreamBlockFinish( );
hb_pp_LiteralEscSeq = HB_TRUE;
break;
}
else
{
lContinue = 1;
continue;
}
}
}
}
if( s_szLine[ lens - 1 ] == ';' )
if( rdlen < 0 )
{
lContinue = pFile->lenBuffer ? 1 : 0;
lens--;
lens--;
while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' ) lens--;
s_szLine[ ++lens ] = ' ';
s_szLine[ ++lens ] = '\0';
}
else
{
lContinue = 0;
lens = 0;
if( hb_comp_files.iFiles == 1 )
return 0; /* we have reached the main EOF */
else
{
hb_pp_CloseInclude();
lLine = 1;
}
/* Ron Pinkas added 2000-06-22 */
s_szLine[ 0 ] = '\0';
break;
/* Ron Pinkas end 2000-06-22 */
}
if( !lContinue )
{
pp_ParseBuffer( pFile, &lLine );
break;
}
}
if( *s_szLine )
break;
}
if( rdlen < 0 )
{
if( lLine )
{
if( hb_comp_files.iFiles == 1 )
return 0; /* we have reached the main EOF */
else
hb_pp_LastOutLine = hb_comp_iLine;
hb_snprintf( ptrOut, HB_PP_STR_SIZE, "#line %d \"%s\"", ( hb_comp_files.pLast->iLine ), hb_comp_files.pLast->szFileName );
while( *ptrOut )
ptrOut++;
/* Ron Pinkas added 2000-06-14 */
tmpPtr = s_szLine;
HB_SKIPTABSPACES( tmpPtr );
/* Last Opened file ended without CR - adding CR to the #line directive. */
if( *tmpPtr != '\0' )
{
hb_pp_CloseInclude();
lLine = 1;
*ptrOut++ = '\n';
*ptrOut = '\0';
}
/* Ron Pinkas added 2000-06-22 */
s_szLine[0] = '\0';
break;
/* Ron Pinkas end 2000-06-22 */
}
if( *s_szLine ) break;
}
if( lLine )
{
if( hb_comp_files.iFiles == 1 )
hb_pp_LastOutLine = hb_comp_iLine;
hb_snprintf( ptrOut, HB_PP_STR_SIZE, "#line %d \"%s\"", ( hb_comp_files.pLast->iLine ) , hb_comp_files.pLast->szFileName );
while( *ptrOut ) ptrOut++;
/* Ron Pinkas added 2000-06-14 */
tmpPtr = s_szLine;
HB_SKIPTABSPACES( tmpPtr );
/* Last Opened file ended without CR - adding CR to the #line directive. */
if( *tmpPtr != '\0' )
{
*ptrOut++ = '\n';
*ptrOut = '\0';
}
/* Ron Pinkas end 2000-06-14 */
}
else
{
/* Ron Pinkas added 2000-06-13 */
/* Ignore empty lines in #included files. */
/* Ron Pinkas removed 2001-01-20 */
/* Ron Pinkas end 2000-06-14 */
}
else
{
/* Ron Pinkas added 2000-06-13 */
/* Ignore empty lines in #included files. */
/* Ron Pinkas removed 2001-01-20 */
#if 0
if( ( hb_pp_LastOutLine != hb_comp_iLine ) && hb_comp_files.iFiles == 1 && handl_o )
/* Ron Pinkas end 2000-06-13 */
for( ; hb_pp_LastOutLine < hb_comp_iLine; hb_pp_LastOutLine++ )
if( ( hb_pp_LastOutLine != hb_comp_iLine ) && hb_comp_files.iFiles == 1 && handl_o )
/* Ron Pinkas end 2000-06-13 */
for(; hb_pp_LastOutLine < hb_comp_iLine; hb_pp_LastOutLine++ )
hb_pp_WrStr( handl_o, "\n" );
#endif
/* END Ron Pinkas removed 2001-01-20 */
}
/* END Ron Pinkas removed 2001-01-20 */
}
lens = hb_pp_strocpy( ptrOut, s_szLine ) + ( ptrOut - sOut );
lens = hb_pp_strocpy( ptrOut, s_szLine ) + ( ptrOut - sOut );
*( sOut + lens++ ) = '\n';
*( sOut + lens ) = '\0';
*( sOut + lens++ ) = '\n';
*( sOut + lens ) = '\0';
if( hb_comp_iLineINLINE && hb_pp_StreamBlock == 0 )
{
hb_comp_iLine = hb_comp_iLinePRG + ( hb_comp_iLine - hb_comp_iLineINLINE );
hb_comp_iLine++;
hb_comp_iLineINLINE = 0;
}
if( hb_comp_iLineINLINE && hb_pp_StreamBlock == 0 )
{
hb_comp_iLine = hb_comp_iLinePRG + ( hb_comp_iLine - hb_comp_iLineINLINE );
hb_comp_iLine++;
hb_comp_iLineINLINE = 0;
}
if( handl_o )
{
hb_pp_WrStr( handl_o, sOut );
}
if( handl_o )
{
hb_pp_WrStr( handl_o, sOut );
}
#if 0
printf( "%d : %s\n", hb_comp_iLine, sOut );
printf( "%d : %s\n", hb_comp_iLine, sOut );
#endif
return lens;
return lens;
}
static void pp_ParseBuffer( PFILE pFile, int *plLine )
static void pp_ParseBuffer( PFILE pFile, int * plLine )
{
HB_BOOL bCont = HB_TRUE;
char * ptr;
HB_BOOL bCont = HB_TRUE;
char * ptr;
while( bCont && *s_szLine != '\0' )
{
@@ -353,8 +356,8 @@ static void pp_ParseBuffer( PFILE pFile, int *plLine )
else
*s_szLine = '\0';
hb_snprintf( s_szLine + strlen(s_szLine), HB_PP_STR_SIZE - strlen(s_szLine),
"#line 1 \"%s\"", hb_comp_files.pLast->szFileName );
hb_snprintf( s_szLine + strlen( s_szLine ), HB_PP_STR_SIZE - strlen( s_szLine ),
"#line 1 \"%s\"", hb_comp_files.pLast->szFileName );
bCont = HB_FALSE;
}
else if( bIgnore )
@@ -389,39 +392,39 @@ static void pp_ParseBuffer( PFILE pFile, int *plLine )
}
}
static char *pp_TextCommand( char * ptr, int *pLen )
static char * pp_TextCommand( char * ptr, int * pLen )
{
int i;
char *cCommand = NULL;
int i;
char * cCommand = NULL;
i = 0;
while( ptr[i] && ptr[i] != '|' )
while( ptr[ i ] && ptr[ i ] != '|' )
{
i++;
}
if( i > 0 )
{
cCommand = (char *)hb_xgrab( i+1 );
i = 0;
while( ptr[i] && ptr[i] != '|' )
cCommand = ( char * ) hb_xgrab( i + 1 );
i = 0;
while( ptr[ i ] && ptr[ i ] != '|' )
{
cCommand[ i ] = ptr[ i ];
i++;
}
cCommand[ i ] = '\0';
*pLen -= i+1;
*pLen -= i + 1;
if( *pLen )
memcpy( ptr, ptr+i+1, *pLen );
memcpy( ptr, ptr + i + 1, *pLen );
else
ptr[ 0 ] ='\0';
ptr[ 0 ] = '\0';
}
else if( i == 0 && *ptr == '|' )
{
(*pLen)--;
( *pLen )--;
if( *pLen )
memcpy( ptr, ptr+1, *pLen );
memcpy( ptr, ptr + 1, *pLen );
else
*ptr ='\0';
*ptr = '\0';
}
return cCommand;
@@ -455,73 +458,67 @@ static void pp_TextBlockFinish( void )
HB_BOOL hb_pp_StreamBlockBegin( char * ptr, int iStreamType )
{
HB_BOOL bIgnore = HB_TRUE;
int len;
HB_BOOL bIgnore = HB_TRUE;
int len;
switch( iStreamType )
{
case HB_PP_STREAM_CLIPPER:
{
/* internal handling of TEXT/ENDTEXT command
* #pragma __text|functionOut|functionEnd|functionStart
*/
len = strlen(ptr) - 6;
memcpy( ptr, ptr+7, len );
s_TextOutFunc = pp_TextCommand( ptr, &len );
s_TextEndFunc = pp_TextCommand( ptr, &len );
s_TextStartFunc = pp_TextCommand( ptr, &len );
if( s_TextStartFunc )
{
memcpy( ptr, s_TextStartFunc, strlen(s_TextStartFunc)+1 );
bIgnore = HB_FALSE;
}
hb_pp_StreamBlock = iStreamType;
break;
}
switch( iStreamType )
{
case HB_PP_STREAM_CLIPPER:
/* internal handling of TEXT/ENDTEXT command
* #pragma __text|functionOut|functionEnd|functionStart
*/
len = strlen( ptr ) - 6;
memcpy( ptr, ptr + 7, len );
s_TextOutFunc = pp_TextCommand( ptr, &len );
s_TextEndFunc = pp_TextCommand( ptr, &len );
s_TextStartFunc = pp_TextCommand( ptr, &len );
if( s_TextStartFunc )
{
memcpy( ptr, s_TextStartFunc, strlen( s_TextStartFunc ) + 1 );
bIgnore = HB_FALSE;
}
hb_pp_StreamBlock = iStreamType;
break;
case HB_PP_STREAM_PRG:
{
/* internal handling of TEXT/ENDTEXT command
* #pragma __stream|functionOut|functionEnd|functionStart
* (lines are joined with CR/LF or LF)
*/
len = strlen(ptr) - 8;
memcpy( ptr, ptr+9, len );
s_TextOutFunc = pp_TextCommand( ptr, &len );
s_TextEndFunc = pp_TextCommand( ptr, &len );
s_TextStartFunc = pp_TextCommand( ptr, &len );
*ptr ='\0';
hb_pp_StreamBlock = iStreamType;
break;
}
case HB_PP_STREAM_PRG:
/* internal handling of TEXT/ENDTEXT command
* #pragma __stream|functionOut|functionEnd|functionStart
* (lines are joined with CR/LF or LF)
*/
len = strlen( ptr ) - 8;
memcpy( ptr, ptr + 9, len );
s_TextOutFunc = pp_TextCommand( ptr, &len );
s_TextEndFunc = pp_TextCommand( ptr, &len );
s_TextStartFunc = pp_TextCommand( ptr, &len );
*ptr = '\0';
hb_pp_StreamBlock = iStreamType;
break;
case HB_PP_STREAM_C:
{
/* internal handling of TEXT/ENDTEXT command
* #pragma __cstream|functionOut|functionEnd|functionStart
* (lines are joined and C esc sequences are converted)
*/
len = strlen(ptr) - 9;
memcpy( ptr, ptr+10, len );
s_TextOutFunc = pp_TextCommand( ptr, &len );
s_TextEndFunc = pp_TextCommand( ptr, &len );
s_TextStartFunc = pp_TextCommand( ptr, &len );
*ptr ='\0';
hb_pp_StreamBlock = iStreamType;
break;
}
case HB_PP_STREAM_C:
/* internal handling of TEXT/ENDTEXT command
* #pragma __cstream|functionOut|functionEnd|functionStart
* (lines are joined and C esc sequences are converted)
*/
len = strlen( ptr ) - 9;
memcpy( ptr, ptr + 10, len );
s_TextOutFunc = pp_TextCommand( ptr, &len );
s_TextEndFunc = pp_TextCommand( ptr, &len );
s_TextStartFunc = pp_TextCommand( ptr, &len );
*ptr = '\0';
hb_pp_StreamBlock = iStreamType;
break;
default:
break;
}
return bIgnore;
default:
break;
}
return bIgnore;
}
static void pp_StreamBlockFinish( void )
{
hb_pp_StreamBlock = 0;
hb_pp_StreamBlock = 0;
hb_snprintf( s_szOutLine, HB_PP_STR_SIZE, s_TextOutFunc, s_szLine );
s_szLine[ 0 ] = '\0';
s_szLine[ 0 ] = '\0';
if( s_TextStartFunc )
{
hb_strncat( s_szLine, s_TextStartFunc, sizeof( s_szLine ) - 1 );
@@ -545,7 +542,7 @@ static void pp_StreamBlockFinish( void )
hb_pp_NestedLiteralString = HB_TRUE;
}
void hb_pp_BlockEnd( )
void hb_pp_BlockEnd()
{
if( hb_pp_StreamBlock == HB_PP_STREAM_CLIPPER )
pp_TextBlockFinish();
@@ -556,78 +553,79 @@ void hb_pp_BlockEnd( )
int hb_pp_ReadRules( void )
{
PFILE pFile;
char * ptr;
int lContinue;
int lens, rdlen;
PFILE pFile;
char * ptr;
int lContinue;
int lens, rdlen;
HB_TRACE(HB_TR_DEBUG, ("hb_pp_ReadRules()"));
#if defined(HB_PP_DEBUG_MEMORY)
HB_TRACE( HB_TR_DEBUG, ( "hb_pp_ReadRules()" ) );
#if defined( HB_PP_DEBUG_MEMORY )
if( ! s_szLine )
s_szLine = (char *) hb_xgrab( HB_PP_STR_SIZE );
s_szLine = ( char * ) hb_xgrab( HB_PP_STR_SIZE );
if( ! s_szOutLine )
s_szOutLine = (char *) hb_xgrab( HB_PP_STR_SIZE );
s_szOutLine = ( char * ) hb_xgrab( HB_PP_STR_SIZE );
#endif
for( ;; )
{
pFile = hb_comp_files.pLast;
lens = lContinue = 0;
while( ( rdlen = hb_pp_RdStr( pFile->handle, s_szLine + lens, HB_PP_STR_SIZE -
lens, lContinue, ( char * ) pFile->pBuffer, &( pFile->lenBuffer ),
&( pFile->iBuffer ) ) ) >= 0 )
{
lens += rdlen;
hb_comp_iLine++;
for(;; )
{
pFile = hb_comp_files.pLast;
lens = lContinue = 0;
while( ( rdlen = hb_pp_RdStr( pFile->handle, s_szLine + lens, HB_PP_STR_SIZE -
lens, lContinue, ( char * ) pFile->pBuffer, &( pFile->lenBuffer ),
&( pFile->iBuffer ) ) ) >= 0 )
{
lens += rdlen;
hb_comp_iLine++;
if( s_szLine[ lens - 1 ] == ';' )
{
lContinue = 1;
lens--;
lens--;
while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' ) lens--;
s_szLine[ ++lens ] = ' ';
s_szLine[ ++lens ] = '\0';
}
else
{
lContinue = 0;
lens = 0;
}
if( s_szLine[ lens - 1 ] == ';' )
{
lContinue = 1;
lens--;
lens--;
while( s_szLine[ lens ] == ' ' || s_szLine[ lens ] == '\t' )
lens--;
s_szLine[ ++lens ] = ' ';
s_szLine[ ++lens ] = '\0';
}
else
{
lContinue = 0;
lens = 0;
}
if( ! lContinue )
{
if( *s_szLine != '\0' )
{
ptr = s_szLine;
HB_SKIPTABSPACES( ptr );
if( ! lContinue )
{
if( *s_szLine != '\0' )
{
ptr = s_szLine;
HB_SKIPTABSPACES( ptr );
if( *ptr == '#' )
{
hb_pp_ParseDirective_( ptr );
}
if( *ptr == '#' )
{
hb_pp_ParseDirective_( ptr );
}
*s_szLine = '\0';
}
*s_szLine = '\0';
}
break;
}
}
break;
}
}
if( rdlen < 0 )
{
if( hb_comp_files.iFiles == 1 )
{
break; /* we have reached the main EOF */
}
else
{
hb_pp_CloseInclude();
hb_pp_LastOutLine = hb_comp_iLine;
}
if( rdlen < 0 )
{
if( hb_comp_files.iFiles == 1 )
{
break; /* we have reached the main EOF */
}
else
{
hb_pp_CloseInclude();
hb_pp_LastOutLine = hb_comp_iLine;
}
*s_szLine = '\0';
}
}
*s_szLine = '\0';
}
}
return 0;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -69,7 +69,7 @@ typedef struct _DEFINES
char * name;
int namelen;
char * pars;
int npars;
int npars;
char * value;
struct _DEFINES * last;
} DEFINES;
@@ -88,34 +88,34 @@ typedef struct _COMMANDS
/* #include support */
typedef struct
{
FILE * handle; /* handle of the opened file */
void * pBuffer; /* file buffer */
char * yyBuffer; /* buffer used by yyac */
int iBuffer; /* current position in file buffer */
int lenBuffer; /* current length of data in file buffer */
char * szFileName; /* name of the file */
void * pPrev; /* pointer to the previous opened file */
void * pNext; /* pointer to the next opened file */
int iLine; /* currently processed line number */
} _FILE, * PFILE; /* structure to hold an opened PRG or CH */
FILE * handle; /* handle of the opened file */
void * pBuffer; /* file buffer */
char * yyBuffer; /* buffer used by yyac */
int iBuffer; /* current position in file buffer */
int lenBuffer; /* current length of data in file buffer */
char * szFileName; /* name of the file */
void * pPrev; /* pointer to the previous opened file */
void * pNext; /* pointer to the next opened file */
int iLine; /* currently processed line number */
} _FILE, * PFILE; /* structure to hold an opened PRG or CH */
/* structure to control several opened PRGs and CHs */
typedef struct
{
PFILE pLast; /* pointer to the last opened file */
int iFiles; /* number of files currently opened */
PFILE pLast; /* pointer to the last opened file */
int iFiles; /* number of files currently opened */
} FILES;
#define HB_PP_STR_SIZE 12288
#define HB_PP_BUFF_SIZE 4096
#define HB_SKIPTABSPACES( sptr ) while( *( sptr ) == ' ' || *( sptr ) == '\t' ) ( sptr )++
#define HB_SKIPTABSPACES( sptr ) while( *( sptr ) == ' ' || *( sptr ) == '\t' ) ( sptr )++
/* ppcore.c exported functions and variables */
#define HB_INCLUDE_FUNC_( hbFunc ) HB_BOOL hbFunc( char *, HB_PATHNAMES * )
typedef HB_INCLUDE_FUNC_( HB_INCLUDE_FUNC );
#define HB_INCLUDE_FUNC_( hbFunc ) HB_BOOL hbFunc( char *, HB_PATHNAMES * )
typedef HB_INCLUDE_FUNC_ ( HB_INCLUDE_FUNC );
typedef HB_INCLUDE_FUNC * HB_INCLUDE_FUNC_PTR;
extern void hb_pp_SetRules_( HB_INCLUDE_FUNC_PTR hb_compInclude, HB_BOOL hb_comp_bQuiet );
@@ -123,51 +123,51 @@ extern int hb_pp_ReadRules( void );
extern void hb_pp_Init( void );
extern void hb_pp_Free( void );
extern void hb_pp_CloseInclude( void );
extern int hb_pp_ParseDirective_( char * ); /* Parsing preprocessor directives ( #... ) */
extern int hb_pp_ParseExpression( char *, char *, HB_BOOL ); /* Parsing a line ( without preprocessor directive ) */
extern int hb_pp_ParseDirective_( char * ); /* Parsing preprocessor directives ( #... ) */
extern int hb_pp_ParseExpression( char *, char *, HB_BOOL ); /* Parsing a line ( without preprocessor directive ) */
extern int hb_pp_WrStr( FILE *, char * );
extern int hb_pp_RdStr( FILE *, char *, int, HB_BOOL, char *, int *, int * );
extern void hb_pp_Stuff( char *, char *, int, int, int );
extern int hb_pp_strocpy( char *, char * );
extern DEFINES * hb_pp_AddDefine_( char *, char * ); /* Add new #define to a linked list */
extern DEFINES * hb_pp_AddDefine_( char *, char * ); /* Add new #define to a linked list */
extern PHB_FNAME hb_comp_pFileName;
extern HB_BOOL hb_comp_bQuiet;
extern HB_BOOL hb_comp_bStartProc;
extern HB_BOOL hb_comp_bAutoMemvarAssume;
extern HB_BOOL hb_comp_bForceMemvars;
extern HB_BOOL hb_comp_bShortCuts;
extern HB_BOOL hb_comp_bDebugInfo;
extern HB_BOOL hb_comp_bLineNumbers;
extern int hb_comp_iExitLevel;
extern int hb_comp_iWarnings;
extern int hb_comp_iLine;
extern int hb_comp_iLineINLINE;
extern int hb_comp_iLinePRG;
extern int hb_pp_lInclude;
extern int * hb_pp_aCondCompile;
extern int hb_pp_nCondCompile;
extern const char * hb_pp_szErrors[];
extern const char * hb_pp_szWarnings[];
extern int hb_pp_nEmptyStrings;
extern int hb_pp_LastOutLine;
extern int hb_pp_StreamBlock;
extern HB_BOOL hb_pp_NestedLiteralString;
extern HB_BOOL hb_pp_LiteralEscSeq;
extern unsigned int hb_pp_MaxTranslateCycles;
extern HB_PATHNAMES * hb_comp_pIncludePath;
extern FILES hb_comp_files;
extern HB_BOOL hb_comp_bPPO;
extern FILE * hb_comp_yyppo;
extern PHB_FNAME hb_comp_pFileName;
extern HB_BOOL hb_comp_bQuiet;
extern HB_BOOL hb_comp_bStartProc;
extern HB_BOOL hb_comp_bAutoMemvarAssume;
extern HB_BOOL hb_comp_bForceMemvars;
extern HB_BOOL hb_comp_bShortCuts;
extern HB_BOOL hb_comp_bDebugInfo;
extern HB_BOOL hb_comp_bLineNumbers;
extern int hb_comp_iExitLevel;
extern int hb_comp_iWarnings;
extern int hb_comp_iLine;
extern int hb_comp_iLineINLINE;
extern int hb_comp_iLinePRG;
extern int hb_pp_lInclude;
extern int * hb_pp_aCondCompile;
extern int hb_pp_nCondCompile;
extern const char * hb_pp_szErrors[];
extern const char * hb_pp_szWarnings[];
extern int hb_pp_nEmptyStrings;
extern int hb_pp_LastOutLine;
extern int hb_pp_StreamBlock;
extern HB_BOOL hb_pp_NestedLiteralString;
extern HB_BOOL hb_pp_LiteralEscSeq;
extern unsigned int hb_pp_MaxTranslateCycles;
extern HB_PATHNAMES * hb_comp_pIncludePath;
extern FILES hb_comp_files;
extern HB_BOOL hb_comp_bPPO;
extern FILE * hb_comp_yyppo;
/* ppcomp.c exported functions */
extern int hb_pp_Internal_( FILE *, char * );
extern void hb_pp_InternalFree( void );
#define HB_PP_STREAM_DUMP_C 1 /* pragma BEGINDUMP */
#define HB_PP_STREAM_CLIPPER 2 /* clipper compatible TEXT/ENDTEXT */
#define HB_PP_STREAM_PRG 4 /* TEXT/ENDTEXT lines joined with LF */
#define HB_PP_STREAM_C 8 /* TEXT/ENDTEXT lines joined and ESC seq processed */
#define HB_PP_STREAM_DUMP_C 1 /* pragma BEGINDUMP */
#define HB_PP_STREAM_CLIPPER 2 /* clipper compatible TEXT/ENDTEXT */
#define HB_PP_STREAM_PRG 4 /* TEXT/ENDTEXT lines joined with LF */
#define HB_PP_STREAM_C 8 /* TEXT/ENDTEXT lines joined and ESC seq processed */
extern HB_BOOL hb_pp_StreamBlockBegin( char *, int );
extern void hb_pp_BlockEnd( void );
@@ -187,30 +187,30 @@ extern HB_BOOL hb_pp_ParsePragma( char * szline );
/*
* Errors generated by Harbour preprocessor
*/
#define HB_PP_ERR_CANNOT_OPEN 1
#define HB_PP_ERR_DIRECTIVE_ELSE 2
#define HB_PP_ERR_DIRECTIVE_ENDIF 3
#define HB_PP_ERR_WRONG_NAME 4
#define HB_PP_ERR_DEFINE_ABSENT 5
#define HB_PP_ERR_COMMAND_DEFINITION 6
#define HB_PP_ERR_PATTERN_DEFINITION 7
#define HB_PP_ERR_RECURSE 8
#define HB_PP_ERR_WRONG_DIRECTIVE 9
#define HB_PP_ERR_EXPLICIT 10
#define HB_PP_ERR_MEMALLOC 11
#define HB_PP_ERR_MEMREALLOC 12
#define HB_PP_ERR_MEMFREE 13
#define HB_PP_ERR_PRAGMA_BAD_VALUE 14
#define HB_PP_ERR_CANNOT_OPEN_RULES 15
#define HB_PP_ERR_BAD_RULES_FILE_NAME 16
#define HB_PP_ERR_TOO_MANY_INCLUDES 17
#define HB_PP_ERR_BUFFER_OVERFLOW 18
#define HB_PP_ERR_LABEL_MISSING_IN_DEFINE 19
#define HB_PP_ERR_PARE_MISSING_IN_DEFINE 20
#define HB_PP_ERR_LABEL_DUPL_IN_DEFINE 21
#define HB_PP_ERR_CANNOT_OPEN 1
#define HB_PP_ERR_DIRECTIVE_ELSE 2
#define HB_PP_ERR_DIRECTIVE_ENDIF 3
#define HB_PP_ERR_WRONG_NAME 4
#define HB_PP_ERR_DEFINE_ABSENT 5
#define HB_PP_ERR_COMMAND_DEFINITION 6
#define HB_PP_ERR_PATTERN_DEFINITION 7
#define HB_PP_ERR_RECURSE 8
#define HB_PP_ERR_WRONG_DIRECTIVE 9
#define HB_PP_ERR_EXPLICIT 10
#define HB_PP_ERR_MEMALLOC 11
#define HB_PP_ERR_MEMREALLOC 12
#define HB_PP_ERR_MEMFREE 13
#define HB_PP_ERR_PRAGMA_BAD_VALUE 14
#define HB_PP_ERR_CANNOT_OPEN_RULES 15
#define HB_PP_ERR_BAD_RULES_FILE_NAME 16
#define HB_PP_ERR_TOO_MANY_INCLUDES 17
#define HB_PP_ERR_BUFFER_OVERFLOW 18
#define HB_PP_ERR_LABEL_MISSING_IN_DEFINE 19
#define HB_PP_ERR_PARE_MISSING_IN_DEFINE 20
#define HB_PP_ERR_LABEL_DUPL_IN_DEFINE 21
#define HB_PP_WARN_DEFINE_REDEF 1
#define HB_PP_WARN_NO_DIRECTIVES 2
#define HB_PP_WARN_DEFINE_REDEF 1
#define HB_PP_WARN_NO_DIRECTIVES 2
HB_EXTERN_END

View File

@@ -65,11 +65,11 @@ static void DebugPragma( char *, int, HB_BOOL );
static HB_BOOL s_bTracePragma = HB_FALSE;
/* Size of abreviated pragma commands */
#define PRAGMAS_LEN 8
#define PRAGMAS_LEN 8
/* TODO: Add support for:
RequestLib /R
*/
*/
static PINLINE hb_compInlineAdd_( char * szFunName )
{
@@ -81,7 +81,7 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
{
HB_BOOL bIgnore = HB_TRUE;
HB_TRACE(HB_TR_DEBUG, ("hb_pp_ParsePragma(%s)", szLine));
HB_TRACE( HB_TR_DEBUG, ( "hb_pp_ParsePragma(%s)", szLine ) );
HB_SKIPTABSPACES( szLine );
@@ -97,8 +97,8 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
case 'b':
case 'B':
hb_comp_bDebugInfo = IsOnOffSwitch( szLine, hb_comp_bDebugInfo );
hb_comp_bLineNumbers = hb_comp_bDebugInfo;
hb_comp_bDebugInfo = IsOnOffSwitch( szLine, hb_comp_bDebugInfo );
hb_comp_bLineNumbers = hb_comp_bDebugInfo;
DebugPragma( szLine, -1, hb_comp_bDebugInfo );
break;
@@ -194,20 +194,20 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
}
else if( hb_strnicmp( szLine, "BEGINDUMP", PRAGMAS_LEN ) == 0 )
{
char sBuffer[ HB_PP_STR_SIZE ], *pBuffer, sDirective[9] ;
int iSize, iOldSize;
PINLINE pInline;
char sBuffer[ HB_PP_STR_SIZE ], * pBuffer, sDirective[ 9 ];
int iSize, iOldSize;
PINLINE pInline;
if( hb_comp_bPPO )
{
hb_pp_WrStr( hb_comp_yyppo, "#pragma BEGINDUMP" );
}
hb_pp_StreamBlock = HB_PP_STREAM_DUMP_C;
hb_pp_StreamBlock = HB_PP_STREAM_DUMP_C;
pInline = hb_compInlineAdd_( NULL );
pInline = hb_compInlineAdd_( NULL );
DigestInline :
DigestInline:
iSize = hb_pp_Internal_( hb_comp_bPPO ? hb_comp_yyppo : NULL, sBuffer );
if( iSize == 0 )
@@ -216,7 +216,7 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
return bIgnore;
}
pBuffer = (char*) sBuffer;
pBuffer = ( char * ) sBuffer;
while( *pBuffer == ' ' || *pBuffer == '\t' )
{
@@ -246,16 +246,16 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
}
}
iOldSize = 0;
iSize = strlen( (char*) sBuffer );
iOldSize = 0;
iSize = strlen( ( char * ) sBuffer );
if( pInline->pCode == NULL )
{
pInline->pCode = (BYTE *) hb_xgrab( iSize + 1 );
pInline->pCode = ( BYTE * ) hb_xgrab( iSize + 1 );
}
else
{
iOldSize = strlen( (char*)pInline->pCode );
pInline->pCode = (BYTE *) hb_xrealloc( pInline->pCode, iOldSize + iSize + 1 );
iOldSize = strlen( ( char * ) pInline->pCode );
pInline->pCode = ( BYTE * ) hb_xrealloc( pInline->pCode, iOldSize + iSize + 1 );
}
memcpy( pInline->pCode + iOldSize, sBuffer, iSize + 1 );
@@ -263,8 +263,8 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
}
else if( hb_strnicmp( szLine, "DEBUGINFO", PRAGMAS_LEN ) == 0 )
{
hb_comp_bDebugInfo = StringToBool( szLine, hb_comp_bDebugInfo );
hb_comp_bLineNumbers = hb_comp_bDebugInfo;
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 )
@@ -275,8 +275,8 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
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 &&
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 );
@@ -335,13 +335,13 @@ HB_BOOL hb_pp_ParsePragma( char * szLine )
}
else if( hb_strnicmp( szLine, "__endtext", 9 ) == 0 )
{
hb_pp_BlockEnd( );
hb_pp_BlockEnd();
DebugPragma( szLine, -1, s_bTracePragma );
}
else if( hb_strnicmp( szLine, "RECURSELEVEL", PRAGMAS_LEN ) == 0 )
{
int iOverflow;
int iMax;
int iOverflow;
int iMax;
iMax = ( int ) hb_strValInt( szLine, &iOverflow );
if( iOverflow || iMax < 1 )

View File

@@ -53,8 +53,8 @@
/*
* Avoid tracing in preprocessor/compiler.
*/
#if ! defined(HB_TRACE_UTILS)
#if defined(HB_TRACE_LEVEL)
#if ! defined( HB_TRACE_UTILS )
#if defined( HB_TRACE_LEVEL )
#undef HB_TRACE_LEVEL
#endif
#endif
@@ -64,7 +64,7 @@
#include <string.h>
/* malloc.h has been obsoleted by stdlib.h (and does not even exist in gcc 3.x).
#include <malloc.h>
*/
*/
#include "hbppdef.h"
#include "hbcomp.h"
@@ -72,140 +72,141 @@
extern int hb_pp_ParseDefine_( char * );
static void AddSearchPath( char * szPath, HB_PATHNAMES * * pSearchList );
static void AddSearchPath( char * szPath, HB_PATHNAMES ** pSearchList );
static void OutTable( DEFINES * endDefine, COMMANDS * endCommand );
static HB_BOOL hb_pp_fopen( char * szFileName );
static char s_szLine[ HB_PP_STR_SIZE ];
static int s_iWarnings = 0;
static char * hb_buffer;
static char s_szLine[ HB_PP_STR_SIZE ];
static int s_iWarnings = 0;
static char * hb_buffer;
HB_PATHNAMES * hb_comp_pIncludePath = NULL;
PHB_FNAME hb_comp_pFileName = NULL;
HB_PATHNAMES * hb_comp_pIncludePath = NULL;
PHB_FNAME hb_comp_pFileName = NULL;
FILES hb_comp_files;
int hb_comp_iLine = 1; /* currently parsed file line number */
int hb_comp_iLine = 1; /* currently parsed file line number */
/* These are need for the PP #pragma support */
HB_BOOL hb_comp_bPPO = HB_FALSE; /* flag indicating, is ppo output needed */
HB_BOOL hb_comp_bStartProc = HB_TRUE; /* holds if we need to create the starting procedure */
HB_BOOL hb_comp_bLineNumbers = HB_TRUE; /* holds if we need pcodes with line numbers */
HB_BOOL hb_comp_bShortCuts = HB_TRUE; /* .and. & .or. expressions shortcuts */
int hb_comp_iWarnings = 0; /* enable parse warnings */
HB_BOOL hb_comp_bAutoMemvarAssume = HB_FALSE; /* holds if undeclared variables are automatically assumed MEMVAR (-a)*/
HB_BOOL hb_comp_bForceMemvars = HB_FALSE; /* holds if memvars are assumed when accesing undeclared variable (-v)*/
HB_BOOL hb_comp_bDebugInfo = HB_FALSE; /* holds if generate debugger required info */
int hb_comp_iExitLevel = HB_EXITLEVEL_DEFAULT; /* holds if there was any warning during the compilation process */
FILE * hb_comp_yyppo = NULL;
HB_BOOL hb_comp_bPPO = HB_FALSE; /* flag indicating, is ppo output needed */
HB_BOOL hb_comp_bStartProc = HB_TRUE; /* holds if we need to create the starting procedure */
HB_BOOL hb_comp_bLineNumbers = HB_TRUE; /* holds if we need pcodes with line numbers */
HB_BOOL hb_comp_bShortCuts = HB_TRUE; /* .and. & .or. expressions shortcuts */
int hb_comp_iWarnings = 0; /* enable parse warnings */
HB_BOOL hb_comp_bAutoMemvarAssume = HB_FALSE; /* holds if undeclared variables are automatically assumed MEMVAR (-a)*/
HB_BOOL hb_comp_bForceMemvars = HB_FALSE; /* holds if memvars are assumed when accesing undeclared variable (-v)*/
HB_BOOL hb_comp_bDebugInfo = HB_FALSE; /* holds if generate debugger required info */
int hb_comp_iExitLevel = HB_EXITLEVEL_DEFAULT; /* holds if there was any warning during the compilation process */
FILE * hb_comp_yyppo = NULL;
int hb_comp_iLinePRG;
int hb_comp_iLineINLINE = 0;
int hb_comp_iLinePRG;
int hb_comp_iLineINLINE = 0;
int main( int argc, char * argv[] )
{
FILE * handl_o;
char szFileName[ HB_PATH_MAX ];
char szPpoName[ HB_PATH_MAX ];
int iArg = 1;
HB_BOOL bOutTable = HB_FALSE;
HB_BOOL bOutNew = HB_FALSE;
DEFINES * stdef;
COMMANDS * stcmd;
FILE * handl_o;
char szFileName[ HB_PATH_MAX ];
char szPpoName[ HB_PATH_MAX ];
int iArg = 1;
HB_BOOL bOutTable = HB_FALSE;
HB_BOOL bOutNew = HB_FALSE;
DEFINES * stdef;
COMMANDS * stcmd;
HB_TRACE(HB_TR_DEBUG, ("main(%d, %p)", argc, argv));
HB_TRACE( HB_TR_DEBUG, ( "main(%d, %p)", argc, argv ) );
printf( "Harbour Preprocessor (old version) %d.%d.%d\n",
HB_VER_MAJOR, HB_VER_MINOR, HB_VER_RELEASE );
printf( "Copyright (c) 1999-2008, http://harbour-project.org/\n" );
printf( "Harbour Preprocessor (old version) %d.%d.%d\n",
HB_VER_MAJOR, HB_VER_MINOR, HB_VER_RELEASE );
printf( "Copyright (c) 1999-2008, http://harbour-project.org/\n" );
hb_pp_Table();
stdef = hb_pp_topDefine;
stcmd = hb_pp_topCommand;
hb_pp_Init();
hb_pp_Table();
stdef = hb_pp_topDefine;
stcmd = hb_pp_topCommand;
hb_pp_Init();
while( iArg < argc )
{
if( HB_ISOPTSEP(argv[ iArg ][ 0 ]))
{
switch( argv[ iArg ][ 1 ] )
{
while( iArg < argc )
{
if( HB_ISOPTSEP( argv[ iArg ][ 0 ] ) )
{
switch( argv[ iArg ][ 1 ] )
{
case 'd':
case 'D': /* defines a #define from the command line */
{
char *szDefText = hb_strdup( argv[iArg] + 2 ), *pAssign, *sDefLine;
unsigned int i = 0;
{
char * szDefText = hb_strdup( argv[ iArg ] + 2 ), * pAssign, * sDefLine;
unsigned int i = 0;
while( i < strlen( szDefText ) && ! HB_ISOPTSEP( szDefText[ i ] ) )
i++;
while( i < strlen( szDefText ) && ! HB_ISOPTSEP( szDefText[ i ] ) )
i++;
szDefText[ i ] = '\0';
if( szDefText )
{
if( ( pAssign = strchr( szDefText, '=' ) ) == NULL )
{
hb_pp_AddDefine_( szDefText, 0 );
}
else
{
szDefText[ pAssign - szDefText ] = '\0';
szDefText[ i ] = '\0';
if( szDefText )
{
if( ( pAssign = strchr( szDefText, '=' ) ) == NULL )
{
hb_pp_AddDefine_( szDefText, 0 );
}
else
{
szDefText[ pAssign - szDefText ] = '\0';
/* hb_pp_AddDefine_( szDefText, pAssign + 1 ); */
sDefLine = hb_xstrcpy( NULL, szDefText, " ", pAssign + 1, NULL );
hb_pp_ParseDefine_( sDefLine );
hb_xfree( sDefLine );
}
}
/* hb_pp_AddDefine_( szDefText, pAssign + 1 ); */
sDefLine = hb_xstrcpy( NULL, szDefText, " ", pAssign + 1, NULL );
hb_pp_ParseDefine_( sDefLine );
hb_xfree( sDefLine );
}
}
hb_xfree( szDefText );
}
break;
hb_xfree( szDefText );
}
break;
case 'i':
case 'I':
AddSearchPath( argv[ iArg ]+2, &hb_comp_pIncludePath );
break;
AddSearchPath( argv[ iArg ] + 2, &hb_comp_pIncludePath );
break;
case 'o':
case 'O':
bOutTable = HB_TRUE;
break;
bOutTable = HB_TRUE;
break;
case 'n':
case 'N':
bOutNew = HB_TRUE;
break;
bOutNew = HB_TRUE;
break;
case 'w':
case 'W':
s_iWarnings = 1;
if( argv[ iArg ][ 2 ] )
{ /*there is -w<0,1,2,3> probably */
s_iWarnings = 1;
if( argv[ iArg ][ 2 ] ) /* there is -w<0,1,2,3> probably */
{
s_iWarnings = argv[ iArg ][ 2 ] - '0';
if( s_iWarnings < 0 || s_iWarnings > 3 )
printf( "\nInvalid command line option: %s\n", argv[ iArg ] );
}
break;
printf( "\nInvalid command line option: %s\n", argv[ iArg ] );
}
break;
default:
printf( "\nInvalid command line option: %s\n", &argv[ iArg ][ 1 ] );
break;
}
}
else hb_comp_pFileName = hb_fsFNameSplit( argv[ iArg ] );
printf( "\nInvalid command line option: %s\n", &argv[ iArg ][ 1 ] );
break;
}
}
else
hb_comp_pFileName = hb_fsFNameSplit( argv[ iArg ] );
iArg++;
}
}
if( hb_comp_pFileName )
{
if( hb_comp_pFileName )
{
if( ! hb_comp_pFileName->szExtension )
hb_comp_pFileName->szExtension =".prg";
hb_comp_pFileName->szExtension = ".prg";
hb_fsFNameMerge( szFileName, hb_comp_pFileName );
if( !hb_pp_fopen( szFileName ) )
{
printf("\nCan't open %s\n", szFileName );
return 1;
}
if( ! hb_pp_fopen( szFileName ) )
{
printf( "\nCan't open %s\n", szFileName );
return 1;
}
printf( "\nParsing file %s\n", szFileName );
}
else
{
}
else
{
printf( "\nSyntax: %s <file[.prg]> [options]"
"\n"
"\nOptions: /d<id>[=<val>] #define <id>"
@@ -217,272 +218,275 @@ int main( int argc, char * argv[] )
, argv[ 0 ] );
if( bOutTable )
OutTable( NULL, NULL );
OutTable( NULL, NULL );
return 1;
}
}
hb_comp_pFileName->szExtension = ".ppo";
hb_fsFNameMerge( szPpoName, hb_comp_pFileName );
hb_comp_pFileName->szExtension = ".ppo";
hb_fsFNameMerge( szPpoName, hb_comp_pFileName );
if( ( handl_o = fopen( szPpoName, "wt" ) ) == NULL )
{
printf("\nCan't open %s\n", szPpoName );
if( ( handl_o = fopen( szPpoName, "wt" ) ) == NULL )
{
printf( "\nCan't open %s\n", szPpoName );
return 1;
}
}
{
char * szInclude = hb_getenv( "INCLUDE" );
{
char * szInclude = hb_getenv( "INCLUDE" );
if( szInclude )
if( szInclude )
{
char * pPath;
char * pDelim;
char * pPath;
char * pDelim;
pPath = szInclude;
while( ( pDelim = strchr( pPath, HB_OS_PATH_LIST_SEP_CHR ) ) != NULL )
{
pPath = szInclude;
while( ( pDelim = strchr( pPath, HB_OS_PATH_LIST_SEP_CHR ) ) != NULL )
{
*pDelim = '\0';
AddSearchPath( pPath, &hb_comp_pIncludePath );
pPath = pDelim + 1;
}
AddSearchPath( pPath, &hb_comp_pIncludePath );
hb_xfree( szInclude );
pPath = pDelim + 1;
}
AddSearchPath( pPath, &hb_comp_pIncludePath );
hb_xfree( szInclude );
}
}
}
hb_buffer = ( char* ) hb_xgrab( HB_PP_STR_SIZE );
while( hb_pp_Internal_( handl_o,hb_buffer ) > 0 );
fclose( hb_comp_files.pLast->handle );
hb_xfree( hb_comp_files.pLast->pBuffer );
hb_xfree( hb_comp_files.pLast );
hb_xfree( hb_buffer );
fclose( handl_o );
hb_buffer = ( char * ) hb_xgrab( HB_PP_STR_SIZE );
while( hb_pp_Internal_( handl_o, hb_buffer ) > 0 )
;
fclose( hb_comp_files.pLast->handle );
hb_xfree( hb_comp_files.pLast->pBuffer );
hb_xfree( hb_comp_files.pLast );
hb_xfree( hb_buffer );
fclose( handl_o );
if( bOutTable )
OutTable( NULL, NULL );
else if( bOutNew )
OutTable( stdef, stcmd );
if( bOutTable )
OutTable( NULL, NULL );
else if( bOutNew )
OutTable( stdef, stcmd );
printf( "\nOk" );
printf( "\nOk" );
return 0;
return 0;
}
static void OutTable( DEFINES * endDefine, COMMANDS * endCommand )
{
FILE *handl_o;
int ipos, len_mpatt = 0, len_value;
int num;
DEFINES * stdef1 = hb_pp_topDefine, * stdef2 = NULL, * stdef3;
COMMANDS * stcmd1 = hb_pp_topCommand, * stcmd2 = NULL, * stcmd3;
FILE * handl_o;
int ipos, len_mpatt = 0, len_value;
int num;
DEFINES * stdef1 = hb_pp_topDefine, * stdef2 = NULL, * stdef3;
COMMANDS * stcmd1 = hb_pp_topCommand, * stcmd2 = NULL, * stcmd3;
HB_TRACE(HB_TR_DEBUG, ("OutTable(%p, %p)", endDefine, endCommand));
HB_TRACE( HB_TR_DEBUG, ( "OutTable(%p, %p)", endDefine, endCommand ) );
while( stdef1 != endDefine )
{
stdef3 = stdef1->last;
stdef1->last = stdef2;
stdef2 = stdef1;
stdef1 = stdef3;
}
while( stcmd1 != endCommand )
{
stcmd3 = stcmd1->last;
stcmd1->last = stcmd2;
stcmd2 = stcmd1;
stcmd1 = stcmd3;
}
while( stdef1 != endDefine )
{
stdef3 = stdef1->last;
stdef1->last = stdef2;
stdef2 = stdef1;
stdef1 = stdef3;
}
while( stcmd1 != endCommand )
{
stcmd3 = stcmd1->last;
stcmd1->last = stcmd2;
stcmd2 = stcmd1;
stcmd1 = stcmd3;
}
if( ( handl_o = fopen( "hbpp.out", "wt" ) ) == NULL )
{
if( ( handl_o = fopen( "hbpp.out", "wt" ) ) == NULL )
{
printf( "\nCan't open hbpp.out\n" );
return;
}
}
num = 1;
while( stdef2 != NULL )
{
num = 1;
while( stdef2 != NULL )
{
fprintf( handl_o, "\n static DEFINES sD___%i = ", num );
fprintf( handl_o, "{\"%s\",", stdef2->name );
if( stdef2->pars )
fprintf( handl_o, "\"%s\",", stdef2->pars );
fprintf( handl_o, "\"%s\",", stdef2->pars );
else
fprintf( handl_o, "NULL," );
fprintf( handl_o, "NULL," );
fprintf( handl_o, "%d,", stdef2->npars );
if( stdef2->value )
fprintf( handl_o, "\"%s\"", stdef2->value );
fprintf( handl_o, "\"%s\"", stdef2->value );
else
fprintf( handl_o, "NULL" );
fprintf( handl_o, "NULL" );
if( num == 1 )
fprintf( handl_o, ", NULL };" );
fprintf( handl_o, ", NULL };" );
else
fprintf( handl_o, ", &sD___%i };", num - 1 );
fprintf( handl_o, ", &sD___%i };", num - 1 );
stdef2 = stdef2->last;
num++;
}
fprintf( handl_o, "\n DEFINES * hb_pp_topDefine = " );
if( num == 1 )
fprintf( handl_o, "NULL;" );
else
fprintf( handl_o, " = &sD___%i;\n", num - 1 );
}
fprintf( handl_o, "\n DEFINES * hb_pp_topDefine = " );
if( num == 1 )
fprintf( handl_o, "NULL;" );
else
fprintf( handl_o, " = &sD___%i;\n", num - 1 );
num = 1;
while( stcmd2 != NULL )
{
num = 1;
while( stcmd2 != NULL )
{
fprintf( handl_o, "\n static COMMANDS sC___%i = ", num );
fprintf( handl_o, "{%d,\"%s\",", stcmd2->com_or_xcom, stcmd2->name );
if( stcmd2->mpatt != NULL )
{
len_mpatt = hb_pp_strocpy( s_szLine, stcmd2->mpatt );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt );
len_mpatt++;
}
fprintf( handl_o, "\"%s\",", s_szLine );
}
{
len_mpatt = hb_pp_strocpy( s_szLine, stcmd2->mpatt );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt );
len_mpatt++;
}
fprintf( handl_o, "\"%s\",", s_szLine );
}
else
fprintf( handl_o, "NULL," );
fprintf( handl_o, "NULL," );
if( stcmd2->value != NULL )
{
len_value = hb_pp_strocpy( s_szLine, stcmd2->value );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value );
len_value++;
}
if( len_mpatt + len_value > 80 )
{
len_value = hb_pp_strocpy( s_szLine, stcmd2->value );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value );
len_value++;
}
if( len_mpatt + len_value > 80 )
fprintf( handl_o, "\n " );
fprintf( handl_o, "\"%s\"", s_szLine );
}
else fprintf( handl_o, "NULL" );
if( num == 1 )
fprintf( handl_o, ",NULL };" );
fprintf( handl_o, "\"%s\"", s_szLine );
}
else
fprintf( handl_o, ",&sC___%i };", num - 1 );
fprintf( handl_o, "NULL" );
if( num == 1 )
fprintf( handl_o, ",NULL };" );
else
fprintf( handl_o, ",&sC___%i };", num - 1 );
stcmd2 = stcmd2->last;
num++;
}
fprintf( handl_o, "\n COMMANDS * hb_pp_topCommand = " );
if( num == 1 )
fprintf( handl_o, "NULL;" );
else
fprintf( handl_o, " = &sC___%i;\n", num - 1 );
}
fprintf( handl_o, "\n COMMANDS * hb_pp_topCommand = " );
if( num == 1 )
fprintf( handl_o, "NULL;" );
else
fprintf( handl_o, " = &sC___%i;\n", num - 1 );
stcmd1 = hb_pp_topTranslate;
stcmd2 = NULL;
while( stcmd1 != NULL )
{
stcmd3 = stcmd1->last;
stcmd1->last = stcmd2;
stcmd2 = stcmd1;
stcmd1 = stcmd3;
}
num = 1;
while( stcmd2 != NULL )
{
stcmd1 = hb_pp_topTranslate;
stcmd2 = NULL;
while( stcmd1 != NULL )
{
stcmd3 = stcmd1->last;
stcmd1->last = stcmd2;
stcmd2 = stcmd1;
stcmd1 = stcmd3;
}
num = 1;
while( stcmd2 != NULL )
{
fprintf( handl_o, "\n static COMMANDS sC___%i = ", num );
fprintf( handl_o, "{%d,\"%s\",", stcmd2->com_or_xcom, stcmd2->name );
if( stcmd2->mpatt != NULL )
{
len_mpatt = hb_pp_strocpy( s_szLine, stcmd2->mpatt );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt );
len_mpatt++;
}
fprintf( handl_o, "\"%s\",", s_szLine );
}
{
len_mpatt = hb_pp_strocpy( s_szLine, stcmd2->mpatt );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_mpatt ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_mpatt );
len_mpatt++;
}
fprintf( handl_o, "\"%s\",", s_szLine );
}
else
fprintf( handl_o, "NULL," );
fprintf( handl_o, "NULL," );
if( stcmd2->value != NULL )
{
len_value = hb_pp_strocpy( s_szLine, stcmd2->value );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value );
len_value++;
}
if( len_mpatt + len_value > 80 )
{
len_value = hb_pp_strocpy( s_szLine, stcmd2->value );
while( ( ipos = hb_strAt( "\1", 1, s_szLine, len_value ) ) > 0 )
{
hb_pp_Stuff( "\\1", s_szLine + ipos - 1, 2, 1, len_value );
len_value++;
}
if( len_mpatt + len_value > 80 )
fprintf( handl_o, "\n " );
fprintf( handl_o, "\"%s\"", s_szLine );
}
else fprintf( handl_o, "NULL" );
if( num == 1 )
fprintf( handl_o, ",NULL };" );
fprintf( handl_o, "\"%s\"", s_szLine );
}
else
fprintf( handl_o, ",&sC___%i };", num - 1 );
fprintf( handl_o, "NULL" );
if( num == 1 )
fprintf( handl_o, ",NULL };" );
else
fprintf( handl_o, ",&sC___%i };", num - 1 );
stcmd2 = stcmd2->last;
num++;
}
fprintf( handl_o, "\n COMMANDS * hb_pp_topTranslate = " );
if( num == 1 )
fprintf( handl_o, "NULL;" );
else
fprintf( handl_o, " = &sT___%i;", num );
}
fprintf( handl_o, "\n COMMANDS * hb_pp_topTranslate = " );
if( num == 1 )
fprintf( handl_o, "NULL;" );
else
fprintf( handl_o, " = &sT___%i;", num );
fclose( handl_o );
fclose( handl_o );
}
/*
* Function that adds specified path to the list of pathnames to search
*/
static void AddSearchPath( char * szPath, HB_PATHNAMES * * pSearchList )
static void AddSearchPath( char * szPath, HB_PATHNAMES ** pSearchList )
{
HB_PATHNAMES * pPath = *pSearchList;
HB_PATHNAMES * pPath = *pSearchList;
HB_TRACE(HB_TR_DEBUG, ("AddSearchPath(%s, %p)", szPath, pSearchList));
HB_TRACE( HB_TR_DEBUG, ( "AddSearchPath(%s, %p)", szPath, pSearchList ) );
if( pPath )
{
if( pPath )
{
while( pPath->pNext )
pPath = pPath->pNext;
pPath->pNext = ( HB_PATHNAMES * ) hb_xgrab( sizeof( HB_PATHNAMES ) );
pPath = pPath->pNext;
}
else
{
pPath = pPath->pNext;
pPath->pNext = ( HB_PATHNAMES * ) hb_xgrab( sizeof( HB_PATHNAMES ) );
pPath = pPath->pNext;
}
else
{
*pSearchList = pPath = ( HB_PATHNAMES * ) hb_xgrab( sizeof( HB_PATHNAMES ) );
}
pPath->pNext = NULL;
pPath->szPath = szPath;
}
pPath->pNext = NULL;
pPath->szPath = szPath;
}
void hb_compGenError( HB_COMP_DECL, const char * _szErrors[], char cPrefix, int iError, const char * szError1, const char * szError2 )
{
HB_TRACE(HB_TR_DEBUG, ("hb_compGenError(%p, %c, %d, %s, %s)", _szErrors, cPrefix, iError, szError1, szError2));
HB_TRACE( HB_TR_DEBUG, ( "hb_compGenError(%p, %c, %d, %s, %s)", _szErrors, cPrefix, iError, szError1, szError2 ) );
HB_SYMBOL_UNUSED( HB_COMP_PARAM );
HB_SYMBOL_UNUSED( HB_COMP_PARAM );
printf( "\r(%i) ", hb_comp_iLine );
printf( "Error %c%04i ", cPrefix, iError );
printf( _szErrors[ iError - 1 ], szError1, szError2 );
printf( "\n\n" );
printf( "\r(%i) ", hb_comp_iLine );
printf( "Error %c%04i ", cPrefix, iError );
printf( _szErrors[ iError - 1 ], szError1, szError2 );
printf( "\n\n" );
/*
exit( EXIT_FAILURE );
*/
/*
exit( EXIT_FAILURE );
*/
}
void hb_compGenWarning( HB_COMP_DECL, const char* _szWarnings[], char cPrefix, int iWarning, const char * szWarning1, const char * szWarning2)
void hb_compGenWarning( HB_COMP_DECL, const char * _szWarnings[], char cPrefix, int iWarning, const char * szWarning1, const char * szWarning2 )
{
HB_TRACE(HB_TR_DEBUG, ("hb_compGenWarning(%p, %c, %d, %s, %s)", _szWarnings, cPrefix, iWarning, szWarning1, szWarning2));
HB_TRACE( HB_TR_DEBUG, ( "hb_compGenWarning(%p, %c, %d, %s, %s)", _szWarnings, cPrefix, iWarning, szWarning1, szWarning2 ) );
HB_SYMBOL_UNUSED( HB_COMP_PARAM );
HB_SYMBOL_UNUSED( HB_COMP_PARAM );
if( s_iWarnings )
{
const char *szText = _szWarnings[ iWarning - 1 ];
if( s_iWarnings )
{
const char * szText = _szWarnings[ iWarning - 1 ];
if( ( ( int ) ( szText[ 0 ] - '0' ) ) <= s_iWarnings )
{
printf( "\r(%i) ", hb_comp_iLine );
printf( "Warning %c%04i ", cPrefix, iWarning );
printf( szText + 1, szWarning1, szWarning2 );
printf( "\n" );
}
}
{
printf( "\r(%i) ", hb_comp_iLine );
printf( "Warning %c%04i ", cPrefix, iWarning );
printf( szText + 1, szWarning1, szWarning2 );
printf( "\n" );
}
}
}
int hb_verSvnID( void )
@@ -492,25 +496,25 @@ int hb_verSvnID( void )
static HB_BOOL hb_pp_fopen( char * szFileName )
{
PFILE pFile;
FILE * handl_i = fopen( szFileName, "r" );
PFILE pFile;
FILE * handl_i = fopen( szFileName, "r" );
if( !handl_i )
if( ! handl_i )
return HB_FALSE;
pFile = ( PFILE ) hb_xgrab( sizeof( _FILE ) );
pFile->handle = handl_i;
pFile->pBuffer = hb_xgrab( HB_PP_BUFF_SIZE );
pFile->iBuffer = pFile->lenBuffer = 10;
pFile->szFileName = szFileName;
pFile->pPrev = NULL;
pFile = ( PFILE ) hb_xgrab( sizeof( _FILE ) );
pFile->handle = handl_i;
pFile->pBuffer = hb_xgrab( HB_PP_BUFF_SIZE );
pFile->iBuffer = pFile->lenBuffer = 10;
pFile->szFileName = szFileName;
pFile->pPrev = NULL;
hb_comp_files.pLast = pFile;
hb_comp_files.iFiles = 1;
hb_comp_files.pLast = pFile;
hb_comp_files.iFiles = 1;
return HB_TRUE;
}
#if defined( HB_OS_WIN_CE ) && !defined( __CEGCC__ )
#if defined( HB_OS_WIN_CE ) && ! defined( __CEGCC__ )
# include "hbwmain.c"
#endif