From dad9264dc324291bd5c7938ceea1946f68a2be7e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 25 Aug 1999 21:47:39 +0000 Subject: [PATCH] 19990825-23:30 GMT+1 --- harbour/ChangeLog | 49 ++++++ harbour/gt.b32 | 13 +- harbour/include/compiler.h | 3 +- harbour/include/external.ch | 1 - harbour/include/hberrors.h | 7 + harbour/include/hbpp.h | 3 +- harbour/source/compiler/genobj32.c | 2 +- harbour/source/compiler/harbour.l | 2 +- harbour/source/compiler/harbour.y | 122 +++++++------- harbour/source/hbpp/hbpp.c | 6 +- harbour/source/hbpp/hbpplib.c | 9 +- harbour/source/hbpp/stdalone/hbpp.c | 40 ++--- harbour/source/rtl/console.c | 143 +++++++++-------- harbour/source/rtl/do.c | 15 +- harbour/source/runner/stdalone/external.prg | 1 - harbour/source/tools/io.c | 166 +++++++++----------- 16 files changed, 298 insertions(+), 284 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 15e9557c94..9e0314cf8c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,52 @@ +19990825-23:30 GMT+1 Victor Szel + + * source/compiler/harbour.y + source/compiler/harbour.l + source/compiler/genobj32.c + source/hbpp/stdalone/hbpp.c + source/hbpp/hbpplib.c + include/hbpp.h + include/compiler.h + include/hberrors.h + + + Added standard error messages for memory management errors. + + Changed yyerror so that it calls the standard error launcher. + - hb_xalloc() functions removed, since it was not used anymore. + * hb_xalloc() changed to hb_xgrab(), it was not tested for the possible + NULL return value. + - One exit() after GenError() removed (source/hbpp/hbpp.c). + * exit( 1 ) -> exit( EXIT_FAILURE ) + ! GenWarning(), GenError(), CheckArgs() was allocating memory which was not + freed.Now the stack is used instead of calling memalloc functions, so + they can be used to report memory errors, too. + ! The last printf() changed to GenError() in harbour.l + + * source/tools/io.c + include/external.ch + source/runner/stdalone/external.prg + + - RENFILE() removed since there is already a function with the exact same + functionality in the standard Harbour RTL, named FRENAME(). + * Cleanup in io.c. + * Some __DOS__ guards changed to DOS. Some left since the code guarded + is compiler specific. Warning! This change could cause problems with some + other DOS compilers. + + TOFIX: added about a chdir call in RD() code. + + Code added to the non DOS branch. + + * source/rtl/console.c + + % SCROLL() - Some hb_pcount()s removed, parameter init optimed. + ! hb_out() - hb_parinfo() changed to pItem->type, since hb_parinfo() + can now contain the IT_BYREF flag, so if something would be passed + by reference, it would not be recognized as a valid type. + + * source/rtl/do.c + * Small cleanup. + + * gt.b32 + ! Fixes by Luiz Rafael Culik implemented. + 19990825-17:22 GMT+1 Bruno Cantero * source/vm/hvm.c + Added support for FIELD symbols diff --git a/harbour/gt.b32 b/harbour/gt.b32 index 7a7c1b4479..108d83e66f 100644 --- a/harbour/gt.b32 +++ b/harbour/gt.b32 @@ -2,13 +2,15 @@ # porting gt.lib's string functions to harbour .path.c = source\tools +.path.exe = bin +.path.prg = source\tools .path.h = include .path.lib = libs\b32 .path.obj = obj libs\b32\hbgt.lib : \ ascpos.obj atdiff.obj chareven.obj charodd.obj chrcount.obj \ - chrtotal.obj charmix.obj asciisum.obj chrfirst.obj \ + chrtotal.obj charmix.obj asciisum.obj chrfirst.obj io.obj numtxthu.obj numtxten.obj\ strasint.obj strcount.obj strcspn.obj strdiff.obj strexpan.obj \ strleft.obj strpbrk.obj strright.obj @@ -29,9 +31,16 @@ strexpan.obj : strexpan.c extend.h hbdefs.h strleft.obj : strleft.c extend.h hbdefs.h strpbrk.obj : strpbrk.c extend.h hbdefs.h strright.obj : strright.c extend.h hbdefs.h +numtxthu.obj : numtxthu.c extend.h hbdefs.h +numtxten.obj : numtxten.c extend.h hbdefs.h +io.obj : io.c extend.h hbdefs.h + +numtxthu.c : numtxthu.prg harbour.exe +numtxten.c : numtxten.prg harbour.exe + .prg.c: - bin\b32\harbour $< /n + bin\harbour $< /n /osource\tools /iinclude .c.obj: bcc32 -c -O2 -I.\include -o$@ $< diff --git a/harbour/include/compiler.h b/harbour/include/compiler.h index 516063c426..e0d5e3d3c6 100644 --- a/harbour/include/compiler.h +++ b/harbour/include/compiler.h @@ -94,9 +94,8 @@ typedef struct _STACK_VAL_TYPE extern PFUNCTION GetFunction( char * szFunName ); /* locates a previously defined function */ extern WORD GetFunctionPos( char * szSymbolName ); /* returns the index + 1 of a function on the functions defined list */ -extern void * hb_xalloc( ULONG lSize ); /* allocates memory, returns NULL on failure */ extern void * hb_xgrab( ULONG lSize ); /* allocates memory, exists on failure */ -extern void hb_xfree( void * pMem ); /* frees memory */ extern void * hb_xrealloc( void * pMem, ULONG lSize ); /* reallocates memory */ +extern void hb_xfree( void * pMem ); /* frees memory */ #endif /* HB_COMPILER_H_ */ diff --git a/harbour/include/external.ch b/harbour/include/external.ch index ebdf59d3cc..6984e8813c 100644 --- a/harbour/include/external.ch +++ b/harbour/include/external.ch @@ -574,7 +574,6 @@ EXTERNAL HB_FSELECT // //symbols from file: tools\io.c // -EXTERNAL RENFILE EXTERNAL CD EXTERNAL MD EXTERNAL RD diff --git a/harbour/include/hberrors.h b/harbour/include/hberrors.h index 1a5ad31a98..97ae7b41d0 100644 --- a/harbour/include/hberrors.h +++ b/harbour/include/hberrors.h @@ -65,6 +65,10 @@ #define ERR_PARAMETERS_NOT_ALLOWED 24 #define ERR_EXIT_IN_SEQUENCE 25 #define ERR_UNTERM_ARRAY_INDEX 26 +#define ERR_MEMALLOC 27 +#define ERR_MEMREALLOC 28 +#define ERR_MEMFREE 29 +#define ERR_YACC 30 #define WARN_AMBIGUOUS_VAR 1 #define WARN_MEMVAR_ASSUMED 2 @@ -92,6 +96,9 @@ #define ERR_RECURSE 8 #define ERR_WRONG_DIRECTIVE 9 #define ERR_EXPLICIT 10 +#define ERR_PPMEMALLOC 11 +#define ERR_PPMEMREALLOC 12 +#define ERR_PPMEMFREE 13 #define WARN_NONDIRECTIVE 1 diff --git a/harbour/include/hbpp.h b/harbour/include/hbpp.h index 634dd0a46e..d75c761a7a 100644 --- a/harbour/include/hbpp.h +++ b/harbour/include/hbpp.h @@ -80,10 +80,9 @@ typedef struct extern PHB_FNAME hb_fsFNameSplit ( char * szFilename ); /* Split given filename into path, name and extension */ extern char * hb_fsFNameMerge ( char * szFileName, PHB_FNAME pFileName ); /* This function joins path, name and extension into a string with a filename */ -extern void * hb_xalloc( ULONG lSize ); /* allocates memory, returns NULL on failure */ extern void * hb_xgrab( ULONG lSize ); /* allocates memory, exists on failure */ -extern void hb_xfree( void * pMem ); /* frees memory */ extern void * hb_xrealloc( void * pMem, ULONG lSize ); /* reallocates memory */ +extern void hb_xfree( void * pMem ); /* frees memory */ /* Needed support variables, but not contained in HBPP.C */ diff --git a/harbour/source/compiler/genobj32.c b/harbour/source/compiler/genobj32.c index 25460f4594..c762820565 100644 --- a/harbour/source/compiler/genobj32.c +++ b/harbour/source/compiler/genobj32.c @@ -291,7 +291,7 @@ static void GenerateExternals( FILE * hObjFile ) } if( wExternals ) { - externNames = ( char * * ) hb_xalloc( sizeof( char * ) * ( wExternals + 2 ) ); + externNames = ( char * * ) hb_xgrab( sizeof( char * ) * ( wExternals + 2 ) ); w = 1; externNames[ 0 ] = "_hb_vmExecute"; diff --git a/harbour/source/compiler/harbour.l b/harbour/source/compiler/harbour.l index 20fba4ad2a..7c8c877563 100644 --- a/harbour/source/compiler/harbour.l +++ b/harbour/source/compiler/harbour.l @@ -122,7 +122,7 @@ Separator {SpaceTab} %% -"&"("'"|\"|\[) { printf( "\nSyntax error : '%s'\n", yytext ); exit(1); } +"&"("'"|\"|\[) { GenError( _szCErrors, 'E', ERR_SYNTAX, yytext, NULL ); } ' BEGIN STRING1; \" BEGIN STRING2; diff --git a/harbour/source/compiler/harbour.y b/harbour/source/compiler/harbour.y index fba3e7e159..8839d2d6f0 100644 --- a/harbour/source/compiler/harbour.y +++ b/harbour/source/compiler/harbour.y @@ -310,7 +310,11 @@ char * _szCErrors[] = "Invalid use of \'@\' (pass by reference): \'%s\'", "Formal parameters already declared", "Invalid %s from within of SEQUENCE code", - "Unterminated array index" + "Unterminated array index", + "Memory allocation error", + "Memory reallocation error", + "Freeing a NULL memory pointer", + "%s" /* YACC error messages */ }; /* Table with parse warnings */ @@ -1237,13 +1241,12 @@ Crlf : '\n' void yyerror( char * s ) { - printf( "\n%s at line %i\n", s, iLine ); - exit( 1 ); + GenError( _szCErrors, 'E', ERR_YACC, s, NULL ); } void * GenElseIf( void * pFirst, WORD wOffset ) { - PELSEIF pElseIf = ( PELSEIF ) hb_xalloc( sizeof( _ELSEIF ) ), pLast; + PELSEIF pElseIf = ( PELSEIF ) hb_xgrab( sizeof( _ELSEIF ) ), pLast; pElseIf->wOffset = wOffset; pElseIf->pNext = 0; @@ -1262,22 +1265,29 @@ void * GenElseIf( void * pFirst, WORD wOffset ) void GenError( char* _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ) { - char * szLine = ( char * ) hb_xalloc( 160 ); /*2 lines of text */ - printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); + char szLine[ 160 ]; /* 2 lines of text */ + + if( files.pLast->szFileName ) + printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); + else + printf( "\rLine %i ", iLine ); printf( "Error %c%i ", cPrefix, iError ); - sprintf( szLine, _szErrors[ iError - 1 ], szError1, szError2 ); + sprintf( szLine, _szCErrors[ iError - 1 ], szError1, szError2 ); printf( "%s\n\n", szLine ); - exit( 1 ); + + exit( EXIT_FAILURE ); } void GenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarning1, char * szWarning2) { if( _bWarnings && iWarning < WARN_ASSIGN_SUSPECT ) /* TODO: add switch to set level */ { - char * szLine = ( char * ) hb_xalloc( 160 ); /*2 lines of text */ + char szLine[ 160 ]; /* 2 lines of text */ + printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); printf( "Warning %c%i ", cPrefix, iWarning ); sprintf( szLine, _szWarnings[ iWarning - 1 ], szWarning1, szWarning2 ); + printf( "%s\n", szLine ); } } @@ -1386,7 +1396,7 @@ int harbour_main( int argc, char * argv[] ) default: printf( "\nUnsupported output language option\n" ); - exit( 1 ); + exit( EXIT_FAILURE ); } break; @@ -1656,12 +1666,12 @@ void AddSearchPath( char *szPath, PATHNAMES * *pSearchList ) { while( pPath->pNext ) pPath = pPath->pNext; - pPath->pNext = ( PATHNAMES * ) hb_xalloc( sizeof( PATHNAMES ) ); + pPath->pNext = ( PATHNAMES * ) hb_xgrab( sizeof( PATHNAMES ) ); pPath = pPath->pNext; } else { - *pSearchList =pPath =(PATHNAMES *)hb_xalloc( sizeof(PATHNAMES) ); + *pSearchList =pPath =(PATHNAMES *)hb_xgrab( sizeof(PATHNAMES) ); } pPath->pNext = NULL; pPath->szPath = szPath; @@ -1699,7 +1709,7 @@ PFUNCTION AddFunCall( char * szFunctionName ) */ void AddExtern( char * szExternName ) /* defines a new extern name */ { - PEXTERN pExtern = ( PEXTERN ) hb_xalloc( sizeof( _EXTERN ) ), pLast; + PEXTERN pExtern = ( PEXTERN ) hb_xgrab( sizeof( _EXTERN ) ), pLast; pExtern->szName = szExternName; pExtern->pNext = 0; @@ -1766,7 +1776,7 @@ void AddVar( char * szVarName ) iVarScope =VS_PARAMETER; CheckDuplVars( pFunc->pLocals, szVarName, iVarScope ); - pVar = ( PVAR ) hb_xalloc( sizeof( VAR ) ); + pVar = ( PVAR ) hb_xgrab( sizeof( VAR ) ); pVar->szName = szVarName; pVar->szAlias = NULL; pVar->cType = cVarType; @@ -1824,7 +1834,7 @@ void AddVar( char * szVarName ) */ if( bNewParameter ) { - pVar = ( PVAR ) hb_xalloc( sizeof( VAR ) ); + pVar = ( PVAR ) hb_xgrab( sizeof( VAR ) ); pVar->szName = yy_strdup( szVarName ); pVar->szAlias = NULL; pVar->cType = cVarType; @@ -1929,7 +1939,7 @@ void AddVar( char * szVarName ) PCOMSYMBOL AddSymbol( char * szSymbolName, WORD *pwPos ) { - PCOMSYMBOL pSym = ( PCOMSYMBOL ) hb_xalloc( sizeof( COMSYMBOL ) ); + PCOMSYMBOL pSym = ( PCOMSYMBOL ) hb_xgrab( sizeof( COMSYMBOL ) ); pSym->szName = szSymbolName; pSym->cScope = 0; @@ -1977,7 +1987,7 @@ void AliasRemove( void ) */ void AliasAddInt( int iWorkarea ) { - ALIASID_PTR pAlias = (ALIASID_PTR) hb_xalloc( sizeof( ALIASID ) ); + ALIASID_PTR pAlias = (ALIASID_PTR) hb_xgrab( sizeof( ALIASID ) ); pAlias->type =ALIAS_NUMBER; pAlias->alias.iAlias =iWorkarea; @@ -1988,7 +1998,7 @@ void AliasAddInt( int iWorkarea ) */ void AliasAddExp( void ) { - ALIASID_PTR pAlias = (ALIASID_PTR) hb_xalloc( sizeof( ALIASID ) ); + ALIASID_PTR pAlias = (ALIASID_PTR) hb_xgrab( sizeof( ALIASID ) ); pAlias->type =ALIAS_EVAL; AliasAdd( pAlias ); @@ -1998,7 +2008,7 @@ void AliasAddExp( void ) */ void AliasAddStr( char * szAlias ) { - ALIASID_PTR pAlias = (ALIASID_PTR) hb_xalloc( sizeof( ALIASID ) ); + ALIASID_PTR pAlias = (ALIASID_PTR) hb_xgrab( sizeof( ALIASID ) ); pAlias->type =ALIAS_NAME; pAlias->alias.szAlias =szAlias; @@ -2063,7 +2073,7 @@ int Include( char * szFileName, PATHNAMES *pSearch ) if( ! _bQuiet ) printf( "\nparsing file %s\n", szFileName ); - pFile = ( PFILE ) hb_xalloc( sizeof( _FILE ) ); + pFile = ( PFILE ) hb_xgrab( sizeof( _FILE ) ); pFile->handle = yyin; pFile->szFileName = szFileName; pFile->pPrev = NULL; @@ -2125,7 +2135,7 @@ void Duplicate( void ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = pStackValType->cType; pNewStackType->pPrev = pStackValType; @@ -2164,7 +2174,7 @@ PFUNCTION FunctionNew( char *szName, SYMBOLSCOPE cScope ) { PFUNCTION pFunc; - pFunc = ( PFUNCTION ) hb_xalloc( sizeof( _FUNC ) ); + pFunc = ( PFUNCTION ) hb_xgrab( sizeof( _FUNC ) ); pFunc->szName = szName; pFunc->cScope = cScope; pFunc->pLocals = 0; @@ -3333,7 +3343,7 @@ WORD GetVarPos( PVAR pVars, char * szVarName ) /* returns the order + 1 of a var pVars->iUsed = 1; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = pVars->cType; pNewStackType->pPrev = pStackValType; @@ -3405,7 +3415,7 @@ int GetLocalVarPos( char * szVarName ) /* returns the order + 1 of a variable if /* this variable was not referenced yet - add it to the list */ PVAR pVar; - pVar = (PVAR) hb_xalloc( sizeof(VAR) ); + pVar = (PVAR) hb_xgrab( sizeof(VAR) ); pVar->szName = szVarName; pVar->cType = ' '; pVar->iUsed = 0; @@ -3862,7 +3872,7 @@ void Message( char * szMsgName ) /* sends a message to an object */ cType = pSym->cType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = cType; pNewStackType->pPrev = pStackValType; pStackValType = pNewStackType; @@ -4111,7 +4121,7 @@ void PushId( char * szVarName ) /* generates the pcode to push a variable value { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = cVarType; pNewStackType->pPrev = pStackValType; @@ -4161,7 +4171,7 @@ void PushLogical( int iTrueFalse ) /* pushes a logical value on the virtual mach { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = 'L'; pNewStackType->pPrev = pStackValType; @@ -4178,7 +4188,7 @@ void PushNil( void ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = ' ' /*TODO maybe 'U'*/ ; pNewStackType->pPrev = pStackValType; @@ -4198,7 +4208,7 @@ void PushDouble( double dNumber, BYTE bDec ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = 'N'; pNewStackType->pPrev = pStackValType; @@ -4235,7 +4245,7 @@ void PushInteger( int iNumber ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = 'N'; pNewStackType->pPrev = pStackValType; @@ -4262,7 +4272,7 @@ void PushLong( long lNumber ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = 'N'; pNewStackType->pPrev = pStackValType; @@ -4283,7 +4293,7 @@ void PushString( char * szText ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = 'C'; pNewStackType->pPrev = pStackValType; @@ -4334,7 +4344,7 @@ void PushSymbol( char * szSymbolName, int iIsFunction ) else cType = cVarType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = cType; pNewStackType->pPrev = pStackValType; @@ -4579,7 +4589,7 @@ void GenArray( WORD wElements ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = 'A'; pNewStackType->pPrev = pStackValType; @@ -4606,7 +4616,7 @@ void GenPCode1( BYTE byte ) { PSTACK_VAL_TYPE pNewStackType; - pNewStackType = ( STACK_VAL_TYPE * )hb_xalloc( sizeof( STACK_VAL_TYPE ) ); + pNewStackType = ( STACK_VAL_TYPE * )hb_xgrab( sizeof( STACK_VAL_TYPE ) ); pNewStackType->cType = 'O'; pNewStackType->pPrev = pStackValType; @@ -4826,7 +4836,7 @@ void GenPCode1( BYTE byte ) if( ! pFunc->pCode ) /* has been created the memory block to hold the pcode ? */ { - pFunc->pCode = (BYTE *) hb_xalloc( PCODE_CHUNK ); + pFunc->pCode = (BYTE *) hb_xgrab( PCODE_CHUNK ); pFunc->lPCodeSize = PCODE_CHUNK; pFunc->lPCodePos = 0; } @@ -4843,7 +4853,7 @@ void GenPCode3( BYTE byte1, BYTE byte2, BYTE byte3 ) if( ! pFunc->pCode ) /* has been created the memory block to hold the pcode ? */ { - pFunc->pCode = (BYTE *) hb_xalloc( PCODE_CHUNK ); + pFunc->pCode = (BYTE *) hb_xgrab( PCODE_CHUNK ); pFunc->lPCodeSize = PCODE_CHUNK; pFunc->lPCodePos = 0; } @@ -4863,7 +4873,7 @@ void GenPCodeN( BYTE * pBuffer, WORD wSize ) if( ! pFunc->pCode ) /* has been created the memory block to hold the pcode ? */ { pFunc->lPCodeSize = ((wSize / PCODE_CHUNK) +1) * PCODE_CHUNK; - pFunc->pCode = (BYTE *) hb_xalloc( pFunc->lPCodeSize ); + pFunc->pCode = (BYTE *) hb_xgrab( pFunc->lPCodeSize ); pFunc->lPCodePos = 0; } else if( pFunc->lPCodePos + wSize > pFunc->lPCodeSize ) @@ -4879,7 +4889,7 @@ void GenPCodeN( BYTE * pBuffer, WORD wSize ) char * SetData( char * szMsg ) /* generates an underscore-symbol name for a data assignment */ { - char * szResult = ( char * ) hb_xalloc( strlen( szMsg ) + 2 ); + char * szResult = ( char * ) hb_xgrab( strlen( szMsg ) + 2 ); strcpy( szResult, "_" ); strcat( szResult, szMsg ); @@ -5146,7 +5156,7 @@ void StaticAssign( void ) */ static void LoopStart( void ) { - PTR_LOOPEXIT pLoop = ( PTR_LOOPEXIT ) hb_xalloc( sizeof(LOOPEXIT) ); + PTR_LOOPEXIT pLoop = ( PTR_LOOPEXIT ) hb_xgrab( sizeof(LOOPEXIT) ); if( pLoops ) { @@ -5181,7 +5191,7 @@ static void LoopLoop( void ) GenError( _szCErrors, 'E', ERR_EXIT_IN_SEQUENCE, "LOOP", NULL ); } - pLoop = (PTR_LOOPEXIT) hb_xalloc( sizeof( LOOPEXIT ) ); + pLoop = (PTR_LOOPEXIT) hb_xgrab( sizeof( LOOPEXIT ) ); pLoop->pLoopList =NULL; pLoop->wOffset =functions.pLast->lPCodePos; /* store the position to fix */ @@ -5213,7 +5223,7 @@ static void LoopExit( void ) GenError( _szCErrors, 'E', ERR_EXIT_IN_SEQUENCE, "EXIT", NULL ); } - pLoop = (PTR_LOOPEXIT) hb_xalloc( sizeof( LOOPEXIT ) ); + pLoop = (PTR_LOOPEXIT) hb_xgrab( sizeof( LOOPEXIT ) ); pLoop->pExitList =NULL; pLoop->wOffset =functions.pLast->lPCodePos; /* store the position to fix */ @@ -5390,26 +5400,12 @@ char * hb_fsFNameMerge( char *szFileName, PHB_FNAME pFileName ) return szFileName; } -void * hb_xalloc( ULONG ulSize ) /* allocates fixed memory, returns NULL on failure */ -{ - void * pMem = malloc( ulSize ); - - if( ! pMem ) - { - yyerror( "\nhb_xalloc error: can't allocate memory!\n" ); - } - - return pMem; -} - void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on failure */ { void * pMem = malloc( ulSize ); if( ! pMem ) - { - yyerror( "\nhb_xgrab error: can't allocate memory!\n" ); - } + GenError( _szCErrors, 'E', ERR_MEMALLOC, NULL, NULL ); return pMem; } @@ -5419,9 +5415,7 @@ void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */ void * pResult = realloc( pMem, ulSize ); if( ! pResult ) - { - yyerror( "\nhb_xrealloc error: can't reallocate memory!\n" ); - } + GenError( _szCErrors, 'E', ERR_MEMREALLOC, NULL, NULL ); return pResult; } @@ -5431,9 +5425,7 @@ void hb_xfree( void * pMem ) /* frees fixed memory */ if( pMem ) free( pMem ); else - { - yyerror( "\nhb_xfree error: freeing a NULL pointer!\n" ); - } + GenError( _szCErrors, 'E', ERR_MEMFREE, NULL, NULL ); } char * yy_strupr( char * p ) @@ -5451,7 +5443,7 @@ char * yy_strdup( char *p ) int iLen; iLen = strlen( p ) +1; - pDup = (char *) hb_xalloc( iLen ); + pDup = (char *) hb_xgrab( iLen ); memcpy( pDup, p, iLen ); return pDup; @@ -5904,7 +5896,7 @@ void CheckArgs( char *cFuncCall, int iArgs ) if( iPos >= 0 && ( f[iPos].iMinParam != -1 ) ) if( iArgs < f[iPos].iMinParam || iArgs > f[iPos].iMaxParam ) { - char *szMsg = ( char * ) hb_xalloc( 30 ); + char szMsg[ 30 ]; sprintf( szMsg, " Passed: %i Expected: %i", iArgs, f[iPos].iMinParam ); GenError( _szCErrors, 'E', ERR_CHECKING_ARGS, cFuncCall, szMsg ); diff --git a/harbour/source/hbpp/hbpp.c b/harbour/source/hbpp/hbpp.c index 8f74dd0673..213bbc0ce8 100644 --- a/harbour/source/hbpp/hbpp.c +++ b/harbour/source/hbpp/hbpp.c @@ -136,7 +136,10 @@ char * _szPErrors[] = "Error in pattern definition", "Cycled #define", "Wrong directive \"%s\"", - "#error: \'%s\'" + "#error: \'%s\'", + "Memory allocation error", + "Memory reallocation error", + "Freeing a NULL memory pointer" }; /* Table with parse warnings */ @@ -227,7 +230,6 @@ int ParseDirective( char* sLine ) else if ( i == 5 && memcmp ( sDirective, "ERROR", 5 ) == 0 ) { /* --- #error --- */ GenError( _szPErrors, 'P', ERR_EXPLICIT, sLine, NULL ); - exit(1); } else if ( i == 4 && memcmp ( sDirective, "LINE", 4 ) == 0 ) return -1; diff --git a/harbour/source/hbpp/hbpplib.c b/harbour/source/hbpp/hbpplib.c index 3d34042d35..e03879f00c 100644 --- a/harbour/source/hbpp/hbpplib.c +++ b/harbour/source/hbpp/hbpplib.c @@ -79,19 +79,22 @@ HARBOUR HB___PREPROCESS(void) void GenError( char* _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ) { - char * szLine = ( char * ) hb_xgrab( 160 ); /*2 lines of text */ + char szLine[ 160 ]; /* 2 lines of text */ + /* printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); */ printf( "Error %c%i ", cPrefix, iError ); sprintf( szLine, _szErrors[ iError - 1 ], szError1, szError2 ); printf( "%s\n\n", szLine ); - exit( 1 ); + + exit( EXIT_FAILURE ); } void GenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarning1, char * szWarning2) { if( _bWarnings && iWarning < WARN_ASSIGN_SUSPECT ) /* TODO: add switch to set level */ { - char * szLine = ( char * ) hb_xgrab( 160 ); /*2 lines of text */ + char szLine[ 160 ]; /* 2 lines of text */ + /* printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); */ printf( "Warning %c%i ", cPrefix, iWarning ); sprintf( szLine, _szWarnings[ iWarning - 1 ], szWarning1, szWarning2 ); diff --git a/harbour/source/hbpp/stdalone/hbpp.c b/harbour/source/hbpp/stdalone/hbpp.c index 2558aef7cc..a252f7b4c5 100644 --- a/harbour/source/hbpp/stdalone/hbpp.c +++ b/harbour/source/hbpp/stdalone/hbpp.c @@ -395,12 +395,12 @@ void AddSearchPath( char *szPath, PATHNAMES * *pSearchList ) { while( pPath->pNext ) pPath = pPath->pNext; - pPath->pNext = ( PATHNAMES * ) hb_xalloc( sizeof( PATHNAMES ) ); + pPath->pNext = ( PATHNAMES * ) hb_xgrab( sizeof( PATHNAMES ) ); pPath = pPath->pNext; } else { - *pSearchList =pPath =(PATHNAMES *)hb_xalloc( sizeof(PATHNAMES) ); + *pSearchList =pPath =(PATHNAMES *)hb_xgrab( sizeof(PATHNAMES) ); } pPath->pNext = NULL; pPath->szPath = szPath; @@ -408,19 +408,22 @@ void AddSearchPath( char *szPath, PATHNAMES * *pSearchList ) void GenError( char* _szErrors[], char cPrefix, int iError, char * szError1, char * szError2 ) { - char * szLine = ( char * ) hb_xalloc( 160 ); /*2 lines of text */ + char szLine[ 160 ]; /* 2 lines of text */ + /* printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); */ printf( "\tError %c%i ", cPrefix, iError ); sprintf( szLine, _szErrors[ iError - 1 ], szError1, szError2 ); printf( "%s\n\n", szLine ); - exit( 1 ); + + exit( EXIT_FAILURE ); } void GenWarning( char* _szWarnings[], char cPrefix, int iWarning, char * szWarning1, char * szWarning2) { if( _bWarnings && iWarning < WARN_ASSIGN_SUSPECT ) /* TODO: add switch to set level */ { - char * szLine = ( char * ) hb_xalloc( 160 ); /*2 lines of text */ + char szLine[ 160 ]; /* 2 lines of text */ + /* printf( "\r%s(%i) ", files.pLast->szFileName, iLine ); */ printf( "Warning %c%i ", cPrefix, iWarning ); sprintf( szLine, _szWarnings[ iWarning - 1 ], szWarning1, szWarning2 ); @@ -540,27 +543,12 @@ char * hb_fsFNameMerge( char *szFileName, PHB_FNAME pFileName ) return szFileName; } -void * hb_xalloc( ULONG ulSize ) /* allocates fixed memory, returns NULL on failure */ -{ - void * pMem = malloc( ulSize ); - - if( ! pMem ) - { - printf( "\nhb_xalloc error: can't allocate memory!\n" ); - } - - return pMem; -} - void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on failure */ { void * pMem = malloc( ulSize ); if( ! pMem ) - { - printf( "\nhb_xgrab error: can't allocate memory!\n" ); - exit( 1 ); - } + GenError( _szPErrors, 'P', ERR_PPMEMALLOC, NULL, NULL ); return pMem; } @@ -570,10 +558,7 @@ void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */ void * pResult = realloc( pMem, ulSize ); if( ! pResult ) - { - printf( "\nhb_xrealloc error: can't reallocate memory!\n" ); - exit( 1 ); - } + GenError( _szPErrors, 'P', ERR_PPMEMREALLOC, NULL, NULL ); return pResult; } @@ -583,9 +568,6 @@ void hb_xfree( void * pMem ) /* frees fixed memory */ if( pMem ) free( pMem ); else - { - printf( "\nhb_xfree error: freeing a NULL pointer!\n" ); - exit( 1 ); - } + GenError( _szPErrors, 'P', ERR_PPMEMFREE, NULL, NULL ); } diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index b6ac378956..c339d3235f 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -93,10 +93,10 @@ void hb_consoleInitialize( void ) #if defined(OS_DOS_COMPATIBLE) CrLf[ 0 ] = 13; CrLf[ 1 ] = 10; - CrLf[ 2 ] = 0; + CrLf[ 2 ] = '\0'; #else CrLf[ 0 ] = 10; - CrLf[ 1 ] = 0; + CrLf[ 1 ] = '\0'; #endif p_row = p_col = 0; @@ -139,14 +139,14 @@ WORD hb_max_col( void ) } #ifndef HARBOUR_USE_GTAPI -static void adjust_pos( char * fpStr, ULONG len, WORD * row, WORD * col, WORD max_row, WORD max_col ) +static void adjust_pos( char * pStr, ULONG len, WORD * row, WORD * col, WORD max_row, WORD max_col ) { ULONG count; - char * fpPtr = fpStr; + char * pPtr = pStr; for( count = 0; count < len; count++ ) { - switch( *fpPtr++ ) + switch( *pPtr++ ) { case 7: break; @@ -183,24 +183,26 @@ static void hb_out( WORD wParam, hb_out_func_typedef * hb_out_func ) { char * szText; PHB_ITEM pItem = hb_param( wParam, IT_ANY ); - char szBuffer[ 11 ]; - switch( hb_parinfo( wParam ) ) + switch( pItem->type ) { case IT_STRING: hb_out_func( hb_parc( wParam ), hb_parclen( wParam ) ); break; case IT_DATE: + { + char szBuffer[ 11 ]; szText = hb_dtoc( hb_pards( wParam ), szBuffer, hb_set.HB_SET_DATEFORMAT ); if( szText ) hb_out_func( szText, strlen( szText ) ); break; + } case IT_DOUBLE: case IT_INTEGER: case IT_LONG: - szText = hb_itemStr( pItem, 0, 0 ); /* Let hb_itemStr() do the hard work */ + szText = hb_itemStr( pItem, NULL, NULL ); /* Let hb_itemStr() do the hard work */ if( szText ) { hb_out_func( szText, strlen( szText ) ); @@ -225,19 +227,19 @@ static void hb_out( WORD wParam, hb_out_func_typedef * hb_out_func ) } /* Output an item to STDOUT */ -static void hb_outstd( char * fpStr, ULONG len ) +static void hb_outstd( char * pStr, ULONG len ) { ULONG count = len; - char * fpPtr = fpStr; + char * pPtr = pStr; #ifdef HARBOUR_USE_GTAPI hb_gtPreExt(); #endif - if( strlen( fpStr ) != count ) - while( count-- ) printf( "%c", *fpPtr++ ); + if( strlen( pStr ) != count ) + while( count-- ) printf( "%c", *pPtr++ ); else - printf( "%s", fpStr ); + printf( "%s", pStr ); fflush( stdout ); #ifdef HARBOUR_USE_GTAPI #ifndef __CYGWIN__ @@ -250,24 +252,24 @@ static void hb_outstd( char * fpStr, ULONG len ) } hb_gtPostExt(); #else - adjust_pos( fpStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); + adjust_pos( pStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } /* Output an item to STDERR */ -static void hb_outerr( char * fpStr, ULONG len ) +static void hb_outerr( char * pStr, ULONG len ) { ULONG count = len; - char * fpPtr = fpStr; + char * pPtr = pStr; #ifdef HARBOUR_USE_GTAPI hb_gtPreExt(); #endif - if( strlen( fpStr ) != count ) - while( count-- ) fprintf( stderr, "%c", *fpPtr++ ); + if( strlen( pStr ) != count ) + while( count-- ) fprintf( stderr, "%c", *pPtr++ ); else - fprintf( stderr, "%s", fpStr ); + fprintf( stderr, "%s", pStr ); fflush( stderr ); #ifdef HARBOUR_USE_GTAPI #ifndef __CYGWIN__ @@ -280,27 +282,27 @@ static void hb_outerr( char * fpStr, ULONG len ) } hb_gtPostExt(); #else - adjust_pos( fpStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); + adjust_pos( pStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } /* Output an item to the screen and/or printer and/or alternate */ -static void hb_altout( char * fpStr, ULONG len ) +static void hb_altout( char * pStr, ULONG len ) { - char * fpPtr = fpStr; + char * pPtr = pStr; if( hb_set.HB_SET_CONSOLE ) { #ifdef HARBOUR_USE_GTAPI - hb_gtWriteCon( fpStr, len ); + hb_gtWriteCon( pStr, len ); hb_gtGetPos( &dev_row, &dev_col ); #else ULONG count = len; - if( strlen( fpStr ) != count ) - while( count-- ) printf( "%c", *fpPtr++ ); + if( strlen( pStr ) != count ) + while( count-- ) printf( "%c", *pPtr++ ); else - printf( "%s", fpStr ); - adjust_pos( fpStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); + printf( "%s", pStr ); + adjust_pos( pStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } if( hb_set.HB_SET_ALTERNATE && hb_set_althan >= 0 ) @@ -308,7 +310,7 @@ static void hb_altout( char * fpStr, ULONG len ) /* Print to alternate file if SET ALTERNATE ON and valid alternate file */ unsigned write_len; ULONG count = len; - fpPtr = fpStr; + pPtr = pStr; while( count ) { if( count > UINT_MAX ) @@ -321,8 +323,8 @@ static void hb_altout( char * fpStr, ULONG len ) write_len = count; count = 0; } - write( hb_set_althan, fpPtr, write_len ); - fpPtr += write_len; + write( hb_set_althan, pPtr, write_len ); + pPtr += write_len; } } if( hb_set_extrahan >= 0 ) @@ -330,7 +332,7 @@ static void hb_altout( char * fpStr, ULONG len ) /* Print to extra file if valid alternate file */ unsigned write_len; ULONG count = len; - fpPtr = fpStr; + pPtr = pStr; while( count ) { if( count > UINT_MAX ) @@ -343,8 +345,8 @@ static void hb_altout( char * fpStr, ULONG len ) write_len = count; count = 0; } - write( hb_set_extrahan, fpPtr, write_len ); - fpPtr += write_len; + write( hb_set_extrahan, pPtr, write_len ); + pPtr += write_len; } } if( hb_set.HB_SET_PRINTER && hb_set_printhan >= 0 ) @@ -352,7 +354,7 @@ static void hb_altout( char * fpStr, ULONG len ) /* Print to printer if SET PRINTER ON and valid printer file */ unsigned write_len; ULONG count = len; - fpPtr = fpStr; + pPtr = pStr; while( count ) { if( count > UINT_MAX ) @@ -365,8 +367,8 @@ static void hb_altout( char * fpStr, ULONG len ) write_len = count; count = 0; } - write( hb_set_printhan, fpPtr, write_len ); - fpPtr += write_len; + write( hb_set_printhan, pPtr, write_len ); + pPtr += write_len; } if( len + p_col > USHRT_MAX ) p_col = USHRT_MAX; else p_col += len; @@ -374,14 +376,14 @@ static void hb_altout( char * fpStr, ULONG len ) } /* Output an item to the screen and/or printer */ -static void hb_devout( char * fpStr, ULONG len ) +static void hb_devout( char * pStr, ULONG len ) { if( hb_set_printhan >= 0 && hb_stricmp( hb_set.HB_SET_DEVICE, "PRINTER" ) == 0 ) { /* Display to printer if SET DEVICE TO PRINTER and valid printer file */ unsigned write_len; ULONG count = len; - char * fpPtr = fpStr; + char * pPtr = pStr; while( count ) { if( count > UINT_MAX ) @@ -394,8 +396,8 @@ static void hb_devout( char * fpStr, ULONG len ) write_len = count; count = 0; } - write( hb_set_printhan, fpPtr, write_len ); - fpPtr += write_len; + write( hb_set_printhan, pPtr, write_len ); + pPtr += write_len; } if( len + p_col > USHRT_MAX ) p_col = USHRT_MAX; else p_col += len; @@ -404,35 +406,35 @@ static void hb_devout( char * fpStr, ULONG len ) { #ifdef HARBOUR_USE_GTAPI /* Otherwise, display to console */ - hb_gtWrite( fpStr, len ); + hb_gtWrite( pStr, len ); hb_gtGetPos( &dev_row, &dev_col ); #else ULONG count = len; - char * fpPtr = fpStr; - if( strlen( fpStr ) != count ) - while( count-- ) printf( "%c", *fpPtr++ ); + char * pPtr = pStr; + if( strlen( pStr ) != count ) + while( count-- ) printf( "%c", *pPtr++ ); else - printf( "%s", fpStr ); - adjust_pos( fpStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); + printf( "%s", pStr ); + adjust_pos( pStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } } /* Output an item to the screen */ -static void hb_dispout( char * fpStr, ULONG len ) +static void hb_dispout( char * pStr, ULONG len ) { #ifdef HARBOUR_USE_GTAPI /* Display to console */ - hb_gtWrite( fpStr, len ); + hb_gtWrite( pStr, len ); hb_gtGetPos( &dev_row, &dev_col ); #else ULONG count = len; - char * fpPtr = fpStr; - if( strlen( fpStr ) != count ) - while( count-- ) printf( "%c", *fpPtr++ ); + char * pPtr = pStr; + if( strlen( pStr ) != count ) + while( count-- ) printf( "%c", *pPtr++ ); else - printf( "%s", fpStr ); - adjust_pos( fpStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); + printf( "%s", pStr ); + adjust_pos( pStr, len, &dev_row, &dev_col, hb_max_row(), hb_max_col() ); #endif } @@ -592,11 +594,11 @@ HARBOUR HB_DEVOUT( void ) /* writes a single value to the current device (screen if( hb_pcount() > 0 ) { #ifdef HARBOUR_USE_GTAPI - char fpOldColor[ CLR_STRLEN ]; + char pOldColor[ CLR_STRLEN ]; if( ISCHAR( 2 ) ) { - hb_gtGetColorStr( fpOldColor ); + hb_gtGetColorStr( pOldColor ); hb_gtSetColorStr( hb_parc( 2 ) ); } #endif @@ -606,7 +608,7 @@ HARBOUR HB_DEVOUT( void ) /* writes a single value to the current device (screen #ifdef HARBOUR_USE_GTAPI if( ISCHAR( 2 ) ) { - hb_gtSetColorStr( fpOldColor ); + hb_gtSetColorStr( pOldColor ); } #endif } @@ -617,11 +619,11 @@ HARBOUR HB_DISPOUT( void ) /* writes a single value to the current device (scree if( hb_pcount() > 0 ) { #ifdef HARBOUR_USE_GTAPI - char fpOldColor[ CLR_STRLEN ]; + char pOldColor[ CLR_STRLEN ]; if( ISCHAR( 2 ) ) { - hb_gtGetColorStr( fpOldColor ); + hb_gtGetColorStr( pOldColor ); hb_gtSetColorStr( hb_parc( 2 ) ); } #endif @@ -631,7 +633,7 @@ HARBOUR HB_DISPOUT( void ) /* writes a single value to the current device (scree #ifdef HARBOUR_USE_GTAPI if( ISCHAR( 2 ) ) { - hb_gtSetColorStr( fpOldColor ); + hb_gtSetColorStr( pOldColor ); } #endif } @@ -683,22 +685,17 @@ HARBOUR HB_SETPRC( void ) /* Sets the current printer row and column positions * HARBOUR HB_SCROLL( void ) /* Scrolls a screen region (requires the GT API) */ { - int i_top = 0, i_left = 0,iMR, iMC, i_bottom = iMR=hb_max_row(), i_right = iMC = hb_max_col(), - v_scroll = 0, h_scroll = 0; WORD top, left, bottom, right; - if( hb_pcount() > 0 && ISNUM( 1 ) ) - i_top = hb_parni( 1 ); - if( hb_pcount() > 1 && ISNUM( 2 ) ) - i_left = hb_parni( 2 ); - if( hb_pcount() > 2 && ISNUM( 3 ) ) - i_bottom = hb_parni( 3 ); - if( hb_pcount() > 3 && ISNUM( 4 ) ) - i_right = hb_parni( 4 ); - if( hb_pcount() > 4 && ISNUM( 5 ) ) - v_scroll = hb_parni( 5 ); - if( hb_pcount() > 5 && ISNUM( 6 ) ) - h_scroll = hb_parni( 6 ); + int iMR = hb_max_row(); + int iMC = hb_max_col(); + + int i_top = ISNUM( 1 ) ? hb_parni( 1 ) : 0; + int i_left = ISNUM( 2 ) ? hb_parni( 2 ) : 0; + int i_bottom = ISNUM( 3 ) ? hb_parni( 3 ) : iMR; + int i_right = ISNUM( 4 ) ? hb_parni( 4 ) : iMC; + int v_scroll = ISNUM( 5 ) ? hb_parni( 5 ) : 0; + int h_scroll = ISNUM( 6 ) ? hb_parni( 6 ) : 0; /* Enforce limits of (0,0) to (MAXROW(),MAXCOL()) */ if( i_top < 0 ) top = 0; diff --git a/harbour/source/rtl/do.c b/harbour/source/rtl/do.c index 3661f2cf09..422c6a1665 100644 --- a/harbour/source/rtl/do.c +++ b/harbour/source/rtl/do.c @@ -1,6 +1,7 @@ /* * $Id$ - Harbour Project source code + + Harbour Project source code This file is a part of Harbour Runtime Library and it contains code that defined DO function ussed in DO WITH statement. @@ -83,14 +84,12 @@ */ HARBOUR HB_DO( void ) { - PHB_ITEM pItem; + PHB_ITEM pItem = hb_param( 1, IT_ANY ); - pItem =hb_param( 1, IT_ANY ); - if( IS_STRING(pItem) ) + if( IS_STRING( pItem ) ) { - PHB_DYNS pDynSym; + PHB_DYNS pDynSym = hb_dynsymGet( pItem->item.asString.value ); - pDynSym =hb_dynsymGet( pItem->item.asString.value ); if( pDynSym ) { int i; @@ -104,7 +103,7 @@ HARBOUR HB_DO( void ) else hb_errRT_BASE( EG_NOFUNC, 1001, NULL, pItem->item.asString.value ); } - else if( IS_BLOCK(pItem) ) + else if( IS_BLOCK( pItem ) ) { int i; @@ -114,7 +113,7 @@ HARBOUR HB_DO( void ) hb_vmPush( hb_param( i, IT_ANY ) ); hb_vmDo( hb_pcount() - 1 ); } - else if( IS_SYMBOL(pItem) ) + else if( IS_SYMBOL( pItem ) ) { int i; diff --git a/harbour/source/runner/stdalone/external.prg b/harbour/source/runner/stdalone/external.prg index 3b369a1ad5..b8a2d9f748 100644 --- a/harbour/source/runner/stdalone/external.prg +++ b/harbour/source/runner/stdalone/external.prg @@ -574,7 +574,6 @@ EXTERNAL HB_FSELECT // //symbols from file: tools\io.c // -EXTERNAL RENFILE EXTERNAL CD EXTERNAL MD EXTERNAL RD diff --git a/harbour/source/tools/io.c b/harbour/source/tools/io.c index 0ab226261e..99cb4d3b66 100644 --- a/harbour/source/tools/io.c +++ b/harbour/source/tools/io.c @@ -2,64 +2,52 @@ * $Id$ */ -#include #include "extend.h" -#ifdef __DOS__ +#ifdef DOS #include #include #include #endif -HARBOUR HB_RENFILE(void) -{ -#ifdef __DOS__ - int ok; - PHB_ITEM arg1 = hb_param(1,IT_STRING); - PHB_ITEM arg2 = hb_param(2,IT_STRING); - if( arg1 && arg2) - { - ok=rename(hb_parc(1),hb_parc(2)); - if(!ok) - _retl(TRUE); - else - _retl(FALSE); - } -#endif -} - /* $DOC$ * $FUNCNAME$ * CD() * $CATEGORY$ * DOS * $ONELINER$ - * * $SYNTAX$ * CD() * $ARGUMENTS$ - * DIR TO BE CHANGED + * DIR TO BE CHANGED * $RETURNS$ - * .T. IF SUCEFUL - * .F. IF NOT + * .T. IF SUCEFUL + * .F. IF NOT * * $DESCRIPTION$ - * CHANGE THE CURRENT DIRECTORY + * CHANGE THE CURRENT DIRECTORY * $EXAMPLES$ - * IF CD("OLA") - * RETURN(.T.) - * ELSE - * RETURN(.F.) - * ENDIF + * IF CD("OLA") + * RETURN(.T.) + * ELSE + * RETURN(.F.) + * ENDIF * * $SEEALSO$ * * $INCLUDE$ - * extend.h dos.h dir.h bios.h internal.h + * extend.h dos.h dir.h bios.h * $END$ */ - +HARBOUR HB_CD( void ) +{ +#ifdef __DOS__ + hb_retni( ISCHAR( 1 ) ? chdir( hb_parc( 1 ) ) : 0 ); +#else + hb_retni( 0 ); +#endif +} /* $DOC$ * $FUNCNAME$ @@ -88,10 +76,19 @@ HARBOUR HB_RENFILE(void) * $SEEALSO$ * * $INCLUDE$ - * extend.h dos.h dir.h bios.h internal.h + * extend.h dos.h dir.h bios.h * $END$ */ +HARBOUR HB_MD(void) +{ +#ifdef __DOS__ + hb_retni( ISCHAR( 1 ) ? mkdir( hb_parc( 1 ) ) : 0 ); +#else + hb_retni( 0 ); +#endif +} + /* $DOC$ * $FUNCNAME$ * RD() @@ -119,86 +116,67 @@ HARBOUR HB_RENFILE(void) * $SEEALSO$ * * $INCLUDE$ - * extend.h dos.h dir.h bios.h internal.h + * extend.h dos.h dir.h bios.h * $END$ */ - -HARBOUR HB_CD(void) +HARBOUR HB_RD( void ) { + /* TOFIX: chdir() is wrong here */ #ifdef __DOS__ - PHB_ITEM MEUDIR = hb_param(1,IT_STRING); - if(MEUDIR) - { - hb_retni(chdir(hb_parc(1))); - } + hb_retni( ISCHAR( 1 ) ? chdir( hb_parc( 1 ) ) : 0 ); +#else + hb_retni( 0 ); #endif } -HARBOUR HB_MD(void) +HARBOUR HB_DISKUSED( void ) { -#ifdef __DOS__ - PHB_ITEM MEUDIR = hb_param(1,IT_STRING); - if(MEUDIR) - { +#ifdef DOS + struct diskfree_t disk; + long bytsfree, bytsfull; - hb_retni(mkdir(hb_parc(1))); - } + _dos_getdiskfree( 0, &disk ); + + bytsfree = ( long ) disk.avail_clusters * + ( long ) disk.sectors_per_cluster * + ( long ) disk.bytes_per_sector; + bytsfull = ( long ) disk.total_clusters * + ( long ) disk.sectors_per_cluster * + ( long ) disk.bytes_per_sector; + + hb_retnl( bytsfull - bytsfree ); +#else + hb_retnl( 0 ); #endif } -HARBOUR HB_RD(void) +HARBOUR HB_DISKFREE( void ) { -#ifdef __DOS__ - PHB_ITEM MEUDIR = hb_param(1,IT_STRING); - if(MEUDIR) - { +#ifdef DOS + struct diskfree_t disk; - hb_retni(chdir(hb_parc(1))); - } + _dos_getdiskfree( 0, &disk ); + + hb_retnl( ( long ) disk.avail_clusters * + ( long ) disk.sectors_per_cluster * + ( long ) disk.bytes_per_sector ); +#else + hb_retnl( 0 ); #endif } -HARBOUR HB_DISKUSED(void) +HARBOUR HB_DISKFULL( void ) { -#ifdef __DOS__ - long bytsfree,bytsfull; - struct diskfree_t disk; - _dos_getdiskfree(0,&disk); - bytsfree = ((long) disk.avail_clusters * - (long) disk.sectors_per_cluster * - (long ) disk.bytes_per_sector); - bytsfull = ((long) disk.total_clusters * - (long) disk.sectors_per_cluster * - (long ) disk.bytes_per_sector); - hb_retnl(bytsfull-bytsfree); -#endif -} - -HARBOUR HB_DISKFREE(void) -{ -#ifdef __DOS__ - long bytsfree; - struct diskfree_t disk; - _dos_getdiskfree(0,&disk); - bytsfree = ((long) disk.avail_clusters * - (long) disk.sectors_per_cluster * - (long ) disk.bytes_per_sector); - - hb_retnl(bytsfree); -#endif -} - -HARBOUR HB_DISKFULL(void) -{ -#ifdef __DOS__ - long bytsfull; - struct diskfree_t disk; - _dos_getdiskfree(0,&disk); - - bytsfull = ((long) disk.total_clusters * - (long) disk.sectors_per_cluster * - (long ) disk.bytes_per_sector); - hb_retnl(bytsfull); +#ifdef DOS + struct diskfree_t disk; + + _dos_getdiskfree( 0, &disk ); + + hb_retnl( ( long ) disk.total_clusters * + ( long ) disk.sectors_per_cluster * + ( long ) disk.bytes_per_sector ); +#else + hb_retnl( 0 ); #endif }