From cb4b88ddc265ad895533a2465950fa07fadb7825 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 30 Aug 1999 17:21:54 +0000 Subject: [PATCH] 19990830-19:00 GMT+1 --- harbour/ChangeLog | 59 ++ harbour/funclist.txt | 2 +- harbour/include/filesys.h | 2 +- harbour/source/rtl/arrays.c | 26 +- harbour/source/rtl/classes.c | 126 +-- harbour/source/rtl/codebloc.c | 156 ++-- harbour/source/rtl/console.c | 40 +- harbour/source/rtl/dates.c | 4 +- harbour/source/rtl/dir.c | 466 +++++----- harbour/source/rtl/environ.c | 126 +-- harbour/source/rtl/filesys.c | 138 ++- harbour/source/rtl/fm.c | 10 +- harbour/source/rtl/gtapi.c | 1225 ++++++++++++++------------- harbour/source/rtl/inkey.c | 86 +- harbour/source/rtl/langapi.c | 20 +- harbour/source/rtl/memvars.c | 271 +++--- harbour/source/rtl/mouse/mouseos2.c | 156 ++-- harbour/source/rtl/set.c | 26 +- harbour/source/rtl/setcolor.c | 10 +- harbour/source/rtl/strings.c | 6 +- harbour/source/rtl/tone.c | 24 +- harbour/source/rtl/transfrm.c | 4 +- harbour/source/vm/hvm.c | 79 +- 23 files changed, 1638 insertions(+), 1424 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 959c6bfdae..36d23997ea 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,62 @@ +19990830-19:00 GMT+1 Victor Szel + + * source/filesys.c + include/filesys.h + funclist.txt + + Added: DIRCHANGE(), MAKEDIR(), DIRREMOVE(), DISKCHANGE(), DISKNAME() + All of them are Clipper 5.3 compatible functions. Some of them will not + work, since the underlying low level API is not worked out. + ! Fixed CURDIR() to preserve the FERROR() value. + ! Fixed prototype of hb_fsChDrv(). + + DISKSPACE() added (currently only working in DOS). + * source/rtl/arrays.c + + hb_arrayAdd() added BASE/1187 Bound error "AADD" error message. + ! 1068 Not an array errors changed to the 9999 code, until we allocate + a 3xxx error for. This error was not there in Clipper. + * source/vm/hvm.c + + Added standard "no exported method" and "no exported variable" + runtime error instead of the internal error. + ( ErrorNew():hello := 1, ErrorNew():hello ) + + hb_vmPlus() and hb_vmMinus() added "string overflow" runtime errors + (1209, 1210) (could not test this though :) + * Error code 1000 in BADALIAS errors changed to 9999, until someone finds + out the correct error code, since there's no 1000 error code in Clipper. + * source/rtl/set.c + ! Fixed to also accept strings that *begin* with "ON" or "OFF", like + Clipper. + * source/rtl/tone.c + source/rtl/codebloc.c + source/rtl/memvars.c + source/rtl/environ.c + source/rtl/classes.c + source/rtl/console.c + source/rtl/langapi.c + source/rtl/setcolor.c + source/rtl/strings.c + source/rtl/dates.c + source/rtl/set.c + source/rtl/transfrm.c (removed static) + source/rtl/inkey.c + source/rtl/fm.c + source/rtl/dir.c + source/rtl/gtapi.c + * Formatting errors corrected. + + static variables prefixed with "s_" + * Some type changed to BOOL. + +19990830-16:59 +0300 Chen Kedem + * source/rtl/mouse/mouseos2.c + * hb_mouse_Hide() now work in any text screen mode. + * hb_mouse_IsButtonPressed() now return TRUE if any button was + pressed. + TOFIX: every time I read event from the queue I lose the result + so I can not check if iButton was pressed, so for now I ignore + iButton and return TRUE if the last event saved had DOWN in it. + also to keep the noise level down I mask out MOUSE_MOTION + events. + * suMouHandle changed to s_uMouHandle + * Some reformatting. + 19990830-12:49 EDT Paul Tucker * source/rtl/gtapi.c * Handle nesting of gtPre/PostExt diff --git a/harbour/funclist.txt b/harbour/funclist.txt index 3b07f93c59..d0571b5d39 100644 --- a/harbour/funclist.txt +++ b/harbour/funclist.txt @@ -90,7 +90,7 @@ DEVOUT ;R; DEVOUTPICT ;R; DEVPOS ;R; DIRECTORY ;R; -DISKSPACE ;N; +DISKSPACE ;R; DISPBEGIN ;S; DISPBOX ;R; DISPCOUNT ;S; diff --git a/harbour/include/filesys.h b/harbour/include/filesys.h index de867c8d31..e1cbfa6e40 100644 --- a/harbour/include/filesys.h +++ b/harbour/include/filesys.h @@ -62,7 +62,7 @@ typedef struct } HB_FNAME, * PHB_FNAME, * HB_FNAME_PTR; extern BOOL hb_fsChDir ( BYTE * pDirName ); -extern USHORT hb_fsChDrv ( BYTE * nDrive ); +extern USHORT hb_fsChDrv ( BYTE nDrive ); extern void hb_fsClose ( FHANDLE hFileHandle ); extern void hb_fsCommit ( FHANDLE hFileHandle ); extern FHANDLE hb_fsCreate ( BYTE * pFilename, USHORT uiAttribute ); diff --git a/harbour/source/rtl/arrays.c b/harbour/source/rtl/arrays.c index 528f95e8d7..3ae0cb60b1 100644 --- a/harbour/source/rtl/arrays.c +++ b/harbour/source/rtl/arrays.c @@ -147,9 +147,15 @@ void hb_arrayNew( PHB_ITEM pItem, ULONG ulLen ) /* creates a new array */ void hb_arrayAdd( PHB_ITEM pArray, PHB_ITEM pValue ) { PBASEARRAY pBaseArray = ( PBASEARRAY ) pArray->item.asArray.value; - hb_arraySize( pArray, pBaseArray->ulLen + 1 ); - pBaseArray = ( PBASEARRAY ) pArray->item.asArray.value; - hb_itemCopy( pBaseArray->pItems + ( pBaseArray->ulLen - 1 ), pValue ); + + if( pBaseArray->ulLen < ULONG_MAX ) + { + hb_arraySize( pArray, pBaseArray->ulLen + 1 ); + pBaseArray = ( PBASEARRAY ) pArray->item.asArray.value; + hb_itemCopy( pBaseArray->pItems + ( pBaseArray->ulLen - 1 ), pValue ); + } + else + hb_errRT_BASE( EG_BOUND, 1187, NULL, "AADD" ); } void hb_arrayGet( PHB_ITEM pArray, ULONG ulIndex, PHB_ITEM pItem ) @@ -313,7 +319,7 @@ void hb_arrayFill( PHB_ITEM pArray, PHB_ITEM pValue, ULONG ulStart, ULONG ulCoun hb_itemCopy( pBaseArray->pItems + ( ulStart - 1 ), pValue ); } else - hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + hb_errRT_BASE( EG_ARG, 9999, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); } void hb_arrayDel( PHB_ITEM pArray, ULONG ulIndex ) @@ -335,7 +341,7 @@ void hb_arrayDel( PHB_ITEM pArray, ULONG ulIndex ) } } else - hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + hb_errRT_BASE( EG_ARG, 9999, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); } void hb_arrayIns( PHB_ITEM pArray, ULONG ulIndex ) @@ -357,7 +363,7 @@ void hb_arrayIns( PHB_ITEM pArray, ULONG ulIndex ) } } else - hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + hb_errRT_BASE( EG_ARG, 9999, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); } int hb_arrayScan( PHB_ITEM pArray, PHB_ITEM pValue, ULONG ulStart, ULONG ulCount ) @@ -432,7 +438,7 @@ int hb_arrayScan( PHB_ITEM pArray, PHB_ITEM pValue, ULONG ulStart, ULONG ulCount } } else - hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + hb_errRT_BASE( EG_ARG, 9999, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); return 0; } @@ -491,7 +497,7 @@ void hb_arrayRelease( PHB_ITEM pArray ) pArray->item.asArray.value = NULL; } else - hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + hb_errRT_BASE( EG_ARG, 9999, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); } void hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG ulStart, @@ -525,7 +531,7 @@ void hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG ulStart, hb_itemCopy( pDstBaseArray->pItems + ( ulTarget + ulStart ), pSrcBaseArray->pItems + ulStart ); } else - hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + hb_errRT_BASE( EG_ARG, 9999, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); } PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray ) @@ -559,7 +565,7 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray ) } } else - hb_errRT_BASE( EG_ARG, 1068, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); + hb_errRT_BASE( EG_ARG, 9999, NULL, hb_langDGetErrorDesc( EG_NOTARRAY ) ); return pDstArray; } diff --git a/harbour/source/rtl/classes.c b/harbour/source/rtl/classes.c index 58155a4fc0..659b2ce636 100644 --- a/harbour/source/rtl/classes.c +++ b/harbour/source/rtl/classes.c @@ -72,13 +72,13 @@ typedef struct #define BUCKET 4 #define HASH_KEY ( BASE_METHODS / BUCKET ) -static PCLASS pClasses = 0; -static WORD wClasses = 0; -static PMETHOD pMethod = 0; -static PHB_DYNS msgClassName = 0; -static PHB_DYNS msgClassH = 0; -static PHB_DYNS msgEval = 0; -static PHB_DYNS msgClassSel = 0; +static PCLASS s_pClasses = NULL; +static WORD s_wClasses = 0; +static PMETHOD s_pMethod = NULL; +static PHB_DYNS s_msgClassName = NULL; +static PHB_DYNS s_msgClassH = NULL; +static PHB_DYNS s_msgEval = NULL; +static PHB_DYNS s_msgClassSel = NULL; /* All functions contained in classes.c */ @@ -120,9 +120,9 @@ HARBOUR HB___CLSADDMSG( void ) { WORD wClass = hb_parnl( 1 ); - if( wClass && wClass <= wClasses ) + if( wClass && wClass <= s_wClasses ) { - PCLASS pClass = &pClasses[ wClass - 1 ]; + PCLASS pClass = &s_pClasses[ wClass - 1 ]; PHB_DYNS pMessage = hb_dynsymGet( hb_parc( 2 ) ); WORD wType = hb_parni( 4 ); WORD wAt = ( ( ( unsigned ) pMessage ) % pClass->wHashKey ) * BUCKET; @@ -225,19 +225,19 @@ HARBOUR HB___CLSNEW( void ) WORD wSuper = hb_parni( 3 ); /* Super class present */ PCLASS pNewCls; - if( pClasses ) - pClasses = ( PCLASS ) hb_xrealloc( pClasses, - sizeof( CLASS ) * ( wClasses + 1 ) ); + if( s_pClasses ) + s_pClasses = ( PCLASS ) hb_xrealloc( s_pClasses, + sizeof( CLASS ) * ( s_wClasses + 1 ) ); else - pClasses = ( PCLASS ) hb_xgrab( sizeof( CLASS ) ); + s_pClasses = ( PCLASS ) hb_xgrab( sizeof( CLASS ) ); - pNewCls = pClasses + wClasses; + pNewCls = s_pClasses + s_wClasses; pNewCls->szName = ( char * ) hb_xgrab( hb_parclen( 1 ) + 1 ); strcpy( pNewCls->szName, hb_parc( 1 ) ); if( wSuper ) { - PCLASS pSprCls = pClasses + wSuper - 1; + PCLASS pSprCls = s_pClasses + wSuper - 1; WORD wSize; pNewCls->wDataFirst = pSprCls->wDatas; @@ -266,7 +266,7 @@ HARBOUR HB___CLSNEW( void ) memset( pNewCls->pMethods, 0, BASE_METHODS * sizeof( METHOD ) ); } - hb_retni( ++wClasses ); + hb_retni( ++s_wClasses ); } @@ -283,9 +283,9 @@ HARBOUR HB___CLSDELMSG( void ) WORD wClass = hb_parni( 1 ); PHB_ITEM pString = hb_param( 2, IT_STRING ); - if( wClass && wClass <= wClasses && pString ) + if( wClass && wClass <= s_wClasses && pString ) { - PCLASS pClass = pClasses + wClass - 1; + PCLASS pClass = s_pClasses + wClass - 1; PHB_SYMB pMessage = hb_dynsymGet( pString->item.asString.value )->pSymbol; PHB_DYNS pMsg = pMessage->pDynSym; WORD wAt = ( ( ( unsigned ) pMsg ) % pClass->wHashKey ) * BUCKET; @@ -349,9 +349,9 @@ HARBOUR HB___CLSINST( void ) { WORD wClass = hb_parni( 1 ); - if( wClass <= wClasses ) + if( wClass <= s_wClasses ) { - PCLASS pClass = pClasses + ( wClass - 1 ); + PCLASS pClass = s_pClasses + ( wClass - 1 ); WORD wAt; WORD wLimit = pClass->wHashKey * BUCKET; PMETHOD pMeth = pClass->pMethods; /* Initialize DATA */ @@ -375,9 +375,9 @@ HARBOUR HB___CLSMODMSG( void ) WORD wClass = hb_parni( 1 ); PHB_ITEM pString = hb_param( 2, IT_STRING ); - if( wClass && wClass <= wClasses && pString ) + if( wClass && wClass <= s_wClasses && pString ) { - PCLASS pClass = pClasses + wClass - 1; + PCLASS pClass = s_pClasses + wClass - 1; PHB_SYMB pMessage = hb_dynsymGet( pString->item.asString.value )->pSymbol; PHB_DYNS pMsg = pMessage->pDynSym; WORD wAt = ( ( ( unsigned ) pMsg ) % pClass->wHashKey ) * BUCKET; @@ -449,14 +449,14 @@ HARBOUR HB___OBJGETCLSNAME( void ) { wClass = pObject->item.asArray.value->wClass; - hb_retc( pClasses[ wClass - 1 ].szName ); + hb_retc( s_pClasses[ wClass - 1 ].szName ); } else { wClass = hb_parni( 1 ); - if( wClass <= wClasses ) - hb_retc( pClasses[ wClass - 1 ].szName ); + if( wClass <= s_wClasses ) + hb_retc( s_pClasses[ wClass - 1 ].szName ); else hb_retc( "" ); } @@ -482,9 +482,9 @@ static HARBOUR hb___msgClsSel( void ) wClass = pItemRef->item.asArray.value->wClass; } - if( wClass && wClass <= wClasses ) + if( wClass && wClass <= s_wClasses ) { - PCLASS pClass = &pClasses[ wClass - 1 ]; + PCLASS pClass = &s_pClasses[ wClass - 1 ]; WORD wLimit = pClass->wHashKey * BUCKET; /* Number of Hash keys */ WORD wPos = 0; WORD wAt; @@ -533,7 +533,7 @@ static HARBOUR hb___msgEvalInline( void ) WORD wClass = ( stack.pBase + 1 )->item.asArray.value->wClass; WORD w; - hb_arrayGet( pClasses[ wClass - 1 ].pInlines, pMethod->wData, &block ); + hb_arrayGet( s_pClasses[ wClass - 1 ].pInlines, s_pMethod->wData, &block ); hb_vmPushSymbol( &symEval ); hb_vmPush( &block ); @@ -562,7 +562,7 @@ char * hb_objGetClsName( PHB_ITEM pObject ) szClassName = "ARRAY"; else szClassName = - ( pClasses + pObject->item.asArray.value->wClass - 1 )->szName; + ( s_pClasses + pObject->item.asArray.value->wClass - 1 )->szName; } else /* built in types */ { @@ -614,10 +614,10 @@ char * hb_objGetClsName( PHB_ITEM pObject ) static HARBOUR hb___msgGetClsData( void ) { WORD wClass = ( stack.pBase + 1 )->item.asArray.value->wClass; - WORD wIndex = pMethod->wData; + WORD wIndex = s_pMethod->wData; - if( wClass && wClass <= wClasses ) - hb_arrayGet( pClasses[ wClass - 1 ].pClassDatas, wIndex, &stack.Return ); + if( wClass && wClass <= s_wClasses ) + hb_arrayGet( s_pClasses[ wClass - 1 ].pClassDatas, wIndex, &stack.Return ); } @@ -629,7 +629,7 @@ static HARBOUR hb___msgGetClsData( void ) static HARBOUR hb___msgGetData( void ) { PHB_ITEM pObject = stack.pBase + 1; - WORD wIndex = pMethod->wData; + WORD wIndex = s_pMethod->wData; if( wIndex > ( WORD ) hb_arrayLen ( pObject ) ) /* Resize needed */ @@ -654,29 +654,29 @@ PHB_FUNC hb_objGetMethod( PHB_ITEM pObject, PHB_SYMB pMessage ) else wClass = 0; - if( ! msgClassName ) + if( ! s_msgClassName ) { - msgClassName = hb_dynsymGet( "CLASSNAME" ); /* Standard messages */ - msgClassH = hb_dynsymGet( "CLASSH" ); /* Not present in classdef. */ - msgClassSel = hb_dynsymGet( "CLASSSEL" ); - msgEval = hb_dynsymGet( "EVAL" ); + s_msgClassName = hb_dynsymGet( "CLASSNAME" ); /* Standard messages */ + s_msgClassH = hb_dynsymGet( "CLASSH" ); /* Not present in classdef. */ + s_msgClassSel = hb_dynsymGet( "CLASSSEL" ); + s_msgEval = hb_dynsymGet( "EVAL" ); } - if( wClass && wClass <= wClasses ) + if( wClass && wClass <= s_wClasses ) { - PCLASS pClass = &pClasses[ wClass - 1 ]; + PCLASS pClass = &s_pClasses[ wClass - 1 ]; WORD wAt = ( ( ( unsigned ) pMsg ) % pClass->wHashKey ) * BUCKET; WORD wMask = pClass->wHashKey * BUCKET; WORD wLimit = wAt ? ( wAt - 1 ) : ( wMask - 1 ); - pMethod = 0; /* Current method pointer */ + s_pMethod = NULL; /* Current method pointer */ while( wAt != wLimit ) { if( pClass->pMethods[ wAt ].pMessage == pMsg ) { - pMethod = pClass->pMethods + wAt; - return pMethod->pFunction; + s_pMethod = pClass->pMethods + wAt; + return s_pMethod->pFunction; } wAt++; if( wAt == wMask ) @@ -684,19 +684,19 @@ PHB_FUNC hb_objGetMethod( PHB_ITEM pObject, PHB_SYMB pMessage ) } } - if( pMsg == msgClassName ) + if( pMsg == s_msgClassName ) return hb___msgClsName; - else if( pMsg == msgClassH ) + else if( pMsg == s_msgClassH ) return hb___msgClsH; - else if( pMsg == msgClassSel ) + else if( pMsg == s_msgClassSel ) return hb___msgClsSel; - else if( pMsg == msgEval ) + else if( pMsg == s_msgEval ) return hb___msgEvalInline; - return 0; + return NULL; } @@ -810,11 +810,11 @@ void hb_clsReleaseAll( void ) { WORD w; - for( w = 0; w < wClasses; w++ ) - hb_clsRelease( pClasses + w ); + for( w = 0; w < s_wClasses; w++ ) + hb_clsRelease( s_pClasses + w ); - if( pClasses ) - hb_xfree( pClasses ); + if( s_pClasses ) + hb_xfree( s_pClasses ); } @@ -828,7 +828,7 @@ static HARBOUR hb___msgSuper( void ) PHB_ITEM pObject = stack.pBase + 1; PHB_ITEM pSuper = ( PHB_ITEM ) hb_xgrab( sizeof( HB_ITEM ) ); PBASEARRAY pNewBase = ( PBASEARRAY ) hb_xgrab( sizeof( BASEARRAY ) ); - WORD wSuperCls = pMethod->wData; /* Get handle of superclass */ + WORD wSuperCls = s_pMethod->wData; /* Get handle of superclass */ memcpy( pSuper, pObject, sizeof( HB_ITEM ) ); /* Allocate new structures */ @@ -855,10 +855,10 @@ static HARBOUR hb___msgSetClsData( void ) WORD wClass = ( stack.pBase + 1 )->item.asArray.value->wClass; PHB_ITEM pReturn = stack.pBase + 2; - if( wClass && wClass <= wClasses ) + if( wClass && wClass <= s_wClasses ) { - hb_arraySet( pClasses[ wClass - 1 ].pClassDatas, - pMethod->wData, pReturn ); + hb_arraySet( s_pClasses[ wClass - 1 ].pClassDatas, + s_pMethod->wData, pReturn ); hb_itemCopy( &stack.Return, pReturn ); } } @@ -873,7 +873,7 @@ static HARBOUR hb___msgSetData( void ) { PHB_ITEM pObject = stack.pBase + 1; PHB_ITEM pReturn = stack.pBase + 2; - WORD wIndex = pMethod->wData; + WORD wIndex = s_pMethod->wData; if( wIndex > ( WORD ) hb_arrayLen( pObject ) ) /* Resize needed */ @@ -917,9 +917,9 @@ HARBOUR HB___CLSINSTSUPER( void ) hb_errRT_BASE( EG_ARG, 3002, "Super class does not return an object", "__CLSINSTSUPER" ); } - for( w = 0; !bFound && w < wClasses; w++ ) + for( w = 0; !bFound && w < s_wClasses; w++ ) { /* Locate the entry */ - if( !hb_stricmp( pString->item.asString.value, pClasses[ w ].szName ) ) + if( !hb_stricmp( pString->item.asString.value, s_pClasses[ w ].szName ) ) { hb_retni( w + 1 ); /* Entry + 1 = hb___msgClsH */ bFound = TRUE; @@ -945,7 +945,7 @@ HARBOUR HB___CLS_CNTCLSDATA( void ) if( wClass ) { - PCLASS pClass = &pClasses[ wClass - 1 ]; + PCLASS pClass = &s_pClasses[ wClass - 1 ]; hb_retni( hb_arrayLen( pClass->pClassDatas ) ); } } @@ -960,7 +960,7 @@ HARBOUR HB___CLS_CNTDATA( void ) WORD wClass = hb_parnl( 1 ); if( wClass ) - hb_retni( pClasses[ wClass - 1 ].wDatas ); + hb_retni( s_pClasses[ wClass - 1 ].wDatas ); } /* @@ -973,7 +973,7 @@ HARBOUR HB___CLS_DECDATA( void ) WORD wClass = hb_parnl( 1 ); if( wClass ) - hb_retni( pClasses[ wClass - 1 ].wDatas-- ); + hb_retni( s_pClasses[ wClass - 1 ].wDatas-- ); } @@ -987,6 +987,6 @@ HARBOUR HB___CLS_INCDATA( void ) WORD wClass = hb_parnl( 1 ); if( wClass ) - hb_retni( ++pClasses[ wClass - 1 ].wDatas ); + hb_retni( ++s_pClasses[ wClass - 1 ].wDatas ); } diff --git a/harbour/source/rtl/codebloc.c b/harbour/source/rtl/codebloc.c index 4b9daa7155..e4f4535416 100644 --- a/harbour/source/rtl/codebloc.c +++ b/harbour/source/rtl/codebloc.c @@ -58,87 +58,87 @@ HB_CODEBLOCK_PTR hb_codeblockNew( BYTE * pBuffer, WORD *pLocalPosTable, PHB_SYMB pSymbols ) { - HB_CODEBLOCK_PTR pCBlock; + HB_CODEBLOCK_PTR pCBlock; - pCBlock =( HB_CODEBLOCK_PTR ) hb_xgrab( sizeof(HB_CODEBLOCK) ); + pCBlock = ( HB_CODEBLOCK_PTR ) hb_xgrab( sizeof( HB_CODEBLOCK ) ); - /* Store the number of referenced local variables - */ - pCBlock->wLocals =wLocals; - if( wLocals ) - { - /* NOTE: if a codeblock will be created by macro compiler then - * wLocal have to be ZERO - */ - WORD w = 0; - PHB_ITEM pLocal; - HB_HANDLE hMemvar; - - /* Create a table that will store the values of local variables - * accessed in a codeblock - */ - pCBlock->pLocals =(PHB_ITEM) hb_xgrab( wLocals * sizeof(HB_ITEM) ); - - while( wLocals-- ) - { - /* Swap the current value of local variable with the reference to this - * value. - * TODO: If Harbour will support threads in the future then we need - * to implement some kind of semaphores here. + /* Store the number of referenced local variables + */ + pCBlock->wLocals = wLocals; + if( wLocals ) + { + /* NOTE: if a codeblock will be created by macro compiler then + * wLocal have to be ZERO */ - pLocal =stack.pBase +1 +(*pLocalPosTable++); + WORD w = 0; + PHB_ITEM pLocal; + HB_HANDLE hMemvar; - if( ! IS_MEMVAR( pLocal ) ) + /* Create a table that will store the values of local variables + * accessed in a codeblock + */ + pCBlock->pLocals = ( PHB_ITEM ) hb_xgrab( wLocals * sizeof( HB_ITEM ) ); + + while( wLocals-- ) { - /* Change the value only if this variable is not referenced - * by another codeblock yet. - * In this case we have to copy the current value to a global memory - * pool so it can be shared by codeblocks + /* Swap the current value of local variable with the reference to this + * value. + * TODO: If Harbour will support threads in the future then we need + * to implement some kind of semaphores here. */ + pLocal = stack.pBase + 1 + ( *pLocalPosTable++ ); - hMemvar =hb_memvarValueNew( pLocal, FALSE ); + if( ! IS_MEMVAR( pLocal ) ) + { + /* Change the value only if this variable is not referenced + * by another codeblock yet. + * In this case we have to copy the current value to a global memory + * pool so it can be shared by codeblocks + */ - pLocal->type =IT_BYREF | IT_MEMVAR; - pLocal->item.asMemvar.itemsbase =hb_memvarValueBaseAddress(); - pLocal->item.asMemvar.offset =0; - pLocal->item.asMemvar.value =hMemvar; + hMemvar = hb_memvarValueNew( pLocal, FALSE ); - hb_memvarValueIncRef( pLocal->item.asMemvar.value ); - memcpy( pCBlock->pLocals + w, pLocal, sizeof(HB_ITEM) ); + pLocal->type = IT_BYREF | IT_MEMVAR; + pLocal->item.asMemvar.itemsbase = hb_memvarValueBaseAddress(); + pLocal->item.asMemvar.offset = 0; + pLocal->item.asMemvar.value = hMemvar; + + hb_memvarValueIncRef( pLocal->item.asMemvar.value ); + memcpy( pCBlock->pLocals + w, pLocal, sizeof( HB_ITEM ) ); + } + else + { + /* This variable is already detached (by another codeblock) + * - copy the reference to a value + */ + /* Increment the reference counter so this value will not be + * released if other codeblock will be deleted + */ + hb_memvarValueIncRef( pLocal->item.asMemvar.value ); + memcpy( pCBlock->pLocals + w, pLocal, sizeof( HB_ITEM ) ); + + } + + ++w; } - else - { - /* This variable is already detached (by another codeblock) - * - copy the reference to a value - */ - /* Increment the reference counter so this value will not be - * released if other codeblock will be deleted - */ - hb_memvarValueIncRef( pLocal->item.asMemvar.value ); - memcpy( pCBlock->pLocals + w, pLocal, sizeof(HB_ITEM) ); + } + else + pCBlock->pLocals = NULL; - } + /* + * The codeblock pcode is stored in static segment. + * The only allowed operation on a codeblock is evaluating it then + * there is no need to duplicate its pcode - just store the pointer to it + */ + pCBlock->pCode = pBuffer; - ++w; - } - } - else - pCBlock->pLocals =NULL; - - /* - * The codeblock pcode is stored in static segment. - * The only allowed operation on a codeblock is evaluating it then - * there is no need to duplicate its pcode - just store the pointer to it - */ - pCBlock->pCode = pBuffer; - - pCBlock->pSymbols =pSymbols; - pCBlock->lCounter =1; + pCBlock->pSymbols = pSymbols; + pCBlock->lCounter = 1; #ifdef CODEBLOCKDEBUG - printf( "\ncodeblock created (%li) %lx", pCBlock->lCounter, pCBlock ); + printf( "\ncodeblock created (%li) %lx", pCBlock->lCounter, pCBlock ); #endif - return pCBlock; + return pCBlock; } /* Delete a codeblock @@ -181,11 +181,11 @@ void hb_codeblockDelete( HB_ITEM_PTR pItem ) */ void hb_codeblockEvaluate( HB_ITEM_PTR pItem ) { - int iStatics = stack.iStatics; + int iStatics = stack.iStatics; - stack.iStatics = pItem->item.asBlock.statics; - hb_vmExecute( pItem->item.asBlock.value->pCode, pItem->item.asBlock.value->pSymbols ); - stack.iStatics = iStatics; + stack.iStatics = pItem->item.asBlock.statics; + hb_vmExecute( pItem->item.asBlock.value->pCode, pItem->item.asBlock.value->pSymbols ); + stack.iStatics = iStatics; } /* Get local variable referenced in a codeblock @@ -194,16 +194,16 @@ PHB_ITEM hb_codeblockGetVar( PHB_ITEM pItem, LONG iItemPos ) { HB_CODEBLOCK_PTR pCBlock = pItem->item.asBlock.value; /* local variables accessed in a codeblock are always stored as reference */ - return hb_itemUnRef( pCBlock->pLocals -iItemPos -1 ); + return hb_itemUnRef( pCBlock->pLocals - iItemPos - 1 ); } /* Get local variable passed by reference */ PHB_ITEM hb_codeblockGetRef( PHB_ITEM pItem, PHB_ITEM pRefer ) { - HB_CODEBLOCK_PTR pCBlock = pItem->item.asBlock.value; + HB_CODEBLOCK_PTR pCBlock = pItem->item.asBlock.value; - return pCBlock->pLocals -pRefer->item.asRefer.value -1; + return pCBlock->pLocals - pRefer->item.asRefer.value - 1; } /* Copy the codeblock @@ -212,9 +212,9 @@ PHB_ITEM hb_codeblockGetRef( PHB_ITEM pItem, PHB_ITEM pRefer ) */ void hb_codeblockCopy( PHB_ITEM pDest, PHB_ITEM pSource ) { - pDest->item.asBlock.value =pSource->item.asBlock.value; - pDest->item.asBlock.value->lCounter++; - #ifdef CODEBLOCKDEBUG - printf( "\ncopy a codeblock (%li) %lx", pSource->item.asBlock.value->lCounter, pSource->item.asBlock.value ); - #endif + pDest->item.asBlock.value = pSource->item.asBlock.value; + pDest->item.asBlock.value->lCounter++; + #ifdef CODEBLOCKDEBUG + printf( "\ncopy a codeblock (%li) %lx", pSource->item.asBlock.value->lCounter, pSource->item.asBlock.value ); + #endif } diff --git a/harbour/source/rtl/console.c b/harbour/source/rtl/console.c index 776c846f41..c4b791afaf 100644 --- a/harbour/source/rtl/console.c +++ b/harbour/source/rtl/console.c @@ -61,25 +61,25 @@ we can always get the border styles */ #if defined(__GNUC__) - #include - #if defined(__DJGPP__) || defined(__CYGWIN__) || defined(HARBOUR_GCC_OS2) - #include - #endif + #include + #if defined(__DJGPP__) || defined(__CYGWIN__) || defined(HARBOUR_GCC_OS2) + #include + #endif #else - #include + #include #endif #include #define ACCEPT_BUFFER_LEN 256 /*length of input buffer for ACCEPT command */ #if defined(OS_UNIX_COMPATIBLE) -#define CRLF_BUFFER_LEN 2 /*length of buffer for CR/LF characters */ + #define CRLF_BUFFER_LEN 2 /*length of buffer for CR/LF characters */ #else -#define CRLF_BUFFER_LEN 3 /*length of buffer for CR/LF characters */ + #define CRLF_BUFFER_LEN 3 /*length of buffer for CR/LF characters */ #endif static USHORT dev_row, dev_col, p_row, p_col; -static char CrLf[ CRLF_BUFFER_LEN ]; +static char s_szCrLf[ CRLF_BUFFER_LEN ]; void hb_consoleRelease( void ) { @@ -91,12 +91,12 @@ void hb_consoleRelease( void ) void hb_consoleInitialize( void ) { #if defined(OS_DOS_COMPATIBLE) - CrLf[ 0 ] = '\r'; - CrLf[ 1 ] = '\n'; - CrLf[ 2 ] = '\0'; + s_szCrLf[ 0 ] = '\r'; + s_szCrLf[ 1 ] = '\n'; + s_szCrLf[ 2 ] = '\0'; #else - CrLf[ 0 ] = '\n'; - CrLf[ 1 ] = '\0'; + s_szCrLf[ 0 ] = '\n'; + s_szCrLf[ 1 ] = '\0'; #endif p_row = p_col = 0; @@ -122,7 +122,7 @@ void hb_consoleInitialize( void ) char * hb_consoleGetNewLine( void ) { - return CrLf; + return s_szCrLf; } WORD hb_max_row( void ) @@ -452,12 +452,12 @@ void hb_setpos( WORD row, WORD col ) if( row < dev_row || col < dev_col ) { - printf( CrLf ); + printf( s_szCrLf ); dev_col = 0; dev_row++; } else if( row > dev_row ) dev_col = 0; - for( count = dev_row; count < row; count++ ) printf( CrLf ); + for( count = dev_row; count < row; count++ ) printf( s_szCrLf ); for( count = dev_col; count < col; count++ ) printf( " " ); #endif @@ -477,7 +477,7 @@ void hb_devpos( WORD row, WORD col ) write( hb_set_printhan, "\x0C", 1 ); p_row = p_col = 0; } - for( count = p_row; count < row; count++ ) write( hb_set_printhan, CrLf, CRLF_BUFFER_LEN-1 ); + for( count = p_row; count < row; count++ ) write( hb_set_printhan, s_szCrLf, CRLF_BUFFER_LEN-1 ); if( row > p_row ) p_col = 0; col += hb_set.HB_SET_MARGIN; for( count = p_col; count < col; count++ ) write( hb_set_printhan, " ", 1 ); @@ -527,7 +527,7 @@ HARBOUR HB_QOUT( void ) { WORD count; - hb_altout( CrLf, CRLF_BUFFER_LEN - 1 ); + hb_altout( s_szCrLf, CRLF_BUFFER_LEN - 1 ); if( hb_set.HB_SET_PRINTER && hb_set_printhan >= 0 ) { @@ -725,7 +725,7 @@ HARBOUR HB_SCROLL( void ) /* Scrolls a screen region (requires the GT API) */ { WORD count; dev_row = iMR; - for( count = 0; count < dev_row ; count++ ) printf( CrLf ); + for( count = 0; count < dev_row ; count++ ) printf( s_szCrLf ); dev_row = dev_col = 0; } #endif @@ -1065,7 +1065,7 @@ HARBOUR HB___ACCEPT( void ) /* Internal Clipper function used in ACCEPT command if( hb_pcount() == 1 ) /* cPrompt passed */ { - hb_altout( CrLf, CRLF_BUFFER_LEN - 1 ); + hb_altout( s_szCrLf, CRLF_BUFFER_LEN - 1 ); hb_altout( szPrompt, len ); } #ifdef OS_UNIX_COMPATIBLE diff --git a/harbour/source/rtl/dates.c b/harbour/source/rtl/dates.c index 5f3440255c..3ebe8301f5 100644 --- a/harbour/source/rtl/dates.c +++ b/harbour/source/rtl/dates.c @@ -44,10 +44,10 @@ #include #include #if defined(__TURBOC__) || defined(__BORLANDC__) || defined(__DJGPP__) - #include + #include #endif #if defined(_MSC_VER) - #include + #include #endif #ifndef HARBOUR_STRICT_CLIPPER_COMPATIBILITY #define HB_OPTIMIZE_DTOS diff --git a/harbour/source/rtl/dir.c b/harbour/source/rtl/dir.c index 8a08f12b26..d61f64f17f 100644 --- a/harbour/source/rtl/dir.c +++ b/harbour/source/rtl/dir.c @@ -25,117 +25,117 @@ #include "itemapi.h" #if defined(__GNUC__) - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include - #include - #if defined(__DJGPP__) - #include - #endif + #include + #if defined(__DJGPP__) + #include + #endif - #if !defined(HAVE_POSIX_IO) - #define HAVE_POSIX_IO - #endif + #if !defined(HAVE_POSIX_IO) + #define HAVE_POSIX_IO + #endif #endif #if defined(__CYGWIN__) - #include + #include #endif #if defined(__WATCOMC__) || defined(_MSC_VER) - #include - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include + #include - #if !defined(HAVE_POSIX_IO) - #define HAVE_POSIX_IO - #endif + #if !defined(HAVE_POSIX_IO) + #define HAVE_POSIX_IO + #endif #endif #if defined(__IBMCPP__) - #include -/* #include */ -/* #include */ -/* #include */ -/* #include */ -/* #include */ - #include + #include +/* #include */ +/* #include */ +/* #include */ +/* #include */ +/* #include */ + #include - #if !defined(HAVE_POSIX_IO) - #define HAVE_POSIX_IO - #endif + #if !defined(HAVE_POSIX_IO) + #define HAVE_POSIX_IO + #endif #endif #if defined(__BORLANDC__) - #include - #include - #include - #include - #include - #include - #include - #include - #include + #include + #include + #include + #include + #include + #include + #include + #include + #include - #if !defined(HAVE_POSIX_IO) - #define HAVE_POSIX_IO - #ifndef S_IEXEC - #define S_IEXEC 0x0040 /* owner may execute */ - #endif - #ifndef S_IRWXU - #define S_IRWXU 0x01c0 /* RWE permissions mask for owner */ - #endif - #ifndef S_IRUSR - #define S_IRUSR 0x0100 /* owner may read */ - #endif - #ifndef S_IWUSR - #define S_IWUSR 0x0080 /* owner may write */ - #endif - #ifndef S_IXUSR - #define S_IXUSR 0x0040 /* owner may execute */ - #endif - #endif + #if !defined(HAVE_POSIX_IO) + #define HAVE_POSIX_IO + #ifndef S_IEXEC + #define S_IEXEC 0x0040 /* owner may execute */ + #endif + #ifndef S_IRWXU + #define S_IRWXU 0x01c0 /* RWE permissions mask for owner */ + #endif + #ifndef S_IRUSR + #define S_IRUSR 0x0100 /* owner may read */ + #endif + #ifndef S_IWUSR + #define S_IWUSR 0x0080 /* owner may write */ + #endif + #ifndef S_IXUSR + #define S_IXUSR 0x0040 /* owner may execute */ + #endif + #endif #endif #if !defined(FA_RDONLY) - #define FA_RDONLY 1 - #define FA_HIDDEN 2 - #define FA_SYSTEM 4 - #define FA_LABEL 8 - #define FA_DIREC 16 - #define FA_ARCH 32 + #define FA_RDONLY 1 + #define FA_HIDDEN 2 + #define FA_SYSTEM 4 + #define FA_LABEL 8 + #define FA_DIREC 16 + #define FA_ARCH 32 #endif /* this may not work, but lets find out (only implimented for msvc) */ #if !defined(FA_ENCRYPTED) - #define FA_ENCRYPTED 64 - #define FA_NORMAL 128 - #define FA_TEMPORARY 256 - #define FA_SPARSE 512 - #define FA_REPARSE 1024 - #define FA_COMPRESSED 2048 - #define FA_OFFLINE 4096 - #define FA_NOTINDEXED 8192 - #define FA_VOLCOMP 32764 + #define FA_ENCRYPTED 64 + #define FA_NORMAL 128 + #define FA_TEMPORARY 256 + #define FA_SPARSE 512 + #define FA_REPARSE 1024 + #define FA_COMPRESSED 2048 + #define FA_OFFLINE 4096 + #define FA_NOTINDEXED 8192 + #define FA_VOLCOMP 32764 #endif HARBOUR HB_DIRECTORY( void ) { #if defined(HAVE_POSIX_IO) - PHB_ITEM arg1_it = hb_param(1,IT_STRING); - PHB_ITEM arg2_it = hb_param(2,IT_STRING); + PHB_ITEM arg1_it = hb_param( 1, IT_STRING ); + PHB_ITEM arg2_it = hb_param( 2, IT_STRING ); struct stat statbuf; - struct tm *ft; + struct tm * ft; #if defined(_MSC_VER ) struct _finddata_t entry; @@ -151,19 +151,19 @@ HARBOUR HB_DIRECTORY( void ) DIR * dir; #endif - char fullfile[_POSIX_PATH_MAX+1]; - char filename[_POSIX_PATH_MAX+1]; - char pattern[_POSIX_PATH_MAX+1]; - char dirname[_POSIX_PATH_MAX+1]; - char string[_POSIX_PATH_MAX+1]; - char pfname[_POSIX_PATH_MAX+1]; - char pfext[_POSIX_PATH_MAX+1]; - char fname[_POSIX_PATH_MAX+1]; - char fext[_POSIX_PATH_MAX+1]; - char filesize[10]; - char ddate[9]; - char ttime[9]; - char aatrib[8]; + char fullfile[ _POSIX_PATH_MAX + 1 ]; + char filename[ _POSIX_PATH_MAX + 1 ]; + char pattern[ _POSIX_PATH_MAX + 1 ]; + char dirname[ _POSIX_PATH_MAX + 1 ]; + char string[ _POSIX_PATH_MAX + 1 ]; + char pfname[ _POSIX_PATH_MAX + 1 ]; + char pfext[ _POSIX_PATH_MAX + 1 ]; + char fname[ _POSIX_PATH_MAX + 1 ]; + char fext[ _POSIX_PATH_MAX + 1 ]; + char filesize[ 10 ]; + char ddate[ 9 ]; + char ttime[ 9 ]; + char aatrib[ 8 ]; int attrib; long fsize; time_t ftime; @@ -178,178 +178,178 @@ HARBOUR HB_DIRECTORY( void ) PHB_ITEM ptime; PHB_ITEM pattr; - dirname[0] = '\0'; - pattern[0] = '\0'; + dirname[ 0 ] = '\0'; + pattern[ 0 ] = '\0'; if( arg1_it ) { - strcpy(string, hb_parc(1)); - pos = strrchr(string,OS_PATH_DELIMITER); + strcpy( string, hb_parc( 1 ) ); + pos = strrchr( string, OS_PATH_DELIMITER ); if( pos ) { - strcpy(pattern,(pos+1)); - *(pos+1) = '\0'; - strcpy(dirname,string); + strcpy( pattern, pos + 1 ); + *( pos + 1 ) = '\0'; + strcpy( dirname, string ); } else { - strcpy(pattern,string); - strcpy(dirname,".X"); - dirname[1] = OS_PATH_DELIMITER; + strcpy( pattern, string ); + strcpy( dirname, ".X" ); + dirname[ 1 ] = OS_PATH_DELIMITER; } } - if (strlen(pattern) < 1) - strcpy(pattern,"*.*"); - iDirnameLen =strlen(dirname); + if( strlen( pattern ) < 1 ) + strcpy( pattern, "*.*" ); + iDirnameLen = strlen( dirname ); if( iDirnameLen < 1 ) { - strcpy(dirname,".X"); - dirname[1] = OS_PATH_DELIMITER; - iDirnameLen =2; + strcpy( dirname, ".X" ); + dirname[ 1 ] = OS_PATH_DELIMITER; + iDirnameLen = 2; } - if (strlen(pattern) > 0) + if( strlen( pattern ) > 0 ) { - strcpy(string,pattern); - pos = strrchr(string,'.'); + strcpy( string, pattern ); + pos = strrchr( string, '.' ); if( pos ) { - strcpy(pfext,(pos+1)); + strcpy( pfext, pos + 1 ); *pos = '\0'; - strcpy(pfname,string); + strcpy( pfname, string ); } else { - strcpy(pfname,string); - pfext[0] = '\0'; + strcpy( pfname, string ); + pfext[ 0 ] = '\0'; } } /* redundant - if (strlen(pfext) < 1) - pfext[0] = '\0'; + if( strlen( pfext ) < 1 ) + pfext[ 0 ] = '\0'; */ - if (strlen(pfname) < 1) - strcpy(pfname,"*"); + if( strlen( pfname ) < 1 ) + strcpy( pfname, "*" ); /* debug code - printf("\n dirname pattern %s %s ",dirname,pattern); - printf("\n pfname pfext %s %s ",pfname,pfext); - while(0==getchar()); + printf( "\n dirname pattern %s %s ", dirname, pattern ); + printf( "\n pfname pfext %s %s ", pfname, pfext ); + while( 0 == getchar() ); */ /* should have drive,directory in dirname and filespec in pattern */ tzset(); - pdir = hb_itemArrayNew(0); + pdir = hb_itemArrayNew( 0 ); #if defined(_MSC_VER) - strcpy(string,dirname); - strcat(string,pattern); - if( (hFile = _findfirst( string, &entry )) != -1L ) + strcpy( string, dirname ); + strcat( string, pattern ); + if( ( hFile = _findfirst( string, &entry ) ) != -1L ) { do { - strcpy(string,entry.name); + strcpy( string, entry.name ); #elif defined(__IBMCPP__) - strcpy(string,dirname); - strcat(string,pattern); + strcpy( string, dirname ); + strcat( string, pattern ); if( DosFindFirst( string, &hFind, fileTypes, &entry, findSize, &findCount, FIL_STANDARD ) == NO_ERROR && findCount > 0 ) { do { - strcpy(string,entry.achName); + strcpy( string, entry.achName ); #else #if defined(__WATCOMC__) /* opendir in Watcom doesn't like the path delimiter at the end of a string */ - dirname[ iDirnameLen ] ='.'; - dirname[ iDirnameLen+1 ] ='\x0'; + dirname[ iDirnameLen ] = '.'; + dirname[ iDirnameLen+1 ] = '\x0'; #endif dir = opendir( dirname ); #if defined(__WATCOMC__) - dirname[ iDirnameLen ] ='\x0'; - #endif - if (NULL == dir) + dirname[ iDirnameLen ] = '\x0'; + #endif + if( NULL == dir ) { /* TODO: proper error handling */ - printf("\n invalid dirname %s ",dirname); - while(0==getchar()); + printf( "\n invalid dirname %s ", dirname ); + while( 0 == getchar() ); } /* now put everything into an array */ - while ((entry = readdir( dir )) != NULL) + while( ( entry = readdir( dir ) ) != NULL ) { - strcpy(string,entry->d_name); + strcpy( string, entry->d_name ); #endif - pos = strrchr(string,'.'); + pos = strrchr( string, '.' ); if( pos ) { - strcpy(fext,(pos+1)); + strcpy( fext, pos + 1 ); *pos = '\0'; - strcpy(fname,string); + strcpy( fname, string ); } else { - strcpy(fname,string); - fext[0] = '\0'; + strcpy( fname, string ); + fext[ 0 ] = '\0'; } /* redundant - if (strlen(fext) < 1) - fext[0] = '\0'; + if( strlen( fext ) < 1 ) + fext[ 0 ] = '\0'; */ - if (strlen(fname) < 1) - strcpy(fname,"*"); + if( strlen( fname ) < 1 ) + strcpy( fname, "*" ); /* debug code - printf("\n fname fext %s %s ",fname,fext); - while(0==getchar()); + printf( "\n fname fext %s %s ", fname, fext ); + while( 0 == getchar() ); */ - if (hb_strMatchRegExp( fname,pfname) && hb_strMatchRegExp( fext,pfext)) + if( hb_strMatchRegExp( fname, pfname ) && hb_strMatchRegExp( fext, pfext ) ) { - attrib = 0; - aatrib[0] = '\0'; - filesize[0] = '\0'; + attrib = 0; + aatrib[ 0 ] = '\0'; + filesize[ 0 ] = '\0'; #if defined(_MSC_VER) - strcpy(filename,entry.name); + strcpy( filename, entry.name ); #elif defined(__IBMCPP__) strcpy( filename, entry.achName ); #else - strcpy(filename,entry->d_name); + strcpy( filename, entry->d_name ); #endif - strcpy(fullfile,dirname); - strcat(fullfile,filename); + strcpy( fullfile, dirname ); + strcat( fullfile, filename ); - if (-1 == stat(fullfile,&statbuf)) + if( -1 == stat( fullfile, &statbuf ) ) { /* TODO: proper error handling */ - printf("\n invalid file %s ",fullfile); - while(0==getchar()); + printf( "\n invalid file %s ", fullfile ); + while( 0 == getchar() ); } else { /* This might be a problem under Novell when the file is a directory */ /* needs test */ fsize = statbuf.st_size; - sprintf(filesize, "%ld", fsize); + sprintf( filesize, "%ld", fsize ); ftime = statbuf.st_mtime; - ft = localtime(&ftime); - sprintf(ddate, "%04d%02d%02d", - ft->tm_year+1900, ft->tm_mon + 1, ft->tm_mday); + ft = localtime( &ftime ); + sprintf( ddate, "%04d%02d%02d", + ft->tm_year + 1900, ft->tm_mon + 1, ft->tm_mday ); - sprintf(ttime, "%02d:%02d:%02d", - ft->tm_hour, ft->tm_min, ft->tm_sec); + sprintf( ttime, "%02d:%02d:%02d", + ft->tm_hour, ft->tm_min, ft->tm_sec ); /* debug code - printf("\n name date time %s %s %s ",filename,ddate,ttime); - while(0==getchar()); + printf( "\n name date time %s %s %s ", filename, ddate, ttime ); + while( 0 == getchar() ); */ } @@ -357,19 +357,19 @@ HARBOUR HB_DIRECTORY( void ) #if defined(OS_UNIX_COMPATIBLE) /* GNU C on Linux or on other UNIX */ aatrib[ 0 ] = '\0'; - if( S_ISREG(statbuf.st_mode) ) + if( S_ISREG( statbuf.st_mode ) ) strcat( aatrib, "A" ); - if( S_ISDIR(statbuf.st_mode) ) + if( S_ISDIR( statbuf.st_mode ) ) strcat( aatrib, "D" ); - if( S_ISLNK(statbuf.st_mode) ) + if( S_ISLNK( statbuf.st_mode ) ) strcat( aatrib, "L" ); - if( S_ISCHR(statbuf.st_mode) ) + if( S_ISCHR( statbuf.st_mode ) ) strcat( aatrib, "C" ); - if( S_ISBLK(statbuf.st_mode) ) + if( S_ISBLK( statbuf.st_mode ) ) strcat( aatrib, "B" ); - if( S_ISFIFO(statbuf.st_mode) ) + if( S_ISFIFO( statbuf.st_mode ) ) strcat( aatrib, "F" ); - if( S_ISSOCK(statbuf.st_mode) ) + if( S_ISSOCK( statbuf.st_mode ) ) strcat( aatrib, "K" ); #else #if defined(__IBMCPP__) @@ -388,84 +388,84 @@ HARBOUR HB_DIRECTORY( void ) #if defined(_MSC_VER) attrib = entry.attrib; #elif defined(__BORLANDC__) || defined(__DJGPP__) - attrib = _chmod(fullfile,0); + attrib = _chmod( fullfile, 0 ); #else attrib = 0; #endif - if (attrib & FA_ARCH) - strcat(aatrib,"A"); - if (attrib & FA_DIREC) - strcat(aatrib,"D"); - if (attrib & FA_HIDDEN) - strcat(aatrib,"H"); - if (attrib & FA_RDONLY) - strcat(aatrib,"R"); - if (attrib & FA_SYSTEM) - strcat(aatrib,"S"); - if (attrib & FA_LABEL) + if( attrib & FA_ARCH ) + strcat( aatrib, "A" ); + if( attrib & FA_DIREC ) + strcat( aatrib,"D" ); + if( attrib & FA_HIDDEN ) + strcat( aatrib,"H" ); + if( attrib & FA_RDONLY ) + strcat( aatrib,"R" ); + if( attrib & FA_SYSTEM ) + strcat( aatrib,"S" ); + if( attrib & FA_LABEL ) { - strcat(aatrib,"V"); - if (attrib & FA_VOLCOMP) - strcat(aatrib,"L"); /* volume supports compression. */ + strcat( aatrib, "V" ); + if( attrib & FA_VOLCOMP ) + strcat( aatrib, "L" ); /* volume supports compression. */ } /* some of these are known to work under NT - I picked the letters to use.*/ /* needs testing on a Novell drive */ #if defined(USE_NT) - if (attrib & FA_ENCRYPTED) - strcat(aatrib,"E"); -/* if (attrib & FA_NORMAL) */ -/* strcat(aatrib,"N"); */ - if (attrib & FA_TEMPORARY) - strcat(aatrib,"T"); - if (attrib & FA_SPARSE) - strcat(aatrib,"P"); - if (attrib & FA_REPARSE) - strcat(aatrib,"Z"); - if (attrib & FA_COMPRESSED) - strcat(aatrib,"C"); - if (attrib & FA_OFFLINE) - strcat(aatrib,"O"); - if (attrib & FA_NOTINDEXED) - strcat(aatrib,"X"); + if( attrib & FA_ENCRYPTED ) + strcat( aatrib, "E" ); +/* if( attrib & FA_NORMAL ) */ +/* strcat( aatrib, "N" ); */ + if( attrib & FA_TEMPORARY ) + strcat( aatrib, "T" ); + if( attrib & FA_SPARSE ) + strcat( aatrib, "P" ); + if( attrib & FA_REPARSE ) + strcat( aatrib, "Z" ); + if( attrib & FA_COMPRESSED ) + strcat( aatrib, "C" ); + if( attrib & FA_OFFLINE ) + strcat( aatrib, "O" ); + if( attrib & FA_NOTINDEXED ) + strcat( aatrib, "X" ); #endif #endif #endif /* TODO: attribute match rtn */ pos = string; - if( arg2_it && hb_parclen(2) >= 1) + if( arg2_it && hb_parclen( 2 ) >= 1 ) { - strcpy(string, hb_parc(2)); - while (*pos != '\0') + strcpy( string, hb_parc( 2 ) ); + while( *pos != '\0' ) { - *pos = (char)toupper(*pos); + *pos = ( char ) toupper( *pos ); pos++; } - pos = strchr(string,*aatrib); + pos = strchr( string, *aatrib ); } - if ( pos ) + if( pos ) { /* array cname, csize, ddate, ctime, cattributes */ - pfilename = hb_itemPutC(NULL,filename); - psize = hb_itemPutC(NULL,filesize); - pdate = hb_itemPutDS(NULL,ddate); - ptime = hb_itemPutC(NULL,ttime); - pattr = hb_itemPutC(NULL,aatrib); - psubarray = hb_itemArrayNew(5); - hb_itemArrayPut(psubarray,1,pfilename); - hb_itemArrayPut(psubarray,2,psize); - hb_itemArrayPut(psubarray,3,pdate); - hb_itemArrayPut(psubarray,4,ptime); - hb_itemArrayPut(psubarray,5,pattr); + pfilename = hb_itemPutC( NULL, filename ); + psize = hb_itemPutC( NULL, filesize ); + pdate = hb_itemPutDS( NULL, ddate ); + ptime = hb_itemPutC( NULL, ttime ); + pattr = hb_itemPutC( NULL, aatrib ); + psubarray = hb_itemArrayNew( 5 ); + hb_itemArrayPut( psubarray, 1, pfilename ); + hb_itemArrayPut( psubarray, 2, psize ); + hb_itemArrayPut( psubarray, 3, pdate ); + hb_itemArrayPut( psubarray, 4, ptime ); + hb_itemArrayPut( psubarray, 5, pattr ); - hb_arrayAdd(pdir,psubarray); + hb_arrayAdd( pdir, psubarray ); - hb_itemRelease(pfilename); - hb_itemRelease(psize); - hb_itemRelease(pdate); - hb_itemRelease(ptime); - hb_itemRelease(pattr); - hb_itemRelease(psubarray); + hb_itemRelease( pfilename ); + hb_itemRelease( psize ); + hb_itemRelease( pdate ); + hb_itemRelease( ptime ); + hb_itemRelease( pattr ); + hb_itemRelease( psubarray ); } } } @@ -473,7 +473,7 @@ HARBOUR HB_DIRECTORY( void ) while( _findnext( hFile, &entry ) == 0 ); _findclose( hFile ); #elif defined(__IBMCPP__) - while( DosFindNext (hFind, &entry, findSize, &findCount) == NO_ERROR && findCount > 0 ); + while( DosFindNext( hFind, &entry, findSize, &findCount ) == NO_ERROR && findCount > 0 ); DosFindClose( hFind ); #else closedir( dir ); @@ -481,7 +481,7 @@ HARBOUR HB_DIRECTORY( void ) hb_itemCopy( &stack.Return, pdir ); /* DIRECTORY() returns an array */ - hb_itemRelease(pdir); + hb_itemRelease( pdir ); #if defined(_MSC_VER) || defined(__IBMCPP__) diff --git a/harbour/source/rtl/environ.c b/harbour/source/rtl/environ.c index de34986fb7..8de47a3de0 100644 --- a/harbour/source/rtl/environ.c +++ b/harbour/source/rtl/environ.c @@ -12,7 +12,7 @@ be ahead of any and all #include statements! */ #ifdef __IBMCPP__ - #define INCL_DOSMISC + #define INCL_DOSMISC #endif #include "extend.h" @@ -20,47 +20,47 @@ #include "hbver.h" #if defined(__TURBOC__) || defined(__BORLANDC__) || defined(__MSC__) || defined(_MSC_VER) || defined(__DJGPP__) - #include - #include + #include + #include #endif #if defined(__GNUC__) && !defined(__DJGPP__) - #include + #include #endif #ifdef __WATCOMC__ - #include - #if defined(__386__) && !defined(__WINDOWS_386__) - #define INT_86 int386 - #else - #define INT_86 int86 - #endif + #include + #if defined(__386__) && !defined(__WINDOWS_386__) + #define INT_86 int386 + #else + #define INT_86 int86 + #endif #else - #if defined(__EMX__) - #define INT_86 _int86 - #else - #define INT_86 int86 - #endif + #if defined(__EMX__) + #define INT_86 _int86 + #else + #define INT_86 int86 + #endif #endif -HARBOUR HB_OS(void) +HARBOUR HB_OS( void ) { #ifdef __MPW__ /* TODO: not implemented yet */ - hb_retc ( "MacOS" ); + hb_retc( "MacOS" ); #else int hb_osmajor = -1, hb_osminor = -1, hb_osletter = -1; - char * hb_os = 0; - char version [128]; + char * hb_os = NULL; + char version[ 128 ]; #ifdef __IBMCPP__ - unsigned long aulQSV [QSV_MAX] = {0}; - APIRET rc= DosQuerySysInfo (1L, QSV_MAX, (void *) aulQSV, sizeof (ULONG) * QSV_MAX); - if (!rc) + unsigned long aulQSV[ QSV_MAX ] = { 0 }; + APIRET rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX ); + if( ! rc ) { - hb_osmajor = aulQSV [QSV_VERSION_MAJOR] / 10; - hb_osminor = aulQSV [QSV_VERSION_MINOR]; - hb_osletter = (aulQSV [QSV_VERSION_REVISION] > 0 && aulQSV [QSV_VERSION_REVISION] < 26) ? '@' + aulQSV [QSV_VERSION_REVISION] : 0; + hb_osmajor = aulQSV[ QSV_VERSION_MAJOR ] / 10; + hb_osminor = aulQSV[ QSV_VERSION_MINOR ]; + hb_osletter = ( aulQSV[ QSV_VERSION_REVISION ] > 0 && aulQSV[ QSV_VERSION_REVISION ] < 26 ) ? '@' + aulQSV[ QSV_VERSION_REVISION ] : 0; } hb_os = "OS/2"; @@ -91,21 +91,21 @@ HARBOUR HB_OS(void) hb_os = "Windows"; #else #if defined(__MSC__) || defined(_MSC_VER) - if (_osmode == _WIN_MODE) + if( _osmode == _WIN_MODE ) { hb_os = "Windows"; - hb_osmajor = _osmajor; - hb_osminor = _osminor + hb_osmajor = _osmajor; + hb_osminor = _osminor hb_osletter = 0; } #else /* detect Windows */ _AX = 0x160A; - geninterrupt(0x2F); - if(_AX == 0) + geninterrupt( 0x2F ); + if( _AX == 0 ) { - hb_osmajor = _BX / 256; - hb_osminor = _BX % 256; + hb_osmajor = _BX / 256; + hb_osminor = _BX % 256; hb_osletter = 0; hb_os = "Windows 95/98"; } @@ -113,8 +113,8 @@ HARBOUR HB_OS(void) else { hb_os = "DOS"; - hb_osmajor = _osmajor; - hb_osminor = _osminor; + hb_osmajor = _osmajor; + hb_osminor = _osminor; hb_osletter = 0; } @@ -129,34 +129,34 @@ HARBOUR HB_OS(void) INT_86( 0x21, ®s, ®s ); - if(regs.h.al >= 10) + if( regs.h.al >= 10 ) { hb_os = "OS/2"; - if (regs.h.al == 20 && regs.h.ah > 20) + if( regs.h.al == 20 && regs.h.ah > 20 ) { hb_osmajor = regs.h.ah / 10; hb_osminor = regs.h.ah % 10; } else { - hb_osmajor = regs.h.al / 10; - hb_osminor = regs.h.ah; + hb_osmajor = regs.h.al / 10; + hb_osminor = regs.h.ah; } hb_osletter = 0; } else { - hb_osmajor = _osmajor; - hb_osminor = _osminor; + hb_osmajor = _osmajor; + hb_osminor = _osminor; regs.w.ax = 0x160A; INT_86( 0x2F, ®s, ®s ); - if( regs.w.ax == 0) + if( regs.w.ax == 0 ) { hb_os = "Windows"; - hb_osmajor = regs.w.bx / 256; - hb_osminor = regs.w.bx % 256; + hb_osmajor = regs.w.bx / 256; + hb_osminor = regs.w.bx % 256; hb_osletter = 0; } else @@ -167,8 +167,8 @@ HARBOUR HB_OS(void) } #endif /* __TURBOC__ or __BORLANDC__ or __MSC__ 0r __DJGPP__ */ #ifdef __DJGPP__ - hb_os = hb_xgrab (strlen (_os_flavor) + 1); - strcpy (hb_os, _os_flavor); + hb_os = hb_xgrab( strlen( _os_flavor ) + 1 ); + strcpy( hb_os, _os_flavor ); hb_osmajor = _osmajor; hb_osminor = _osminor; hb_osletter = 0; @@ -179,49 +179,51 @@ HARBOUR HB_OS(void) #endif /* __GNUC__ */ #endif /* __IBMCPP__ */ - if (!hb_os) strcpy (version, "Unknown"); - else if (hb_osmajor == -1) strcpy (version, hb_os); - else if (hb_osmajor == -2 ) { /* NOP */ } - else sprintf (version, "%s %d.%02d%c", hb_os, hb_osmajor, hb_osminor, hb_osletter); - hb_retc (version); + if( ! hb_os ) strcpy( version, "Unknown" ); + else if( hb_osmajor == -1 ) strcpy( version, hb_os ); + else if( hb_osmajor == -2 ) { /* NOP */ } + else sprintf( version, "%s %d.%02d%c", hb_os, hb_osmajor, hb_osminor, hb_osletter ); + hb_retc( version ); #ifdef __DJGPP__ - hb_xfree (hb_os); + hb_xfree( hb_os ); #endif #endif /* __MPW__ */ } -HARBOUR HB_VERSION(void) +HARBOUR HB_VERSION( void ) { char hb_ver[ 80 ]; + sprintf( hb_ver, "Harbour %d.%d Intl. (Build %d%s) (%04d.%02d.%02d)", hb_major, hb_minor, hb_build, hb_revision, hb_year, hb_month, hb_day ); + hb_retc( hb_ver ); } -HARBOUR HB_GETENV(void) +HARBOUR HB_GETENV( void ) { if( hb_pcount() == 1 ) { - char *szName = hb_parc(1); - long lName = hb_parclen(1); + char * szName = hb_parc( 1 ); + long lName = hb_parclen( 1 ); - while( lName && szName[lName - 1] == '=' ) + while( lName && szName[ lName - 1 ] == '=' ) { /* strip the '=' or else it will clear the variable! */ - szName[lName - 1] = 0; + szName[ lName - 1 ] = '\0'; lName--; } if( lName ) { - char *Value = getenv(szName); - hb_retc(Value? Value: ""); + char * Value = getenv( szName ); + hb_retc( Value ? Value : "" ); } else - hb_retc(""); + hb_retc( "" ); } else - hb_retc(""); + hb_retc( "" ); } /* @@ -237,7 +239,7 @@ HARBOUR HB_GETENV(void) * Do not use it to run Terminate and Stay Resident programs (in case of DOS) * since it cause several problems * $Examples$ - * __Run( "edit "+cMyTextFile ) // Runs an external editor + * __Run( "edit " + cMyTextFile ) // Runs an external editor * __Run( "command" ) // Gives a DOS shell (DOS only) * $Files$ * source/rtl/environ.c diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 43501f5cff..d9c9f46d7a 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -2,6 +2,19 @@ * $Id$ */ +/* Harbour Project source code + http://www.Harbour-Project.org/ + The following functions are Copyright 1999 Victor Szel : + HB_CURDIR() + HB_DIRCHANGE() + HB_MAKEDIR() + HB_DIRREMOVE() + HB_DISKCHANGE() + HB_DISKNAME() + HB_DISKSPACE() (parts by Luiz Rafael Culik ) + See doc/hdr_tpl.txt, Version 1.2 or later, for licensing terms. +*/ + /* NOTE: In DOS/DJGPP under WinNT4 hb_fsSeek( fhnd, offset < 0, FS_SET) will set the file pointer to the passed negative value, and the subsequent hb_fsWrite() call will fail. In CA-Clipper hb_fsSeek() will fail, @@ -70,6 +83,10 @@ #include #endif +#ifdef DOS + #include +#endif + #ifndef O_BINARY #define O_BINARY 0 /* O_BINARY not defined on Linux */ #endif @@ -618,7 +635,7 @@ BYTE * hb_fsCurDir ( USHORT uiDrive ) /* TODO: Implement nDrive */ -USHORT hb_fsChDrv ( BYTE * nDrive ) +USHORT hb_fsChDrv ( BYTE nDrive ) { USHORT iResult; @@ -894,10 +911,129 @@ HARBOUR HB_FREADSTR( void ) /* NOTE: This function should not return the leading and trailing */ /* (back)slashes. */ +/* NOTE: Clipper 5.3 only */ + HARBOUR HB_CURDIR( void ) { + int uiErrorOld = s_uiErrorLast; + hb_retc( ( char * ) hb_fsCurDir( ( ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) ? ( USHORT )( toupper( *hb_parc( 1 ) ) - 'A' + 1 ) : 0 ) ); + + s_uiErrorLast = uiErrorOld; +} + +/* NOTE: Clipper 5.3 only */ + +HARBOUR HB_DIRCHANGE( void ) +{ + int uiErrorOld = s_uiErrorLast; + int iResult; + + if( ISCHAR( 1 ) ) + { + if( hb_fsChDir( ( BYTE * ) hb_parc( 1 ) ) ) + iResult = 0; + else + iResult = s_uiErrorLast; + } + else + iResult = -1; + + hb_retni( iResult ); + + s_uiErrorLast = uiErrorOld; +} + +/* NOTE: Clipper 5.3 only */ +/* NOTE: Clipper 5.3 NG incorrectly states that the name if this function is + DIRMAKE(), in reality it's not. */ + +HARBOUR HB_MAKEDIR( void ) +{ + int uiErrorOld = s_uiErrorLast; + int iResult; + + if( ISCHAR( 1 ) ) + { + if( hb_fsMkDir( ( BYTE * ) hb_parc( 1 ) ) ) + iResult = 0; + else + iResult = s_uiErrorLast; + } + else + iResult = -1; + + hb_retni( iResult ); + + s_uiErrorLast = uiErrorOld; +} + +/* NOTE: Clipper 5.3 only */ + +HARBOUR HB_DIRREMOVE( void ) +{ + int uiErrorOld = s_uiErrorLast; + int iResult; + + if( ISCHAR( 1 ) ) + { + if( hb_fsRmDir( ( BYTE * ) hb_parc( 1 ) ) ) + iResult = 0; + else + iResult = s_uiErrorLast; + } + else + iResult = -1; + + hb_retni( iResult ); + + s_uiErrorLast = uiErrorOld; +} + +HARBOUR HB_DISKSPACE( void ) +{ + USHORT nDrive = ( ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) ? + ( USHORT )( toupper( *hb_parc( 1 ) ) - 'A' + 1 ) : 0; + +#ifdef DOS + struct diskfree_t disk; + + _dos_getdiskfree( nDrive, &disk ); + + hb_retnl( ( LONG ) ( ( ULONG ) disk.avail_clusters * + ( ULONG ) disk.sectors_per_cluster * + ( ULONG ) disk.bytes_per_sector ) ); +#else + + HB_SYMBOL_UNUSED( nDrive ); + + hb_retnl( 0 ); + +#endif +} + +HARBOUR HB_DISKCHANGE( void ) +{ + int uiErrorOld = s_uiErrorLast; + + hb_retl( ( ISCHAR( 1 ) && hb_parclen( 1 ) > 0 ) ? + hb_fsChDrv( ( USHORT )( toupper( *hb_parc( 1 ) ) - 'A' + 1 ) ) == 0 : + FALSE ); + + s_uiErrorLast = uiErrorOld; +} + +HARBOUR HB_DISKNAME( void ) +{ + int uiErrorOld = s_uiErrorLast; + char szDrive[ 1 ]; + + szDrive[ 0 ] = ( ( char ) hb_fsCurDrv() ) + 'A'; + + hb_retclen( szDrive, 1 ); + + s_uiErrorLast = uiErrorOld; } HARBOUR HB_BIN2I( void ) diff --git a/harbour/source/rtl/fm.c b/harbour/source/rtl/fm.c index 4250ba7e67..d7e750f0b5 100644 --- a/harbour/source/rtl/fm.c +++ b/harbour/source/rtl/fm.c @@ -29,17 +29,17 @@ #define HB_FM_STATISTICS #ifndef __MPW__ - #include + #include #endif #include "extend.h" #include "errorapi.h" #ifdef HB_FM_STATISTICS -static ULONG s_ulMemoryBlocks = 0; /* memory blocks used */ -static ULONG s_ulMemoryMaxBlocks = 0; /* maximum number of used memory blocks */ -static ULONG s_ulMemoryMaxConsumed = 0; /* memory size consumed */ -static ULONG s_ulMemoryConsumed = 0; /* memory max size consumed */ +static ULONG s_ulMemoryBlocks = 0; /* memory blocks used */ +static ULONG s_ulMemoryMaxBlocks = 0; /* maximum number of used memory blocks */ +static ULONG s_ulMemoryMaxConsumed = 0; /* memory size consumed */ +static ULONG s_ulMemoryConsumed = 0; /* memory max size consumed */ #endif void * hb_xalloc( ULONG ulSize ) /* allocates fixed memory, returns NULL on failure */ diff --git a/harbour/source/rtl/gtapi.c b/harbour/source/rtl/gtapi.c index 12eee7e34f..1abee743c4 100644 --- a/harbour/source/rtl/gtapi.c +++ b/harbour/source/rtl/gtapi.c @@ -6,6 +6,8 @@ * GTAPI.C: Generic Terminal for Harbour * * Latest mods: + * 1.66 19990830 vszel Reformatted using Harbour standard. Some + * small cleanups. * 1.65 19990830 ptucker Handle nesting of gtPre/PostExt - corrected * s_uiPreCount handling in gtDispEnd * 1.63 19990811 ptucker Implimented gtPre and PostExt to be used when @@ -74,197 +76,198 @@ static USHORT s_uiColorIndex = 0; static USHORT s_uiMaxCol; static USHORT s_uiMaxRow; -int *_Color; /* masks: 0x0007 Foreground - 0x0070 Background - 0x0008 Bright - 0x0080 Blink - 0x0800 Underline foreground - 0x8000 Underline background - */ -int _ColorCount; +static int * s_Color; /* masks: 0x0007 Foreground + 0x0070 Background + 0x0008 Bright + 0x0080 Blink + 0x0800 Underline foreground + 0x8000 Underline background + */ +static int s_ColorCount; /* gt API functions */ -void hb_gtInit(void) +void hb_gtInit( void ) { /* ptucker */ - _Color = (int *)hb_xgrab(5*sizeof( int ) ); - _ColorCount = 5; - hb_gt_Init(); - hb_gtSetColorStr( hb_set.HB_SET_COLOR ); - hb_gtMaxRow(); - hb_gtMaxCol(); + + s_Color = ( int * ) hb_xgrab( 5 * sizeof( int ) ); + s_ColorCount = 5; + hb_gt_Init(); + hb_gtSetColorStr( hb_set.HB_SET_COLOR ); + hb_gtMaxRow(); + hb_gtMaxCol(); } -void hb_gtExit(void) +void hb_gtExit( void ) { /* ptucker */ - while( s_uiDispCount ) - hb_gtDispEnd(); - hb_gt_Done(); - hb_xfree( _Color ); + while( s_uiDispCount ) + hb_gtDispEnd(); + + hb_gt_Done(); + hb_xfree( s_Color ); } -int hb_gtBox (USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, char* pbyFrame) +int hb_gtBox( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, char * pbyFrame ) { - char pszBox [10]; - char cPadChar; + char pszBox[ 10 ]; + char cPadChar; - USHORT uiRow; - USHORT uiCol; - USHORT height, width, tmp; + USHORT uiRow; + USHORT uiCol; + USHORT height, width, tmp; - USHORT uiTopBak = uiTop; - USHORT uiLeftBak = uiLeft; + USHORT uiTopBak = uiTop; + USHORT uiLeftBak = uiLeft; - USHORT uiMRow = s_uiMaxRow; - USHORT uiMCol = s_uiMaxCol; + USHORT uiMRow = s_uiMaxRow; + USHORT uiMCol = s_uiMaxCol; - /* TODO: Would be better to support these cases, Clipper implementation */ - /* was quite messy for these cases, which can be considered as */ - /* a bug there. */ + /* TODO: Would be better to support these cases, Clipper implementation */ + /* was quite messy for these cases, which can be considered as */ + /* a bug there. */ - if ( uiTop > uiMRow || uiBottom > uiMRow || - uiLeft > uiMCol || uiRight > uiMCol ) - { - return 1; - } + if( uiTop > uiMRow || uiBottom > uiMRow || + uiLeft > uiMCol || uiRight > uiMCol ) + { + return 1; + } - /* For full compatibility, pad box string with last char if too short */ + /* For full compatibility, pad box string with last char if too short */ - cPadChar = ' '; - for (tmp = 0; *pbyFrame && tmp < 9; tmp++) cPadChar = pszBox[tmp] = *pbyFrame++; - while (tmp < 8) pszBox[tmp++] = cPadChar; - pszBox[tmp] = '\0'; + cPadChar = ' '; + for( tmp = 0; *pbyFrame && tmp < 9; tmp++ ) cPadChar = pszBox[ tmp ] = *pbyFrame++; + while( tmp < 8 ) pszBox[ tmp++ ] = cPadChar; + pszBox[ tmp ] = '\0'; - /* Ensure that box is drawn from top left to bottom right. */ - if( uiTop > uiBottom ) - { - tmp = uiTop; - uiTop = uiBottom; - uiBottom = tmp; - } - if( uiLeft > uiRight ) - { - tmp = uiLeft; - uiLeft = uiRight; - uiRight = tmp; - } + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } - uiRow = uiTop; - uiCol = uiLeft; + uiRow = uiTop; + uiCol = uiLeft; - /* Draw the box or line as specified */ - height = uiBottom - uiTop + 1; - width = uiRight - uiLeft + 1; + /* Draw the box or line as specified */ + height = uiBottom - uiTop + 1; + width = uiRight - uiLeft + 1; /* hb_gtDispBegin(); */ - if( height > 1 && width > 1 ) - { - hb_gtWriteAt(uiRow, uiCol, pszBox + 0, sizeof(BYTE)); - hb_gtWriteAt(uiRow, uiRight, pszBox + 2, sizeof(BYTE)); - hb_gtWriteAt(uiBottom, uiCol, pszBox + 6, sizeof(BYTE)); - hb_gtWriteAt(uiBottom, uiRight, pszBox + 4, sizeof(BYTE)); - } + if( height > 1 && width > 1 ) + { + hb_gtWriteAt( uiRow , uiCol , pszBox + 0, sizeof( BYTE ) ); + hb_gtWriteAt( uiRow , uiRight, pszBox + 2, sizeof( BYTE ) ); + hb_gtWriteAt( uiBottom, uiCol , pszBox + 6, sizeof( BYTE ) ); + hb_gtWriteAt( uiBottom, uiRight, pszBox + 4, sizeof( BYTE ) ); + } - uiCol = (height > 1 ? uiLeft + 1 : uiLeft); + uiCol = ( height > 1 ? uiLeft + 1 : uiLeft ); - if( uiCol <= uiRight ) - { - hb_gtRepChar( uiRow, uiCol, pszBox[1], uiRight - uiLeft + (height > 1 ? -1: 1 )); - if( height > 1 ) - hb_gtRepChar( uiBottom, uiCol, pszBox[5], uiRight - uiLeft + (height > 1 ? -1: 1) ); - } + if( uiCol <= uiRight ) + { + hb_gtRepChar( uiRow, uiCol, pszBox[ 1 ], uiRight - uiLeft + ( height > 1 ? -1 : 1 ) ); + if( height > 1 ) + hb_gtRepChar( uiBottom, uiCol, pszBox[ 5 ], uiRight - uiLeft + ( height > 1 ? -1 : 1 ) ); + } - if( pszBox[8] && height > 2 && width > 2 ) - { - for (uiRow = uiTop + 1; uiRow < uiBottom; uiRow++) - { - uiCol = uiLeft; - hb_gtWriteAt(uiRow, uiCol++, pszBox + 7, sizeof(BYTE)); - hb_gtRepChar( uiRow, uiCol, pszBox[8], uiRight - uiLeft - 1 ); - hb_gtWriteAt( uiRow, uiRight, pszBox + 3, sizeof(BYTE)); - } - } - else - { - for( uiRow = (width > 1 ? uiTop + 1 : uiTop); uiRow < (width > 1 ? uiBottom : uiBottom + 1); uiRow++ ) - { - hb_gtWriteAt(uiRow, uiLeft, pszBox + 7, sizeof(BYTE)); - if( width > 1 ) - hb_gtWriteAt(uiRow, uiRight, pszBox + 3, sizeof(BYTE)); - } - } + if( pszBox[ 8 ] && height > 2 && width > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gtWriteAt( uiRow, uiCol++, pszBox + 7, sizeof( BYTE ) ); + hb_gtRepChar( uiRow, uiCol , pszBox[ 8 ], uiRight - uiLeft - 1 ); + hb_gtWriteAt( uiRow, uiRight, pszBox + 3, sizeof( BYTE ) ); + } + } + else + { + for( uiRow = ( width > 1 ? uiTop + 1 : uiTop ); uiRow < ( width > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gtWriteAt( uiRow, uiLeft, pszBox + 7, sizeof( BYTE ) ); + if( width > 1 ) + hb_gtWriteAt( uiRow, uiRight, pszBox + 3, sizeof( BYTE ) ); + } + } -/* speed issue for now */ -/* hb_gtDispEnd(); */ +/* speed issue for now */ +/* hb_gtDispEnd(); */ - hb_gtSetPos(uiTopBak + 1, uiLeftBak + 1); + hb_gtSetPos( uiTopBak + 1, uiLeftBak + 1 ); - return 0; + return 0; } -int hb_gtBoxD(USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight) +int hb_gtBoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight ) { - return(hb_gtBox(uiTop, uiLeft, uiBottom, uiRight, B_DOUBLE)); + return hb_gtBox( uiTop, uiLeft, uiBottom, uiRight, B_DOUBLE ); } -int hb_gtBoxS(USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight) +int hb_gtBoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight ) { - return(hb_gtBox(uiTop, uiLeft, uiBottom, uiRight, B_SINGLE)); + return hb_gtBox( uiTop, uiLeft, uiBottom, uiRight, B_SINGLE ); } int hb_gtColorSelect(USHORT uiColorIndex) { - if(uiColorIndex > _ColorCount ) - { - return(1); - } - else - { - s_uiColorIndex = uiColorIndex; - } + if( uiColorIndex > s_ColorCount ) + return 1; + else + s_uiColorIndex = uiColorIndex; - return(0); + return 0; } -int hb_gtDispBegin(void) +int hb_gtDispBegin( void ) { /* ptucker */ - if( s_uiPreCount == 0 ) - { - ++s_uiDispCount; - hb_gt_DispBegin(); - } - else - ++s_uiPreCount; - return(0); + if( s_uiPreCount == 0 ) + { + ++s_uiDispCount; + hb_gt_DispBegin(); + } + else + ++s_uiPreCount; + + return 0; } -USHORT hb_gtDispCount(void) +USHORT hb_gtDispCount( void ) { - return(s_uiDispCount); + return s_uiDispCount; } -int hb_gtDispEnd(void) +int hb_gtDispEnd( void ) { /* ptucker */ - if( s_uiPreCount == 0 ) - { - hb_gt_DispEnd(); - --s_uiDispCount; - } - else - --s_uiPreCount; - return(0); + if( s_uiPreCount == 0 ) + { + hb_gt_DispEnd(); + --s_uiDispCount; + } + else + --s_uiPreCount; + + return 0; } -int hb_gtPreExt(void) +int hb_gtPreExt( void ) { /* ptucker */ + /* an external (printf...) write is about to take place */ if( s_uiPreCNest == 0 ) @@ -290,7 +293,7 @@ int hb_gtPreExt(void) } -int hb_gtPostExt(void) +int hb_gtPostExt( void ) { /* ptucker */ @@ -312,555 +315,564 @@ int hb_gtPostExt(void) return 0; } -int hb_gtGetColorStr(char * fpColorString) +int hb_gtGetColorStr( char * fpColorString ) { /* ptucker */ - char *sColors; - int i,j=0,k = 0, nColor; + char * sColors; + int i, k = 0; - sColors = (char *)hb_xgrab( _ColorCount * 8 + 1 ); /* max possible */ + sColors = ( char * ) hb_xgrab( s_ColorCount * 8 + 1 ); /* max possible */ - for( i=0; i<_ColorCount; i++ ) - { - j = 0; - nColor = _Color[i] & 7; - do - { - if( ( _Color[i] & (j ? 0x8000 : 0x800)) != 0 ) - sColors[k++] = 'U'; + for( i = 0; i < s_ColorCount; i++ ) + { + int j = 0; + int nColor = s_Color[ i ] & 7; + + do + { + if( ( s_Color[ i ] & ( j ? 0x8000 : 0x800 ) ) != 0 ) + sColors[ k++ ] = 'U'; + else + { + if( nColor == 7 ) + sColors[ k++ ] = 'W'; else { - if( nColor == 7 ) - sColors[k++] = 'W'; - else - { - if( nColor == 0 ) - sColors[k++] = 'N'; - else - { - if( ( nColor & 1 ) != 0 ) - sColors[k++] = 'B'; + if( nColor == 0 ) + sColors[ k++ ] = 'N'; + else + { + if( ( nColor & 1 ) != 0 ) + sColors[ k++ ] = 'B'; - if( ( nColor & 2 ) != 0 ) - sColors[k++] = 'G'; + if( ( nColor & 2 ) != 0 ) + sColors[ k++ ] = 'G'; - if( ( nColor & 4 ) != 0 ) - sColors[k++] = 'R'; - } - } + if( ( nColor & 4 ) != 0 ) + sColors[ k++ ] = 'R'; + } } - if( j == 0 ) - { - if( ( _Color[i] & 8 ) != 0 ) - sColors[k++] = '+'; - sColors[k++] = '/'; - } - else - if( ( _Color[i] & 128 ) != 0 ) - sColors[k++] = '*'; + } + if( j == 0 ) + { + if( ( s_Color[ i ] & 8 ) != 0 ) + sColors[ k++ ] = '+'; + sColors[ k++ ] = '/'; + } + else + if( ( s_Color[ i ] & 128 ) != 0 ) + sColors[ k++ ] = '*'; - nColor = (_Color[i] >> 4) & 7; - } - while( ++j < 2 ); + nColor = ( s_Color[ i ] >> 4 ) & 7; + } + while( ++j < 2 ); - if( i+1 < _ColorCount ) - sColors[k++] = ','; - } - sColors[k++] = '\0'; + if( i + 1 < s_ColorCount ) + sColors[ k++ ] = ','; + } + sColors[ k++ ] = '\0'; - strcpy( fpColorString, sColors ); - hb_xfree( sColors ); + strcpy( fpColorString, sColors ); + hb_xfree( sColors ); - return(0); + return 0; } -int hb_gtSetColorStr(char * fpColorString) +int hb_gtSetColorStr( char * fpColorString ) { /* ptucker */ - char c, buff[6]; - int nPos = 0, - nFore = 0, - nHasI = 0, - nHasU = 0, - nHasX = 0, - nColor = 0, - nSlash = 0, - nCount =-1, - i=0, y; + char c, buff[ 6 ]; + BOOL bHasI = FALSE; + BOOL bHasU = FALSE; + BOOL bHasX = FALSE; + BOOL bSlash = FALSE; + int nPos = 0; + int nFore = 0; + int nColor = 0; + int nCount = -1, i = 0, y; - do - { - c = *fpColorString++; - if( c > 'A' ) - c &= 0x5f; /* convert to upper case */ + do + { + c = *fpColorString++; + if( c > 'A' ) + c &= 0x5f; /* convert to upper case */ - while( c <= '9' && c >= '0' && i < 6 ) - { - if( i==0 ) - memset( buff, '\0', 6 ); + while( c <= '9' && c >= '0' && i < 6 ) + { + if( i == 0 ) + memset( buff, '\0', 6 ); - buff[i++] = c; - c = *fpColorString++; - } - if( i > 0 ) - { - i--; + buff[ i++ ] = c; + c = *fpColorString++; + } + if( i > 0 ) + { + i--; + nColor = 0; + /* TODO: this can probably be replaced with atoi() */ + /* ie: nColor = atoi( buff ); */ + for( y = 1; i + 1; y *= 10, i-- ) + { + if( buff[ i ] != '\0') + nColor += ( ( buff[ i ] - '0' ) * y ); + } + nColor &= 0xf; + i = 0; + ++nCount; + } + + ++nCount; + switch ( c ) + { + case 'B': + nColor |= 1; + break; + case 'G': + nColor |= 2; + break; + case 'I': + bHasI = TRUE; + break; + case 'N': + nColor = 0; + break; + case 'R': + nColor |= 4; + break; + case 'U': + bHasU = TRUE; + break; + case 'W': + nColor = 7; + break; + case 'X': /* always sets forground to 'N' */ + bHasX = TRUE; + break; + case '*': + nFore |= 128; + break; + case '+': + nFore |= 8; + break; + case '/': + if( bHasU ) + { + bHasU = FALSE; + nFore |= 0x800; /* foreground underline bit */ + } + else if( bHasX ) + { + nColor = 0; + bHasX = FALSE; + } + else if( bHasI ) + { + nColor = 7; + bHasI = FALSE; + } + + nFore |= nColor; nColor = 0; - /* TODO: this can probably be replaced with atoi() */ - /* ie: nColor = atoi(buff); */ - for( y=1; i+1; y *= 10, i-- ) + bSlash = TRUE; + break; + case ',': + case '\0': + if( ! nCount ) + nFore = s_Color[ nPos ]; + nCount = -1; + if( nPos == s_ColorCount ) { - if( buff[ i ] != '\0') - nColor += ( ( buff[i] - '0' ) * y ); + s_Color = ( int * ) hb_xrealloc( s_Color, sizeof( int ) * ( nPos + 1 ) ); + ++s_ColorCount; } - nColor &= 0xf; - i=0; - ++nCount; - } + if( bHasX ) + nFore &= 0x88F8; - ++nCount; - switch (c) { - case 'B': - nColor |= 1; - break; - case 'G': - nColor |= 2; - break; - case 'I': - nHasI = 1; - break; - case 'N': - nColor = 0; - break; - case 'R': - nColor |= 4; - break; - case 'U': - nHasU = 1; - break; - case 'W': - nColor = 7; - break; - case 'X': /* always sets forground to 'N' */ - nHasX = 1; - break; - case '*': - nFore |= 128; - break; - case '+': - nFore |= 8; - break; - case '/': - if( nHasU != 0 ) - { - nHasU = 0; - nFore |= 0x800; /* foreground underline bit */ - } - else if( nHasX != 0 ) - { - nColor = 0; - nHasX = 0; - } - else if( nHasI != 0 ) - { - nColor = 7; - nHasI = 0; - } + if( bHasU ) /* background if slash, else foreground */ + nColor |= 0x800; - nFore |= nColor; - nColor = 0; - nSlash = 1; - break; - case ',': - case '\0': - if(!nCount) - nFore = _Color[nPos]; - nCount = -1; - if( nPos == _ColorCount ) - { - _Color = (int *)hb_xrealloc( _Color, sizeof(int)*(nPos +1) ); - ++ _ColorCount; - } - if( nHasX != 0 ) - nFore &= 0x88F8; + if( bHasI ) + { + if( bSlash ) + { + nColor &= 0x88F; + nColor |= 0x007; + nFore &= 0x88F8; + } + else + { + nColor &= 0x8F8; + nColor |= 0x070; + nFore &= 0x888F; + } + } + if( ( nFore & 0x8800 ) != 0 && ( ( nFore | nColor ) & 0x77 ) == 0) + nFore |= 1; - if( nHasU != 0 ) /* background if slash, else foreground */ - nColor |= 0x800; + if( bSlash ) + s_Color[ nPos++ ] = ( nColor << 4 ) | nFore; + else + s_Color[ nPos++ ] = nColor | nFore; - if( nHasI != 0 ) - { - if( nSlash != 0 ) - { - nColor &= 0x88F; - nColor |= 0x007; - nFore &= 0x88F8; - } - else - { - nColor &= 0x8F8; - nColor |= 0x070; - nFore &= 0x888F; - } - } - if( (nFore &0x8800 ) != 0 && ( ( nFore | nColor ) & 0x77 ) == 0) - nFore |= 1; + nColor = nFore = 0; + bSlash = bHasX = bHasU = bHasI = FALSE; + } + } + while( c ); - if( nSlash != 0 ) - _Color[nPos++] = ( nColor << 4 ) | nFore; - else - _Color[nPos++] = nColor | nFore; + if( nPos > 0 && nPos < 4 ) + s_Color[ 4 ] = s_Color[ 1 ]; - nColor=nFore=nSlash=nHasX=nHasU=nHasI=0; - } - } - while( c ); - - if( nPos > 0 && nPos < 4 ) - _Color[4] = _Color[1]; - - return(0); + return 0; } -int hb_gtGetCursor(USHORT * uipCursorShape) +int hb_gtGetCursor( USHORT * uipCursorShape ) { - int i=hb_gt_GetCursorStyle(); - int rc=0; + int i = hb_gt_GetCursorStyle(); + int rc = 0; - if(i <= SC_SPECIAL2) - { - *uipCursorShape = i; - } - else - { - rc=i; - } + if( i <= SC_SPECIAL2 ) + { + * uipCursorShape = i; + } + else + { + rc = i; + } - return(rc); + return rc; } -int hb_gtSetCursor(USHORT uiCursorShape) +int hb_gtSetCursor( USHORT uiCursorShape ) { - hb_gt_SetCursorStyle(uiCursorShape); - return(0); + hb_gt_SetCursorStyle( uiCursorShape ); + + return 0; } -int hb_gtGetPos(USHORT * uipRow, USHORT * uipCol) +int hb_gtGetPos( USHORT * uipRow, USHORT * uipCol ) { - *uipRow = s_uiCurrentRow = hb_gt_Row(); - *uipCol = s_uiCurrentCol = hb_gt_Col(); + *uipRow = s_uiCurrentRow = hb_gt_Row(); + *uipCol = s_uiCurrentCol = hb_gt_Col(); - return(0); + return 0; } -int hb_gtSetPos(USHORT uiRow, USHORT uiCol) +int hb_gtSetPos( USHORT uiRow, USHORT uiCol ) { - /* TODO: in this situation Clipper just turns off the cursor */ - /* any further writes would be accounted for by clipping */ - if(uiRow > s_uiMaxRow || uiCol > s_uiMaxCol) - return(1); + /* TODO: in this situation Clipper just turns off the cursor */ + /* any further writes would be accounted for by clipping */ + if( uiRow > s_uiMaxRow || uiCol > s_uiMaxCol ) + return 1; - s_uiCurrentRow = uiRow; - s_uiCurrentCol = uiCol; + s_uiCurrentRow = uiRow; + s_uiCurrentCol = uiCol; - hb_gt_SetPos( uiRow, uiCol ); + hb_gt_SetPos( uiRow, uiCol ); - return(0); + return 0; } -BOOL hb_gtIsColor(void) +BOOL hb_gtIsColor( void ) { - return hb_gt_IsColor(); + return hb_gt_IsColor(); } -USHORT hb_gtMaxCol(void) +USHORT hb_gtMaxCol( void ) { - return(s_uiMaxCol = hb_gt_GetScreenWidth() - 1); + return s_uiMaxCol = hb_gt_GetScreenWidth() - 1; } -USHORT hb_gtMaxRow(void) +USHORT hb_gtMaxRow( void ) { - return(s_uiMaxRow = hb_gt_GetScreenHeight() - 1); + return s_uiMaxRow = hb_gt_GetScreenHeight() - 1; } -int hb_gtRectSize(USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, USHORT * uipBuffSize) +int hb_gtRectSize( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, USHORT * uipBuffSize ) { - USHORT uiMRow = s_uiMaxRow; - USHORT uiMCol = s_uiMaxCol; + USHORT uiMRow = s_uiMaxRow; + USHORT uiMCol = s_uiMaxCol; - if( uiBottom > uiMRow ) - uiBottom = uiMRow; - if( uiRight > uiMCol ) - uiRight = uiMCol; + if( uiBottom > uiMRow ) + uiBottom = uiMRow; + if( uiRight > uiMCol ) + uiRight = uiMCol; - if( uiTop > uiMRow || uiBottom > uiMRow || - uiLeft > uiMCol || uiRight > uiMCol || - uiTop > uiBottom || uiLeft > uiRight ) - { - return(1); - } - - *uipBuffSize = (uiBottom - uiTop+1) * (uiRight - uiLeft+1) * 2; + if( uiTop > uiMRow || uiBottom > uiMRow || + uiLeft > uiMCol || uiRight > uiMCol || + uiTop > uiBottom || uiLeft > uiRight ) + { + return 1; + } - return(0); + *uipBuffSize = ( uiBottom - uiTop + 1 ) * ( uiRight - uiLeft + 1 ) * 2; + + return 0; } -int hb_gtRepChar(USHORT uiRow, USHORT uiCol, USHORT uiChar, USHORT uiCount) +int hb_gtRepChar( USHORT uiRow, USHORT uiCol, USHORT uiChar, USHORT uiCount ) { - int rc; - char buff[255]; + int rc; + char buff[ 255 ]; - memset(buff, uiChar, uiCount); - buff[uiCount] = 0; - rc=hb_gtSetPos(uiRow, uiCol); - if(rc != 0) - return(rc); - rc=hb_gtWrite(buff, uiCount); + memset( buff, uiChar, uiCount ); + buff[ uiCount ] = 0; + rc = hb_gtSetPos( uiRow, uiCol ); + if( rc != 0 ) + return rc; + rc = hb_gtWrite( buff, uiCount ); - return(rc); + return rc; } -int hb_gtRest(USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, char * vlpScrBuff) +int hb_gtRest( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, char * vlpScrBuff ) { - hb_gt_PutText( uiTop, uiLeft, uiBottom, uiRight, vlpScrBuff); - return(0); + hb_gt_PutText( uiTop, uiLeft, uiBottom, uiRight, vlpScrBuff ); + + return 0; } -int hb_gtSave(USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, char * vlpScrBuff) +int hb_gtSave( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, char * vlpScrBuff ) { - hb_gt_GetText( uiTop, uiLeft, uiBottom, uiRight, vlpScrBuff); - return(0); + hb_gt_GetText( uiTop, uiLeft, uiBottom, uiRight, vlpScrBuff ); + + return 0; } -int hb_gtScrDim(USHORT * uipHeight, USHORT * uipWidth) +int hb_gtScrDim( USHORT * uipHeight, USHORT * uipWidth ) { - *uipHeight = s_uiMaxRow; - *uipWidth = s_uiMaxCol; + *uipHeight = s_uiMaxRow; + *uipWidth = s_uiMaxCol; - return(0); + return 0; } -int hb_gtGetBlink(BOOL * bBlink) +int hb_gtGetBlink( BOOL * bBlink ) { - *bBlink = hb_gt_GetBlink(); + *bBlink = hb_gt_GetBlink(); - return(0); + return 0; } -int hb_gtSetBlink(BOOL bBlink) +int hb_gtSetBlink( BOOL bBlink ) { - hb_gt_SetBlink( bBlink ); - return(0); + hb_gt_SetBlink( bBlink ); + + return 0; } -int hb_gtSetMode(USHORT uiRows, USHORT uiCols) +int hb_gtSetMode( USHORT uiRows, USHORT uiCols ) { /* ptucker */ - hb_gt_SetMode( uiRows, uiCols ); - s_uiMaxRow = hb_gtMaxRow(); - s_uiMaxCol = hb_gtMaxCol(); - return(0); + hb_gt_SetMode( uiRows, uiCols ); + s_uiMaxRow = hb_gtMaxRow(); + s_uiMaxCol = hb_gtMaxCol(); + + return 0; } -int hb_gtSetSnowFlag(BOOL bNoSnow) +int hb_gtSetSnowFlag( BOOL bNoSnow ) { /* COMMENT: This is a compatibility function. If you're running on a CGA and snow is a problem speak up! */ HB_SYMBOL_UNUSED( bNoSnow ); - return(0); + + return 0; } -int hb_gtWrite(char * fpStr, ULONG length) +int hb_gtWrite( char * fpStr, ULONG length ) { - int iRow, iCol, iMaxCol, iMaxRow; - ULONG size = length; - char attr=_Color[s_uiColorIndex] & 0xff, - *fpPointer = fpStr; + int iRow, iCol, iMaxCol, iMaxRow; + ULONG size = length; + char attr = s_Color[ s_uiColorIndex ] & 0xff, + *fpPointer = fpStr; - /* Determine where the cursor is going to end up */ - iRow = s_uiCurrentRow; - iCol = s_uiCurrentCol; - iMaxRow = s_uiMaxRow; - iMaxCol = s_uiMaxCol; + /* Determine where the cursor is going to end up */ + iRow = s_uiCurrentRow; + iCol = s_uiCurrentCol; + iMaxRow = s_uiMaxRow; + iMaxCol = s_uiMaxCol; - length = ( length < iMaxCol-iCol+1 ) ? length : iMaxCol-iCol+1; + length = ( length < iMaxCol-iCol+1 ) ? length : iMaxCol - iCol + 1; - size = length; + size = length; #ifndef HARBOUR_USE_WIN_GTAPI - if (iCol + size > iMaxCol) - { - /* Calculate eventual row position and the remainder size for the column adjust */ - iRow += (size / (iMaxCol + 1)); - size = size % (iMaxCol + 1); - } - iCol += size; - if (iCol > iMaxCol) - { - /* Column movement overflows onto next row */ - iRow++; - iCol -= (iMaxCol + 1); - } - /* If needed, prescroll the display to the new position and adjust the current row - position to account for the prescroll */ - if (iRow > iMaxRow) - { - int iTemp; + if( iCol + size > iMaxCol ) + { + /* Calculate eventual row position and the remainder size for the column adjust */ + iRow += ( size / ( iMaxCol + 1 ) ); + size = size % ( iMaxCol + 1 ); + } + iCol += size; + if( iCol > iMaxCol ) + { + /* Column movement overflows onto next row */ + iRow++; + iCol -= ( iMaxCol + 1 ); + } + /* If needed, prescroll the display to the new position and adjust the current row + position to account for the prescroll */ + if( iRow > iMaxRow ) + { + int iTemp; - hb_gtScroll(0, 0, iMaxRow, iMaxCol, iRow - iMaxRow, 0); - iTemp = s_uiCurrentRow - (iRow - iMaxRow); - if (iTemp < 0) - { - /* The string is too long to fit on the screen. Only display part of it. */ - fpPointer += iMaxCol * abs (iTemp); - iTemp = 0; - if (s_uiCurrentCol > 0) - { - /* Ensure that the truncated text will fill the screen */ - fpPointer -= s_uiCurrentCol; - s_uiCurrentCol = 0; - } - } - else size = length; + hb_gtScroll( 0, 0, iMaxRow, iMaxCol, iRow - iMaxRow, 0 ); + iTemp = s_uiCurrentRow - ( iRow - iMaxRow ); + if( iTemp < 0 ) + { + /* The string is too long to fit on the screen. Only display part of it. */ + fpPointer += iMaxCol * abs( iTemp ); + iTemp = 0; + if( s_uiCurrentCol > 0 ) + { + /* Ensure that the truncated text will fill the screen */ + fpPointer -= s_uiCurrentCol; + s_uiCurrentCol = 0; + } + } + else size = length; - /* Save the new starting row and the new ending row */ - s_uiCurrentRow = iTemp; - iRow = iMaxRow; - } - else size = length; + /* Save the new starting row and the new ending row */ + s_uiCurrentRow = iTemp; + iRow = iMaxRow; + } + else size = length; #endif - /* Now the text string can be displayed */ - hb_gt_Puts( s_uiCurrentRow, s_uiCurrentCol, attr, fpPointer, size); + /* Now the text string can be displayed */ + hb_gt_Puts( s_uiCurrentRow, s_uiCurrentCol, attr, fpPointer, size ); #ifdef HARBOUR_USE_WIN_GTAPI - /* yeah yeah, looks weird */ - hb_gtSetPos( iRow, iCol+size); + /* yeah yeah, looks weird */ + hb_gtSetPos( iRow, iCol + size ); #else - /* Finally, save the new cursor position */ - hb_gtSetPos (iRow, iCol); + /* Finally, save the new cursor position */ + hb_gtSetPos( iRow, iCol ); #endif - return(0); + return 0; } -int hb_gtWriteAt(USHORT uiRow, USHORT uiCol, char * fpStr, ULONG length) +int hb_gtWriteAt( USHORT uiRow, USHORT uiCol, char * fpStr, ULONG length ) { - int rc; + int rc; - if((rc=hb_gtSetPos(uiRow, uiCol)) != 0) - return(rc); + if( ( rc = hb_gtSetPos( uiRow, uiCol ) ) != 0 ) + return rc; - return(hb_gtWrite(fpStr, length)); + return hb_gtWrite( fpStr, length ); } -int hb_gtWriteCon(char * fpStr, ULONG length) +int hb_gtWriteCon( char * fpStr, ULONG length ) { - int rc = 0, ldisp=FALSE, nLen = 0; - USHORT uiRow = s_uiCurrentRow, uiCol = s_uiCurrentCol; - USHORT tmpRow = s_uiCurrentRow, tmpCol = s_uiCurrentCol; - int ch; - char * fpPtr = fpStr; - #define STRNG_SIZE 500 - char strng[ STRNG_SIZE ]; + int rc = 0, nLen = 0; + BOOL ldisp = FALSE; + USHORT uiRow = s_uiCurrentRow, uiCol = s_uiCurrentCol; + USHORT tmpRow = s_uiCurrentRow, tmpCol = s_uiCurrentCol; + int ch; + char * fpPtr = fpStr; + #define STRNG_SIZE 500 + char strng[ STRNG_SIZE ]; - while( length-- ) - { - ch = *fpPtr++; - switch( ch ) - { - case 7: - break; - case 8: + while( length-- ) + { + ch = *fpPtr++; + switch( ch ) + { + case 7: + break; + case 8: /* - COMMENT: Clipper does not scroll backwards up the screen! - if(uiCol > 0) uiCol--; - else if(uiRow > 0) - { - uiRow--; - uiCol=s_uiMaxCol; - } - else - { - hb_gtScroll(0, 0, s_uiMaxRow, s_uiMaxCol, -1, 0); - uiCol=s_uiMaxCol; - } + COMMENT: Clipper does not scroll backwards up the screen! + if( uiCol > 0 ) uiCol--; + else if( uiRow > 0 ) + { + uiRow--; + uiCol = s_uiMaxCol; + } + else + { + hb_gtScroll( 0, 0, s_uiMaxRow, s_uiMaxCol, -1, 0 ); + uiCol = s_uiMaxCol; + } */ - if( nLen > 0 ) - --nLen; - if( uiCol > 0 ) - --uiCol; - - break; - case 10: + if( nLen > 0 ) + --nLen; + if( uiCol > 0 ) + --uiCol; + + break; + case 10: /* - if(uiRow < s_uiMaxRow) uiRow++; - else - { - hb_gtScroll(0, 0, s_uiMaxRow, s_uiMaxCol, 1, 0); - } - hb_gtSetPos (uiRow, uiCol); + if( uiRow < s_uiMaxRow ) uiRow++; + else + hb_gtScroll( 0, 0, s_uiMaxRow, s_uiMaxCol, 1, 0 ); + + hb_gtSetPos( uiRow, uiCol ); */ - ++uiRow; - ldisp=TRUE; - break; + ++uiRow; + ldisp = TRUE; + break; - case 13: - uiCol = 0; - if( *fpPtr != '\n') ldisp=TRUE; - break; + case 13: + uiCol = 0; + if( *fpPtr != '\n') ldisp = TRUE; + break; - default: - if( ++uiCol > s_uiMaxCol ) - { - uiCol = 0; - ++uiRow; - ldisp = TRUE; - } - strng[ nLen++ ] = ch; - if( nLen >= STRNG_SIZE ) ldisp = TRUE; - } - if( ldisp || ! length ) - { - if( nLen ) - rc = hb_gtWrite( strng, nLen ); - nLen=0; - if( uiRow > s_uiMaxRow ) - { - hb_gtScroll( 0, 0, s_uiMaxRow, s_uiMaxCol, uiRow - s_uiMaxRow, 0 ); - uiRow = s_uiMaxRow; - uiCol = 0; - } - tmpRow=uiRow; tmpCol=uiCol; - hb_gtSetPos( uiRow, uiCol); - ldisp = FALSE; - } - if( rc ) - break; - } - return rc; + default: + if( ++uiCol > s_uiMaxCol ) + { + uiCol = 0; + ++uiRow; + ldisp = TRUE; + } + strng[ nLen++ ] = ch; + if( nLen >= STRNG_SIZE ) ldisp = TRUE; + } + if( ldisp || ! length ) + { + if( nLen ) + rc = hb_gtWrite( strng, nLen ); + nLen = 0; + if( uiRow > s_uiMaxRow ) + { + hb_gtScroll( 0, 0, s_uiMaxRow, s_uiMaxCol, uiRow - s_uiMaxRow, 0 ); + uiRow = s_uiMaxRow; + uiCol = 0; + } + tmpRow = uiRow; tmpCol = uiCol; + hb_gtSetPos( uiRow, uiCol); + ldisp = FALSE; + } + if( rc ) + break; + } + + return rc; } -int hb_gtScroll(USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, SHORT iRows, SHORT iCols) +int hb_gtScroll( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, SHORT iRows, SHORT iCols ) { #ifdef HARBOUR_USE_WIN_GTAPI - hb_gt_Scroll( uiTop, uiLeft, uiBottom, uiRight, _Color[s_uiColorIndex], iRows, iCols ); + hb_gt_Scroll( uiTop, uiLeft, uiBottom, uiRight, s_Color[ s_uiColorIndex ], iRows, iCols ); #else USHORT uiRow = s_uiCurrentRow, uiCol = s_uiCurrentCol, uiSize; - int iLength = (uiRight - uiLeft) + 1; + int iLength = ( uiRight - uiLeft ) + 1; int iCount, iColOld, iColNew, iColSize; - if (hb_gtRectSize (uiTop, uiLeft, uiBottom, uiRight, &uiSize) == 0) + if( hb_gtRectSize( uiTop, uiLeft, uiBottom, uiRight, &uiSize ) == 0 ) { - char * fpBlank = (char *)hb_xgrab (iLength); - char * fpBuff = (char *)hb_xgrab (iLength * 2); - if (fpBlank && fpBuff) + char * fpBlank = ( char * ) hb_xgrab( iLength ); + char * fpBuff = ( char * ) hb_xgrab( iLength * 2 ); + if( fpBlank && fpBuff ) { - char attr = _Color[s_uiColorIndex] & 0xff; + char attr = s_Color[ s_uiColorIndex ] & 0xff; memset( fpBlank, ' ', iLength ); iColOld = iColNew = uiLeft; - if (iCols >= 0) + if( iCols >= 0 ) { iColOld += iCols; iColSize = uiRight - uiLeft; @@ -873,103 +885,104 @@ int hb_gtScroll(USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, SH iColSize += iCols; } - for (iCount = (iRows >= 0 ? uiTop : uiBottom); - (iRows >= 0 ? iCount <= uiBottom : iCount >= uiTop); - (iRows >= 0 ? iCount++ : iCount--)) + for( iCount = ( iRows >= 0 ? uiTop : uiBottom ); + ( iRows >= 0 ? iCount <= uiBottom : iCount >= uiTop ); + ( iRows >= 0 ? iCount++ : iCount-- ) ) { int iRowPos = iCount + iRows; /* Blank the scroll region in the current row */ - hb_gt_Puts ( iCount, uiLeft, attr, fpBlank, iLength); + hb_gt_Puts( iCount, uiLeft, attr, fpBlank, iLength ); - if ((iRows || iCols) && iRowPos <= uiBottom && iRowPos >= uiTop) + if( ( iRows || iCols ) && iRowPos <= uiBottom && iRowPos >= uiTop ) { /* Read the text to be scrolled into the current row */ - hb_gt_GetText( iRowPos, iColOld, iRowPos, iColOld + iColSize, fpBuff); + hb_gt_GetText( iRowPos, iColOld, iRowPos, iColOld + iColSize, fpBuff ); /* Write the scrolled text to the current row */ - hb_gt_PutText ( iCount, iColNew, iCount, iColNew + iColSize, fpBuff); + hb_gt_PutText ( iCount, iColNew, iCount, iColNew + iColSize, fpBuff ); } } } - if (fpBlank) hb_xfree (fpBlank); - if (fpBuff) hb_xfree (fpBuff); + if( fpBlank ) hb_xfree( fpBlank ); + if( fpBuff ) hb_xfree( fpBuff ); } s_uiCurrentRow = uiRow; s_uiCurrentCol = uiCol; #endif - return(0); + + return 0; } #ifdef TEST -void main(void) +void main( void ) { - char *test="Testing GT API Functions"; - char *test2="This message wraps!"; - int iRow, iCol; + char * test = "Testing GT API Functions"; + char * test2 = "This message wraps!"; + int iRow, iCol; - /* NOTE: always have to initialze video subsystem */ - hb_gtInit(); + /* NOTE: always have to initialze video subsystem */ + hb_gtInit(); - /* save screen (doesn't work under DOS) */ - /* - char *scr; - USHORT size; + /* save screen (doesn't work under DOS) */ + /* + char * scr; + USHORT size; - hb_gtRectSize(1, 1, hb_gtMaxRow(), hb_gtMaxCol(), &size); - scr=(char *)malloc(size); - hb_gtSave(1, 1, hb_gtMaxRow()-1, hb_gtMaxCol()-1, scr); - */ + hb_gtRectSize( 1, 1, hb_gtMaxRow(), hb_gtMaxCol(), &size ); + scr = ( char * ) hb_xgrab( size ); + hb_gtSave( 1, 1, hb_gtMaxRow() - 1, hb_gtMaxCol() - 1, scr ); + */ - /* writing text */ - hb_gtSetPos(3, 3); - hb_gtWrite(test, strlen(test)); - hb_gtSetPos(12, 42); - hb_gtWrite(test, strlen(test)); + /* writing text */ + hb_gtSetPos( 3, 3 ); + hb_gtWrite( test, strlen( test ) ); + hb_gtSetPos( 12, 42 ); + hb_gtWrite( test, strlen( test ) ); - /* wrapping text */ - hb_gtSetPos(7, 70); - hb_gtWrite(test2, strlen(test2)); + /* wrapping text */ + hb_gtSetPos( 7, 70 ); + hb_gtWrite( test2, strlen( test2 ) ); - /* writing color text */ - hb_gtSetColorStr( "W+/B, B/W" ); - hb_gtColorSelect(_CLR_STANDARD); - hb_gtWrite( "Enhanced color (B/W)", 20 ); - hb_gtSetPos(22, 62); - hb_gtColorSelect(_CLR_ENHANCED); - hb_gtWrite( "Standard Color (W+/B)", 21 ); + /* writing color text */ + hb_gtSetColorStr( "W+/B, B/W" ); + hb_gtColorSelect( _CLR_STANDARD ); + hb_gtWrite( "Enhanced color (B/W)", 20 ); + hb_gtSetPos( 22, 62 ); + hb_gtColorSelect( _CLR_ENHANCED ); + hb_gtWrite( "Standard Color (W+/B)", 21 ); - /* boxes */ - hb_gtBoxS(10, 10, 20, 20); - hb_gtBoxD(10, 40, 15, 45); + /* boxes */ + hb_gtBoxS( 10, 10, 20, 20 ); + hb_gtBoxD( 10, 40, 15, 45 ); - /* cursor functions */ - hb_gtSetPos(12, 1); + /* cursor functions */ + hb_gtSetPos( 12, 1 ); - /* none */ - hb_gtSetCursor(_SC_NONE); - getch(); + /* none */ + hb_gtSetCursor( _SC_NONE ); + getch(); - /* underline */ - hb_gtSetCursor(_SC_NORMAL); - getch(); + /* underline */ + hb_gtSetCursor( _SC_NORMAL ); + getch(); - /* lower half block */ - hb_gtSetCursor(_SC_INSERT); - getch(); + /* lower half block */ + hb_gtSetCursor( _SC_INSERT ); + getch(); - /* full block */ - hb_gtSetCursor(_SC_SPECIAL1); - getch(); + /* full block */ + hb_gtSetCursor( _SC_SPECIAL1 ); + getch(); - /* upper half block */ - hb_gtSetCursor(_SC_SPECIAL2); - getch(); + /* upper half block */ + hb_gtSetCursor( _SC_SPECIAL2 ); + getch(); - /* restore screen (doesn't work under DOS) */ - /* - hb_gtRest(1, 1, hb_gtMaxRow()-1, hb_gtMaxCol()-1, scr); - free(scr); - */ + /* restore screen (doesn't work under DOS) */ + /* + hb_gtRest( 1, 1, hb_gtMaxRow() - 1, hb_gtMaxCol() - 1, scr ); + hb_xfree( scr ); + */ } #endif diff --git a/harbour/source/rtl/inkey.c b/harbour/source/rtl/inkey.c index 0072a95ac5..1597b300d1 100644 --- a/harbour/source/rtl/inkey.c +++ b/harbour/source/rtl/inkey.c @@ -43,7 +43,7 @@ Harbour includes are ahead of platform includes. */ #ifdef __IBMCPP__ - #define INCL_DOSPROCESS + #define INCL_DOSPROCESS #endif #include "extend.h" @@ -52,45 +52,45 @@ #include "init.h" #if defined(__TURBOC__) || defined(__BORLANDC__) || defined(__MSC__) || defined(_MSC_VER) - #include - #include + #include + #include #elif defined(__DJGPP__) - #include - #include + #include + #include #elif defined(HARBOUR_GCC_OS2) - #include + #include #elif defined(__IBMCPP__) - #define INCL_DOSPROCESS - #include - #include + #define INCL_DOSPROCESS + #include + #include #elif defined(__CYGWIN__) - #include + #include #endif #include #ifdef __WATCOMC__ - #include - #include - #if defined(__386__) && !defined(__WINDOWS_386__) - #define INT_86 int386 - #define DOS_REGS REGS - #else - #define INT_86 int86 - #define DOS_REGS REGS - #endif + #include + #include + #if defined(__386__) && !defined(__WINDOWS_386__) + #define INT_86 int386 + #define DOS_REGS REGS + #else + #define INT_86 int86 + #define DOS_REGS REGS + #endif #elif defined(__EMX__) - #define INT_86 _int86 - #define DOS_REGS REGS + #define INT_86 _int86 + #define DOS_REGS REGS #elif defined(_MSC_VER) - #define INT_86 _int86 - #define DOS_REGS _REGS + #define INT_86 _int86 + #define DOS_REGS _REGS #else - #define INT_86 int86 - #define DOS_REGS REGS + #define INT_86 int86 + #define DOS_REGS REGS #endif #if defined(HARBOUR_GCC_OS2) - ULONG DosSleep( ULONG ulMilliseconds ); + ULONG DosSleep( ULONG ulMilliseconds ); #endif #if defined(OS_UNIX_COMPATIBLE) @@ -144,23 +144,23 @@ void hb_releaseCPU( void ) returns zero on failure. (means not supported) */ - #if defined(__TURBOC__) - _AX = 0x1680; - geninterrupt( 0x2f ); - _AH = 0; - _AL ^= 0x80; - #else - union REGS regs; - regs.h.ah = 0x16; - regs.h.al = 0x80; - #if defined(__WATCOMC__) && defined(__386__) - int386( 0x2f, ®s, ®s ); - #else - int86( 0x2f, ®s, ®s ); - #endif - regs.h.ah = 0; - regs.h.al ^= 0x80; - #endif + #if defined(__TURBOC__) + _AX = 0x1680; + geninterrupt( 0x2f ); + _AH = 0; + _AL ^= 0x80; + #else + union REGS regs; + regs.h.ah = 0x16; + regs.h.al = 0x80; + #if defined(__WATCOMC__) && defined(__386__) + int386( 0x2f, ®s, ®s ); + #else + int86( 0x2f, ®s, ®s ); + #endif + regs.h.ah = 0; + regs.h.al ^= 0x80; + #endif #elif defined(OS_UNIX_COMPATIBLE) #else #endif diff --git a/harbour/source/rtl/langapi.c b/harbour/source/rtl/langapi.c index 4b69b5d627..fea1becfb2 100644 --- a/harbour/source/rtl/langapi.c +++ b/harbour/source/rtl/langapi.c @@ -147,51 +147,51 @@ static HB_LANG langEN = } }; -static PHB_LANG langDef = &langEN; +static PHB_LANG s_langDef = &langEN; void hb_langDSet ( PHB_LANG lang ) { if( lang ) - langDef = lang; + s_langDef = lang; } PHB_LANG hb_langDGet ( void ) { - return langDef; + return s_langDef; } char * hb_langDGetName ( void ) { - return langDef->szName; + return s_langDef->szName; } char * hb_langDGetID ( void ) { - return langDef->szID; + return s_langDef->szID; } char * hb_langDGetText ( ULONG ulIndex ) { - return langDef->szTextList[ ( ulIndex < sizeof( langDef->szTextList ) / sizeof( langDef->szTextList[ 0 ] ) ) ? ulIndex : 0 ]; + return s_langDef->szTextList[ ( ulIndex < sizeof( s_langDef->szTextList ) / sizeof( s_langDef->szTextList[ 0 ] ) ) ? ulIndex : 0 ]; } char * hb_langDGetDayName ( ULONG ulIndex ) { - return langDef->szDayNameList[ ( ulIndex < sizeof( langDef->szDayNameList ) / sizeof( langDef->szDayNameList[ 0 ] ) ) ? ulIndex : 0 ]; + return s_langDef->szDayNameList[ ( ulIndex < sizeof( s_langDef->szDayNameList ) / sizeof( s_langDef->szDayNameList[ 0 ] ) ) ? ulIndex : 0 ]; } char * hb_langDGetMonthName ( ULONG ulIndex ) { - return langDef->szMonthNameList[ ( ulIndex < sizeof( langDef->szMonthNameList ) / sizeof( langDef->szMonthNameList[ 0 ] ) ) ? ulIndex : 0 ]; + return s_langDef->szMonthNameList[ ( ulIndex < sizeof( s_langDef->szMonthNameList ) / sizeof( s_langDef->szMonthNameList[ 0 ] ) ) ? ulIndex : 0 ]; } char * hb_langDGetErrorDesc ( ULONG ulIndex ) { - return langDef->szErrorDescList[ ( ulIndex < sizeof( langDef->szErrorDescList ) / sizeof( langDef->szErrorDescList[ 0 ] ) ) ? ulIndex : 0 ]; + return s_langDef->szErrorDescList[ ( ulIndex < sizeof( s_langDef->szErrorDescList ) / sizeof( s_langDef->szErrorDescList[ 0 ] ) ) ? ulIndex : 0 ]; } char * hb_langDGetErrorIntr ( ULONG ulIndex ) { - return langDef->szErrorIntrList[ ( ulIndex < sizeof( langDef->szErrorIntrList ) / sizeof( langDef->szErrorIntrList[ 0 ] ) ) ? ulIndex : 0 ]; + return s_langDef->szErrorIntrList[ ( ulIndex < sizeof( s_langDef->szErrorIntrList ) / sizeof( s_langDef->szErrorIntrList[ 0 ] ) ) ? ulIndex : 0 ]; } diff --git a/harbour/source/rtl/memvars.c b/harbour/source/rtl/memvars.c index 544a48e7a2..4a9447199c 100644 --- a/harbour/source/rtl/memvars.c +++ b/harbour/source/rtl/memvars.c @@ -42,16 +42,16 @@ #define VS_PRIVATE 64 #define VS_PUBLIC 128 -static PHB_DYNS * _privateStack = NULL; -static ULONG _privateStackSize = 0; -static ULONG _privateStackCnt = 0; -static ULONG _privateStackBase = 0; +static PHB_DYNS * s_privateStack = NULL; +static ULONG s_privateStackSize = 0; +static ULONG s_privateStackCnt = 0; +static ULONG s_privateStackBase = 0; -static ULONG _globalTableSize = 0; -static ULONG _globalFirstFree = 0; -static ULONG _globalLastFree = 0; -static ULONG _globalFreeCnt = 0; -static HB_VALUE_PTR _globalTable = NULL; +static ULONG s_globalTableSize = 0; +static ULONG s_globalFirstFree = 0; +static ULONG s_globalLastFree = 0; +static ULONG s_globalFreeCnt = 0; +static HB_VALUE_PTR s_globalTable = NULL; #define TABLE_INITHB_VALUE 100 #define TABLE_EXPANDHB_VALUE 50 @@ -66,38 +66,38 @@ static void hb_memvarAddPrivate( PHB_DYNS ); void hb_memvarsInit( void ) { - _globalTable = (HB_VALUE_PTR) hb_xgrab( sizeof(HB_VALUE) * TABLE_INITHB_VALUE ); - _globalTableSize = TABLE_INITHB_VALUE; - _globalFreeCnt = 0; - _globalFirstFree = _globalLastFree = 1; + s_globalTable = ( HB_VALUE_PTR ) hb_xgrab( sizeof( HB_VALUE ) * TABLE_INITHB_VALUE ); + s_globalTableSize = TABLE_INITHB_VALUE; + s_globalFreeCnt = 0; + s_globalFirstFree = s_globalLastFree = 1; - _privateStack = (PHB_DYNS *) hb_xgrab( sizeof(PHB_DYNS) * TABLE_INITHB_VALUE ); - _privateStackSize = TABLE_INITHB_VALUE; - _privateStackCnt = _privateStackBase = 0; + s_privateStack = ( PHB_DYNS * ) hb_xgrab( sizeof( PHB_DYNS ) * TABLE_INITHB_VALUE ); + s_privateStackSize = TABLE_INITHB_VALUE; + s_privateStackCnt = s_privateStackBase = 0; } void hb_memvarsRelease( void ) { - ULONG ulCnt = _globalLastFree; + ULONG ulCnt = s_globalLastFree; - if( _globalTable ) + if( s_globalTable ) { while( ulCnt ) { - if( _globalTable[ ulCnt ].counter ) + if( s_globalTable[ ulCnt ].counter ) { - hb_itemClear( &_globalTable[ ulCnt ].item ); - _globalTable[ ulCnt ].counter =0; + hb_itemClear( &s_globalTable[ ulCnt ].item ); + s_globalTable[ ulCnt ].counter = 0; } --ulCnt; } - hb_xfree( _globalTable ); + hb_xfree( s_globalTable ); } - if( _privateStack ) - hb_xfree( _privateStack ); + if( s_privateStack ) + hb_xfree( s_privateStack ); } /* @@ -105,7 +105,7 @@ void hb_memvarsRelease( void ) */ HB_VALUE_PTR *hb_memvarValueBaseAddress( void ) { - return &_globalTable; + return &s_globalTable; } @@ -130,59 +130,59 @@ HB_HANDLE hb_memvarValueNew( HB_ITEM_PTR pSource, BOOL bTrueMemvar ) HB_VALUE_PTR pValue; HB_HANDLE hValue = 1; /* handle 0 is reserved */ - if( _globalFreeCnt ) + if( s_globalFreeCnt ) { /* There are holes in the table * Get a first available hole */ - hValue =_globalFirstFree; - --_globalFreeCnt; + hValue = s_globalFirstFree; + --s_globalFreeCnt; /* Now find the next hole */ - if( _globalFreeCnt ) + if( s_globalFreeCnt ) { - ++_globalFirstFree; - while( _globalTable[ _globalFirstFree ].counter ) - ++_globalFirstFree; + ++s_globalFirstFree; + while( s_globalTable[ s_globalFirstFree ].counter ) + ++s_globalFirstFree; } else /* No more holes */ - _globalFirstFree =_globalLastFree; + s_globalFirstFree = s_globalLastFree; } else { /* Allocate the value from the end of table */ - if( _globalFirstFree < _globalTableSize ) + if( s_globalFirstFree < s_globalTableSize ) { - hValue =_globalFirstFree; - _globalFirstFree = ++_globalLastFree; + hValue = s_globalFirstFree; + s_globalFirstFree = ++s_globalLastFree; } else { /* No more free values in the table - expand the table */ - hValue = _globalTableSize; - _globalFirstFree =_globalLastFree = _globalTableSize +1; - _globalTableSize += TABLE_EXPANDHB_VALUE; - _globalTable =(HB_VALUE_PTR) hb_xrealloc( _globalTable, sizeof(HB_VALUE) * _globalTableSize ); + hValue = s_globalTableSize; + s_globalFirstFree = s_globalLastFree = s_globalTableSize + 1; + s_globalTableSize += TABLE_EXPANDHB_VALUE; + s_globalTable = ( HB_VALUE_PTR ) hb_xrealloc( s_globalTable, sizeof( HB_VALUE ) * s_globalTableSize ); } } - pValue =_globalTable + hValue; - pValue->counter =1; + pValue = s_globalTable + hValue; + pValue->counter = 1; if( pSource ) { if( bTrueMemvar ) hb_itemCopy( &pValue->item, pSource ); else - memcpy( &pValue->item, pSource, sizeof(HB_ITEM) ); + memcpy( &pValue->item, pSource, sizeof( HB_ITEM ) ); } else - pValue->item.type =IT_NIL; + pValue->item.type = IT_NIL; #ifdef MEMVARDEBUG printf( "\n>>>>>Memvar item created with handle =%i", hValue ); @@ -202,15 +202,15 @@ static void hb_memvarAddPrivate( PHB_DYNS pDynSym ) { /* Allocate the value from the end of table */ - if( _privateStackCnt == _privateStackSize ) + if( s_privateStackCnt == s_privateStackSize ) { /* No more free values in the table - expand the table */ - _privateStackSize += TABLE_EXPANDHB_VALUE; - _privateStack =(PHB_DYNS *) hb_xrealloc( _privateStack, sizeof(PHB_DYNS) * _privateStackSize ); + s_privateStackSize += TABLE_EXPANDHB_VALUE; + s_privateStack = ( PHB_DYNS * ) hb_xrealloc( s_privateStack, sizeof( PHB_DYNS ) * s_privateStackSize ); } - _privateStack[ _privateStackCnt++ ] =pDynSym; + s_privateStack[ s_privateStackCnt++ ] = pDynSym; } /* @@ -218,8 +218,8 @@ static void hb_memvarAddPrivate( PHB_DYNS pDynSym ) */ ULONG hb_memvarGetPrivatesBase( void ) { - ULONG ulBase = _privateStackBase; - _privateStackBase =_privateStackCnt; + ULONG ulBase = s_privateStackBase; + s_privateStackBase = s_privateStackCnt; return ulBase; } @@ -231,18 +231,18 @@ void hb_memvarSetPrivatesBase( ULONG ulBase ) { HB_HANDLE hVar, hOldValue; - while( _privateStackCnt > _privateStackBase ) + while( s_privateStackCnt > s_privateStackBase ) { - --_privateStackCnt; - hVar =_privateStack[ _privateStackCnt ]->hMemvar; - hOldValue =_globalTable[ hVar ].hPrevMemvar; + --s_privateStackCnt; + hVar = s_privateStack[ s_privateStackCnt ]->hMemvar; + hOldValue = s_globalTable[ hVar ].hPrevMemvar; hb_memvarValueDecRef( hVar ); /* * Restore previous value for variables that were overridden */ - _privateStack[ _privateStackCnt ]->hMemvar =hOldValue; + s_privateStack[ s_privateStackCnt ]->hMemvar = hOldValue; } - _privateStackBase =ulBase; + s_privateStackBase = ulBase; } /* @@ -252,17 +252,17 @@ void hb_memvarSetPrivatesBase( ULONG ulBase ) void hb_memvarValueIncRef( HB_HANDLE hValue ) { #ifdef MEMVARDEBUG - if( hValue < 1 || hValue > _globalTableSize ) + if( hValue < 1 || hValue > s_globalTableSize ) { - printf( "\nInvalid MEMVAR handle %i (max %li)\n", hValue, _globalTableSize ); + printf( "\nInvalid MEMVAR handle %i (max %li)\n", hValue, s_globalTableSize ); exit( 1 ); } #endif - _globalTable[ hValue ].counter++; + s_globalTable[ hValue ].counter++; #ifdef MEMVARDEBUG - printf( "\n+++Memvar item (%i) increment refCounter=%li", hValue, _globalTable[ hValue ].counter ); + printf( "\n+++Memvar item (%i) increment refCounter=%li", hValue, s_globalTable[ hValue ].counter ); #endif } @@ -276,14 +276,14 @@ void hb_memvarValueDecRef( HB_HANDLE hValue ) HB_VALUE_PTR pValue; #ifdef MEMVARDEBUG - if( hValue < 1 || hValue > _globalTableSize ) + if( hValue < 1 || hValue > s_globalTableSize ) { - printf( "\nInvalid MEMVAR handle %i (max %li)\n", hValue, _globalTableSize ); + printf( "\nInvalid MEMVAR handle %i (max %li)\n", hValue, s_globalTableSize ); exit( 1 ); } #endif - pValue =_globalTable + hValue; + pValue = s_globalTable + hValue; #ifdef MEMVARDEBUG printf( "\n---Memvar item (%i) decrement refCounter=%li", hValue, pValue->counter-1 ); #endif @@ -292,24 +292,24 @@ void hb_memvarValueDecRef( HB_HANDLE hValue ) if( --pValue->counter == 0 ) { hb_itemClear( &pValue->item ); - if( _globalFirstFree > hValue ) + if( s_globalFirstFree > hValue ) { - if( (_globalLastFree - hValue) == 1 ) - _globalFirstFree = _globalLastFree =hValue; /* last item */ + if( ( s_globalLastFree - hValue ) == 1 ) + s_globalFirstFree = s_globalLastFree = hValue; /* last item */ else { - _globalFirstFree =hValue; - ++_globalFreeCnt; /* middle item */ + s_globalFirstFree = hValue; + ++s_globalFreeCnt; /* middle item */ } } - else if( (_globalLastFree - hValue) == 1 ) + else if( ( s_globalLastFree - hValue ) == 1 ) { - _globalLastFree =hValue; /* last item */ - if( _globalLastFree == _globalFirstFree ) - _globalFreeCnt =0; + s_globalLastFree = hValue; /* last item */ + if( s_globalLastFree == s_globalFirstFree ) + s_globalFreeCnt = 0; } else - ++_globalFreeCnt; + ++s_globalFreeCnt; #ifdef MEMVARDEBUG printf( "\n<<<<pDynSym; + PHB_DYNS pDyn = ( PHB_DYNS ) pMemvarSymb->pDynSym; if( pDyn ) { @@ -348,9 +346,9 @@ void hb_memvarSetValue( PHB_SYMB pMemvarSymb, HB_ITEM_PTR pItem ) if( pDyn->hMemvar ) { /* value is already created */ - HB_ITEM_PTR pSetItem = &_globalTable[ pDyn->hMemvar ].item; - if( IS_BYREF(pSetItem) ) - hb_itemCopy( hb_itemUnRef(pSetItem), pItem ); + HB_ITEM_PTR pSetItem = &s_globalTable[ pDyn->hMemvar ].item; + if( IS_BYREF( pSetItem ) ) + hb_itemCopy( hb_itemUnRef( pSetItem ), pItem ); else hb_itemCopy( pSetItem, pItem ); } @@ -367,9 +365,7 @@ void hb_memvarSetValue( PHB_SYMB pMemvarSymb, HB_ITEM_PTR pItem ) void hb_memvarGetValue( HB_ITEM_PTR pItem, PHB_SYMB pMemvarSymb ) { - PHB_DYNS pDyn; - - pDyn = (PHB_DYNS) pMemvarSymb->pDynSym; + PHB_DYNS pDyn = ( PHB_DYNS ) pMemvarSymb->pDynSym; if( pDyn ) { @@ -380,9 +376,9 @@ void hb_memvarGetValue( HB_ITEM_PTR pItem, PHB_SYMB pMemvarSymb ) { /* value is already created */ - HB_ITEM_PTR pGetItem = &_globalTable[ pDyn->hMemvar ].item; - if( IS_BYREF(pGetItem) ) - hb_itemCopy( pItem, hb_itemUnRef(pGetItem) ); + HB_ITEM_PTR pGetItem = &s_globalTable[ pDyn->hMemvar ].item; + if( IS_BYREF( pGetItem ) ) + hb_itemCopy( pItem, hb_itemUnRef( pGetItem ) ); else hb_itemCopy( pItem, pGetItem ); } @@ -395,9 +391,7 @@ void hb_memvarGetValue( HB_ITEM_PTR pItem, PHB_SYMB pMemvarSymb ) void hb_memvarGetRefer( HB_ITEM_PTR pItem, PHB_SYMB pMemvarSymb ) { - PHB_DYNS pDyn; - - pDyn = (PHB_DYNS) pMemvarSymb->pDynSym; + PHB_DYNS pDyn = ( PHB_DYNS ) pMemvarSymb->pDynSym; if( pDyn ) { @@ -410,8 +404,8 @@ void hb_memvarGetRefer( HB_ITEM_PTR pItem, PHB_SYMB pMemvarSymb ) pItem->type = IT_BYREF | IT_MEMVAR; pItem->item.asMemvar.offset = 0; pItem->item.asMemvar.value = pDyn->hMemvar; - pItem->item.asMemvar.itemsbase = &_globalTable; - ++_globalTable[ pDyn->hMemvar ].counter; + pItem->item.asMemvar.itemsbase = &s_globalTable; + ++s_globalTable[ pDyn->hMemvar ].counter; } else hb_errRT_BASE( EG_NOVAR, 1003, NULL, pMemvarSymb->szName ); @@ -439,9 +433,9 @@ static void hb_memvarCreateFromItem( PHB_ITEM pMemvar, BYTE bScope, PHB_ITEM pVa /* find dynamic symbol or creeate one */ if( IS_SYMBOL( pMemvar ) ) - pDynVar =hb_dynsymGet( pMemvar->item.asSymbol.value->szName ); + pDynVar = hb_dynsymGet( pMemvar->item.asSymbol.value->szName ); else if( IS_STRING( pMemvar ) ) - pDynVar =hb_dynsymGet( pMemvar->item.asString.value ); + pDynVar = hb_dynsymGet( pMemvar->item.asString.value ); else hb_errRT_BASE( EG_ARG, 3008, NULL, "&" ); @@ -464,16 +458,16 @@ static void hb_memvarCreateFromDynSymbol( PHB_DYNS pDynVar, BYTE bScope, PHB_ITE /* new PUBLIC variable - initialize it to .F. */ - _globalTable[ pDynVar->hMemvar ].item.type = IT_LOGICAL; + s_globalTable[ pDynVar->hMemvar ].item.type = IT_LOGICAL; /* NOTE: PUBLIC variables named CLIPPER and HARBOUR are initialized */ /* to .T., this is normal Clipper behaviour */ - if ( strcmp( pDynVar->pSymbol->szName, "HARBOUR" ) == 0 || + if( strcmp( pDynVar->pSymbol->szName, "HARBOUR" ) == 0 || strcmp( pDynVar->pSymbol->szName, "CLIPPER" ) == 0 ) - _globalTable[ pDynVar->hMemvar ].item.item.asLogical.value = TRUE; + s_globalTable[ pDynVar->hMemvar ].item.item.asLogical.value = TRUE; else - _globalTable[ pDynVar->hMemvar ].item.item.asLogical.value = FALSE; + s_globalTable[ pDynVar->hMemvar ].item.item.asLogical.value = FALSE; } } } @@ -483,10 +477,10 @@ static void hb_memvarCreateFromDynSymbol( PHB_DYNS pDynVar, BYTE bScope, PHB_ITE * visible at this moment so later we can restore this value when * the new variable will be released */ - HB_HANDLE hCurrentValue =pDynVar->hMemvar; + HB_HANDLE hCurrentValue = pDynVar->hMemvar; pDynVar->hMemvar = hb_memvarValueNew( pValue, TRUE ); - _globalTable[ pDynVar->hMemvar ].hPrevMemvar =hCurrentValue; + s_globalTable[ pDynVar->hMemvar ].hPrevMemvar = hCurrentValue; /* Add this variable to the PRIVATE variables stack */ @@ -500,10 +494,10 @@ static void hb_memvarCreateFromDynSymbol( PHB_DYNS pDynVar, BYTE bScope, PHB_ITE */ static void hb_memvarRelease( HB_ITEM_PTR pMemvar ) { - ULONG ulBase = _privateStackCnt; + ULONG ulBase = s_privateStackCnt; PHB_DYNS pDynVar; - if( IS_STRING(pMemvar) ) + if( IS_STRING( pMemvar ) ) { /* Find the variable with a requested name that is currently visible * Start from the top of the stack. @@ -511,7 +505,7 @@ static void hb_memvarRelease( HB_ITEM_PTR pMemvar ) while( ulBase > 0 ) { --ulBase; - pDynVar =_privateStack[ ulBase ]; + pDynVar = s_privateStack[ ulBase ]; /* reset current value to NIL - the overriden variables will be * visible after exit from current procedure */ @@ -519,8 +513,8 @@ static void hb_memvarRelease( HB_ITEM_PTR pMemvar ) { if( hb_stricmp( pDynVar->pSymbol->szName, pMemvar->item.asString.value ) == 0 ) { - hb_itemClear( &_globalTable[ pDynVar->hMemvar ].item ); - ulBase =0; + hb_itemClear( &s_globalTable[ pDynVar->hMemvar ].item ); + ulBase = 0; } } } @@ -537,13 +531,13 @@ static void hb_memvarRelease( HB_ITEM_PTR pMemvar ) */ static void hb_memvarReleaseWithMask( char *szMask, BOOL bInclude ) { - ULONG ulBase = _privateStackCnt; + ULONG ulBase = s_privateStackCnt; PHB_DYNS pDynVar; - while( ulBase > _privateStackBase ) + while( ulBase > s_privateStackBase ) { --ulBase; - pDynVar =_privateStack[ ulBase ]; + pDynVar = s_privateStack[ ulBase ]; /* reset current value to NIL - the overriden variables will be * visible after exit from current procedure */ @@ -551,54 +545,54 @@ static void hb_memvarReleaseWithMask( char *szMask, BOOL bInclude ) { if( bInclude ) { - if( (szMask[ 0 ] == '*') || hb_strMatchRegExp( pDynVar->pSymbol->szName, szMask ) ) - hb_itemClear( &_globalTable[ pDynVar->hMemvar ].item ); + if( ( szMask[ 0 ] == '*') || hb_strMatchRegExp( pDynVar->pSymbol->szName, szMask ) ) + hb_itemClear( &s_globalTable[ pDynVar->hMemvar ].item ); } else if( ! hb_strMatchRegExp( pDynVar->pSymbol->szName, szMask ) ) - hb_itemClear( &_globalTable[ pDynVar->hMemvar ].item ); + hb_itemClear( &s_globalTable[ pDynVar->hMemvar ].item ); } } } /* This function checks the scope of passed variable */ -static int hb_memvarScope( char *szVarName, ULONG ulLength ) +static int hb_memvarScope( char * szVarName, ULONG ulLength ) { int iMemvar = MV_ERROR; - char *szName; + char * szName; - szName =(char *)hb_xalloc( ulLength ); + szName = ( char * ) hb_xalloc( ulLength ); if( szName ) { PHB_DYNS pDynVar; memcpy( szName, szVarName, ulLength ); - pDynVar =hb_dynsymFind( hb_strUpper( szName, ulLength-1 ) ); + pDynVar = hb_dynsymFind( hb_strUpper( szName, ulLength - 1 ) ); if( pDynVar ) { if( pDynVar->hMemvar == 0 ) - iMemvar =MV_UNKNOWN; + iMemvar = MV_UNKNOWN; else { - ULONG ulBase = _privateStackCnt; /* start from the top of the stack */ + ULONG ulBase = s_privateStackCnt; /* start from the top of the stack */ - iMemvar =MV_PUBLIC; + iMemvar = MV_PUBLIC; while( ulBase ) { --ulBase; - if( pDynVar == _privateStack[ ulBase ] ) + if( pDynVar == s_privateStack[ ulBase ] ) { - if( ulBase >= _privateStackBase ) - iMemvar =MV_PRIVATE_LOCAL; + if( ulBase >= s_privateStackBase ) + iMemvar = MV_PRIVATE_LOCAL; else - iMemvar =MV_PRIVATE_GLOBAL; - ulBase =0; + iMemvar = MV_PRIVATE_GLOBAL; + ulBase = 0; } } } } else - iMemvar =MV_NOT_FOUND; + iMemvar = MV_NOT_FOUND; hb_xfree( szName ); } @@ -609,10 +603,11 @@ static HB_DYNS_FUNC( hb_memvarClear ) { if( pDynSymbol->hMemvar ) { - _globalTable[ pDynSymbol->hMemvar ].counter = 1; + s_globalTable[ pDynSymbol->hMemvar ].counter = 1; hb_memvarValueDecRef( pDynSymbol->hMemvar ); - pDynSymbol->hMemvar =0; + pDynSymbol->hMemvar = 0; } + return TRUE; } @@ -662,9 +657,9 @@ HARBOUR HB___MVPUBLIC( void ) if( iCount ) { - for( i=1; i<=iCount; i++ ) + for( i = 1; i <= iCount; i++ ) { - pMemvar =hb_param( i, IT_ANY ); + pMemvar = hb_param( i, IT_ANY ); if( pMemvar ) { if( IS_ARRAY( pMemvar ) ) @@ -674,7 +669,7 @@ HARBOUR HB___MVPUBLIC( void ) ULONG j, ulLen = hb_arrayLen( pMemvar ); HB_ITEM VarItem; - for( j=1; j<=ulLen; j++ ) + for( j = 1; j <= ulLen; j++ ) { hb_arrayGet( pMemvar, j, &VarItem ); hb_memvarCreateFromItem( &VarItem, VS_PUBLIC, NULL ); @@ -730,9 +725,9 @@ HARBOUR HB___MVPRIVATE( void ) if( iCount ) { - for( i=1; i<=iCount; i++ ) + for( i = 1; i <= iCount; i++ ) { - pMemvar =hb_param( i, IT_ANY ); + pMemvar = hb_param( i, IT_ANY ); if( pMemvar ) { if( IS_ARRAY( pMemvar ) ) @@ -742,7 +737,7 @@ HARBOUR HB___MVPRIVATE( void ) ULONG j, ulLen = hb_arrayLen( pMemvar ); HB_ITEM VarItem; - for( j=1; j<=ulLen; j++ ) + for( j = 1; j <= ulLen; j++ ) { hb_arrayGet( pMemvar, j, &VarItem ); hb_memvarCreateFromItem( &VarItem, VS_PRIVATE, NULL ); @@ -823,9 +818,9 @@ HARBOUR HB___MVXRELEASE( void ) if( iCount ) { - for( i=1; i<=iCount; i++ ) + for( i = 1; i <= iCount; i++ ) { - pMemvar =hb_param( i, IT_ANY ); + pMemvar = hb_param( i, IT_ANY ); if( pMemvar ) { if( IS_ARRAY( pMemvar ) ) @@ -835,7 +830,7 @@ HARBOUR HB___MVXRELEASE( void ) ULONG j, ulLen = hb_arrayLen( pMemvar ); HB_ITEM VarItem; - for( j=1; j<=ulLen; j++ ) + for( j = 1; j <= ulLen; j++ ) { hb_arrayGet( pMemvar, j, &VarItem ); hb_memvarRelease( &VarItem ); @@ -896,15 +891,15 @@ HARBOUR HB___MVRELEASE( void ) if( iCount ) { - pMask =hb_param( 1, IT_STRING ); + pMask = hb_param( 1, IT_STRING ); if( pMask ) { BOOL bIncludeVar; if( iCount > 1 ) - bIncludeVar =hb_parl( 2 ); + bIncludeVar = hb_parl( 2 ); else - bIncludeVar =TRUE; + bIncludeVar = TRUE; if( pMask->item.asString.value[ 0 ] == '*' ) bIncludeVar =TRUE; /* delete all memvar variables */ @@ -979,10 +974,10 @@ HARBOUR HB___MVSCOPE( void ) { PHB_ITEM pVarName; - pVarName =hb_param( 1, IT_STRING ); + pVarName = hb_param( 1, IT_STRING ); if( pVarName ) { - iMemvar =hb_memvarScope( pVarName->item.asString.value, pVarName->item.asString.length+1 ); + iMemvar = hb_memvarScope( pVarName->item.asString.value, pVarName->item.asString.length + 1 ); } } hb_retni( iMemvar ); diff --git a/harbour/source/rtl/mouse/mouseos2.c b/harbour/source/rtl/mouse/mouseos2.c index 05368a6987..9f277b445b 100644 --- a/harbour/source/rtl/mouse/mouseos2.c +++ b/harbour/source/rtl/mouse/mouseos2.c @@ -32,81 +32,52 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit their web site at http://www.gnu.org/). + V 1.3 Chen Kedem hb_mouse_Hide() now work in any text + screen mode by calling VioGetMode. + hb_mouse_IsButtonPressed() now return + TRUE if any button was pressed. V 1.0 Chen Kedem Initial version. */ +#define INCL_MOU +#define INCL_VIO /* needed only for VioGetMode/VIOMODEINFO */ +#define INCL_NOPMAPI /* exclude Presentation Manager Include File */ + +#include #include "mouseapi.h" -/*---------------------------------------------------------------------------*/ -/* TODO: those exist in os2.h which I don't have */ -/* #define INCL_???? as needed */ -/* #include */ -typedef unsigned BOOL; -typedef unsigned short USHORT; -typedef unsigned long ULONG; -#define API unsigned extern far pascal -#define TRUE 1 -#define FALSE 0 -API MouOpen ( void far *, unsigned far * ); -API MouClose ( unsigned ); -API MouDrawPtr ( unsigned ); -API MouRemovePtr (); -API MouGetPtrPos (); -API MouSetPtrPos (); -API MouGetNumButtons (); -API MouReadEventQue (); -typedef struct _NOPTRRECT { - USHORT row; - USHORT col; - USHORT cRow; - USHORT cCol; -} NOPTRRECT; -typedef struct _PTRLOC { - USHORT row; - USHORT col; -} PTRLOC; -typedef struct _MOUEVENTINFO { - USHORT fs; /* Bit(s) Significance (if set) Mask ? - 0 mouse move, no buttons down MOUSE_MOTION - 1 mouse move, button 1 down MOUSE_MOTION_WITH_BN1_DOWN - 2 button 1 down MOUSE_BN1_DOWN - 3 mouse move, button 2 down MOUSE_MOTION_WITH_BN2_DOWN - 4 button 2 down MOUSE_BN2_DOWN - 5 mouse move, button 3 down MOUSE_MOTION_WITH_BN3_DOWN - 6 button 3 down MOUSE_BN3_DOWN - 7-15 reserved (0) */ - ULONG time; - USHORT row; - USHORT col; -} MOUEVENTINFO; -/*---------------------------------------------------------------------------*/ - -static unsigned suMouHandle; /* mouse logical handle */ +static unsigned s_uMouHandle; /* mouse logical handle */ void hb_mouse_Init() { - if ( MouOpen ( 0L, &suMouHandle ) ) /* try to open mouse */ - suMouHandle = 0; /* no mouse found */ + USHORT fsEvents = MOUSE_MOTION_WITH_BN1_DOWN | MOUSE_BN1_DOWN | + MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_BN2_DOWN | + MOUSE_MOTION_WITH_BN3_DOWN | MOUSE_BN3_DOWN ; + + if ( MouOpen ( 0L, &s_uMouHandle ) ) /* try to open mouse */ + s_uMouHandle = 0; /* no mouse found */ + else + MouSetEventMask ( &fsEvents, s_uMouHandle ); /* mask some events */ } void hb_mouse_Exit(void) { - if ( suMouHandle ) + if ( s_uMouHandle ) { - MouClose ( suMouHandle ); /* relese mouse handle */ - suMouHandle = 0; + MouClose ( s_uMouHandle ); /* relese mouse handle */ + s_uMouHandle = 0; } } BOOL hb_mouse_IsPresent(void) { - return ( suMouHandle != 0 ); + return ( s_uMouHandle != 0 ); } void hb_mouse_Show(void) { - if ( suMouHandle ) - MouDrawPtr ( suMouHandle ); + if ( s_uMouHandle ) + MouDrawPtr ( s_uMouHandle ); } void hb_mouse_Hide(void) @@ -115,20 +86,22 @@ void hb_mouse_Hide(void) NOTE: mouse cursor always visible if not in full screen */ NOPTRRECT rect; - if ( suMouHandle ) + VIOMODEINFO vi; /* needed to get max Row/Col */ + if ( s_uMouHandle ) { /* - QUESTION: should I call the GT function ? + QUESTION: should I call the GT MaxRow/Col function ? pro: encapsulating of the GetScreen function con: calling function from another module, GT must be linked in con: VioGetMode is been called twice - may be a just a call to MaxRow/Col would be enough */ - rect.row = 0; /* x-coordinate upper left */ - rect.col = 0; /* y-coordinate upper left */ - rect.cRow = 20/*hb_gt_GetScreenHeight()*/; /* x-coordinate lower right */ - rect.cCol = 60/*hb_gt_GetScreenWidth()*/; /* y-coordinate lower right */ - MouRemovePtr ( &rect, suMouHandle ); + vi.cb = sizeof(VIOMODEINFO); + VioGetMode(&vi, 0); + rect.row = 0; /* x-coordinate upper left */ + rect.col = 0; /* y-coordinate upper left */ + rect.cRow = vi.row - 1; /* x-coordinate lower right */ + rect.cCol = vi.col - 1; /* y-coordinate lower right */ + MouRemovePtr ( &rect, s_uMouHandle ); } } @@ -141,9 +114,9 @@ void hb_mouse_Hide(void) int hb_mouse_Col(void) { PTRLOC pos; - if ( suMouHandle ) + if ( s_uMouHandle ) { - MouGetPtrPos ( &pos, suMouHandle ); + MouGetPtrPos ( &pos, s_uMouHandle ); } return ( (int)pos.col ); } @@ -151,9 +124,9 @@ int hb_mouse_Col(void) int hb_mouse_Row(void) { PTRLOC pos; - if ( suMouHandle ) + if ( s_uMouHandle ) { - MouGetPtrPos ( &pos, suMouHandle ); + MouGetPtrPos ( &pos, s_uMouHandle ); } return ( (int)pos.row ); } @@ -161,39 +134,60 @@ int hb_mouse_Row(void) void hb_mouse_SetPos( int row, int col ) { PTRLOC pos; - if ( suMouHandle ) + if ( s_uMouHandle ) { pos.row = (USHORT)row; pos.col = (USHORT)col; - MouSetPtrPos ( &pos, suMouHandle ); + MouSetPtrPos ( &pos, s_uMouHandle ); } } BOOL hb_mouse_IsButtonPressed( int iButton ) { /* - TODO: just a sample, a work should be done here ! + TOFIX: every time I read event from the queue I lose the result + so I can not check if iButton was pressed, so for now I ignore + iButton and return TRUE if the last event saved had DOWN in it. + also to keep the noise level down I mask out MOUSE_MOTION events. */ - BOOL bPressed = FALSE; + USHORT uMask = 0x0000; USHORT WaitOption = 0; /* 1 = wait until mouse event exist, 0 = don't */ MOUEVENTINFO MouEvent; - if ( suMouHandle ) + if ( s_uMouHandle ) { - MouReadEventQue ( &MouEvent, &WaitOption, suMouHandle ); - /* - now MouEvent.fs contain the mask for the mouse event, - what to do next? - */ + MouReadEventQue ( &MouEvent, &WaitOption, s_uMouHandle ); + uMask = MouEvent.fs; + +#ifdef PLEASE_PLEASE_MAKE_IT_WORK + switch(iButton) + { + case 1: + uMask &= ( MOUSE_MOTION_WITH_BN1_DOWN | MOUSE_BN1_DOWN ); + break; + case 2: + uMask &= ( MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_BN2_DOWN ); + break; + case 3: + uMask &= ( MOUSE_MOTION_WITH_BN3_DOWN | MOUSE_BN3_DOWN ); + break; + } +#else + uMask &= ( + MOUSE_MOTION_WITH_BN1_DOWN | MOUSE_BN1_DOWN | + MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_BN2_DOWN | + MOUSE_MOTION_WITH_BN3_DOWN | MOUSE_BN3_DOWN + ) ; +#endif } - return ( bPressed ); + return ( uMask != 0 ); } int hb_mouse_CountButton(void) { USHORT usButtons = 0; - if ( suMouHandle ) + if ( s_uMouHandle ) { - MouGetNumButtons ( &usButtons, suMouHandle ); + MouGetNumButtons ( &usButtons, s_uMouHandle ); } return ( (int)usButtons ); } @@ -201,16 +195,14 @@ int hb_mouse_CountButton(void) void hb_mouse_SetBounds( int iTop, int iLeft, int iBottom, int iRight ) { /* - NOTE: I don't know if the OS/2 got a function to do that, - the old book I'm using does not have such. + TODO: (I don't think that the OS/2 got a function to do it) */ } void hb_mouse_GetBounds( int * piTop, int * piLeft, int * piBottom, int * piRight ) { /* - NOTE: I don't know if the OS/2 got a function to do that, - the old book I'm using does not have such. + TODO: (I don't think that the OS/2 got a function to do it) */ } diff --git a/harbour/source/rtl/set.c b/harbour/source/rtl/set.c index d5e425e7f5..e26b1282e7 100644 --- a/harbour/source/rtl/set.c +++ b/harbour/source/rtl/set.c @@ -149,20 +149,20 @@ */ #if defined(__GNUC__) - #include - #include - #if defined(__DJGPP__) - #include - #endif + #include + #include + #if defined(__DJGPP__) + #include + #endif #else - #ifndef __MPW__ - #include - #endif + #ifndef __MPW__ + #include + #endif #endif #include #ifndef __MPW__ - #include + #include #endif #include @@ -190,13 +190,13 @@ static BOOL set_logical( PHB_ITEM pItem ) if( IS_LOGICAL( pItem ) ) logical = pItem->item.asLogical.value; else if( IS_STRING( pItem ) ) { - if( pItem->item.asString.length == 2 ) + if( pItem->item.asString.length >= 2 ) { if( toupper( pItem->item.asString.value[ 0 ] ) == 'O' && toupper( pItem->item.asString.value[ 1 ] ) == 'N' ) logical = TRUE; } - else if( pItem->item.asString.length == 3 ) + else if( pItem->item.asString.length >= 3 ) { if( toupper( pItem->item.asString.value[ 0 ] ) == 'O' && toupper( pItem->item.asString.value[ 1 ] ) == 'F' @@ -351,13 +351,13 @@ HARBOUR HB___SETCENTURY( void ) if( pItem && IS_LOGICAL( pItem ) ) hb_set_century = pItem->item.asLogical.value; else if( pItem && IS_STRING( pItem ) ) { - if( pItem->item.asString.length == 2 ) + if( pItem->item.asString.length >= 2 ) { if( toupper( pItem->item.asString.value[ 0 ] ) == 'O' && toupper( pItem->item.asString.value[ 1 ] ) == 'N' ) hb_set_century = TRUE; } - else if( pItem->item.asString.length == 3 ) + else if( pItem->item.asString.length >= 3 ) { if( toupper ( pItem->item.asString.value[ 0 ] ) == 'O' && toupper ( pItem->item.asString.value[ 1 ] ) == 'F' diff --git a/harbour/source/rtl/setcolor.c b/harbour/source/rtl/setcolor.c index d3eab76d6c..ace682b3dd 100644 --- a/harbour/source/rtl/setcolor.c +++ b/harbour/source/rtl/setcolor.c @@ -25,9 +25,9 @@ #include "extend.h" #include "set.h" #ifdef HARBOUR_USE_GTAPI - #include "gtapi.h" + #include "gtapi.h" #else - static char old_string[ sizeof( hb_set.HB_SET_COLOR ) ]; + static char s_old_string[ sizeof( hb_set.HB_SET_COLOR ) ]; #endif char * hb_setColor( char * sColor ) @@ -35,8 +35,8 @@ char * hb_setColor( char * sColor ) #ifdef HARBOUR_USE_GTAPI hb_gtGetColorStr( hb_set.HB_SET_COLOR ); #else - strncpy( old_string, hb_set.HB_SET_COLOR, sizeof( hb_set.HB_SET_COLOR ) ); - old_string[ sizeof( hb_set.HB_SET_COLOR ) - 1 ] = 0; + strncpy( s_old_string, hb_set.HB_SET_COLOR, sizeof( hb_set.HB_SET_COLOR ) ); + s_old_string[ sizeof( hb_set.HB_SET_COLOR ) - 1 ] = 0; #endif if( sColor != ( char * ) NULL ) @@ -52,7 +52,7 @@ char * hb_setColor( char * sColor ) #ifdef HARBOUR_USE_GTAPI return hb_set.HB_SET_COLOR; #else - return old_string; + return s_old_string; #endif } diff --git a/harbour/source/rtl/strings.c b/harbour/source/rtl/strings.c index cdecf8df36..0e9590a6e6 100644 --- a/harbour/source/rtl/strings.c +++ b/harbour/source/rtl/strings.c @@ -49,10 +49,10 @@ #include "init.h" -static double infinity = 0; +static double s_dInfinity = 0; HB_CALL_ON_STARTUP_BEGIN( Strings_InitInfinity ) - infinity = -log( 0 ); + s_dInfinity = -log( 0 ); HB_CALL_ON_STARTUP_END( Strings_InitInfinity ) #if ! defined(__GNUC__) #pragma startup Strings_InitInfinity @@ -1169,7 +1169,7 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) double dNumber = hb_itemGetND( pNumber ); #ifdef HARBOUR_STRICT_CLIPPER_COMPATIBILITY - if( pNumber->item.asDouble.length == 99 || dNumber == infinity || dNumber == -infinity ) + if( pNumber->item.asDouble.length == 99 || dNumber == s_dInfinity || dNumber == -s_dInfinity ) /* Numeric overflow */ iBytes = iSize + 1; else diff --git a/harbour/source/rtl/tone.c b/harbour/source/rtl/tone.c index 80c961937d..d31de8d789 100644 --- a/harbour/source/rtl/tone.c +++ b/harbour/source/rtl/tone.c @@ -48,27 +48,27 @@ */ #if defined(__DJGPP__) - #include - #include + #include + #include #elif defined(_Windows) #elif defined(__BORLANDC__) - #include - #include + #include + #include #elif defined(OS2) - #include + #include #elif defined(__CYGWIN__) - #include - #include - #include - #include - #define HB_DONT_DEFINE_BASIC_TYPES + #include + #include + #include + #include + #define HB_DONT_DEFINE_BASIC_TYPES #endif #include "extend.h" #include "inkey.h" /* For hb_releaseCPU() */ #if defined(HARBOUR_GCC_OS2) - ULONG DosBeep (ULONG ulFrequency, ULONG ulDuration); + ULONG DosBeep( ULONG ulFrequency, ULONG ulDuration ); #endif /* $DOC$ @@ -198,7 +198,7 @@ void hb_tone( double frequency, double duration ) #endif } -HARBOUR HB_TONE(void) +HARBOUR HB_TONE( void ) { double frequency, duration; if( PCOUNT > 0 && ISNUM( 1 ) ) diff --git a/harbour/source/rtl/transfrm.c b/harbour/source/rtl/transfrm.c index 0bb6315026..d1db0e2e93 100644 --- a/harbour/source/rtl/transfrm.c +++ b/harbour/source/rtl/transfrm.c @@ -76,8 +76,6 @@ #define DF_YMD 2 #define DF_EOT 3 /* End of table for Century */ -static char * szBritish[] = { "DD/MM/YY", "DD/MM/YYYY" }; /* For @E */ - extern HARBOUR HB_STR( void ); /* NOTE: This is called via its symbol name, so we should make sure */ @@ -363,7 +361,7 @@ static char * NumPicture( char *szPic, ULONG ulPic, WORD wPicFlags, double dValu static char * DatePicture( char * szDate, WORD wPicFlags, char * szResult ) { if( wPicFlags & PF_BRITISH ) - hb_dtoc( szDate, szResult, szBritish[ ( hb_set_century ? 1 : 0 ) ] ); + hb_dtoc( szDate, szResult, hb_set_century ? "DD/MM/YYYY" : "DD/MM/YY" ); else hb_dtoc( szDate, szResult, hb_set.HB_SET_DATEFORMAT ); diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 648d59d559..08f0a7bd1b 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -790,7 +790,7 @@ static void hb_vmAliasPop( void ) default: hb_itemClear( pItem ); - hb_errRT_BASE( EG_BADALIAS, 1000, NULL, NULL ); + hb_errRT_BASE( EG_BADALIAS, 9999, NULL, NULL ); break; } @@ -843,7 +843,7 @@ static void hb_vmAliasSwap( void ) default: hb_itemClear( pWorkArea ); - hb_errRT_BASE( EG_BADALIAS, 1000, NULL, NULL ); + hb_errRT_BASE( EG_BADALIAS, 9999, NULL, NULL ); break; } memcpy( pWorkArea, pItem, sizeof( HB_ITEM ) ); @@ -1066,7 +1066,12 @@ void hb_vmDo( WORD wParams ) pFunc = hb_objGetMethod( pSelf, pSym ); if( ! pFunc ) - hb_errInternal( 9999, "Message %s not implemented for class %s", pSym->szName, hb_objGetClsName( pSelf ) ); + { + if( pSym->szName[ 0 ] == '_' ) + hb_errRT_BASE( EG_NOVARMETHOD, 1005, NULL, pSym->szName + 1 ); + else + hb_errRT_BASE( EG_NOMETHOD, 1004, NULL, pSym->szName ); + } pFunc(); } @@ -1612,28 +1617,31 @@ void hb_vmMinus( void ) } else if( IS_STRING( pItem1 ) && IS_STRING( pItem2 ) ) { - ULONG ulLen = pItem1->item.asString.length; - - pItem1->item.asString.value = (char*)hb_xrealloc( pItem1->item.asString.value, pItem1->item.asString.length + pItem2->item.asString.length + 1 ); - pItem1->item.asString.length += pItem2->item.asString.length; - - while( ulLen && pItem1->item.asString.value[ulLen - 1] == ' ' ) + if( ( double ) ( ( double ) pItem1->item.asString.length + ( double ) pItem2->item.asString.length ) < ( double ) ULONG_MAX ) { - ulLen--; - } + ULONG ulLen = pItem1->item.asString.length; - memcpy( pItem1->item.asString.value + ulLen, pItem2->item.asString.value, pItem2->item.asString.length ); - ulLen += pItem2->item.asString.length; - memset( pItem1->item.asString.value + ulLen, ' ', pItem1->item.asString.length - ulLen); - pItem1->item.asString.value[ pItem1->item.asString.length ] = '\0'; + pItem1->item.asString.value = ( char * ) hb_xrealloc( pItem1->item.asString.value, pItem1->item.asString.length + pItem2->item.asString.length + 1 ); + pItem1->item.asString.length += pItem2->item.asString.length; - if( pItem2->item.asString.value ) - { - hb_xfree( pItem2->item.asString.value ); - pItem2->item.asString.value = NULL; + while( ulLen && pItem1->item.asString.value[ ulLen - 1 ] == ' ' ) + ulLen--; + + memcpy( pItem1->item.asString.value + ulLen, pItem2->item.asString.value, pItem2->item.asString.length ); + ulLen += pItem2->item.asString.length; + memset( pItem1->item.asString.value + ulLen, ' ', pItem1->item.asString.length - ulLen); + pItem1->item.asString.value[ pItem1->item.asString.length ] = '\0'; + + if( pItem2->item.asString.value ) + { + hb_xfree( pItem2->item.asString.value ); + pItem2->item.asString.value = NULL; + } + hb_stackPop(); + return; } - hb_stackPop(); - return; + else + hb_errRT_BASE( EG_STROVERFLOW, 1210, NULL, "-" ); } else if( IS_OBJECT( stack.pPos - 2 ) && hb_objHasMsg( stack.pPos - 2, "-" ) ) hb_vmOperatorCall( stack.pPos - 2, stack.pPos - 1, "-" ); @@ -1728,18 +1736,23 @@ void hb_vmPlus( void ) if( IS_STRING( pItem1 ) && IS_STRING( pItem2 ) ) { - pItem1->item.asString.value = (char*)hb_xrealloc( pItem1->item.asString.value, pItem1->item.asString.length + pItem2->item.asString.length + 1 ); - memcpy( pItem1->item.asString.value+ pItem1->item.asString.length, - pItem2->item.asString.value, pItem2->item.asString.length ); - pItem1->item.asString.length += pItem2->item.asString.length; - pItem1->item.asString.value[ pItem1->item.asString.length ] = '\0'; - if( pItem2->item.asString.value ) + if( ( double ) ( ( double ) pItem1->item.asString.length + ( double ) pItem2->item.asString.length ) < ( double ) ULONG_MAX ) { - hb_xfree( pItem2->item.asString.value ); - pItem2->item.asString.value = NULL; + pItem1->item.asString.value = ( char * ) hb_xrealloc( pItem1->item.asString.value, pItem1->item.asString.length + pItem2->item.asString.length + 1 ); + memcpy( pItem1->item.asString.value+ pItem1->item.asString.length, + pItem2->item.asString.value, pItem2->item.asString.length ); + pItem1->item.asString.length += pItem2->item.asString.length; + pItem1->item.asString.value[ pItem1->item.asString.length ] = '\0'; + if( pItem2->item.asString.value ) + { + hb_xfree( pItem2->item.asString.value ); + pItem2->item.asString.value = NULL; + } + hb_stackPop(); + return; } - hb_stackPop(); - return; + else + hb_errRT_BASE( EG_STROVERFLOW, 1209, NULL, "+" ); } else if( IS_NUMERIC( pItem1 ) && IS_NUMERIC( pItem2 ) ) @@ -1827,7 +1840,7 @@ static void hb_vmPopAliasedField( PHB_SYMB pSym ) default: hb_itemClear( pAlias ); - hb_errRT_BASE( EG_BADALIAS, 1000, NULL, NULL ); + hb_errRT_BASE( EG_BADALIAS, 9999, NULL, NULL ); break; } @@ -2037,7 +2050,7 @@ static void hb_vmPushAliasedField( PHB_SYMB pSym ) default: hb_itemClear( pAlias ); - hb_errRT_BASE( EG_BADALIAS, 1000, NULL, NULL ); + hb_errRT_BASE( EG_BADALIAS, 9999, NULL, NULL ); break; }