diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e9e82e2b78..bb039b72f8 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ +2011-04-26 18:10 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + + contrib/hbnf/tests/ontick.prg + - contrib/hbnf/ontick.c + * contrib/hbnf/hbnf.hbp + * contrib/hbnf/hbnf.hbx + + contrib/hbnf/ontick.prg + + implemented: + FT_ONTICK( [][, ] ) -> NIL + (after spotting thread on clipper.borda.ru) + Note, I didn't test it against original NFLib, and second + param looks like undocumented one. + + * contrib/xhb/bkgtsks.c + * uncrustified + 2011-04-26 07:52 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/qtcore/hbqt.h ! Miss from prev commit. diff --git a/harbour/contrib/hbnf/hbnf.hbp b/harbour/contrib/hbnf/hbnf.hbp index ef3b4f3696..2b33a015e3 100644 --- a/harbour/contrib/hbnf/hbnf.hbp +++ b/harbour/contrib/hbnf/hbnf.hbp @@ -47,7 +47,6 @@ shift.c stod.c # BAD_C_SOURCES -#ontick.c #peek.c #poke.c @@ -119,6 +118,7 @@ ntow.prg nwlstat.prg nwsem.prg nwuid.prg +ontick.prg page.prg pchr.prg pegs.prg diff --git a/harbour/contrib/hbnf/hbnf.hbx b/harbour/contrib/hbnf/hbnf.hbx index 4e93c1975e..da1d6926ba 100644 --- a/harbour/contrib/hbnf/hbnf.hbx +++ b/harbour/contrib/hbnf/hbnf.hbx @@ -160,6 +160,7 @@ DYNAMIC FT_NWSEMSIG DYNAMIC FT_NWSEMUNLOCK DYNAMIC FT_NWSEMWAIT DYNAMIC FT_NWUID +DYNAMIC FT_ONTICK DYNAMIC FT_ORIGIN DYNAMIC FT_PCHR DYNAMIC FT_PEGS diff --git a/harbour/contrib/hbnf/ontick.c b/harbour/contrib/hbnf/ontick.c deleted file mode 100644 index 870a080d6e..0000000000 --- a/harbour/contrib/hbnf/ontick.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * $Id$ - */ - -/* - * File......: ontick.c - * Author....: Ted Means - * CIS ID....: 73067,3332 - * - * This function is an original work by Ted Means and is placed in the - * public domain. - * - * Modification history: - * --------------------- - * - * Rev 1.0 01 Jan 1995 03:01:00 TED - * Initial release - */ - -#include "hbapi.h" -#include "hbapiitm.h" - -#include "cpmi.h" - -typedef union -{ - long far * Address; - struct - { - unsigned int Offset; - unsigned int Segment; - } Pointer; -} LONGPTR; - -void cdecl _evLow( unsigned int, void *, unsigned int ); - -static long far Ticks = 0; -static long far Interval = 1; -static PHB_ITEM far codeBlock; -static char inProgress = 0; - -static void cdecl TickTock( void ) -{ - auto unsigned int ProtMode = cpmiIsProtected(); - auto LONGPTR Timer; - auto HB_EVALINFO eval; - - if ( inProgress ) return; - - inProgress = 1; - - if ( ProtMode ) - { - Timer.Pointer.Segment = cpmiProtectedPtr( ( long * ) ( 0x0000046C ), sizeof( long ) ); - Timer.Pointer.Offset = 0; - - if ( Timer.Pointer.Segment == 0 ) goto Exit; - } - else - Timer.Address = ( long * ) ( 0x0000046C ); - - if ( *Timer.Address >= ( Ticks + Interval ) || - ( *Timer.Address < Ticks ) ) - { - Ticks = *Timer.Address; - - hb_evalNew( &eval, codeBlock ); - - hb_itemRelease( hb_evalLaunch( &eval ) ); - } - - if ( ProtMode ) cpmiFreeSelector( Timer.Pointer.Segment ); - - Exit: inProgress = 0; - - return; -} - -CLIPPER FT_OnTick( void ) -{ - if ( hb_itemType( codeBlock ) == BLOCK ) hb_itemRelease( codeBlock ); - - codeBlock = hb_itemParam( 1 ); - - if ( hb_itemType( codeBlock ) == BLOCK ) - { - Interval = hb_parnl( 2 ); - - _evLow( 5, TickTock, HB_TRUE ); - } - else - _evLow( 5, TickTock, HB_FALSE ); - - return; -} diff --git a/harbour/contrib/hbnf/ontick.prg b/harbour/contrib/hbnf/ontick.prg new file mode 100644 index 0000000000..2546dcfcac --- /dev/null +++ b/harbour/contrib/hbnf/ontick.prg @@ -0,0 +1,87 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * FT_ONTICK() + * + * Copyright 2011 Viktor Szakats (harbour.01 syenar.hu) + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +THREAD STATIC t_bOnTick +THREAD STATIC t_nTickInterval := 0 +THREAD STATIC t_nLastCheck := 0 +THREAD STATIC t_hIdle + +STATIC PROCEDURE __FT_ONTICK() + + IF hb_milliSeconds() >= ( t_nLastCheck + t_nTickInterval ) + t_nLastCheck := hb_milliSeconds() + Eval( t_bOnTick ) + ENDIF + + RETURN + +PROCEDURE FT_ONTICK( bOnTick, nTickInterval ) + + IF hb_isBlock( bOnTick ) + t_bOnTick := bOnTick + IF hb_isNumeric( nTickInterval ) + t_nTickInterval := ( 1 / 18 ) * nTickInterval * 1000 + ENDIF + t_nLastCheck := hb_milliSeconds() + IF Empty( t_hIdle ) + t_hIdle := hb_IdleAdd( {|| __FT_ONTICK() } ) + ENDIF + ELSE + t_bOnTick := NIL + t_nTickInterval := 0 + IF ! Empty( t_hIdle ) + hb_IdleDel( t_hIdle ) + t_hIdle := NIL + ENDIF + ENDIF + + RETURN diff --git a/harbour/contrib/hbnf/tests/ontick.prg b/harbour/contrib/hbnf/tests/ontick.prg new file mode 100644 index 0000000000..f0d4120264 --- /dev/null +++ b/harbour/contrib/hbnf/tests/ontick.prg @@ -0,0 +1,27 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * + * Copyright 2011 Viktor Szakats (harbour.01 syenar.hu) + * www - http://harbour-project.org + * + */ + +PROCEDURE Main() + + FT_ONTICK( {|| OutStd( hb_milliSeconds(), hb_eol() ) } ) + + Inkey( 0 ) + + FT_ONTICK( {|| OutStd( hb_milliSeconds(), hb_eol() ) }, 18 ) + + Inkey( 0 ) + + FT_ONTICK() + + Inkey( 0 ) + + RETURN diff --git a/harbour/contrib/xhb/bkgtsks.c b/harbour/contrib/xhb/bkgtsks.c index 6f3d83581a..9bde211743 100644 --- a/harbour/contrib/xhb/bkgtsks.c +++ b/harbour/contrib/xhb/bkgtsks.c @@ -78,20 +78,20 @@ HB_EXTERN_BEGIN typedef struct HB_BACKGROUNDTASK_ { - HB_ULONG ulTaskID; /* task identifier */ - PHB_ITEM pTask; /* pointer to the task item */ - double dSeconds; /* internal - last time this task has gone */ - int millisec; /* milliseconds after this task must run */ - HB_BOOL bActive; /* task is active ? */ + HB_ULONG ulTaskID; /* task identifier */ + PHB_ITEM pTask; /* pointer to the task item */ + double dSeconds; /* internal - last time this task has gone */ + int millisec; /* milliseconds after this task must run */ + HB_BOOL bActive; /* task is active ? */ } HB_BACKGROUNDTASK, * PHB_BACKGROUNDTASK, * HB_BACKGROUNDTASK_PTR; -extern void hb_backgroundRunSingle( HB_ULONG ulID ); /* run a single background routine */ -extern void hb_backgroundRunForced( void ); /* run all background routines also if them are not active*/ -extern void hb_backgroundRun( void ); /* run all background routines but only if them are active*/ -extern void hb_backgroundReset( void ); /* reset internal counter */ -extern void hb_backgroundShutDown( void ); /* closes all background tasks */ -extern HB_ULONG hb_backgroundAddFunc( PHB_ITEM pBlock, int nMillisec, HB_BOOL bActive ); /* Adds a codeblock or an executable array */ -extern PHB_ITEM hb_backgroundDelFunc( HB_ULONG ulID ); /* Deletes a prevuiously added task */ +extern void hb_backgroundRunSingle( HB_ULONG ulID ); /* run a single background routine */ +extern void hb_backgroundRunForced( void ); /* run all background routines also if them are not active*/ +extern void hb_backgroundRun( void ); /* run all background routines but only if them are active*/ +extern void hb_backgroundReset( void ); /* reset internal counter */ +extern void hb_backgroundShutDown( void ); /* closes all background tasks */ +extern HB_ULONG hb_backgroundAddFunc( PHB_ITEM pBlock, int nMillisec, HB_BOOL bActive ); /* Adds a codeblock or an executable array */ +extern PHB_ITEM hb_backgroundDelFunc( HB_ULONG ulID ); /* Deletes a prevuiously added task */ extern PHB_BACKGROUNDTASK hb_backgroundFind( HB_ULONG ulID ); extern HB_BOOL hb_backgroundActive( HB_ULONG ulID, HB_BOOL bActive ); extern int hb_backgroundTime( HB_ULONG ulID, int nMillisec ); @@ -105,23 +105,23 @@ static HB_ULONG s_ulBackgroundID = 0; /* list of background tasks * A pointer into an array of pointers to items with a codeblock -*/ -static HB_BACKGROUNDTASK_PTR * s_pBackgroundTasks = NULL; + */ +static HB_BACKGROUNDTASK_PTR * s_pBackgroundTasks = NULL; -static HB_BOOL s_bEnabled = HB_FALSE; +static HB_BOOL s_bEnabled = HB_FALSE; /* flag to prevent recursive calls of hb_backgroundRun() */ -static HB_BOOL s_bIamBackground = HB_FALSE; +static HB_BOOL s_bIamBackground = HB_FALSE; /* current task to be executed */ -static HB_USHORT s_uiBackgroundTask = 0; +static HB_USHORT s_uiBackgroundTask = 0; /* number of tasks in the list */ -static HB_USHORT s_uiBackgroundMaxTask = 0; +static HB_USHORT s_uiBackgroundMaxTask = 0; #else #define s_ulBackgroundID HB_VM_STACK.ulBackgroundID -#define s_pBackgroundTasks (HB_VM_STACK.pBackgroundTasks) +#define s_pBackgroundTasks ( HB_VM_STACK.pBackgroundTasks ) #define s_bIamBackground HB_VM_STACK.bIamBackground #define s_uiBackgroundTask HB_VM_STACK.uiBackgroundTask #define s_uiBackgroundMaxTask HB_VM_STACK.uiBackgroundMaxTask @@ -135,19 +135,19 @@ HB_ULONG hb_backgroundAddFunc( PHB_ITEM pBlock, int nMillisec, HB_BOOL bActive ) PHB_BACKGROUNDTASK pBkgTask; /* store a copy of passed codeblock - */ + */ - pBkgTask = ( PHB_BACKGROUNDTASK ) hb_xgrab( sizeof( HB_BACKGROUNDTASK ) ); + pBkgTask = ( PHB_BACKGROUNDTASK ) hb_xgrab( sizeof( HB_BACKGROUNDTASK ) ); - pBkgTask->pTask = hb_itemNew( pBlock ); - pBkgTask->dSeconds = hb_dateSeconds(); - pBkgTask->millisec = nMillisec; - pBkgTask->bActive = bActive; + pBkgTask->pTask = hb_itemNew( pBlock ); + pBkgTask->dSeconds = hb_dateSeconds(); + pBkgTask->millisec = nMillisec; + pBkgTask->bActive = bActive; - if( !s_pBackgroundTasks ) + if( ! s_pBackgroundTasks ) { - pBkgTask->ulTaskID = s_ulBackgroundID = 1; - s_pBackgroundTasks = ( PHB_BACKGROUNDTASK * ) hb_xgrab( sizeof( HB_BACKGROUNDTASK ) ); + pBkgTask->ulTaskID = s_ulBackgroundID = 1; + s_pBackgroundTasks = ( PHB_BACKGROUNDTASK * ) hb_xgrab( sizeof( HB_BACKGROUNDTASK ) ); } else { @@ -172,7 +172,7 @@ HB_ULONG hb_backgroundAddFunc( PHB_ITEM pBlock, int nMillisec, HB_BOOL bActive ) } } } - s_pBackgroundTasks = ( PHB_BACKGROUNDTASK * ) hb_xrealloc( s_pBackgroundTasks, sizeof( HB_BACKGROUNDTASK ) * (s_uiBackgroundMaxTask )); + s_pBackgroundTasks = ( PHB_BACKGROUNDTASK * ) hb_xrealloc( s_pBackgroundTasks, sizeof( HB_BACKGROUNDTASK ) * ( s_uiBackgroundMaxTask ) ); } s_pBackgroundTasks[ s_uiBackgroundMaxTask ] = pBkgTask; ++s_uiBackgroundMaxTask; @@ -193,18 +193,18 @@ void hb_backgroundRun( void ) if( s_uiBackgroundTask < s_uiBackgroundMaxTask ) { double dCurrSeconds = hb_dateSeconds(); - pBkgTask = (PHB_BACKGROUNDTASK) s_pBackgroundTasks[ s_uiBackgroundTask ]; + pBkgTask = ( PHB_BACKGROUNDTASK ) s_pBackgroundTasks[ s_uiBackgroundTask ]; /* check if hb_dateSeconds() is lower than pBkgTask->dSeconds, if so midnight is reached */ - if( !( pBkgTask->dSeconds ) || dCurrSeconds < pBkgTask->dSeconds ) + if( ! ( pBkgTask->dSeconds ) || dCurrSeconds < pBkgTask->dSeconds ) pBkgTask->dSeconds = dCurrSeconds; /* Check if a task can run */ if( pBkgTask->bActive && - ( pBkgTask->millisec == 0 || - ( ( ( hb_dateSeconds() - pBkgTask->dSeconds ) * 1000 ) >= pBkgTask->millisec ) - ) - ) + ( pBkgTask->millisec == 0 || + ( ( ( hb_dateSeconds() - pBkgTask->dSeconds ) * 1000 ) >= pBkgTask->millisec ) + ) + ) { hb_itemRelease( hb_itemDo( pBkgTask->pTask, 0 ) ); pBkgTask->dSeconds = hb_dateSeconds(); @@ -242,7 +242,7 @@ void hb_backgroundRunSingle( HB_ULONG ulID ) { s_bIamBackground = HB_TRUE; - pBkgTask = hb_backgroundFind( ulID ); + pBkgTask = hb_backgroundFind( ulID ); if( pBkgTask ) hb_itemRelease( hb_itemDo( pBkgTask->pTask, 0 ) ); @@ -265,9 +265,9 @@ void hb_backgroundShutDown( void ) do { PHB_BACKGROUNDTASK pBkgTask; - pBkgTask = s_pBackgroundTasks[ --s_uiBackgroundMaxTask ]; + pBkgTask = s_pBackgroundTasks[ --s_uiBackgroundMaxTask ]; hb_itemRelease( pBkgTask->pTask ); - pBkgTask->pTask = NULL; + pBkgTask->pTask = NULL; hb_xfree( pBkgTask ); } while( s_uiBackgroundMaxTask ); @@ -280,14 +280,14 @@ void hb_backgroundShutDown( void ) /* caller have to free return ITEM by hb_itemRelease() if it's not NULL */ PHB_ITEM hb_backgroundDelFunc( HB_ULONG ulID ) { - int iTask; - PHB_BACKGROUNDTASK pBkgTask; - PHB_ITEM pItem = NULL; - HB_BOOL bOldSet = s_bEnabled; + int iTask; + PHB_BACKGROUNDTASK pBkgTask; + PHB_ITEM pItem = NULL; + HB_BOOL bOldSet = s_bEnabled; s_bEnabled = HB_FALSE; - iTask = 0; + iTask = 0; while( iTask < s_uiBackgroundMaxTask ) { pBkgTask = s_pBackgroundTasks[ iTask ]; @@ -325,8 +325,8 @@ PHB_ITEM hb_backgroundDelFunc( HB_ULONG ulID ) /* Find a task */ PHB_BACKGROUNDTASK hb_backgroundFind( HB_ULONG ulID ) { - int iTask; - PHB_BACKGROUNDTASK pBkgTask; + int iTask; + PHB_BACKGROUNDTASK pBkgTask; iTask = 0; while( iTask < s_uiBackgroundMaxTask ) @@ -334,7 +334,7 @@ PHB_BACKGROUNDTASK hb_backgroundFind( HB_ULONG ulID ) pBkgTask = s_pBackgroundTasks[ iTask ]; if( ulID == pBkgTask->ulTaskID ) - return pBkgTask; + return pBkgTask; ++iTask; } @@ -344,15 +344,15 @@ PHB_BACKGROUNDTASK hb_backgroundFind( HB_ULONG ulID ) /* Set task as active */ HB_BOOL hb_backgroundActive( HB_ULONG ulID, HB_BOOL bActive ) { - PHB_BACKGROUNDTASK pBkgTask; - HB_BOOL bOldState = HB_FALSE; + PHB_BACKGROUNDTASK pBkgTask; + HB_BOOL bOldState = HB_FALSE; pBkgTask = hb_backgroundFind( ulID ); if( pBkgTask ) { - bOldState = pBkgTask->bActive; - pBkgTask->bActive = bActive; + bOldState = pBkgTask->bActive; + pBkgTask->bActive = bActive; } return bOldState; @@ -361,15 +361,15 @@ HB_BOOL hb_backgroundActive( HB_ULONG ulID, HB_BOOL bActive ) /* Set task time */ int hb_backgroundTime( HB_ULONG ulID, int nMillisec ) { - PHB_BACKGROUNDTASK pBkgTask; - int nOldState = 0; + PHB_BACKGROUNDTASK pBkgTask; + int nOldState = 0; pBkgTask = hb_backgroundFind( ulID ); if( pBkgTask ) { - nOldState = pBkgTask->millisec; - pBkgTask->millisec = nMillisec; + nOldState = pBkgTask->millisec; + pBkgTask->millisec = nMillisec; } return nOldState; } @@ -411,16 +411,16 @@ HB_FUNC( HB_BACKGROUNDRESET ) /* add a new background task and return its handle */ HB_FUNC( HB_BACKGROUNDADD ) { - HB_ITEM_PTR pBlock = hb_param( 1, HB_IT_ANY ); - HB_ITEM_PTR pMillisec = hb_param( 2, HB_IT_NUMERIC ); - HB_ITEM_PTR pActive = hb_param( 3, HB_IT_LOGICAL ); + HB_ITEM_PTR pBlock = hb_param( 1, HB_IT_ANY ); + HB_ITEM_PTR pMillisec = hb_param( 2, HB_IT_NUMERIC ); + HB_ITEM_PTR pActive = hb_param( 3, HB_IT_LOGICAL ); if( HB_IS_BLOCK( pBlock ) || HB_IS_ARRAY( pBlock ) ) { hb_retnl( hb_backgroundAddFunc( pBlock, ( pMillisec == NULL ? 0 : hb_itemGetNI( pMillisec ) ), - ( pActive == NULL ? HB_TRUE : hb_itemGetL( pActive ) ) - ) ); + ( pActive == NULL ? HB_TRUE : hb_itemGetL( pActive ) ) + ) ); } else hb_retnl( -1 ); /* error - a codeblock is required */ @@ -438,7 +438,7 @@ HB_FUNC( HB_BACKGROUNDDEL ) } if( pItem ) - hb_itemReturnRelease( pItem ); /* return a codeblock */ + hb_itemReturnRelease( pItem ); /* return a codeblock */ } /* Set a task as active or not */