From 08763f7da776d8b9fcec46e25fc066386c15076d Mon Sep 17 00:00:00 2001 From: Paul Tucker Date: Mon, 21 Oct 2002 16:10:50 +0000 Subject: [PATCH] 2002-10-21 12:00 UTC-0500 Paul Tucker --- harbour/ChangeLog | 7 ++ harbour/source/rdd/dbcmd.c | 46 +++++--- harbour/source/rdd/dbf1.c | 2 +- harbour/source/rdd/workarea.c | 4 +- harbour/tests/vidtest.prg | 215 ++++++++++++++++++++++++++++++++++ 5 files changed, 255 insertions(+), 19 deletions(-) create mode 100644 harbour/tests/vidtest.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 07fb8c31f2..ff96934f3a 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,13 @@ 2002-12-01 23:12 UTC+0100 Foo Bar */ +2002-10-21 12:00 UTC-0500 Paul Tucker + + tests/vidtest.prg by Brian Dukes + * source/rdd/dbcmd.c + * source/rdd/workarea.c + * source/rdd/dbf1.c + ! modified string copy operations for efficiency where appropriate. + 2002-10-21 10:20 UTC+0300 Alexander Kresin * contrib/rdd_ads/adsfunc.c ! Few fixes - checking for hb_parc() return value diff --git a/harbour/source/rdd/dbcmd.c b/harbour/source/rdd/dbcmd.c index c09d14bac1..08f3ace54d 100644 --- a/harbour/source/rdd/dbcmd.c +++ b/harbour/source/rdd/dbcmd.c @@ -357,7 +357,9 @@ static int hb_rddRegister( char * szDriver, USHORT uiType ) memset( pRddNewNode, 0, sizeof( RDDNODE ) ); /* Fill the new RDD node */ - strncpy( pRddNewNode->szName, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + + + strncat( pRddNewNode->szName, szDriver, HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); pRddNewNode->uiType = uiType; /* Call _GETFUNCTABLE() */ @@ -1285,12 +1287,14 @@ HB_FUNC( DBCREATE ) szDriver = s_szDefDriver; pFileName = hb_fsFNameSplit( szFileName ); - if( ISCHAR(5) ) - strncpy( szAlias, hb_parc( 5 ), HARBOUR_MAX_RDD_ALIAS_LENGTH ); - uiLen = ( USHORT ) hb_parclen( 5 ); + szAlias[0] = '\0'; + if( ISCHAR(5) ) + strncat( szAlias, hb_parc( 5 ), HARBOUR_MAX_RDD_ALIAS_LENGTH ); + + uiLen = strlen( szAlias ); if( uiLen == 0 ) - strncpy( szAlias, pFileName->szName, HARBOUR_MAX_RDD_ALIAS_LENGTH ); + strncat( szAlias, pFileName->szName, HARBOUR_MAX_RDD_ALIAS_LENGTH ); else if( uiLen == 1 ) { /* Alias with a single letter. Only are valid 'L' and > 'M' */ @@ -1305,6 +1309,7 @@ HB_FUNC( DBCREATE ) /* Create a new WorkArea node */ if( !hb_rddInsertAreaNode( szDriver ) ) { + hb_xfree( pFileName ); hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBCREATE" ); return; } @@ -1313,7 +1318,7 @@ HB_FUNC( DBCREATE ) szFileName[0] = '\0'; if( ISCHAR(1) ) - strncpy( szFileName, hb_parc( 1 ), _POSIX_PATH_MAX ); + strncat( szFileName, hb_parc( 1 ), _POSIX_PATH_MAX ); if( !pFileName->szExtension ) { @@ -1936,6 +1941,8 @@ HB_FUNC( DBUSEAREA ) char szDriverBuffer[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH + 1 ]; char szAlias[ HARBOUR_MAX_RDD_ALIAS_LENGTH + 1 ]; + szDriverBuffer[0] = '\0'; + s_bNetError = FALSE; /* New area? */ @@ -1965,9 +1972,9 @@ HB_FUNC( DBUSEAREA ) szAlias[0] = '\0'; if( ISCHAR(4) ) - strncpy( szAlias, hb_parc( 4 ), HARBOUR_MAX_RDD_ALIAS_LENGTH ); + strncat( szAlias, hb_parc( 4 ), HARBOUR_MAX_RDD_ALIAS_LENGTH ); else - strncpy( szAlias, pFileName->szName, HARBOUR_MAX_RDD_ALIAS_LENGTH ); + strncat( szAlias, pFileName->szName, HARBOUR_MAX_RDD_ALIAS_LENGTH ); uiLen = strlen( szAlias ); if( szAlias[ 0 ] >= '0' && szAlias[ 0 ] <= '9' ) @@ -1976,6 +1983,7 @@ HB_FUNC( DBUSEAREA ) hb_errRT_DBCMD( EG_DUPALIAS, EDBCMD_DUPALIAS, NULL, "DBUSEAREA" ); return; } + if( uiLen == 1 ) { /* Alias with a single letter. Only are valid 'L' and > 'M' */ @@ -1990,12 +1998,15 @@ HB_FUNC( DBUSEAREA ) /* Create a new WorkArea node */ if( !hb_rddInsertAreaNode( szDriver ) ) { + hb_xfree( pFileName ); hb_errRT_DBCMD( EG_ARG, EDBCMD_BADPARAMETER, NULL, "DBUSEAREA" ); return; } szFileName = ( char * ) hb_xgrab( _POSIX_PATH_MAX + 1 ); - strncpy( szFileName, hb_parc( 3 ), _POSIX_PATH_MAX ); + szFileName[0] = '\0'; + strncat( szFileName, hb_parc( 3 ), _POSIX_PATH_MAX ); + if( !pFileName->szExtension ) { pFileExt = hb_itemPutC( NULL, "" ); @@ -2886,18 +2897,15 @@ HB_FUNC( __RDDSETDEFAULT ) uiLen = ( USHORT ) hb_parclen( 1 ); if( uiLen > 0 ) { - if( uiLen > HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ) - uiLen = HARBOUR_MAX_RDD_DRIVERNAME_LENGTH; - s_szDefDriver = ( char * ) hb_xrealloc( s_szDefDriver, uiLen + 1 ); - hb_strncpyUpper( s_szDefDriver, hb_parc( 1 ), uiLen ); + hb_strncpyUpper( s_szDefDriver, hb_parc( 1 ), uiLen+1 ); } } HB_FUNC( RDDSETDEFAULT ) { USHORT uiLen; - char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; + char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH +1 ]; hb_rddCheck(); hb_retc( s_szDefDriver ); @@ -2921,7 +2929,7 @@ HB_FUNC( RDDSETDEFAULT ) HB_FUNC( DBSETDRIVER ) { USHORT uiLen; - char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ]; + char szNewDriver[ HARBOUR_MAX_RDD_DRIVERNAME_LENGTH +1 ]; hb_rddCheck(); hb_retc( s_szDefDriver ); @@ -3363,6 +3371,8 @@ HB_FUNC( DBFILEGET ) char szFileName[ _POSIX_PATH_MAX + 1 ]; USHORT uiFields, uiIndex; + szFileName[0] = '\0'; + if( s_pCurrArea ) { uiIndex = hb_parni( 1 ); @@ -3372,7 +3382,7 @@ HB_FUNC( DBFILEGET ) SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS && uiIndex > 0 && uiIndex <= uiFields ) { - strncpy( szFileName, hb_itemGetCPtr( pFileName ), _POSIX_PATH_MAX ); + strncat( szFileName, hb_itemGetCPtr( pFileName ), _POSIX_PATH_MAX ); hb_retl( SELF_GETVALUEFILE( ( AREAP ) s_pCurrArea->pArea, uiIndex, szFileName, hb_itemGetNI( pMode ) ) ); return; @@ -3391,6 +3401,8 @@ HB_FUNC( DBFILEPUT ) char szFileName[ _POSIX_PATH_MAX + 1 ]; USHORT uiFields, uiIndex; + szFileName[0] = '\0'; + if( s_pCurrArea ) { uiIndex = hb_parni( 1 ); @@ -3399,7 +3411,7 @@ HB_FUNC( DBFILEPUT ) SELF_FIELDCOUNT( ( AREAP ) s_pCurrArea->pArea, &uiFields ) == SUCCESS && uiIndex > 0 && uiIndex <= uiFields ) { - strncpy( szFileName, hb_itemGetCPtr( pFileName ), _POSIX_PATH_MAX ); + strncat( szFileName, hb_itemGetCPtr( pFileName ), _POSIX_PATH_MAX ); hb_retl( SELF_PUTVALUEFILE( ( AREAP ) s_pCurrArea->pArea, uiIndex, szFileName ) ); return; } diff --git a/harbour/source/rdd/dbf1.c b/harbour/source/rdd/dbf1.c index bfa9397af4..8592d47650 100644 --- a/harbour/source/rdd/dbf1.c +++ b/harbour/source/rdd/dbf1.c @@ -1956,7 +1956,7 @@ ERRCODE hb_dbfSysName( DBFAREAP pArea, BYTE * pBuffer ) HB_TRACE(HB_TR_DEBUG, ("hb_dbfSysName(%p, %p)", pArea, pBuffer)); HB_SYMBOL_UNUSED( pArea ); - strncpy( ( char * ) pBuffer, "DBF", HARBOUR_MAX_RDD_DRIVERNAME_LENGTH ); + strncpy( ( char * ) pBuffer, "DBF", 4 ); return SUCCESS; } diff --git a/harbour/source/rdd/workarea.c b/harbour/source/rdd/workarea.c index e2b4d315ca..e33d635742 100644 --- a/harbour/source/rdd/workarea.c +++ b/harbour/source/rdd/workarea.c @@ -446,7 +446,9 @@ ERRCODE hb_waAlias( AREAP pArea, BYTE * szAlias ) { HB_TRACE(HB_TR_DEBUG, ("hb_waAlias(%p, %p)", pArea, szAlias)); - strncpy( ( char * ) szAlias, ( ( PHB_DYNS ) pArea->atomAlias )->pSymbol->szName, + szAlias[0] = '\0'; + + strncat( ( char * ) szAlias, ( ( PHB_DYNS ) pArea->atomAlias )->pSymbol->szName, HARBOUR_MAX_RDD_ALIAS_LENGTH ); return SUCCESS; } diff --git a/harbour/tests/vidtest.prg b/harbour/tests/vidtest.prg new file mode 100644 index 0000000000..857cf07407 --- /dev/null +++ b/harbour/tests/vidtest.prg @@ -0,0 +1,215 @@ +/* + * $Id$ + */ +/* + * Harbour project video test code + * + * Program originally by Brian Dukes + * + * Redirect the output of this program to a file. + * + * ie: VidTest >results + * + */ + +#include "box.ch" + +#ifndef __CLIP__ + #ifndef FlagShip + #xtranslate secondscpu([]) => seconds([]) + #define EOL chr(13) + chr(10) + #endif +#endif +#ifndef EOL + #define EOL chr(10) +#endif +#command ? => outstd(EOL);outerr(EOL) +#command ? => outstd(, EOL);outerr(, EOL) + +#ifdef FlagShip + static nDispCount := 0 + + #xtranslate dispbegin() => iif((++nDispCount)==1, dispbegin(NIL),) + #xtranslate dispend() => iif(nDispCount>0 .and. (--nDispCount)==0, dispend(NIL),) +#endif + +function main() + local aResult := {} + + Initialise() // Initialise Screen Display + + // Perform Tests + aadd(aResult, StaticText() ) + aadd(aResult, WindowBounce() ) + aadd(aResult, ColourBoxes() ) + + // Display Results + Summary(aResult) +return NIL + + +// initialise the screen +static function Initialise() + //SetMode(25,80) + set colour to "W+/BG" + dispbox(0,0,MaxRow(), MaxCol(), replicate(chr(176),9), "BG/B") +return NIL + + +// repeatedly display a string in the same position +// this test determines how well the Screen i/o subsystem is +// caching screen writes. +static function StaticText() + local cResult + local r := MaxRow() / 2 + local str := Version() + local c + local i := 0 + local nEnd := 0 + local nStart := secondscpu() + + str := "Hello World - From " + Left(str,At(" ",str)-1) + c := (MaxCol()-len(str)) / 2 + + for i := 1 to 5000 + @ r, c say str + next i + + nEnd := secondscpu() + + cResult := "StaticText: Iterations=5000, Time="+alltrim(str(nEnd-nStart))+ ; + "secs, Average FPS = "+alltrim(str(round(5000 / (nEnd-nStart),0)))+" FPS" +return cResult + + +// Bounce a window around the screen a few thousand times +// timing the duration, and determining the average FPS +static function WindowBounce() + local cResult := "" + local nBoxes := Min(MaxRow(), MaxCol()-7)-6 /* keep the box in bounds */ + local x := array(NBOXES) + local y := array(NBOXES) + local dx := array(NBOXES) + local dy := array(NBOXES) + local clr := array(NBOXES) + local scr := array(NBOXES) + local nFrames := 0 + local nStart := 0 + local nEnd := 0 + local i := 0 + local aCol := {"N", "B", "G", "BG", "R", "RB", "GR", "W", ; + "N*","B*","G*","BG*","R*","RB*","GR*","W*" } + + // initialise boxes + for i := 1 to nBoxes + x[i] := i + y[i] := i-1 + dx[i] := -1 + dy[i] := 1 + clr[i] := "W+/"+aCol[(i-1)%16+1] + next i + + nStart := secondscpu() + dispbegin() + + do while nFrames < 5000 + + for i := 1 to nBoxes + scr[i] := SaveScreen(x[i], y[i], x[i]+6, y[i]+12) + @ x[i], y[i], x[i]+6, y[i]+12 box B_SINGLE+" " color clr[i] + next i + + dispend() + dispbegin() + + for i := nBoxes to 1 step -1 + // remove boxes from screen + RestScreen(x[i], y[i], x[i]+6, y[i]+12, scr[i]) + + // move + x[i] += dx[i] + y[i] += dy[i] + if x[i] <= 0 .or. x[i]+6 >= MaxRow() + dx[i] := -dx[i] + endif + if y[i] <= 0 .or. y[i]+12 >= MaxCol() + dy[i] := -dy[i] + endif + next i + + ++nFrames + enddo + + dispend() + nEnd := secondscpu() + + cResult := "WindowBounce:Iterations="+alltrim(str(nFrames))+", Time="+alltrim(str(nEnd-nStart))+ ; + "secs, Average FPS = "+alltrim(str(round(nFrames / (nEnd-nStart),0)))+" FPS" + +return cResult + + +// Display colour boxes, repeatedly, this will determine +// how efficiently the screen i/o subsystem is caching the +// dispbegin()'s and dispend()'s +static function ColourBoxes() + local cResult := "" + local nFrames := 0 + local nStart := 0 + local nEnd := 0 + local i := 0 + local nDir := 1 + local nDepth := 0 + local aCol := {"N", "B", "G", "BG", "R", "RB", "GR", "W", ; + "N*","B*","G*","BG*","R*","RB*","GR*","W*" } + + nStart := secondscpu() + // display boxes to screen + + do while nFrames < 5000 + if nDir = 1 + dispbegin() + else + dispend() + endif + + nDepth += nDir + + if nDepth > 4 .or. nDepth < 1 + nDir := -nDir + endif + i := nFrames %16 +1 + dispbox(5,10, MaxRow()-5, MaxCol()-10, ; + replicate(chr(i+64),9),; + "W+/"+aCol[i] ) + ++nFrames + enddo + + // remove any nested dispbegins() + do while nDepth > 0 + dispend() + nDepth-- + enddo + + nEnd := secondscpu() + + cResult := "ColourBoxes: Iterations="+alltrim(str(nFrames))+", Time="+alltrim(str(nEnd-nStart))+ ; + "secs, Average FPS = "+alltrim(str(round(nFrames / (nEnd-nStart),0)))+" FPS" + +return cResult + + +// display results +static function Summary(aResult) + local i := 0 + + clear screen + ? "Resolution: " + Ltrim(str( MaxRow()+1 )) + " x " + Ltrim(str( MaxCol()+1 )) + " " + Version() + for i := 1 to len(aResult) + ? aResult[i] + next i + ? + ? "press any key to continue" + inkey(0) + +return aResult