ChangeLogTag:Wed Oct 20 19:28:51 1999 Gonzalo A. Diethelm <Gonzalo.Diethelm@jda.cl>
This commit is contained in:
@@ -1,3 +1,39 @@
|
||||
Wed Oct 20 19:28:51 1999 Gonzalo A. Diethelm <Gonzalo.Diethelm@jda.cl>
|
||||
|
||||
* source/Makefile:
|
||||
* source/common/Makefile:
|
||||
* source/common/hbtrace.c:
|
||||
* include/hbtrace.h:
|
||||
Added a common/ library where all "common" stuff should be
|
||||
implemented. For starters, I placed here a rudimentary tracing
|
||||
facility. Basically, all functions should be of the form:
|
||||
|
||||
int foo(char* name /* other parameters */)
|
||||
{
|
||||
HB_TRACE(("foo(%s)", name));
|
||||
|
||||
/* implementation */
|
||||
}
|
||||
|
||||
If harbour is compiled with HB_DO_TRACE defined, then this will
|
||||
generate a trace on stderr of all functions being called (caution:
|
||||
it generates LOTS of output!!!). If HB_DO_TRACE is not defined,
|
||||
the HB_TRACE() lines are defined out and there is no performance
|
||||
hit.
|
||||
|
||||
* include/hbdefs.h:
|
||||
Included hbtrace.h.
|
||||
|
||||
* source/pp/hbpp.c:
|
||||
* source/pp/hbppint.c:
|
||||
* source/pp/hbpplib.c:
|
||||
* source/pp/stdalone/Makefile:
|
||||
* source/pp/stdalone/hbpp.c:
|
||||
Added tracing calls as a "proof of concept".
|
||||
|
||||
* source/rtl/gt/gtwin.c:
|
||||
Fixed two minor typos.
|
||||
|
||||
19991020-21:30 GMT+1 Victor Szel <info@szelvesz.hu>
|
||||
* source/rtl/achoice.prg
|
||||
% FUNCTION -> PROCEDURE for speed.
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "hbsetup.h"
|
||||
#include "hbtrace.h"
|
||||
|
||||
#if defined(__IBMCPP__)
|
||||
/* With the exception of WORD, the IBM Visual Age C++ compiler has
|
||||
|
||||
59
harbour/include/hbtrace.h
Normal file
59
harbour/include/hbtrace.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* Header file for trace macros and functions.
|
||||
*
|
||||
* Copyright 1999 Gonzalo Diethelm <gonzalo.diethelm@iname.com>
|
||||
* www - http://www.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 of the License, or
|
||||
* (at your option) any later version, with one exception:
|
||||
*
|
||||
* The exception is that if you link the Harbour Runtime Library (HRL)
|
||||
* and/or the Harbour Virtual Machine (HVM) 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 HRL
|
||||
* and/or HVM code into it.
|
||||
*
|
||||
* 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 program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
|
||||
* their web site at http://www.gnu.org/).
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HB_TRACE_H_
|
||||
#define HB_TRACE_H_
|
||||
|
||||
#if defined(HB_DO_TRACE)
|
||||
|
||||
extern char* hb_tr_file_;
|
||||
extern int hb_tr_line_;
|
||||
|
||||
void hb_tr_trace(char* fmt, ...);
|
||||
|
||||
#define HB_TRACE(x) \
|
||||
do { \
|
||||
hb_tr_file_ = __FILE__; \
|
||||
hb_tr_line_ = __LINE__; \
|
||||
hb_tr_trace x ; \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define TRACE(x)
|
||||
|
||||
#endif /* #if defined(HB_DO_TRACE) */
|
||||
|
||||
#endif /* HB_TRACE_H_ */
|
||||
@@ -5,6 +5,7 @@
|
||||
ROOT = ../
|
||||
|
||||
DIRS=\
|
||||
common \
|
||||
pp \
|
||||
compiler \
|
||||
rtl \
|
||||
|
||||
14
harbour/source/common/Makefile
Normal file
14
harbour/source/common/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
|
||||
ROOT = ../../
|
||||
|
||||
C_SOURCES=\
|
||||
hbtrace.c \
|
||||
|
||||
PRG_SOURCES=\
|
||||
|
||||
LIBNAME=common
|
||||
|
||||
include $(TOP)$(ROOT)config/lib.cf
|
||||
74
harbour/source/common/hbtrace.c
Normal file
74
harbour/source/common/hbtrace.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/*
|
||||
* Harbour Project source code:
|
||||
* Tracing functions.
|
||||
*
|
||||
* Copyright 1999 Gonzalo Diethelm <gonzalo.diethelm@iname.com>
|
||||
* www - http://www.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 of the License, or
|
||||
* (at your option) any later version, with one exception:
|
||||
*
|
||||
* The exception is that if you link the Harbour Runtime Library (HRL)
|
||||
* and/or the Harbour Virtual Machine (HVM) 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 HRL
|
||||
* and/or HVM code into it.
|
||||
*
|
||||
* 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 program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
|
||||
* their web site at http://www.gnu.org/).
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(HB_DO_TRACE)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include "hbtrace.h"
|
||||
|
||||
char* hb_tr_file_ = "";
|
||||
int hb_tr_line_ = 0;
|
||||
|
||||
void hb_tr_trace(char* fmt, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
char file[256];
|
||||
int i, j;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsprintf(buf, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
for (i = 0; hb_tr_file_[i] != '\0'; ++i) {
|
||||
if (hb_tr_file_[i] != '.' &&
|
||||
hb_tr_file_[i] != '/' &&
|
||||
hb_tr_file_[i] != '\\')
|
||||
break;
|
||||
}
|
||||
for (j = 0; hb_tr_file_[i] != '\0'; ++i, ++j) {
|
||||
file[j] = hb_tr_file_[i];
|
||||
}
|
||||
file[j] = '\0';
|
||||
|
||||
fprintf(stderr, "%s:%d: %s\n",
|
||||
file, hb_tr_line_, buf);
|
||||
|
||||
hb_tr_file_ = "";
|
||||
hb_tr_line_ = 0;
|
||||
}
|
||||
|
||||
#endif /* #if defined(HB_DO_TRACE) */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,14 +34,14 @@
|
||||
*/
|
||||
|
||||
#if ( defined(_MSC_VER) || defined(__IBMCPP__) || defined(__MINW32__) )
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#elif ( defined(__GNUC__) || defined(__WATCOMC__) )
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#include <alloc.h>
|
||||
#include <mem.h>
|
||||
#include <alloc.h>
|
||||
#include <mem.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include "hbpp.h"
|
||||
@@ -58,129 +58,137 @@ FILE * yyppo;
|
||||
|
||||
void Hbpp_init( void )
|
||||
{
|
||||
lenBuffer = 10;
|
||||
iBuffer = 10;
|
||||
aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 );
|
||||
HB_TRACE(("Hbpp_init()"));
|
||||
|
||||
lenBuffer = 10;
|
||||
iBuffer = 10;
|
||||
aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 );
|
||||
}
|
||||
|
||||
int PreProcess( FILE * handl_i, FILE * handl_o, char * sOut )
|
||||
{
|
||||
static char sBuffer[ BUFF_SIZE ]; /* File read buffer */
|
||||
char *ptr, *ptrOut = sOut;
|
||||
int lContinue = 0;
|
||||
int lens = 0, rdlen;
|
||||
int rezParse;
|
||||
static char sBuffer[ BUFF_SIZE ]; /* File read buffer */
|
||||
char *ptr, *ptrOut = sOut;
|
||||
int lContinue = 0;
|
||||
int lens = 0, rdlen;
|
||||
int rezParse;
|
||||
|
||||
HB_SYMBOL_UNUSED( handl_o );
|
||||
HB_TRACE(("PreProcess(%p, %p, %s)",
|
||||
handl_i, handl_o, sOut));
|
||||
|
||||
while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue,
|
||||
sBuffer, &lenBuffer, &iBuffer ) ) >= 0 )
|
||||
{
|
||||
HB_SYMBOL_UNUSED( handl_o );
|
||||
|
||||
while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue,
|
||||
sBuffer, &lenBuffer, &iBuffer ) ) >= 0 )
|
||||
{
|
||||
if( ! lInclude )
|
||||
nline++;
|
||||
nline++;
|
||||
lens += rdlen;
|
||||
|
||||
if( sLine[ lens - 1 ] == ';' )
|
||||
{
|
||||
lContinue = 1;
|
||||
lens--;
|
||||
lens--;
|
||||
while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--;
|
||||
sLine[ ++lens ] = ' ';
|
||||
sLine[ ++lens ] = '\0';
|
||||
{
|
||||
lContinue = 1;
|
||||
lens--;
|
||||
lens--;
|
||||
while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--;
|
||||
sLine[ ++lens ] = ' ';
|
||||
sLine[ ++lens ] = '\0';
|
||||
|
||||
*ptrOut++ = '\n';
|
||||
}
|
||||
*ptrOut++ = '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
lContinue = 0;
|
||||
lens = 0;
|
||||
}
|
||||
{
|
||||
lContinue = 0;
|
||||
lens = 0;
|
||||
}
|
||||
|
||||
if( !lContinue )
|
||||
{
|
||||
if( *sLine != '\0' )
|
||||
{
|
||||
ptr = sLine;
|
||||
SKIPTABSPACES( ptr );
|
||||
if( *ptr == '#' )
|
||||
{
|
||||
if( ( rezParse = ParseDirective( ptr + 1 ) ) == 0 )
|
||||
*sLine = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if( nCondCompile == 0 || aCondCompile[ nCondCompile - 1 ] )
|
||||
{
|
||||
if( ( rezParse = ParseExpression( ptr, sOutLine ) ) > 0 )
|
||||
{
|
||||
printf( "\nError number %u in line %u\n", rezParse, nline );
|
||||
}
|
||||
}
|
||||
else
|
||||
*sLine = '\0';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( rdlen < 0 ) return 0;
|
||||
{
|
||||
if( *sLine != '\0' )
|
||||
{
|
||||
ptr = sLine;
|
||||
SKIPTABSPACES( ptr );
|
||||
if( *ptr == '#' )
|
||||
{
|
||||
if( ( rezParse = ParseDirective( ptr + 1 ) ) == 0 )
|
||||
*sLine = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if( nCondCompile == 0 || aCondCompile[ nCondCompile - 1 ] )
|
||||
{
|
||||
if( ( rezParse = ParseExpression( ptr, sOutLine ) ) > 0 )
|
||||
{
|
||||
printf( "\nError number %u in line %u\n", rezParse, nline );
|
||||
}
|
||||
}
|
||||
else
|
||||
*sLine = '\0';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( rdlen < 0 ) return 0;
|
||||
|
||||
lens = strocpy( ptrOut, sLine ) + ( ptrOut - sOut );
|
||||
*( sOut + lens++ ) = '\n';
|
||||
*( sOut + lens ) = '\0';
|
||||
lens = strocpy( ptrOut, sLine ) + ( ptrOut - sOut );
|
||||
*( sOut + lens++ ) = '\n';
|
||||
*( sOut + lens ) = '\0';
|
||||
|
||||
if( _bPPO )
|
||||
pp_WrStr( handl_o, sOut );
|
||||
if( _bPPO )
|
||||
pp_WrStr( handl_o, sOut );
|
||||
|
||||
return lens;
|
||||
return lens;
|
||||
}
|
||||
|
||||
int Hp_Parse( FILE * handl_i, FILE * handl_o )
|
||||
{
|
||||
char * sBuffer = ( char * ) hb_xgrab( BUFF_SIZE ); /* File read buffer */
|
||||
char * ptr;
|
||||
int lContinue = 0;
|
||||
int iBuffer = 10, lenBuffer = 10;
|
||||
int lens = 0, rdlen;
|
||||
while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue,
|
||||
sBuffer, &lenBuffer, &iBuffer ) ) >= 0 )
|
||||
{
|
||||
char * sBuffer = ( char * ) hb_xgrab( BUFF_SIZE ); /* File read buffer */
|
||||
char * ptr;
|
||||
int lContinue = 0;
|
||||
int iBuffer = 10, lenBuffer = 10;
|
||||
int lens = 0, rdlen;
|
||||
|
||||
HB_TRACE(("Hp_Parse(%p, %p)", handl_i, handl_o));
|
||||
|
||||
while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue,
|
||||
sBuffer, &lenBuffer, &iBuffer ) ) >= 0 )
|
||||
{
|
||||
lens += rdlen;
|
||||
|
||||
if( sLine[ lens - 1 ] == ';' )
|
||||
{
|
||||
lContinue = 1;
|
||||
lens--;
|
||||
lens--;
|
||||
while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--;
|
||||
sLine[ ++lens ] = ' ';
|
||||
sLine[ ++lens ] = '\0';
|
||||
}
|
||||
{
|
||||
lContinue = 1;
|
||||
lens--;
|
||||
lens--;
|
||||
while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--;
|
||||
sLine[ ++lens ] = ' ';
|
||||
sLine[ ++lens ] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
lContinue = 0;
|
||||
lens = 0;
|
||||
}
|
||||
{
|
||||
lContinue = 0;
|
||||
lens = 0;
|
||||
}
|
||||
|
||||
if( !lContinue )
|
||||
{
|
||||
if( *sLine != '\0' )
|
||||
{
|
||||
ptr = sLine;
|
||||
SKIPTABSPACES( ptr );
|
||||
if( *ptr == '#' )
|
||||
{
|
||||
ParseDirective( ptr + 1 );
|
||||
*sLine = '\0';
|
||||
}
|
||||
else
|
||||
GenWarning( _szPWarnings, 'I', WARN_NONDIRECTIVE, NULL, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
if( *sLine != '\0' )
|
||||
{
|
||||
ptr = sLine;
|
||||
SKIPTABSPACES( ptr );
|
||||
if( *ptr == '#' )
|
||||
{
|
||||
ParseDirective( ptr + 1 );
|
||||
*sLine = '\0';
|
||||
}
|
||||
else
|
||||
GenWarning( _szPWarnings, 'I', WARN_NONDIRECTIVE, NULL, NULL );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hb_xfree( sBuffer );
|
||||
hb_xfree( sBuffer );
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ jmp_buf s_env;
|
||||
*/
|
||||
HARBOUR HB___PREPROCESS( void )
|
||||
{
|
||||
if( ISCHAR( 1 ) )
|
||||
{
|
||||
if( ISCHAR( 1 ) )
|
||||
{
|
||||
char * pText = ( char * ) hb_xgrab( STR_SIZE );
|
||||
char * pOut = ( char * ) hb_xgrab( STR_SIZE );
|
||||
char * ptr = pText;
|
||||
@@ -70,51 +70,57 @@ HARBOUR HB___PREPROCESS( void )
|
||||
SKIPTABSPACES( ptr );
|
||||
|
||||
if( setjmp( s_env ) == 0 )
|
||||
{
|
||||
int resParse;
|
||||
{
|
||||
int resParse;
|
||||
|
||||
if( ( resParse = ParseExpression( ptr, pOut ) ) > 0 )
|
||||
{
|
||||
/* Some error here? */
|
||||
}
|
||||
hb_retc( pText ); /* Preprocessor returns parsed line in input buffer */
|
||||
}
|
||||
if( ( resParse = ParseExpression( ptr, pOut ) ) > 0 )
|
||||
{
|
||||
/* Some error here? */
|
||||
}
|
||||
hb_retc( pText ); /* Preprocessor returns parsed line in input buffer */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* an error occured during parsing.
|
||||
* The longjmp was used in GenError()
|
||||
*/
|
||||
hb_retc( "ERROR" );
|
||||
}
|
||||
{
|
||||
/* an error occured during parsing.
|
||||
* The longjmp was used in GenError()
|
||||
*/
|
||||
hb_retc( "ERROR" );
|
||||
}
|
||||
|
||||
hb_xfree( pText );
|
||||
hb_xfree( pOut );
|
||||
}
|
||||
else
|
||||
hb_retc( "" );
|
||||
}
|
||||
else
|
||||
hb_retc( "" );
|
||||
}
|
||||
|
||||
void GenError( char * _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 )
|
||||
{
|
||||
/* TODO: The internal buffers allocated by the preprocessor should be
|
||||
* deallocated here
|
||||
*/
|
||||
printf( "Error %c%i ", cPrefix, iError );
|
||||
printf( _szErrors[ iError - 1 ], szError1, szError2 );
|
||||
printf( hb_consoleGetNewLine() );
|
||||
printf( hb_consoleGetNewLine() );
|
||||
HB_TRACE(("GenError(%p, %c, %d, %s, %s)",
|
||||
_szErrors, cPrefix, iError, szError1, szError2));
|
||||
|
||||
longjmp( s_env, iError );
|
||||
/* TODO: The internal buffers allocated by the preprocessor should be
|
||||
* deallocated here
|
||||
*/
|
||||
printf( "Error %c%i ", cPrefix, iError );
|
||||
printf( _szErrors[ iError - 1 ], szError1, szError2 );
|
||||
printf( hb_consoleGetNewLine() );
|
||||
printf( hb_consoleGetNewLine() );
|
||||
|
||||
longjmp( s_env, iError );
|
||||
}
|
||||
|
||||
void GenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarning1, char * szWarning2)
|
||||
{
|
||||
/* NOTE:
|
||||
* All warnings are simply ignored
|
||||
*/
|
||||
HB_SYMBOL_UNUSED( _szWarnings );
|
||||
HB_SYMBOL_UNUSED( cPrefix );
|
||||
HB_SYMBOL_UNUSED( iWarning );
|
||||
HB_SYMBOL_UNUSED( szWarning1 );
|
||||
HB_SYMBOL_UNUSED( szWarning2 );
|
||||
HB_TRACE(("GenWarning(%p, %c, %d, %s, %s)",
|
||||
_szWarnings, cPrefix, iWarning, szWarning1, szWarning2));
|
||||
|
||||
/* NOTE:
|
||||
* All warnings are simply ignored
|
||||
*/
|
||||
HB_SYMBOL_UNUSED( _szWarnings );
|
||||
HB_SYMBOL_UNUSED( cPrefix );
|
||||
HB_SYMBOL_UNUSED( iWarning );
|
||||
HB_SYMBOL_UNUSED( szWarning1 );
|
||||
HB_SYMBOL_UNUSED( szWarning2 );
|
||||
}
|
||||
|
||||
@@ -10,5 +10,6 @@ C_MAIN=hbpp.c
|
||||
|
||||
LIBS=\
|
||||
pp \
|
||||
common \
|
||||
|
||||
include $(TOP)$(ROOT)config/bin.cf
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#if ( defined(_MSC_VER) || defined(__IBMCPP__) || defined(__MINGW32__) )
|
||||
#include <memory.h>
|
||||
#include <memory.h>
|
||||
#elif defined(__GNUC__)
|
||||
#include <unistd.h>
|
||||
#include <unistd.h>
|
||||
#elif ! defined(__MPW__)
|
||||
#include <malloc.h>
|
||||
#include <malloc.h>
|
||||
#else
|
||||
#include <mem.h>
|
||||
#include <mem.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -65,90 +65,92 @@ int _iWarnings = 0;
|
||||
|
||||
int main( int argc, char * argv[] )
|
||||
{
|
||||
FILE * handl_i;
|
||||
FILE * handl_o;
|
||||
char szFileName[ _POSIX_PATH_MAX ];
|
||||
char * szDefText;
|
||||
int iArg = 1, i;
|
||||
BOOL bOutTable = FALSE;
|
||||
BOOL bOutNew = FALSE;
|
||||
DEFINES * stdef = topDefine;
|
||||
COMMANDS * stcmd = topCommand;
|
||||
FILE * handl_i;
|
||||
FILE * handl_o;
|
||||
char szFileName[ _POSIX_PATH_MAX ];
|
||||
char * szDefText;
|
||||
int iArg = 1, i;
|
||||
BOOL bOutTable = FALSE;
|
||||
BOOL bOutNew = FALSE;
|
||||
DEFINES * stdef = topDefine;
|
||||
COMMANDS * stcmd = topCommand;
|
||||
|
||||
printf( "Harbour Preprocessor, Build %i%s (%04d.%02d.%02d)\n",
|
||||
hb_build, hb_revision, hb_year, hb_month, hb_day );
|
||||
printf( "Copyright 1999, http://www.harbour-project.org\n" );
|
||||
HB_TRACE(("main(%d, %p)", argc, argv));
|
||||
|
||||
while( iArg < argc )
|
||||
{
|
||||
printf( "Harbour Preprocessor, Build %i%s (%04d.%02d.%02d)\n",
|
||||
hb_build, hb_revision, hb_year, hb_month, hb_day );
|
||||
printf( "Copyright 1999, http://www.harbour-project.org\n" );
|
||||
|
||||
while( iArg < argc )
|
||||
{
|
||||
if( IS_OPT_SEP(argv[ iArg ][ 0 ]))
|
||||
{
|
||||
switch( argv[ iArg ][ 1 ] )
|
||||
{
|
||||
{
|
||||
switch( argv[ iArg ][ 1 ] )
|
||||
{
|
||||
case 'd':
|
||||
case 'D': /* defines a #define from the command line */
|
||||
{
|
||||
i = 0;
|
||||
szDefText = strodup( argv[ iArg ] + 2 );
|
||||
while( i < strolen( szDefText ) && szDefText[ i ] != '=' )
|
||||
i++;
|
||||
if( szDefText[ i ] != '=' )
|
||||
AddDefine( szDefText, 0 );
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
szDefText = strodup( argv[ iArg ] + 2 );
|
||||
while( i < strolen( szDefText ) && szDefText[ i ] != '=' )
|
||||
i++;
|
||||
if( szDefText[ i ] != '=' )
|
||||
AddDefine( szDefText, 0 );
|
||||
else
|
||||
{
|
||||
szDefText[ i ] = 0;
|
||||
AddDefine( szDefText, szDefText + i + 1 );
|
||||
szDefText[ i ] = 0;
|
||||
AddDefine( szDefText, szDefText + i + 1 );
|
||||
}
|
||||
free( szDefText );
|
||||
}
|
||||
break;
|
||||
free( szDefText );
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
case 'I':
|
||||
AddSearchPath( argv[ iArg ]+2, &_pIncludePath );
|
||||
break;
|
||||
AddSearchPath( argv[ iArg ]+2, &_pIncludePath );
|
||||
break;
|
||||
case 'o':
|
||||
case 'O':
|
||||
bOutTable = TRUE;
|
||||
break;
|
||||
bOutTable = TRUE;
|
||||
break;
|
||||
case 'n':
|
||||
case 'N':
|
||||
bOutNew = TRUE;
|
||||
break;
|
||||
bOutNew = TRUE;
|
||||
break;
|
||||
case 'w':
|
||||
case 'W':
|
||||
_iWarnings = 1;
|
||||
if( argv[ iArg ][ 2 ] )
|
||||
{ /*there is -w<0,1,2,3> probably */
|
||||
_iWarnings = 1;
|
||||
if( argv[ iArg ][ 2 ] )
|
||||
{ /*there is -w<0,1,2,3> probably */
|
||||
_iWarnings = argv[ iArg ][ 2 ] - '0';
|
||||
if( _iWarnings < 0 || _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;
|
||||
}
|
||||
}
|
||||
printf( "\nInvalid command line option: %s\n", &argv[ iArg ][ 1 ] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else _pFileName = hb_fsFNameSplit( argv[ iArg ] );
|
||||
iArg++;
|
||||
}
|
||||
if( _pFileName )
|
||||
{
|
||||
}
|
||||
if( _pFileName )
|
||||
{
|
||||
if( ! _pFileName->szExtension )
|
||||
_pFileName->szExtension =".prg";
|
||||
_pFileName->szExtension =".prg";
|
||||
|
||||
hb_fsFNameMerge( szFileName, _pFileName );
|
||||
|
||||
if( ( handl_i = fopen( szFileName, "r" ) ) == NULL )
|
||||
{
|
||||
printf("\nCan't open %s\n", szFileName );
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
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>"
|
||||
@@ -160,265 +162,269 @@ int main( int argc, char * argv[] )
|
||||
, argv[ 0 ] );
|
||||
|
||||
if( bOutTable )
|
||||
OutTable( NULL, NULL );
|
||||
OutTable( NULL, NULL );
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
_pFileName->szExtension = ".ppo";
|
||||
hb_fsFNameMerge( szFileName, _pFileName );
|
||||
_pFileName->szExtension = ".ppo";
|
||||
hb_fsFNameMerge( szFileName, _pFileName );
|
||||
|
||||
if( ( handl_o = fopen( szFileName, "wt" ) ) == NULL )
|
||||
{
|
||||
if( ( handl_o = fopen( szFileName, "wt" ) ) == NULL )
|
||||
{
|
||||
printf("\nCan't open %s\n", szFileName );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char * szInclude = getenv( "INCLUDE" );
|
||||
{
|
||||
char * szInclude = getenv( "INCLUDE" );
|
||||
|
||||
if( szInclude )
|
||||
if( szInclude )
|
||||
{
|
||||
char * pPath;
|
||||
char * pDelim;
|
||||
char * pPath;
|
||||
char * pDelim;
|
||||
|
||||
pPath = szInclude = strodup( szInclude );
|
||||
while( ( pDelim = strchr( pPath, OS_PATH_LIST_SEPARATOR ) ) != NULL )
|
||||
{
|
||||
pPath = szInclude = strodup( szInclude );
|
||||
while( ( pDelim = strchr( pPath, OS_PATH_LIST_SEPARATOR ) ) != NULL )
|
||||
{
|
||||
*pDelim = '\0';
|
||||
AddSearchPath( pPath, &_pIncludePath );
|
||||
pPath = pDelim + 1;
|
||||
}
|
||||
AddSearchPath( pPath, &_pIncludePath );
|
||||
}
|
||||
AddSearchPath( pPath, &_pIncludePath );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 );
|
||||
aCondCompile = ( int * ) hb_xgrab( sizeof( int ) * 5 );
|
||||
|
||||
Hp_Parse( handl_i, handl_o );
|
||||
fclose( handl_i );
|
||||
fclose( handl_o );
|
||||
Hp_Parse( handl_i, handl_o );
|
||||
fclose( handl_i );
|
||||
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;
|
||||
}
|
||||
|
||||
int Hp_Parse( FILE * handl_i, FILE * handl_o )
|
||||
{
|
||||
char sBuffer[ BUFF_SIZE ]; /* File read buffer */
|
||||
char * ptr;
|
||||
int lContinue = 0;
|
||||
int iBuffer = 10, lenBuffer = 10;
|
||||
int lens = 0, rdlen;
|
||||
char sBuffer[ BUFF_SIZE ]; /* File read buffer */
|
||||
char * ptr;
|
||||
int lContinue = 0;
|
||||
int iBuffer = 10, lenBuffer = 10;
|
||||
int lens = 0, rdlen;
|
||||
|
||||
while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue,
|
||||
sBuffer, &lenBuffer, &iBuffer ) ) >= 0 )
|
||||
{
|
||||
HB_TRACE(("Hp_parse(%p, %p)", handl_i, handl_o));
|
||||
|
||||
while( ( rdlen = pp_RdStr( handl_i, sLine + lens, STR_SIZE - lens, lContinue,
|
||||
sBuffer, &lenBuffer, &iBuffer ) ) >= 0 )
|
||||
{
|
||||
if( ! lInclude ) nline++;
|
||||
lens += rdlen;
|
||||
|
||||
if( sLine[ lens - 1 ] == ';' )
|
||||
{
|
||||
lContinue = 1;
|
||||
lens--;
|
||||
lens--;
|
||||
while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--;
|
||||
sLine[ ++lens ] = ' ';
|
||||
sLine[ ++lens ] = '\0';
|
||||
}
|
||||
{
|
||||
lContinue = 1;
|
||||
lens--;
|
||||
lens--;
|
||||
while( sLine[ lens ] == ' ' || sLine[ lens ] == '\t' ) lens--;
|
||||
sLine[ ++lens ] = ' ';
|
||||
sLine[ ++lens ] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
lContinue = 0;
|
||||
lens = 0;
|
||||
}
|
||||
{
|
||||
lContinue = 0;
|
||||
lens = 0;
|
||||
}
|
||||
|
||||
if( *sLine != '\0' && !lContinue )
|
||||
{
|
||||
printf( "\r line %i", nline );
|
||||
ptr = sLine;
|
||||
SKIPTABSPACES( ptr );
|
||||
if( *ptr == '#' )
|
||||
{
|
||||
if( ParseDirective( ptr + 1 ) == 0 )
|
||||
*sLine = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if( nCondCompile == 0 || aCondCompile[ nCondCompile - 1 ] )
|
||||
ParseExpression( ptr, sOutLine );
|
||||
else
|
||||
*sLine = '\0';
|
||||
}
|
||||
}
|
||||
{
|
||||
printf( "\r line %i", nline );
|
||||
ptr = sLine;
|
||||
SKIPTABSPACES( ptr );
|
||||
if( *ptr == '#' )
|
||||
{
|
||||
if( ParseDirective( ptr + 1 ) == 0 )
|
||||
*sLine = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
if( nCondCompile == 0 || aCondCompile[ nCondCompile - 1 ] )
|
||||
ParseExpression( ptr, sOutLine );
|
||||
else
|
||||
*sLine = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if( ! lInclude )
|
||||
{
|
||||
if( lContinue ) pp_WrStr( handl_o, "\n" );
|
||||
else pp_WrStr( handl_o, sLine );
|
||||
}
|
||||
}
|
||||
{
|
||||
if( lContinue ) pp_WrStr( handl_o, "\n" );
|
||||
else pp_WrStr( handl_o, sLine );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OutTable( DEFINES * endDefine, COMMANDS * endCommand )
|
||||
{
|
||||
FILE *handl_o;
|
||||
int ipos, len_mpatt, len_value;
|
||||
int num;
|
||||
DEFINES * stdef1 = topDefine, * stdef2 = NULL, * stdef3;
|
||||
COMMANDS * stcmd1 = topCommand, * stcmd2 = NULL, * stcmd3;
|
||||
FILE *handl_o;
|
||||
int ipos, len_mpatt, len_value;
|
||||
int num;
|
||||
DEFINES * stdef1 = topDefine, * stdef2 = NULL, * stdef3;
|
||||
COMMANDS * stcmd1 = topCommand, * stcmd2 = NULL, * stcmd3;
|
||||
|
||||
while( stdef1 != endDefine )
|
||||
{
|
||||
HB_TRACE(("OutTable(%p, %p)", endDefine, endCommand));
|
||||
|
||||
while( stdef1 != endDefine )
|
||||
{
|
||||
stdef3 = stdef1->last;
|
||||
stdef1->last = stdef2;
|
||||
stdef2 = stdef1;
|
||||
stdef1 = stdef3;
|
||||
}
|
||||
while( stcmd1 != endCommand )
|
||||
{
|
||||
}
|
||||
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 *topDefine = " );
|
||||
if( num == 1 )
|
||||
fprintf( handl_o, "NULL;" );
|
||||
else
|
||||
fprintf( handl_o, " = &sD___%i;\n", num - 1 );
|
||||
}
|
||||
fprintf( handl_o, "\n DEFINES *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 = strocpy( sLine, stcmd2->mpatt );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_mpatt ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_mpatt );
|
||||
len_mpatt++;
|
||||
}
|
||||
fprintf( handl_o, "\"%s\",", sLine );
|
||||
}
|
||||
{
|
||||
len_mpatt = strocpy( sLine, stcmd2->mpatt );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_mpatt ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_mpatt );
|
||||
len_mpatt++;
|
||||
}
|
||||
fprintf( handl_o, "\"%s\",", sLine );
|
||||
}
|
||||
else
|
||||
fprintf( handl_o, "NULL," );
|
||||
fprintf( handl_o, "NULL," );
|
||||
if( stcmd2->value != NULL )
|
||||
{
|
||||
len_value = strocpy( sLine, stcmd2->value );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_value ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_value );
|
||||
len_value++;
|
||||
}
|
||||
if( len_mpatt + len_value > 80 )
|
||||
{
|
||||
len_value = strocpy( sLine, stcmd2->value );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_value ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_value );
|
||||
len_value++;
|
||||
}
|
||||
if( len_mpatt + len_value > 80 )
|
||||
fprintf( handl_o, "\n " );
|
||||
fprintf( handl_o, "\"%s\"", sLine );
|
||||
}
|
||||
fprintf( handl_o, "\"%s\"", sLine );
|
||||
}
|
||||
else fprintf( handl_o, "NULL" );
|
||||
if( num == 1 )
|
||||
fprintf( handl_o, ",NULL };" );
|
||||
fprintf( handl_o, ",NULL };" );
|
||||
else
|
||||
fprintf( handl_o, ",&sC___%i };", num - 1 );
|
||||
fprintf( handl_o, ",&sC___%i };", num - 1 );
|
||||
stcmd2 = stcmd2->last;
|
||||
num++;
|
||||
}
|
||||
fprintf( handl_o, "\n COMMANDS *topCommand = " );
|
||||
if( num == 1 )
|
||||
fprintf( handl_o, "NULL;" );
|
||||
else
|
||||
fprintf( handl_o, " = &sC___%i;\n", num - 1 );
|
||||
}
|
||||
fprintf( handl_o, "\n COMMANDS *topCommand = " );
|
||||
if( num == 1 )
|
||||
fprintf( handl_o, "NULL;" );
|
||||
else
|
||||
fprintf( handl_o, " = &sC___%i;\n", num - 1 );
|
||||
|
||||
stcmd1 = topTranslate;
|
||||
stcmd2 = NULL;
|
||||
while( stcmd1 != NULL )
|
||||
{
|
||||
stcmd1 = topTranslate;
|
||||
stcmd2 = NULL;
|
||||
while( stcmd1 != NULL )
|
||||
{
|
||||
stcmd3 = stcmd1->last;
|
||||
stcmd1->last = stcmd2;
|
||||
stcmd2 = stcmd1;
|
||||
stcmd1 = stcmd3;
|
||||
}
|
||||
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 = strocpy( sLine, stcmd2->mpatt );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_mpatt ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_mpatt );
|
||||
len_mpatt++;
|
||||
}
|
||||
fprintf( handl_o, "\"%s\",", sLine );
|
||||
}
|
||||
{
|
||||
len_mpatt = strocpy( sLine, stcmd2->mpatt );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_mpatt ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_mpatt );
|
||||
len_mpatt++;
|
||||
}
|
||||
fprintf( handl_o, "\"%s\",", sLine );
|
||||
}
|
||||
else
|
||||
fprintf( handl_o, "NULL," );
|
||||
fprintf( handl_o, "NULL," );
|
||||
if( stcmd2->value != NULL )
|
||||
{
|
||||
len_value = strocpy( sLine, stcmd2->value );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_value ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_value );
|
||||
len_value++;
|
||||
}
|
||||
if( len_mpatt + len_value > 80 )
|
||||
{
|
||||
len_value = strocpy( sLine, stcmd2->value );
|
||||
while( ( ipos = pp_strAt( "\1", 1, sLine, len_value ) ) > 0 )
|
||||
{
|
||||
pp_Stuff( "\\1", sLine + ipos - 1, 2, 1, len_value );
|
||||
len_value++;
|
||||
}
|
||||
if( len_mpatt + len_value > 80 )
|
||||
fprintf( handl_o, "\n " );
|
||||
fprintf( handl_o, "\"%s\"", sLine );
|
||||
}
|
||||
fprintf( handl_o, "\"%s\"", sLine );
|
||||
}
|
||||
else fprintf( handl_o, "NULL" );
|
||||
if( num == 1 )
|
||||
fprintf( handl_o, ",NULL };" );
|
||||
fprintf( handl_o, ",NULL };" );
|
||||
else
|
||||
fprintf( handl_o, ",&sC___%i };", num - 1 );
|
||||
fprintf( handl_o, ",&sC___%i };", num - 1 );
|
||||
stcmd2 = stcmd2->last;
|
||||
num++;
|
||||
}
|
||||
fprintf( handl_o, "\n COMMANDS *topTranslate = " );
|
||||
if( num == 1 )
|
||||
fprintf( handl_o, "NULL;" );
|
||||
else
|
||||
fprintf( handl_o, " = &sT___%i;", num );
|
||||
}
|
||||
fprintf( handl_o, "\n COMMANDS *topTranslate = " );
|
||||
if( num == 1 )
|
||||
fprintf( handl_o, "NULL;" );
|
||||
else
|
||||
fprintf( handl_o, " = &sT___%i;", num );
|
||||
|
||||
fclose( handl_o );
|
||||
fclose( handl_o );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -426,47 +432,55 @@ void OutTable( DEFINES * endDefine, COMMANDS * endCommand )
|
||||
*/
|
||||
void AddSearchPath( char * szPath, PATHNAMES * * pSearchList )
|
||||
{
|
||||
PATHNAMES * pPath = *pSearchList;
|
||||
PATHNAMES * pPath = *pSearchList;
|
||||
|
||||
if( pPath )
|
||||
{
|
||||
HB_TRACE(("AddSearchPath(%s, %p)", szPath, pSearchList));
|
||||
|
||||
if( pPath )
|
||||
{
|
||||
while( pPath->pNext )
|
||||
pPath = pPath->pNext;
|
||||
pPath = pPath->pNext;
|
||||
pPath->pNext = ( PATHNAMES * ) hb_xgrab( sizeof( PATHNAMES ) );
|
||||
pPath = pPath->pNext;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
*pSearchList = pPath = ( PATHNAMES * ) hb_xgrab( sizeof( PATHNAMES ) );
|
||||
}
|
||||
pPath->pNext = NULL;
|
||||
pPath->szPath = szPath;
|
||||
}
|
||||
pPath->pNext = NULL;
|
||||
pPath->szPath = szPath;
|
||||
}
|
||||
|
||||
void GenError( char * _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 )
|
||||
{
|
||||
printf( "\r(%i) ", nline );
|
||||
printf( "Error %c%04i ", cPrefix, iError );
|
||||
printf( _szErrors[ iError - 1 ], szError1, szError2 );
|
||||
printf( "\n\n" );
|
||||
HB_TRACE(("GenError(%p, %c, %d, %s, %s)",
|
||||
_szErrors, cPrefix, iError, szError1, szError2));
|
||||
|
||||
exit( EXIT_FAILURE );
|
||||
printf( "\r(%i) ", nline );
|
||||
printf( "Error %c%04i ", cPrefix, iError );
|
||||
printf( _szErrors[ iError - 1 ], szError1, szError2 );
|
||||
printf( "\n\n" );
|
||||
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
void GenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarning1, char * szWarning2)
|
||||
{
|
||||
if( _iWarnings )
|
||||
{
|
||||
HB_TRACE(("GenWarning(%p, %c, %d, %s, %s)",
|
||||
_szWarnings, cPrefix, iWarning, szWarning1, szWarning2));
|
||||
|
||||
if( _iWarnings )
|
||||
{
|
||||
char *szText = _szWarnings[ iWarning - 1 ];
|
||||
|
||||
if( (szText[ 0 ] - '0') <= _iWarnings )
|
||||
{
|
||||
printf( "\r(%i) ", nline );
|
||||
printf( "Warning %c%04i ", cPrefix, iWarning );
|
||||
printf( szText + 1, szWarning1, szWarning2 );
|
||||
printf( "\n" );
|
||||
}
|
||||
}
|
||||
{
|
||||
printf( "\r(%i) ", nline );
|
||||
printf( "Warning %c%04i ", cPrefix, iWarning );
|
||||
printf( szText + 1, szWarning1, szWarning2 );
|
||||
printf( "\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define IS_PATH_SEP( c ) ( strchr( OS_PATH_DELIMITER_LIST, ( c ) ) != NULL )
|
||||
@@ -474,103 +488,107 @@ void GenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarni
|
||||
/* Split given filename into path, name and extension */
|
||||
PHB_FNAME hb_fsFNameSplit( char * szFileName )
|
||||
{
|
||||
PHB_FNAME pFileName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) );
|
||||
PHB_FNAME pFileName = ( PHB_FNAME ) hb_xgrab( sizeof( HB_FNAME ) );
|
||||
|
||||
int iLen = strlen( szFileName );
|
||||
int iSlashPos;
|
||||
int iDotPos;
|
||||
int iPos;
|
||||
int iLen = strlen( szFileName );
|
||||
int iSlashPos;
|
||||
int iDotPos;
|
||||
int iPos;
|
||||
|
||||
pFileName->szPath =
|
||||
pFileName->szName =
|
||||
pFileName->szExtension = NULL;
|
||||
HB_TRACE(("hb_fsFNameSplit(%s)", szFileName));
|
||||
|
||||
iSlashPos = iLen - 1;
|
||||
iPos = 0;
|
||||
pFileName->szPath =
|
||||
pFileName->szName =
|
||||
pFileName->szExtension = NULL;
|
||||
|
||||
while( iSlashPos >= 0 && !IS_PATH_SEP( szFileName[ iSlashPos ] ) )
|
||||
--iSlashPos;
|
||||
iSlashPos = iLen - 1;
|
||||
iPos = 0;
|
||||
|
||||
if( iSlashPos == 0 )
|
||||
{
|
||||
while( iSlashPos >= 0 && !IS_PATH_SEP( szFileName[ iSlashPos ] ) )
|
||||
--iSlashPos;
|
||||
|
||||
if( iSlashPos == 0 )
|
||||
{
|
||||
/* root path -> \filename */
|
||||
pFileName->szBuffer[ 0 ] = OS_PATH_DELIMITER;
|
||||
pFileName->szBuffer[ 1 ] = '\0';
|
||||
pFileName->szPath = pFileName->szBuffer;
|
||||
iPos = 2; /* first free position after the slash */
|
||||
}
|
||||
else if( iSlashPos > 0 )
|
||||
{
|
||||
}
|
||||
else if( iSlashPos > 0 )
|
||||
{
|
||||
/* If we are after a drive letter let's keep the following backslash */
|
||||
if( IS_PATH_SEP( ':' ) &&
|
||||
( szFileName[ iSlashPos ] == ':' || szFileName[ iSlashPos - 1 ] == ':' ) )
|
||||
{
|
||||
/* path with separator -> d:\path\filename or d:path\filename */
|
||||
memcpy( pFileName->szBuffer, szFileName, iSlashPos + 1 );
|
||||
pFileName->szBuffer[ iSlashPos + 1 ] = '\0';
|
||||
iPos = iSlashPos + 2; /* first free position after the slash */
|
||||
}
|
||||
( szFileName[ iSlashPos ] == ':' || szFileName[ iSlashPos - 1 ] == ':' ) )
|
||||
{
|
||||
/* path with separator -> d:\path\filename or d:path\filename */
|
||||
memcpy( pFileName->szBuffer, szFileName, iSlashPos + 1 );
|
||||
pFileName->szBuffer[ iSlashPos + 1 ] = '\0';
|
||||
iPos = iSlashPos + 2; /* first free position after the slash */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* path with separator -> path\filename */
|
||||
memcpy( pFileName->szBuffer, szFileName, iSlashPos );
|
||||
pFileName->szBuffer[ iSlashPos ] = '\0';
|
||||
iPos = iSlashPos + 1; /* first free position after the slash */
|
||||
}
|
||||
{
|
||||
/* path with separator -> path\filename */
|
||||
memcpy( pFileName->szBuffer, szFileName, iSlashPos );
|
||||
pFileName->szBuffer[ iSlashPos ] = '\0';
|
||||
iPos = iSlashPos + 1; /* first free position after the slash */
|
||||
}
|
||||
|
||||
pFileName->szPath = pFileName->szBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
iDotPos = iLen - 1;
|
||||
while( iDotPos > iSlashPos && szFileName[ iDotPos ] != '.' )
|
||||
--iDotPos;
|
||||
iDotPos = iLen - 1;
|
||||
while( iDotPos > iSlashPos && szFileName[ iDotPos ] != '.' )
|
||||
--iDotPos;
|
||||
|
||||
if( ( iDotPos - iSlashPos ) > 1 )
|
||||
{
|
||||
if( ( iDotPos - iSlashPos ) > 1 )
|
||||
{
|
||||
/* the dot was found
|
||||
* and there is at least one character between a slash and a dot
|
||||
*/
|
||||
if( iDotPos == iLen - 1 )
|
||||
{
|
||||
/* the dot is the last character - use it as extension name */
|
||||
pFileName->szExtension = pFileName->szBuffer + iPos;
|
||||
pFileName->szBuffer[ iPos++ ] = '.';
|
||||
pFileName->szBuffer[ iPos++ ] = '\0';
|
||||
}
|
||||
{
|
||||
/* the dot is the last character - use it as extension name */
|
||||
pFileName->szExtension = pFileName->szBuffer + iPos;
|
||||
pFileName->szBuffer[ iPos++ ] = '.';
|
||||
pFileName->szBuffer[ iPos++ ] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
pFileName->szExtension = pFileName->szBuffer + iPos;
|
||||
/* copy rest of the string with terminating ZERO character */
|
||||
memcpy( pFileName->szExtension, szFileName + iDotPos + 1, iLen - iDotPos );
|
||||
iPos += iLen - iDotPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* there is no dot in the filename or it is '.filename' */
|
||||
iDotPos = iLen;
|
||||
{
|
||||
pFileName->szExtension = pFileName->szBuffer + iPos;
|
||||
/* copy rest of the string with terminating ZERO character */
|
||||
memcpy( pFileName->szExtension, szFileName + iDotPos + 1, iLen - iDotPos );
|
||||
iPos += iLen - iDotPos;
|
||||
}
|
||||
}
|
||||
else
|
||||
/* there is no dot in the filename or it is '.filename' */
|
||||
iDotPos = iLen;
|
||||
|
||||
if( ( iDotPos - iSlashPos - 1 ) > 0 )
|
||||
{
|
||||
if( ( iDotPos - iSlashPos - 1 ) > 0 )
|
||||
{
|
||||
pFileName->szName = pFileName->szBuffer + iPos;
|
||||
memcpy( pFileName->szName, szFileName + iSlashPos + 1, iDotPos - iSlashPos - 1 );
|
||||
pFileName->szName[ iDotPos - iSlashPos - 1 ] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
/* DEBUG
|
||||
printf( "\nFilename: %s\n", szFileName );
|
||||
printf( "\n szPath: %s\n", pFileName->szPath );
|
||||
printf( "\n szName: %s\n", pFileName->szName );
|
||||
printf( "\n szExt: %s\n", pFileName->szExtension );
|
||||
*/
|
||||
/* DEBUG
|
||||
printf( "\nFilename: %s\n", szFileName );
|
||||
printf( "\n szPath: %s\n", pFileName->szPath );
|
||||
printf( "\n szName: %s\n", pFileName->szName );
|
||||
printf( "\n szExt: %s\n", pFileName->szExtension );
|
||||
*/
|
||||
|
||||
return pFileName;
|
||||
return pFileName;
|
||||
}
|
||||
|
||||
/* This function joins path, name and extension into a string with a filename */
|
||||
char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName )
|
||||
{
|
||||
if( pFileName->szPath && pFileName->szPath[ 0 ] )
|
||||
{
|
||||
HB_TRACE(("hb_fsFNameMerge(%s, %p)", szFileName, pFileName));
|
||||
|
||||
if( pFileName->szPath && pFileName->szPath[ 0 ] )
|
||||
{
|
||||
/* we have not empty path specified */
|
||||
int iLen = strlen( pFileName->szPath );
|
||||
|
||||
@@ -578,75 +596,80 @@ char * hb_fsFNameMerge( char * szFileName, PHB_FNAME pFileName )
|
||||
|
||||
/* if the path is a root directory then we don't need to add path separator */
|
||||
if( !( IS_PATH_SEP( pFileName->szPath[ 0 ] ) && pFileName->szPath[ 0 ] == '\0' ) )
|
||||
{
|
||||
/* add the path separator only in cases:
|
||||
* when a name doesn't start with it
|
||||
* when the path doesn't end with it
|
||||
*/
|
||||
if( !( IS_PATH_SEP( pFileName->szName[ 0 ] ) || IS_PATH_SEP( pFileName->szPath[ iLen-1 ] ) ) )
|
||||
{
|
||||
szFileName[ iLen++ ] = OS_PATH_DELIMITER;
|
||||
szFileName[ iLen ] = '\0';
|
||||
}
|
||||
}
|
||||
{
|
||||
/* add the path separator only in cases:
|
||||
* when a name doesn't start with it
|
||||
* when the path doesn't end with it
|
||||
*/
|
||||
if( !( IS_PATH_SEP( pFileName->szName[ 0 ] ) || IS_PATH_SEP( pFileName->szPath[ iLen-1 ] ) ) )
|
||||
{
|
||||
szFileName[ iLen++ ] = OS_PATH_DELIMITER;
|
||||
szFileName[ iLen ] = '\0';
|
||||
}
|
||||
}
|
||||
if( pFileName->szName )
|
||||
strcpy( szFileName + iLen, pFileName->szName );
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy( szFileName + iLen, pFileName->szName );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( pFileName->szName )
|
||||
strcpy( szFileName, pFileName->szName );
|
||||
}
|
||||
strcpy( szFileName, pFileName->szName );
|
||||
}
|
||||
|
||||
if( pFileName->szExtension )
|
||||
{
|
||||
if( pFileName->szExtension )
|
||||
{
|
||||
int iLen = strlen( szFileName );
|
||||
|
||||
if( !( pFileName->szExtension[ 0 ] == '.' || szFileName[ iLen - 1 ] == '.') )
|
||||
{
|
||||
/* add extension separator only when extansion doesn't contain it */
|
||||
szFileName[ iLen++ ] = '.';
|
||||
szFileName[ iLen ] = '\0';
|
||||
}
|
||||
{
|
||||
/* add extension separator only when extansion doesn't contain it */
|
||||
szFileName[ iLen++ ] = '.';
|
||||
szFileName[ iLen ] = '\0';
|
||||
}
|
||||
strcpy( szFileName + iLen, pFileName->szExtension );
|
||||
}
|
||||
}
|
||||
|
||||
/* DEBUG
|
||||
printf( "\nMERGE:\n" );
|
||||
printf( "\n szPath: %s\n", pFileName->szPath );
|
||||
printf( "\n szName: %s\n", pFileName->szName );
|
||||
printf( "\n szExt: %s\n", pFileName->szExtension );
|
||||
printf( "\nFilename result: %s\n", szFileName );
|
||||
*/
|
||||
/* DEBUG
|
||||
printf( "\nMERGE:\n" );
|
||||
printf( "\n szPath: %s\n", pFileName->szPath );
|
||||
printf( "\n szName: %s\n", pFileName->szName );
|
||||
printf( "\n szExt: %s\n", pFileName->szExtension );
|
||||
printf( "\nFilename result: %s\n", szFileName );
|
||||
*/
|
||||
|
||||
return szFileName;
|
||||
return szFileName;
|
||||
}
|
||||
|
||||
void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on failure */
|
||||
{
|
||||
void * pMem = malloc( ulSize );
|
||||
void * pMem = malloc( ulSize );
|
||||
|
||||
if( ! pMem )
|
||||
GenError( _szPErrors, 'P', ERR_PPMEMALLOC, NULL, NULL );
|
||||
HB_TRACE(("hb_xgrab(%lu)", ulSize));
|
||||
|
||||
return pMem;
|
||||
if( ! pMem )
|
||||
GenError( _szPErrors, 'P', ERR_PPMEMALLOC, NULL, NULL );
|
||||
|
||||
return pMem;
|
||||
}
|
||||
|
||||
void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */
|
||||
{
|
||||
void * pResult = realloc( pMem, ulSize );
|
||||
void * pResult = realloc( pMem, ulSize );
|
||||
|
||||
if( ! pResult )
|
||||
GenError( _szPErrors, 'P', ERR_PPMEMREALLOC, NULL, NULL );
|
||||
HB_TRACE(("hb_xrealloc(%p, %lu)", pMem, ulSize));
|
||||
|
||||
return pResult;
|
||||
if( ! pResult )
|
||||
GenError( _szPErrors, 'P', ERR_PPMEMREALLOC, NULL, NULL );
|
||||
|
||||
return pResult;
|
||||
}
|
||||
|
||||
void hb_xfree( void * pMem ) /* frees fixed memory */
|
||||
{
|
||||
if( pMem )
|
||||
free( pMem );
|
||||
else
|
||||
GenError( _szPErrors, 'P', ERR_PPMEMFREE, NULL, NULL );
|
||||
}
|
||||
HB_TRACE(("hb_xfree(%p)", pMem));
|
||||
|
||||
if( pMem )
|
||||
free( pMem );
|
||||
else
|
||||
GenError( _szPErrors, 'P', ERR_PPMEMFREE, NULL, NULL );
|
||||
}
|
||||
|
||||
@@ -93,9 +93,9 @@ static HANDLE HCursor; /* When DispBegin is in effect, all cursor related
|
||||
|
||||
#if (defined(HB_LOG) && (HB_LOG != 0))
|
||||
static FILE * flog = 0;
|
||||
int line = 0;
|
||||
static int line = 0;
|
||||
#define LOG(x) \
|
||||
do
|
||||
do \
|
||||
{ \
|
||||
flog = fopen( "c:/tmp/gt.log", "a" ); \
|
||||
fprintf( flog, "%5d> GT: %s\n", line++, x ); \
|
||||
|
||||
Reference in New Issue
Block a user