From 8db4f58efb66f285aff4baa34995faec2d599394 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 8 Aug 2007 13:21:15 +0000 Subject: [PATCH] 2007-08-08 15:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/libnf/at2.prg * harbour/contrib/libnf/min2dhm.prg * harbour/contrib/libnf/ontick.c * harbour/contrib/libnf/sqzn.prg * harbour/contrib/libnf/bytexor.prg * harbour/contrib/libnf/asum.prg * harbour/contrib/libnf/sleep.prg * harbour/contrib/libnf/any2any.prg * harbour/contrib/libnf/origin.c * harbour/contrib/libnf/mouse.c * harbour/contrib/libnf/stod.c * harbour/contrib/libnf/vertmenu.prg * harbour/contrib/libnf/aredit.prg * harbour/contrib/libnf/n2color.c * harbour/contrib/libnf/xbox.prg * harbour/contrib/libnf/hex2dec.prg * harbour/contrib/libnf/getver.c * harbour/contrib/libnf/Makefile * harbour/contrib/libnf/invclr.prg * harbour/contrib/libnf/popadder.prg * harbour/contrib/libnf/d2e.prg * harbour/contrib/libnf/anomatch.prg * harbour/contrib/libnf/color2n.c * harbour/contrib/libnf/datecnfg.prg * harbour/contrib/libnf/easter.prg * harbour/contrib/libnf/ntow.prg * harbour/contrib/libnf/floptst.prg * harbour/contrib/libnf/pchr.prg * harbour/contrib/libnf/tbwhile.prg * harbour/contrib/libnf/e2d.prg * harbour/contrib/libnf/sysmem.prg * harbour/contrib/libnf/dfile.prg * harbour/contrib/libnf/clrsel.prg + harbour/contrib/libnf/fttext.c + harbour/contrib/libnf/putkey.c * basic cleanup and syncing with some of xHarbour fixes and extensions. I'd like to ask Windows users to update non GNU make file * harbour/source/pp/ppcore.c + added support for .T., .F., .Y., .N. in PP and #IF ... / #ELIF ... expressions. It was reported by Nick Van Dyck on xHarbour devel list that old PP supported it. I haven't known that old PP suported .T. and .F. in #IF directive. Please not that there are other diferences between new PP and the old one in expresions which can be used in #IF ... / #ELIF directives. New PP supports C like expressions with support for pseudo functions like defined(), operates on integer numbers only to not damage 64bit values during conversion to double and keep C compatible results (the old one used double values) and is much more restrictive in checking for valid expression. --- harbour/ChangeLog | 51 ++ harbour/contrib/libnf/Makefile | 3 + harbour/contrib/libnf/anomatch.prg | 3 +- harbour/contrib/libnf/any2any.prg | 3 +- harbour/contrib/libnf/aredit.prg | 2 +- harbour/contrib/libnf/asum.prg | 3 +- harbour/contrib/libnf/at2.prg | 68 +- harbour/contrib/libnf/bytexor.prg | 3 +- harbour/contrib/libnf/clrsel.prg | 3 +- harbour/contrib/libnf/color2n.c | 132 +-- harbour/contrib/libnf/d2e.prg | 3 +- harbour/contrib/libnf/datecnfg.prg | 3 +- harbour/contrib/libnf/dfile.prg | 3 +- harbour/contrib/libnf/e2d.prg | 2 +- harbour/contrib/libnf/easter.prg | 13 +- harbour/contrib/libnf/floptst.prg | 3 - harbour/contrib/libnf/fttext.c | 1196 ++++++++++++++++++++++++++++ harbour/contrib/libnf/getver.c | 10 +- harbour/contrib/libnf/hex2dec.prg | 2 +- harbour/contrib/libnf/invclr.prg | 2 +- harbour/contrib/libnf/min2dhm.prg | 2 +- harbour/contrib/libnf/mouse.c | 27 +- harbour/contrib/libnf/n2color.c | 120 +-- harbour/contrib/libnf/ntow.prg | 2 +- harbour/contrib/libnf/ontick.c | 2 +- harbour/contrib/libnf/origin.c | 11 +- harbour/contrib/libnf/pchr.prg | 2 +- harbour/contrib/libnf/popadder.prg | 4 +- harbour/contrib/libnf/putkey.c | 260 ++++++ harbour/contrib/libnf/sleep.prg | 2 +- harbour/contrib/libnf/sqzn.prg | 2 +- harbour/contrib/libnf/stod.c | 9 +- harbour/contrib/libnf/sysmem.prg | 2 +- harbour/contrib/libnf/tbwhile.prg | 2 +- harbour/contrib/libnf/vertmenu.prg | 2 - harbour/contrib/libnf/xbox.prg | 2 +- harbour/source/pp/ppcore.c | 6 + 37 files changed, 1662 insertions(+), 303 deletions(-) create mode 100644 harbour/contrib/libnf/fttext.c create mode 100644 harbour/contrib/libnf/putkey.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4ebb702e81..6d434af86e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,57 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-08-08 15:20 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/libnf/at2.prg + * harbour/contrib/libnf/min2dhm.prg + * harbour/contrib/libnf/ontick.c + * harbour/contrib/libnf/sqzn.prg + * harbour/contrib/libnf/bytexor.prg + * harbour/contrib/libnf/asum.prg + * harbour/contrib/libnf/sleep.prg + * harbour/contrib/libnf/any2any.prg + * harbour/contrib/libnf/origin.c + * harbour/contrib/libnf/mouse.c + * harbour/contrib/libnf/stod.c + * harbour/contrib/libnf/vertmenu.prg + * harbour/contrib/libnf/aredit.prg + * harbour/contrib/libnf/n2color.c + * harbour/contrib/libnf/xbox.prg + * harbour/contrib/libnf/hex2dec.prg + * harbour/contrib/libnf/getver.c + * harbour/contrib/libnf/Makefile + * harbour/contrib/libnf/invclr.prg + * harbour/contrib/libnf/popadder.prg + * harbour/contrib/libnf/d2e.prg + * harbour/contrib/libnf/anomatch.prg + * harbour/contrib/libnf/color2n.c + * harbour/contrib/libnf/datecnfg.prg + * harbour/contrib/libnf/easter.prg + * harbour/contrib/libnf/ntow.prg + * harbour/contrib/libnf/floptst.prg + * harbour/contrib/libnf/pchr.prg + * harbour/contrib/libnf/tbwhile.prg + * harbour/contrib/libnf/e2d.prg + * harbour/contrib/libnf/sysmem.prg + * harbour/contrib/libnf/dfile.prg + * harbour/contrib/libnf/clrsel.prg + + harbour/contrib/libnf/fttext.c + + harbour/contrib/libnf/putkey.c + * basic cleanup and syncing with some of xHarbour fixes and extensions. + I'd like to ask Windows users to update non GNU make file + + * harbour/source/pp/ppcore.c + + added support for .T., .F., .Y., .N. in PP and #IF ... / #ELIF ... + expressions. It was reported by Nick Van Dyck on xHarbour devel list + that old PP supported it. I haven't known that old PP suported .T. + and .F. in #IF directive. Please not that there are other diferences + between new PP and the old one in expresions which can be used in + #IF ... / #ELIF directives. New PP supports C like expressions with + support for pseudo functions like defined(), operates on integer + numbers only to not damage 64bit values during conversion to double + and keep C compatible results (the old one used double values) and + is much more restrictive in checking for valid expression. + 2007-08-07 03:12 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbclass.ch ! fixed typo: AddClsMthds() => AddClsMethod() diff --git a/harbour/contrib/libnf/Makefile b/harbour/contrib/libnf/Makefile index 5c1de800dd..1a44149bf6 100644 --- a/harbour/contrib/libnf/Makefile +++ b/harbour/contrib/libnf/Makefile @@ -13,6 +13,8 @@ C_SOURCES = \ descend.c \ dispc.c \ ftattr.c \ + fttext.c \ + ftshadow.c \ getenvrn.c \ getver.c \ getvid.c \ @@ -25,6 +27,7 @@ C_SOURCES = \ origin.c \ proper.c \ prtscr.c \ + putkey.c \ rmdir.c \ shift.c \ stod.c \ diff --git a/harbour/contrib/libnf/anomatch.prg b/harbour/contrib/libnf/anomatch.prg index a1fe64a42a..2f784b8ec5 100644 --- a/harbour/contrib/libnf/anomatch.prg +++ b/harbour/contrib/libnf/anomatch.prg @@ -87,4 +87,5 @@ FUNCTION FT_ANOMATCHES(aArray, bCompareBlock, nStartIndex, nEndIndex) IIF(EVAL(bCompareBlock, xElement), nNoOfMatches++, NIL) }, ; nStartIndex, nEndIndex - nStartIndex + 1) - RETURN (nNoOfMatches) // FT_ANoMatches + RETURN (nNoOfMatches) // FT_ANoMatches + diff --git a/harbour/contrib/libnf/any2any.prg b/harbour/contrib/libnf/any2any.prg index c496ab895e..eea71b8cad 100644 --- a/harbour/contrib/libnf/any2any.prg +++ b/harbour/contrib/libnf/any2any.prg @@ -165,4 +165,5 @@ FUNCTION FT_XTOY(xValueToConvert, cTypeToConvertTo, lWantYesNo) ENDCASE - RETURN (xValueToConvert) // XToY + RETURN (xValueToConvert) // XToY + diff --git a/harbour/contrib/libnf/aredit.prg b/harbour/contrib/libnf/aredit.prg index a227741b62..8718c01f9d 100644 --- a/harbour/contrib/libnf/aredit.prg +++ b/harbour/contrib/libnf/aredit.prg @@ -300,4 +300,4 @@ FUNCTION FT_ArEdit( nTop, nLeft, nBot, nRight, ; * if no bGetFunc then ESC returns 0, otherwise return value of last element RETURN IF( VALTYPE(bGetFunc) == NIL .AND. nKey == K_ESC, ; 0, ar[b:colPos, nElem] ) -* EOFcn FT_ArEdit() +* EOFcn FT_ArEdit() diff --git a/harbour/contrib/libnf/asum.prg b/harbour/contrib/libnf/asum.prg index 9bcf52d2cc..dfa5cc1ab3 100644 --- a/harbour/contrib/libnf/asum.prg +++ b/harbour/contrib/libnf/asum.prg @@ -83,4 +83,5 @@ FUNCTION FT_ASUM(aArray, nStartIndex, nEndIndex) IF(IS_CHAR(xElement),LEN(xElement),0) }) }, ; nStartIndex, nEndIndex - nStartIndex + 1) - RETURN (nSumTotal) // FT_ASum + RETURN (nSumTotal) // FT_ASum + diff --git a/harbour/contrib/libnf/at2.prg b/harbour/contrib/libnf/at2.prg index 05b9bb3d4d..a8d94dd362 100644 --- a/harbour/contrib/libnf/at2.prg +++ b/harbour/contrib/libnf/at2.prg @@ -59,7 +59,7 @@ * * FT_AT2( cSearch, cTarget, 2, .F. ) // Returns ( 9 ) * $SEEALSO$ - * FT_FINDITH() + * FT_FINDITH(), FT_RAT2() * $END$ */ @@ -134,3 +134,69 @@ FUNCTION FT_AT2( cSearch, cTarget, nOccurs, lCaseSens ) RETURN ( nPos2 ) +/* $DOC$ + * $FUNCNAME$ + * FT_RAT2() + * $CATEGORY$ + * String + * $ONELINER$ + * Find position of the reversed nth occurrence of a substring + * $SYNTAX$ + * FT_RAT2( , [, [, ] ] ) -> nPos + * $ARGUMENTS$ + * is the character substring to search for. + * + * is the character string to search. + * + * is the occurrence of cSearch to look for, + * defaults to 1. + * + * is a logical value denoting case sensitivity. + * If .F., then search is NOT sensitive to case, + * defaults to .T. + * $RETURNS$ + * The position of the nth occurrence of a reversed substring + * $DESCRIPTION$ + * This function will find the nth occurrence of a reversed + * substring within a string. + * $EXAMPLES$ + * cSearch := "t" + * cTarget := "This is the day that the Lord has made." + * + * FT_RAT2( cSearch, cTarget ) // Returns ( 22 ) + * + * FT_RAT2( cSearch, cTarget, 2 ) // Returns ( 20 ) + * + * FT_RAT2( cSearch, cTarget, 2, .F. ) // Returns ( 22 ) + * $SEEALSO$ + * FT_FINDITH(), FT_AT2() + * $END$ + */ + +FUNCTION FT_RAT2( cSearch, cTarget, nOccurs, lCaseSens ) + LOCAL nCount, nPos, nPos2 := 0 + LOCAL cSubstr := cTarget + // Set default parameters as necessary. + IF lCaseSens == NIL + lCaseSens := .T. + ENDIF + IF nOccurs == NIL + nOccurs := 1 + ENDIF + FOR nCount := 1 TO nOccurs + // Store position of next occurrence of cSearch. + IF lCaseSens + nPos := RAT( cSearch, cSubstr ) + ELSE + nPos := RAT( UPPER( cSearch ), UPPER( cSubstr ) ) + ENDIF + // Store position of cSearch relative to original string. + nPos2 := nPos + // Resize cSubstr + cSubstr := SUBSTR( cSubstr, 1, RAT( cSearch, cSubstr ) - 1 ) + // Breakout if there are no occurences here + IF nPos == 0 + EXIT + ENDIF + NEXT + RETURN ( nPos2 ) diff --git a/harbour/contrib/libnf/bytexor.prg b/harbour/contrib/libnf/bytexor.prg index 77e1e0322a..7921e8924d 100644 --- a/harbour/contrib/libnf/bytexor.prg +++ b/harbour/contrib/libnf/bytexor.prg @@ -79,4 +79,5 @@ FUNCTION FT_BYTEXOR(cByte1, cByte2) NEXT ENDIF -RETURN cNewByte +RETURN cNewByte + diff --git a/harbour/contrib/libnf/clrsel.prg b/harbour/contrib/libnf/clrsel.prg index eb929d1e78..ed16674000 100644 --- a/harbour/contrib/libnf/clrsel.prg +++ b/harbour/contrib/libnf/clrsel.prg @@ -783,4 +783,5 @@ DO WHILE lIdentical .AND. n <= LEN(aArr1) n++ ENDDO -RETURN lIdentical +RETURN lIdentical + diff --git a/harbour/contrib/libnf/color2n.c b/harbour/contrib/libnf/color2n.c index 8218cab0f6..879d98c3a9 100644 --- a/harbour/contrib/libnf/color2n.c +++ b/harbour/contrib/libnf/color2n.c @@ -52,134 +52,14 @@ */ #include "hbapi.h" +#include "hbapigt.h" -static int _ftColor2I( char * cColor ); -static int _ftGetColorNum( char * cColor ); -static char * _ftStripIt( char * cColor ); - -HB_FUNC(FT_COLOR2N) +HB_FUNC( FT_COLOR2N ) { -/* #if defined(HB_OS_DOS) || defined(HB_OS_WIN_32) - { */ + int iRet = 0; - int iRet = 0; + if( ISCHAR( 1 ) ) + iRet = hb_gtColorToN( hb_parc( 1 ) ); - // make sure parameter is a char type and that it is 8 chars or less - - if ( ISCHAR( 1 ) && hb_parclen( 1 ) < 8 ) - iRet = _ftColor2I( hb_parc( 1 ) ); - - hb_retni( iRet ); - - return; -/* } -#endif */ -} - - -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ -// Function : _ftColor2I -// Purpose : Converts an Xbase color string to an int -// Parameters: cColor - a pointer to the color string -// Returns : int complement of color string, or 0 if string is invalid -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ - -static int _ftColor2I( char * cColor ) -{ - char * cFore = " ", * cBack = " "; - unsigned int iBlink = 0, iIntense = 0, iBack = 0, i = 0; - - // copy the Clipper string to buffer, check for attributes, and - // make lower case - - while ( ( cFore[ i ] = cColor[ i ] ) != 0 ) - { - // check for a blink attrib - - if ( cFore[ i ] == '*' && iBlink == 0 ) iBlink = 128; - - // check for an intensity attrib - - if ( cFore[ i ] == '+' && iIntense == 0 ) iIntense = 8; - - // make sure all chars are lower case - - if ( 91 > cFore[ i ] && cFore[ i ] > 64 ) cFore[ i ] += 32; - - i++; - } - - // check for the background color - - while ( cColor[ iBack++ ] != '/' && cColor[ iBack ] != 0 ); - - if ( cColor[--iBack ] == '/' ) - { - cBack = cFore + iBack + 1; - cFore[ iBack ] = 0; - } - - // calculate and return the value - - return ( iIntense + iBlink + _ftGetColorNum( _ftStripIt( cFore ) ) + - ( 16 * _ftGetColorNum( _ftStripIt( cBack ) ) ) ); - -} - - -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ -// Function : _ftGetColorNum -// Purpose : Returns the corresponding number for an Xbase color -// Parameters: cColor - a pointer to the color string -// Returns : int complement of a single color -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ - -static int _ftGetColorNum( char * cColor ) -{ - unsigned * iColor = ( unsigned * ) cColor; - - if ( cColor[ 1 ] == 0 ) switch ( cColor[ 0 ] ) - { - case 'n' : *iColor = 0; break; - case 'b' : *iColor = 1; break; - case 'g' : *iColor = 2; break; - case 'r' : *iColor = 4; break; - case 'w' : *iColor = 7; break; - } - else - { - if ( ( cColor[ 0 ] == 'b' ) && cColor[ 1 ] == 'g' ) *iColor = 3; - if ( ( cColor[ 0 ] == 'r' ) && cColor[ 1 ] == 'b' ) *iColor = 5; - if ( ( cColor[ 0 ] == 'g' ) && cColor[ 1 ] == 'r' ) *iColor = 6; - } - - return *iColor; -} - - - -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ -// Function : _ftStripIt -// Purpose : Removes the intensity/blink chars from the passed string -// Parameters: cColor - a pointer to the color string -// Returns : a pointer to the modified color string -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ - -static char * _ftStripIt( char * cColor ) -{ - unsigned i = 0; - - // move past any leading markers - - while ( *cColor == '+' || *cColor == '*' ) cColor++; - - // truncate any trailing markers - - while ( cColor[ i ] && cColor[ i ] != '+' && cColor[ i ] != '*' ) i++; - - // null terminate the string - - cColor[ i ] = 0; - - return cColor; + hb_retni( iRet ); } diff --git a/harbour/contrib/libnf/d2e.prg b/harbour/contrib/libnf/d2e.prg index ae695f863e..f8bd9366f9 100644 --- a/harbour/contrib/libnf/d2e.prg +++ b/harbour/contrib/libnf/d2e.prg @@ -86,4 +86,5 @@ function ft_d2e( nDec, nPrecision ) endif another kludge for stuff like '999999999' sScn := ltrim( str( nDec, nPrecision + 3, nPrecision ) ) - return( sScn + 'E' + alltrim( str( nExp, 5, 0 ) ) ) + return( sScn + 'E' + alltrim( str( nExp, 5, 0 ) ) ) + diff --git a/harbour/contrib/libnf/datecnfg.prg b/harbour/contrib/libnf/datecnfg.prg index 7351e911f3..555c279390 100644 --- a/harbour/contrib/libnf/datecnfg.prg +++ b/harbour/contrib/libnf/datecnfg.prg @@ -327,4 +327,5 @@ FUNCTION FT_DATECNFG( cFYStart ,nDow ) aDatePar[2] := nDow ENDIF -RETURN ACLONE( aDatePar ) +RETURN ACLONE( aDatePar ) + diff --git a/harbour/contrib/libnf/dfile.prg b/harbour/contrib/libnf/dfile.prg index 54dda71acc..4a9cbb5cb6 100644 --- a/harbour/contrib/libnf/dfile.prg +++ b/harbour/contrib/libnf/dfile.prg @@ -224,4 +224,5 @@ function FT_DFCLOSE() nHandle := 0 endif - return (NIL) + return (NIL) + diff --git a/harbour/contrib/libnf/e2d.prg b/harbour/contrib/libnf/e2d.prg index 996b9df422..2828d15c43 100644 --- a/harbour/contrib/libnf/e2d.prg +++ b/harbour/contrib/libnf/e2d.prg @@ -65,4 +65,4 @@ function ft_e2d( sNumE ) len( sNumE ) - at( 'E', sNumE ) ; ) ; ) - return( nMant * 10 ^ nExp ) + return( nMant * 10 ^ nExp ) diff --git a/harbour/contrib/libnf/easter.prg b/harbour/contrib/libnf/easter.prg index 1c6db8c8e6..621f5ebd30 100644 --- a/harbour/contrib/libnf/easter.prg +++ b/harbour/contrib/libnf/easter.prg @@ -1,7 +1,7 @@ /* * File......: EASTER.PRG * Author....: Paul Tucker - * CIS ID....: ? + * Email.....: * * While I can say that I wrote the program, the algorithm is from Donald * Knuth's The Art of Computer Programming, Section 1.3.2. So, the source @@ -52,11 +52,7 @@ FUNCTION FT_EASTER (nYear) local nGold, nCent, nCorx, nCorz, nSunday, nEpact, nMoon,; - nMonth := 0, nDay := 0, lCent := __SetCentury( .t. ) - - // -------------------------------- - // NOTE: __SetCentury() is internal - // -------------------------------- + nMonth := 0, nDay := 0 IF VALTYPE (nYear) == "C" nYear = VAL(nYear) @@ -121,7 +117,4 @@ FUNCTION FT_EASTER (nYear) nYear = 0 ENDIF - set century (lCent) - -RETURN CTOD (RIGHT ("00"+LTRIM (STR (nMonth)),2) + "/" +; - RIGHT ("00"+LTRIM (STR (INT (nDay))) ,2) + "/" +STR (nYear,4)) +RETURN StoD( Str( nYear,4) + PadL( nMonth, 2, "0" ) + PadL( Int( nDay ), 2, "0" ) ) diff --git a/harbour/contrib/libnf/floptst.prg b/harbour/contrib/libnf/floptst.prg index 50b2ddc6c5..e9a3122e88 100644 --- a/harbour/contrib/libnf/floptst.prg +++ b/harbour/contrib/libnf/floptst.prg @@ -287,6 +287,3 @@ STATIC FUNCTION _CallInt13hRetry( ; // logical: did the interrupt succeed? nDriveStatus_o := highByte( aRegisters[AX] ) RETURN lSuccess - -// EOF - diff --git a/harbour/contrib/libnf/fttext.c b/harbour/contrib/libnf/fttext.c new file mode 100644 index 0000000000..5efc2f00ff --- /dev/null +++ b/harbour/contrib/libnf/fttext.c @@ -0,0 +1,1196 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * + * Nanforum Toolkit simulation of text file handlers + * Ideas by Brice de Ganahl and Steve Larsen + * Total rework using xHarbour array implementation by Andi Jahja + * + * Copyright 2005 Andi Jahja + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, 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. + * + */ + +#include "hbapi.h" +#include "hbapifs.h" +#include "hbapiitm.h" +#include "hbstack.h" +#include "hbvmpub.h" +#include "hbpcode.h" +#include "hbinit.h" + +#define __PRG_SOURCE__ __FILE__ + +HB_FUNC( FT_FUSE ); +HB_FUNC( FT_FSEEK ); +HB_FUNC( FT_FRSEEK ); +HB_FUNC( FT_FNEW ); +HB_FUNC( FT_FARRAY ); +HB_FUNC( FT_FACTIVE ); +HB_FUNC( FT_FBUFFERSIZE ); +HB_FUNC( FT_FSETNEWLINE ); +HB_FUNC( FT_FSELECT ); +HB_FUNC( FT_FFLUSH ); +HB_FUNC( FT_FWRITEENABLE ); +HB_FUNC( FT_FFILENAME ); +HB_FUNC( FT_FALIAS ); +HB_FUNC( FT_FCHANGED ); +HB_FUNC( FT_FINSERT ); +HB_FUNC( FT_FDELETE ); +HB_FUNC( FT_FRECALL ); +HB_FUNC( FT_FAPPEND ); +HB_FUNC( FT_FLASTREC ); +HB_FUNC( FT_FRECNO ); +HB_FUNC( FT_FGOTO ); +HB_FUNC( FT_FSKIP ); +HB_FUNC( FT_FBOF ); +HB_FUNC( FT_FEOF ); +HB_FUNC( FT_FGOTOP ); +HB_FUNC( FT_FGOBOTTOM ); +HB_FUNC( FT_FWRITELN ); +HB_FUNC( FT_FREADLN ); +HB_FUNC( FT_FREADLN_EX ); +HB_FUNC( FT_FDELETED ); +HB_FUNC( FT_FCLOSE ); +HB_FUNC( FT_FCLOSEALL ); + +HB_FUNC_EXTERN( ASCAN ); +HB_FUNC_EXTERN( RASCAN ); + +HB_FUNC_INIT( FT_FINIT ); +HB_FUNC_EXIT( FT_FEXIT ); + +#undef HB_PRG_PCODE_VER +#define HB_PRG_PCODE_VER HB_PCODE_VER + +HB_INIT_SYMBOLS_BEGIN( hb_vm_SymbolInit_FTEXT ) +{ "FT_FUSE", {HB_FS_PUBLIC}, {HB_FUNCNAME( FT_FUSE )}, NULL }, +{ "ASCAN", {HB_FS_PUBLIC}, {HB_FUNCNAME( ASCAN )}, NULL }, +{ "RASCAN", {HB_FS_PUBLIC}, {HB_FUNCNAME( RASCAN )}, NULL }, +{ "FT_FINIT$", {HB_FS_INIT}, {HB_INIT_FUNCNAME( FT_FINIT )}, NULL }, +{ "FT_FEXIT$", {HB_FS_EXIT}, {HB_EXIT_FUNCNAME( FT_FEXIT )}, NULL } +HB_INIT_SYMBOLS_END( hb_vm_SymbolInit_FTEXT ) + +#if defined(HB_PRAGMA_STARTUP) + #pragma startup hb_vm_SymbolInit_FTEXT +#elif defined(HB_MSC_STARTUP) + #if _MSC_VER >= 1010 + #pragma data_seg( ".CRT$XIY" ) + #pragma comment( linker, "/Merge:.CRT=.data" ) + #else + #pragma data_seg( "XIY" ) + #endif + static HB_$INITSYM hb_vm_auto_SymbolInit_FTEXT = hb_vm_SymbolInit_FTEXT; + #pragma data_seg() +#endif + +typedef struct _FT_FFILE +{ + LONG nCurrent ; + FILE *fHandle ; + char szFileName[_POSIX_PATH_MAX] ; + char szAlias [HB_SYMBOL_NAME_LEN + 1] ; + int iArea ; + BOOL bChange ; + BOOL bActive ; + BOOL bWrite ; + PHB_ITEM pOrigin ; + PHB_ITEM pArray ; + struct _FT_FFILE * pNext; +} FT_FFILE, * PFT_FFILE; + +static LONG nCurrent = 0; +static PFT_FFILE pCurFile = NULL; +static PFT_FFILE pFT = NULL; +static int iSelect = 0; +static ULONG uBuffSize = 0; +static char *szNewLine; + +static BOOL ft_fread ( FILE *, char * ); +static PFT_FFILE ft_fseekAlias ( int ); +static PFT_FFILE ft_fseekArea ( char * ); +static BOOL ft_fseekActive( void ); +#ifdef __LINE_COUNT__ +static ULONG ft_flinecount ( FILE * ); +#endif +#define DELETION_MARK "" +#define MAX_READ 4096 + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FUSE ) +{ + #ifndef FO_WRITE + #define FO_WRITE 1 + #endif + #ifndef FO_READWRITE + #define FO_READWRITE 2 + #endif + + PHB_ITEM pInFile = hb_param( 1, HB_IT_STRING ); + + if( pInFile && hb_itemGetCLen( pInFile ) > 0 && iSelect > 0 ) + { + PFT_FFILE pTemp; + BOOL bNewFile = FALSE; + PHB_ITEM pArray = hb_itemNew( NULL ); + PFT_FFILE pLast; + PHB_ITEM pTmp = hb_itemNew( NULL ); + BOOL bWriteEnable = FALSE; + char szmode[3]; + int iMode = ISNUM(2) ? hb_parni(2) : 0 ; + FILE *inFile; + + pTemp = ft_fseekAlias( iSelect ); + + // Area already used + if ( pTemp && pTemp->bActive) + { + hb_retl( FALSE ); + return; + } + + if( iMode & ( FO_WRITE | FO_READWRITE ) ) + { + bWriteEnable = TRUE; + szmode[0] = 'r'; + szmode[1] = '+'; + szmode[2] = 0 ; + } + else + { + szmode[0] = 'r'; + szmode[1] = 0 ; + szmode[2] = 0 ; + } + + inFile = fopen( hb_parcx(1), szmode ); + + if( inFile ) + { + PHB_FNAME ft_FileName; + PHB_ITEM pClone; + char *string = ( char *) hb_xgrab( uBuffSize + 1 ); +#ifdef __LINE_COUNT__ + ULONG ulLineCount = ft_flinecount ( inFile ); + ULONG ulCount = 0; + + fseek( inFile, 0, SEEK_SET ); + hb_arrayNew( pArray, ulLineCount ); +#else + hb_arrayNew( pArray, 0 ); +#endif + while ( ft_fread ( inFile, string ) ) + { +#ifdef __LINE_COUNT__ + ulCount ++; + hb_arraySetForward( pArray, ulCount, hb_itemPutC( pTmp, string ) ); +#else + hb_arrayAddForward( pArray, hb_itemPutC( pTmp, string ) ); +#endif + } + + hb_itemRelease(pTmp ); + hb_xfree( string ); + fclose( inFile ); + + ft_FileName = hb_fsFNameSplit( hb_itemGetCPtr( pInFile ) ); + + nCurrent = hb_arrayLen( pArray ) ? 1 : 0; + + if ( pTemp == NULL ) + { + bNewFile = TRUE; + pTemp = (PFT_FFILE) hb_xgrab( sizeof( FT_FFILE ) ); + pTemp->pArray = hb_itemNew(NULL); + pTemp->pOrigin= hb_itemNew(NULL); + + } + else + { + if( pTemp->pArray ) + { + hb_itemRelease( pTemp->pArray ); + pTemp->pArray = NULL; + pTemp->pArray = hb_itemNew(NULL); + + } + if( pTemp->pOrigin ) + { + hb_itemRelease( pTemp->pOrigin ); + pTemp->pOrigin = NULL; + pTemp->pOrigin= hb_itemNew(NULL); + } + } + + + *(pTemp->szFileName) = 0; + *(pTemp->szAlias) = 0; + + pTemp->bWrite = bWriteEnable; + strcpy( pTemp->szFileName, hb_parcx(1) ); + + if( ISCHAR(3) && hb_parclen( 3 ) > 0 ) + { + strcpy( pTemp->szAlias, hb_parcx( 3 ) ); + } + else + { + strcpy( pTemp->szAlias, ft_FileName->szName ); + } + + hb_strupr( pTemp->szAlias ); + + pTemp->bChange = FALSE; + pTemp->fHandle = inFile; + pTemp->iArea = iSelect; + + pClone = hb_arrayClone( pArray ); + hb_itemCopy( pTemp->pArray , pArray ); + hb_itemCopy( pTemp->pOrigin, pClone ); + + hb_itemRelease( pClone ); + + pTemp->nCurrent = nCurrent ; + pTemp->bActive = TRUE; + + pCurFile = pTemp; + + if ( bNewFile ) + { + pTemp->pNext = NULL; + + if( pFT ) + { + pLast = pFT; + while( pLast->pNext ) + { + pLast = pLast->pNext; + } + pLast->pNext = pTemp; + } + else + { + pFT = pTemp; + } + } + + hb_xfree( ft_FileName ); + hb_itemRelease( pArray ); + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } + } + else + { + if( iSelect > 0 ) + { + HB_FUNCNAME( FT_FCLOSE )(); + } + + if( !ft_fseekActive() ) + { + HB_FUNCNAME( FT_FCLOSEALL )(); + } + + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FSEEK ) +{ + PHB_ITEM pSeek = hb_param( 1, HB_IT_STRING ); + + if ( pCurFile && pSeek ) + { + PHB_ITEM pResult = hb_itemDoC( "ASCAN", 2, pCurFile->pArray, pSeek ); + + if( pResult ) + { + nCurrent = hb_itemGetNL( pResult ); + + hb_retl( nCurrent > 0 ); + + if( !nCurrent ) + { + nCurrent = hb_arrayLen( pCurFile->pArray ) + 1; + } + + pCurFile->nCurrent = nCurrent; + + hb_itemRelease( pResult ); + + return; + } + } + + hb_retl( FALSE ); +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FRSEEK ) +{ + PHB_ITEM pSeek = hb_param( 1, HB_IT_STRING ); + + if ( pCurFile && pSeek ) + { + PHB_ITEM pResult = hb_itemDoC( "RASCAN", 2, pCurFile->pArray, pSeek ); + + if( pResult ) + { + nCurrent = hb_itemGetNL( pResult ); + + hb_retl( nCurrent > 0 ); + + if( !nCurrent ) + { + nCurrent = hb_arrayLen( pCurFile->pArray ) + 1; + } + + pCurFile->nCurrent = nCurrent; + + hb_itemRelease( pResult ); + + return; + } + } + + hb_retl( FALSE ); +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FNEW ) +{ + PHB_ITEM pNew = hb_param( 1, HB_IT_STRING ); + + if( pNew && hb_itemGetCLen( pNew ) > 0 ) + { + FILE *inFile; + PHB_ITEM pUse; + PHB_ITEM fTmp = hb_itemNew( NULL ); + PHB_ITEM fMode = hb_itemNew( NULL ); + + inFile = fopen( hb_parcx(1), "wb" ); + + if(!inFile) + { + hb_retl( FALSE ); + return; + } + + fclose( inFile ); + + pUse = hb_itemDoC( "FT_FUSE", + 2, + hb_itemPutC( fTmp, hb_parcx(1) ), + hb_itemPutNI( fMode, FO_READWRITE ) ); + + hb_itemRelease( fTmp ); + hb_itemRelease( fMode ); + + if( pUse ) + { + hb_itemRelease( hb_itemReturn( pUse ) ); + } + else + { + hb_retl( FALSE ); + } + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC ( FT_FARRAY ) +{ + if( pCurFile ) + { + hb_itemCopy( hb_stackReturnItem(), hb_parl(1) ? pCurFile->pOrigin : pCurFile->pArray ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC ( FT_FACTIVE ) +{ + hb_retl( pCurFile ? pCurFile->bActive : FALSE ); +} + +//------------------------------------------------------------------------------ +HB_FUNC ( FT_FBUFFERSIZE ) +{ + LONG uNewBuff = ISNUM(1) ? hb_parnl(1) : ( LONG ) uBuffSize; + + hb_retnl( uBuffSize ); + + if ( uNewBuff > 0 ) + { + uBuffSize = uNewBuff; + } +} + +//------------------------------------------------------------------------------ +HB_FUNC ( FT_FSETNEWLINE ) +{ + hb_retc( szNewLine ); + + if( ISCHAR(1) ) + { + szNewLine = hb_parcx( 1 ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FSELECT ) +{ + PHB_ITEM pSelect = hb_param( 1, HB_IT_ANY ); + + hb_retni( iSelect ); + + if( pSelect ) + { + if( ISNUM( 1 ) ) + { + int iNewSelect = hb_parnl( 1 ); + PFT_FFILE pTmp = ft_fseekAlias( iNewSelect ); + + if ( iNewSelect == 0 ) + { + BOOL bFoundActive = FALSE; + + pTmp = pFT; + + while ( pTmp ) + { + if ( !pTmp->bActive ) + { + bFoundActive = TRUE; + iSelect = pTmp->iArea; + break; + } + pTmp = pTmp->pNext; + } + + if( !bFoundActive ) + { + iSelect ++; + } + } + else if ( pTmp == NULL ) + { + iSelect = iNewSelect; + pCurFile = NULL; + } + else + { + iSelect = pTmp->iArea; + nCurrent = pTmp->nCurrent; + pCurFile = pTmp->bActive ? pTmp : NULL ; + } + } + else if ( ISCHAR(1) ) + { + PFT_FFILE pTmp = ft_fseekArea( hb_parcx( 1 ) ); + + if( pTmp == NULL ) + { + if( pFT == NULL ) + { + iSelect = 1; + } + else + { + BOOL bFoundActive = FALSE; + + pTmp = pFT; + + while ( pTmp ) + { + if ( !pTmp->bActive ) + { + bFoundActive = TRUE; + iSelect = pTmp->iArea; + break; + } + pTmp = pTmp->pNext; + } + + if( !bFoundActive ) + { + iSelect ++; + } + } + } + else + { + iSelect = pTmp->iArea; + nCurrent = pTmp->nCurrent; + pCurFile = pTmp->bActive ? pTmp : NULL ; + } + } + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FFLUSH ) +{ + if( pCurFile && pCurFile->bWrite && pCurFile->bChange ) + { + FILE *inFile = fopen( pCurFile->szFileName, "wb" ); + + if( inFile ) + { + ULONG lEle; + ULONG ulSize = hb_arrayLen( pCurFile->pArray ); + + for ( lEle = 1; lEle <= ulSize ; lEle ++ ) + { + char *szContent = hb_arrayGetC( pCurFile->pArray, lEle ); + if ( strcmp( szContent, DELETION_MARK ) ) + { + fprintf( inFile, "%s%s", szContent, szNewLine ); + } + hb_xfree( szContent ); + } + + fclose( inFile ); + pCurFile->bChange = FALSE; + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FWRITEENABLE ) +{ + int iAlias = ISNUM(1) ? hb_parni( 1 ) : iSelect ; + PFT_FFILE pTmp = ft_fseekAlias( iAlias ); + + if( pTmp != NULL && ( pCurFile || pTmp->bActive ) ) + { + hb_retl( pTmp->bWrite); + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FFILENAME ) +{ + int iAlias = ISNUM(1) ? hb_parni( 1 ) : iSelect ; + PFT_FFILE pTmp = ft_fseekAlias( iAlias ); + + if( pTmp != NULL && ( pCurFile || pTmp->bActive ) ) + { + hb_retc( pTmp->szFileName ); + } + else + { + hb_retc(""); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FALIAS ) +{ + int iAlias = ISNUM(1) ? hb_parni( 1 ) : iSelect ; + PFT_FFILE pTmp = ft_fseekAlias( iAlias ); + + if( pTmp != NULL && ( pCurFile || pTmp->bActive ) ) + { + hb_retc( pTmp->szAlias ); + } + else + { + hb_retc(""); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FCHANGED ) +{ + int iAlias = ISNUM(1) ? hb_parni( 1 ) : iSelect ; + PFT_FFILE pTmp = ft_fseekAlias( iAlias ); + + if( pTmp != NULL && ( pCurFile || pTmp->bActive ) ) + { + hb_retl( pTmp->bChange ); + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FINSERT ) +{ + LONG lInsert = ISNUM(1) ? hb_parnl(1) : 0; + + if( pCurFile && pCurFile->bWrite && lInsert > 0 ) + { + LONG lAdd; + + for ( lAdd = 1; lAdd <= lInsert; lAdd ++ ) + { + PHB_ITEM Tmp = hb_itemNew( NULL ); + hb_arraySize( pCurFile->pArray, hb_arrayLen(pCurFile->pArray)+ 1 ); + hb_arrayIns( pCurFile->pArray, nCurrent + lAdd ); + hb_arraySetForward( pCurFile->pArray, nCurrent + lAdd, hb_itemPutC( Tmp, "" ) ); + hb_itemRelease( Tmp); + } + + pCurFile->bChange = TRUE; + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FDELETE ) +{ + LONG lDelete = ISNUM( 1 ) ? hb_parnl( 1 ) : nCurrent; + ULONG ulSize = hb_arrayLen( pCurFile->pArray ) ; + if( pCurFile && pCurFile->bWrite && lDelete > 0 && (ULONG) lDelete <= ulSize) + { + PHB_ITEM Tmp = hb_itemNew( NULL) ; + hb_arraySetForward( pCurFile->pArray, lDelete, hb_itemPutC( Tmp, DELETION_MARK ) ); + pCurFile->bChange = TRUE; + hb_itemRelease( Tmp ); + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FRECALL ) +{ + LONG lRecall = ISNUM( 1 ) ? hb_parnl( 1 ) : nCurrent; + ULONG ulSize = hb_arrayLen( pCurFile->pArray ) ; + if( pCurFile && pCurFile->bWrite && lRecall > 0 && (ULONG) lRecall <= ulSize ) + { + char *szReadLn = hb_arrayGetC( pCurFile->pArray, lRecall ); + + if( strcmp( szReadLn, DELETION_MARK ) == 0 ) + { + PHB_ITEM Tmp = hb_itemNew(NULL); + char *szOrigin = hb_arrayGetC( pCurFile->pOrigin, lRecall ); + hb_arraySetForward( pCurFile->pArray, lRecall, hb_itemPutC( Tmp, szOrigin ) ); + hb_itemRelease( Tmp ); + if( szOrigin ) + { + hb_xfree( szOrigin ); + } + pCurFile->bChange = TRUE; + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } + + hb_xfree( szReadLn ); + } + else + { + hb_retl( FALSE ); + } +} +//------------------------------------------------------------------------------ +HB_FUNC( FT_FAPPEND ) +{ + LONG lAppend = ISNUM(1) ? hb_parnl(1) : 1; + + if( lAppend > 0 && pCurFile && pCurFile->bWrite ) + { + PHB_ITEM Tmp = hb_itemNew( NULL ); + LONG lStart; + char *szAppend = ISCHAR(2) ? hb_parcx(2) : (char*) ""; + + for( lStart = 1; lStart <= lAppend ; lStart ++ ) + { + hb_arrayAddForward( pCurFile->pArray, hb_itemPutC(Tmp, szAppend ) ); + hb_arrayAddForward( pCurFile->pOrigin, hb_itemPutC(Tmp, szAppend ) ); + } + + nCurrent = hb_arrayLen( pCurFile->pArray ); + pCurFile->nCurrent = nCurrent; + pCurFile->bChange = TRUE; + hb_itemRelease(Tmp); + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FLASTREC ) +{ + ULONG uRet = ULONG_MAX; + + if( pCurFile ) + { + uRet = hb_parl(1) ? hb_arrayLen( pCurFile->pOrigin ) : hb_arrayLen( pCurFile->pArray ); + } + + hb_retnl( uRet ); +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FRECNO ) +{ + hb_retnl( nCurrent ); +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FGOTO ) +{ + if ( ISNUM(1) ) + { + LONG lGoto = hb_parnl(1); + + if( lGoto > 0 ) + { + nCurrent = lGoto; + + if( pCurFile ) + { + pCurFile->nCurrent = nCurrent; + } + } + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FSKIP ) +{ + LONG uSkip = 1; + + if ( ISNUM(1) ) + { + uSkip = hb_parnl( 1 ); + } + + nCurrent += uSkip; + + if ( pCurFile ) + { + pCurFile->nCurrent = nCurrent; + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FBOF ) +{ + hb_retl( nCurrent <= 1 ); +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FEOF ) +{ + hb_retl ( pCurFile ? (ULONG) nCurrent > hb_arrayLen( pCurFile->pArray ) : TRUE ); +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FGOTOP ) +{ + nCurrent = 1 ; + if ( pCurFile ) + { + pCurFile->nCurrent = 1; + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FGOBOTTOM ) +{ + if( pCurFile ) + { + nCurrent = hb_arrayLen( pCurFile->pArray ) ; + pCurFile->nCurrent = nCurrent; + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FWRITELN ) +{ + int iOldArea = iSelect; + char * pSz = hb_parc(1); + LONG lWriteLn = ISNUM(2) ? hb_parnl(2) : nCurrent; + int iAreaWrite = ISNUM(3) ? hb_parni(3) : iSelect; + BOOL bChangeArea = FALSE; + + if( iAreaWrite != iSelect ) + { + pCurFile = ft_fseekAlias( iAreaWrite ); + bChangeArea = TRUE; + } + + if( pCurFile && pCurFile->bWrite && pCurFile->bActive && pSz && lWriteLn > 0 && (ULONG) lWriteLn <= hb_arrayLen(pCurFile->pArray)) + { + PHB_ITEM Tmp = hb_itemNew(NULL); + hb_arraySetForward( pCurFile->pArray, lWriteLn, hb_itemPutC( Tmp, pSz ) ); + hb_arraySetForward( pCurFile->pOrigin, lWriteLn, hb_itemPutC( Tmp, pSz ) ); + hb_itemRelease(Tmp); + pCurFile->bChange = TRUE; + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } + + if( bChangeArea ) + { + iSelect = iOldArea; + pCurFile = ft_fseekAlias( iSelect ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FREADLN ) +{ + LONG lReadLn = ISNUM(1) ? hb_parnl(1) : nCurrent; + ULONG ulSize =hb_arrayLen( pCurFile->pArray ); + if( pCurFile && lReadLn > 0 && (ULONG) lReadLn <= ulSize) + { + char *szReadLn = hb_parl( 2 ) ? hb_arrayGetC( pCurFile->pOrigin, lReadLn ): hb_arrayGetC( pCurFile->pArray, lReadLn ); + hb_retcAdopt( szReadLn ); + } + else + { + hb_retc(""); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FREADLN_EX ) +{ + ULONG ulSize =hb_arrayLen( pCurFile->pArray ); + if( pCurFile && nCurrent > 0 && (ULONG) nCurrent <= ulSize) + { + char *szReadLn = hb_arrayGetC( pCurFile->pArray, nCurrent ); + hb_retcAdopt( szReadLn ); + nCurrent ++; + pCurFile->nCurrent = nCurrent; + } + else + { + hb_retc(""); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FDELETED ) +{ + LONG lQuery = ISNUM(1) ? hb_parnl(1) : nCurrent; + ULONG ulSize =hb_arrayLen( pCurFile->pArray ) ; + if( pCurFile && lQuery > 0 && (ULONG) lQuery <= ulSize ) + { + char *szReadLn = hb_arrayGetC( pCurFile->pArray, lQuery ); + hb_retl( strcmp( szReadLn, DELETION_MARK ) == 0 ); + hb_xfree( szReadLn ); + } + else + { + hb_retl( FALSE ); + } +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FCLOSE ) +{ + PFT_FFILE pTmp = NULL; + int iOldSelect = iSelect; + + if ( ISCHAR( 1 ) ) + { + pTmp = ft_fseekArea( hb_parcx( 1 ) ); + } + else if ( ISNUM( 1 ) ) + { + int iSeek = hb_parni( 1 ); + pTmp = ft_fseekAlias( iSeek ); + } + else if ( ISNIL( 1 ) ) + { + pTmp = ft_fseekAlias( iSelect ); + } + + if ( pTmp != NULL ) + { + if ( pTmp->bActive ) + { + iSelect = pTmp->iArea; + pCurFile = pTmp; + HB_FUNCNAME( FT_FFLUSH )(); + pTmp->bActive = FALSE; + *(pTmp->szFileName) = 0; + *(pTmp->szAlias) = 0; + hb_retl( TRUE ); + } + else + { + hb_retl( FALSE ); + } + + if( !ft_fseekActive() ) + { + HB_FUNCNAME( FT_FCLOSEALL )(); + } + } + else + { + hb_retl( FALSE ); + } + + if( iSelect != iOldSelect ) + { + iSelect = iOldSelect; + } + + pCurFile = NULL; +} + +//------------------------------------------------------------------------------ +HB_FUNC_INIT ( FT_FINIT ) +{ + if( uBuffSize == 0 ) + { + uBuffSize = MAX_READ; + } + + szNewLine = hb_conNewLine(); +} + +//------------------------------------------------------------------------------ +HB_FUNC( FT_FCLOSEALL ) +{ + PFT_FFILE pTmp = pFT; + + while( pTmp ) + { + iSelect = pTmp->iArea; + pCurFile = pTmp; + HB_FUNCNAME( FT_FFLUSH )(); + hb_itemRelease( pTmp->pArray ); + hb_itemRelease( pTmp->pOrigin ); + pTmp->pArray =NULL; + pTmp->pOrigin =NULL; + + pTmp = pTmp->pNext; + hb_xfree( pFT ); + pFT = pTmp; + } + + pCurFile = NULL; +} + +//------------------------------------------------------------------------------ +HB_FUNC_EXIT( FT_FEXIT ) +{ + HB_FUNCNAME( FT_FCLOSEALL )(); +} + +//------------------------------------------------------------------------------ +static PFT_FFILE ft_fseekArea( char *szSeek ) +{ + PFT_FFILE pTmp; + + if ( pFT && szSeek && *szSeek ) + { + char *szSelect = (char *) hb_xgrab( hb_parclen( 1 ) + 1 ); + BOOL bFound = FALSE; + + strcpy( szSelect , szSeek ); + + hb_strupr( szSelect ); + + pTmp = pFT; + + while( pTmp ) + { + if( strcmp( pTmp->szAlias, szSelect ) == 0 ) + { + bFound = TRUE; + break; + } + pTmp = pTmp->pNext; + } + + hb_xfree( szSelect ); + + return ( bFound ? pTmp : NULL ); + } + else + { + return ( NULL ); + } + +} + +//------------------------------------------------------------------------------ +static PFT_FFILE ft_fseekAlias( int iSeek ) +{ + PFT_FFILE pTmp; + + if ( pFT ) + { + BOOL bFound = FALSE; + + pTmp = pFT; + + while( pTmp ) + { + if( pTmp->iArea == iSeek ) + { + bFound = TRUE; + break; + } + pTmp = pTmp->pNext; + } + + return ( bFound ? pTmp : NULL ); + } + else + { + return (NULL); + } +} + +//------------------------------------------------------------------------------ +static BOOL ft_fseekActive() +{ + BOOL bFound = FALSE; + + if ( pFT ) + { + PFT_FFILE pTmp = pFT; + + while( pTmp ) + { + if( pTmp->bActive ) + { + bFound = TRUE; + break; + } + pTmp = pTmp->pNext; + } + } + + return ( bFound ); +} + +//----------------------------------------------------------------------------// +static BOOL ft_fread ( FILE *stream, char *string ) +{ + int ch, cnbr = 0; + + for (;;) + { + ch = fgetc ( stream ); + + if ( ( ch == '\n' ) || ( ch == EOF ) || ( ch == 26 ) ) + { + string [cnbr] = '\0'; + return ( ch == '\n' || cnbr ); + } + else + { + if ( (ULONG) cnbr < uBuffSize && ch != '\r' ) + { + string [cnbr++] = (char) ch; + } + } + + if ( (ULONG) cnbr >= uBuffSize ) + { + string [uBuffSize] = '\0'; + return (TRUE); + } + } +} + +#ifdef __LINE_COUNT__ +//----------------------------------------------------------------------------// +static ULONG ft_flinecount( FILE *inFile ) +{ + ULONG ulLineCount = 0; + int ch; + + while ( ( ch = fgetc ( inFile ) ) != EOF ) + { + if ( ch == '\n' ) + { + ulLineCount ++; + } + } + + return( ulLineCount ); +} +#endif diff --git a/harbour/contrib/libnf/getver.c b/harbour/contrib/libnf/getver.c index a78919bf6f..63c6b41039 100644 --- a/harbour/contrib/libnf/getver.c +++ b/harbour/contrib/libnf/getver.c @@ -66,7 +66,7 @@ HB_FUNC(_GET_DOSVER) char * pszPlatform; union REGS regs; pszPlatform = ( char * ) hb_xgrab( 256 ); - + regs.h.ah = 0x30; HB_DOS_INT86( 0x21, ®s, ®s ); @@ -123,7 +123,7 @@ HB_FUNC(_FT_NWKSTAT) HB_FUNC(_FT_SETMODE) { #if defined(HB_OS_DOS) - { + { union REGS regs; regs.h.ah=0; regs.h.al=hb_parni(1); @@ -135,7 +135,7 @@ HB_FUNC(_FT_GETMODE) { int iMode; #if defined(HB_OS_DOS) - { + { union REGS regs; regs.h.ah=0x0F; HB_DOS_INT86(0x10,®s,®s); @@ -164,7 +164,7 @@ HB_FUNC(_FT_TEMPFIL) union REGS regs; struct SREGS sregs; segread(&sregs); - cPath=hb_parc(1); + cPath=hb_parcx(1); regs.h.ah=0x5A; regs.HB_XREGS.cx=iMode; sregs.ds=FP_SEG(cPath); @@ -178,7 +178,7 @@ HB_FUNC(_FT_TEMPFIL) nax=0; iflags=0; - cPath=hb_parc(1); + cPath=hb_parcx(1); } #endif { diff --git a/harbour/contrib/libnf/hex2dec.prg b/harbour/contrib/libnf/hex2dec.prg index cfaf14dfc7..150a683da2 100644 --- a/harbour/contrib/libnf/hex2dec.prg +++ b/harbour/contrib/libnf/hex2dec.prg @@ -65,4 +65,4 @@ FUNCTION FT_HEX2DEC( cHexNum ) nHexPower *= 16 next -RETURN nDec +RETURN nDec diff --git a/harbour/contrib/libnf/invclr.prg b/harbour/contrib/libnf/invclr.prg index e3ff6bcf25..14d63660d3 100644 --- a/harbour/contrib/libnf/invclr.prg +++ b/harbour/contrib/libnf/invclr.prg @@ -70,4 +70,4 @@ FUNCTION FT_INVCLR(cDsrdColor) cBackground := ALLTRIM(SUBSTR(cDsrdColor, AT("/", cDsrdColor) + 1)) RETURN (STRTRAN(STRTRAN(cBackground, "+"), "*") + cModifiers + "/" + ; - STRTRAN(STRTRAN(cForeground, "+"), "*")) + STRTRAN(STRTRAN(cForeground, "+"), "*")) diff --git a/harbour/contrib/libnf/min2dhm.prg b/harbour/contrib/libnf/min2dhm.prg index d3a2f42af7..047ac9f3c9 100644 --- a/harbour/contrib/libnf/min2dhm.prg +++ b/harbour/contrib/libnf/min2dhm.prg @@ -55,4 +55,4 @@ function FT_MIN2DHM(nMINS) aDHM_[2] = ltrim(str(int((nMINS%1440)/60))) aDHM_[3] = ltrim(str(int((nMINS%1440)%60))) - return aDHM_ + return aDHM_ diff --git a/harbour/contrib/libnf/mouse.c b/harbour/contrib/libnf/mouse.c index 785f36b646..5ac1838431 100644 --- a/harbour/contrib/libnf/mouse.c +++ b/harbour/contrib/libnf/mouse.c @@ -51,9 +51,6 @@ * */ -/* NOTE: we need this to prevent base types redefinition */ -#define _CLIPDEFS_H - #include "extend.h" #if defined(HB_OS_DOS) #include "dos.h" @@ -500,6 +497,29 @@ HB_FUNC( _M_MBUTPRS) } } +HB_FUNC( _M_MBUTREL ) +{ +#if defined(HB_OS_DOS) + union REGS regs; + regs.HB_XREGS.ax=0x0A; + regs.HB_XREGS.bx=hb_parni(1); + + HB_DOS_INT86(0x33,®s,®s); + + hb_reta( 4 ); + hb_storni( regs.HB_XREGS.bx, -1, 1 ); + hb_storni( regs.HB_XREGS.cx, -1, 2 ); + hb_storni( regs.HB_XREGS.dx, -1, 3 ); + hb_storni( regs.HB_XREGS.ax, -1, 4 ); +#else + hb_reta( 4 ); + hb_storni( 0, -1, 1 ); + hb_storni( 0, -1, 2 ); + hb_storni( 0, -1, 3 ); + hb_storni( 0, -1, 4 ); +#endif +} + HB_FUNC( _M_MDEFCRS) { #if defined(HB_OS_DOS) @@ -563,4 +583,3 @@ int inButton; hb_itemRelease(pnButton); } } - diff --git a/harbour/contrib/libnf/n2color.c b/harbour/contrib/libnf/n2color.c index b5c64bae13..a5ad1ff66b 100644 --- a/harbour/contrib/libnf/n2color.c +++ b/harbour/contrib/libnf/n2color.c @@ -52,118 +52,18 @@ */ #include "hbapi.h" +#include "hbapigt.h" -static void _ftI2Color( int iColor, char * cColor ); -static int _ftGetColorStr( int iColor, char * cColor ); - -HB_FUNC(FT_N2COLOR ) +HB_FUNC( FT_N2COLOR ) { -/* #if defined(HB_OS_DOS) - { */ - char * cColor = " "; + int iColor = ISNUM( 1 ) ? hb_parni( 1 ) : -1; - // make sure parameter is a numeric type - if ( ISNUM(1)) - _ftI2Color( hb_parni( 1 ), cColor ); + if( iColor >= 0x00 && iColor <= 0xff ) + { + char szColorString[ 10 ]; + hb_gtColorsToString( &iColor, 1, szColorString, 10 ); + hb_retc( szColorString ); + } else - cColor = NULL; - - hb_retc( cColor ); - - return; -/* } -#endif */ -} - - - -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ -// Function : _ftI2Color -// Purpose : Converts a color int to an Xbase color string -// Parameters: iColor - the color number -// *cColor - pointer to the color string -// Returns : void (string is modified directly) -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ - -static void _ftI2Color( int iColor, char * cColor ) -{ - unsigned int iBack, iFore, i = 0; - - // check for blink attribute - - if ( iColor > 127 ) - { - cColor[ i++ ] = '*'; - - iColor %= 128; - } - - // check for background and foreground colors - -// if ( iColor > 15 ) -// { - iFore = iColor % 16; - - iBack = ( iColor - iFore ) / 16; -// } - - // check for intensity attrib - - if ( iFore > 7 ) - { - cColor[ i++ ] = '+'; - - iFore %= 8; - } - - // get forground color - - i += _ftGetColorStr( iFore, ( cColor + i ) ); - - // add the seperator - - cColor[ i++ ] = '/'; - - // get background color - - i += _ftGetColorStr( iBack, ( cColor + i ) ); - - // null terminate the color string - - cColor[ i ] = 0; - - return ; -} - - - -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ -// Function : _ftGetColorStr -// Purpose : Returns the corresponding Xbase color for passed number -// Parameters: iColor - a color number -// *cColor - pointer to the color string -// Returns : length of added color string -// ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ - -static int _ftGetColorStr( int iColor, char * cColor ) -{ - int iLen = 0; - - switch ( iColor ) - { - case 0 : cColor[iLen++] = 'n'; break; - case 1 : cColor[iLen++] = 'b'; break; - case 2 : cColor[iLen++] = 'g'; break; - case 3 : cColor[iLen++] = 'b'; - cColor[iLen++] = 'g'; break; - case 4 : cColor[iLen++] = 'r'; break; - case 5 : cColor[iLen++] = 'r'; - cColor[iLen++] = 'b'; break; - case 6 : cColor[iLen++] = 'g'; - cColor[iLen++] = 'r'; break; - case 7 : cColor[iLen++] = 'w'; - } - - return iLen; - + hb_retc( NULL ); } diff --git a/harbour/contrib/libnf/ntow.prg b/harbour/contrib/libnf/ntow.prg index 848eb211a0..7d1350390f 100644 --- a/harbour/contrib/libnf/ntow.prg +++ b/harbour/contrib/libnf/ntow.prg @@ -131,4 +131,4 @@ static function sol10( nNumber ) local sTemp sTemp := ltrim( str( int(nNumber), 0) ) - return( len(sTemp) - 1 ) + return( len(sTemp) - 1 ) diff --git a/harbour/contrib/libnf/ontick.c b/harbour/contrib/libnf/ontick.c index 57d053d711..8d69e15c76 100644 --- a/harbour/contrib/libnf/ontick.c +++ b/harbour/contrib/libnf/ontick.c @@ -136,4 +136,4 @@ CLIPPER FT_OnTick( void ) _evLow( 5, TickTock, FALSE ); return; -} +} diff --git a/harbour/contrib/libnf/origin.c b/harbour/contrib/libnf/origin.c index d74a65dd9f..8355a3e1fb 100644 --- a/harbour/contrib/libnf/origin.c +++ b/harbour/contrib/libnf/origin.c @@ -64,14 +64,5 @@ HB_FUNC(FT_ORIGIN) { -#if defined(HB_OS_DOS) || defined(HB_OS_WIN_32) - { - - extern char **_argv; - - hb_retc( *_argv ); - - return; -} -#endif + hb_retc( hb_cmdargARGV()[0] ); } diff --git a/harbour/contrib/libnf/pchr.prg b/harbour/contrib/libnf/pchr.prg index 0a172b5e1d..8b5421b991 100644 --- a/harbour/contrib/libnf/pchr.prg +++ b/harbour/contrib/libnf/pchr.prg @@ -221,4 +221,4 @@ Function FT_PCHR(c_nums) Enddo -Return c_ret +Return c_ret diff --git a/harbour/contrib/libnf/popadder.prg b/harbour/contrib/libnf/popadder.prg index 92e0768ea7..e0c6e24463 100644 --- a/harbour/contrib/libnf/popadder.prg +++ b/harbour/contrib/libnf/popadder.prg @@ -1962,6 +1962,4 @@ RETURN LEN(cString)-LEN(LTRIM(cString)) ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ */ STATIC FUNCTION _ftPosIns(cString,cChar,nPosit) -RETURN LEFT(cString,nPosit-1)+cChar+SUBSTR(cString,nPosit) - - +RETURN LEFT(cString,nPosit-1)+cChar+SUBSTR(cString,nPosit) diff --git a/harbour/contrib/libnf/putkey.c b/harbour/contrib/libnf/putkey.c new file mode 100644 index 0000000000..6c8746abac --- /dev/null +++ b/harbour/contrib/libnf/putkey.c @@ -0,0 +1,260 @@ +/* + * $Id$ + */ + +/* File......: PUTKEY.ASM +* Author....: Ted Means +* CIS ID....: 73067,3332 +* +* This is an original work by Ted Means and is placed in the +* public domain. +* +* Modification history: +* --------------------- +* +* Rev 1.4 16 Oct 1992 00:00:56 GLENN +* Just making sure we have Ted's latest revisions. +* +* Rev 1.3 01 Jul 1992 01:07:02 GLENN +* PUTKEY.ASM now bypasses the BIOS completely and uses Clipper's +* internal event handler to stuff the keystroke. Modifications by +* Ted Means. +* +* Rev 1.2 15 Aug 1991 23:07:10 GLENN +* Forest Belt proofread/edited/cleaned up doc +* +* Rev 1.1 14 Jun 1991 19:54:56 GLENN +* Minor edit to file header +* +* Rev 1.0 01 Apr 1991 01:03:48 GLENN +* Nanforum Toolkit +* + +* $DOC$ +* $FUNCNAME$ +* FT_PUTKEY() +* $CATEGORY$ +* Keyboard/Mouse +* $ONELINER$ +* Stuff a keystroke into the keyboard buffer +* $SYNTAX$ +* FT_PUTKEY( ) -> lResult +* $ARGUMENTS$ +* is the INKEY() value of the keystroke to be stuffed. +* $RETURNS$ +* .T. if the keystroke was put into the keyboard buffer. +* .F. if nKeyValue was invalid or the buffer was full. +* $DESCRIPTION$ +* This function is similar to the KEYBOARD command, with a few +* exceptions. First, this function does not clear the keyboard buffer +* before inserting the keystroke. In addition, since it uses the +* Inkey() value, you can stuff any key, including function keys, into +* the keyboard buffer. However, this also means that unlike the KEYBOARD +* command, you can only stuff one keystroke at a time. +* +* You can easily create a User-Defined Command that makes this function +* even more like the KEYBOARD command. For example, +* +* #command KEYSTROKE => FT_PUTKEY( ) +* +* will create a command called KEYSTROKE that could be used as a +* companion command to KEYBOARD. The only difference is that it would +* insert a single keystroke instead of a string. +* +* Be aware that this function makes use of Clipper's internal event +* handler. If you don't like using internals, then don't use this +* function, you sniveling coward. +* +* This function is written to adhere to Turbo Assembler's IDEAL mode. +* To use another assembler, rearrange the SEGMENT and PROC directives +* and make any other necessary changes to the source code. +* $EXAMPLES$ +* FT_PUTKEY( -9 ) // Stuff the F10 key +* FT_PUTKEY( 276 ) // Stuff the Alt T key +* KEYSTROKE 28 // Stuff the F1 key using a User-Defined Command +* $END$ +*/ + +/*This is the Original FT_PUTKEY() code +IDEAL + +Public FT_PutKey + +Extrn __ParInfo:Far +Extrn __Parni:Far +Extrn __RetL:Far +Extrn __evLow:Far ; Internal!! Sniveling cowards + ; beware! + +Segment _NanFor Word Public "CODE" + Assume CS:_NanFor + +Proc FT_PutKey Far + + Xor AX,AX ; Prepare to count params + Push AX ; Save on stack + Call __ParInfo ; Get param count + Add SP,2 ; Realign stack + Or AX,AX ; Zero params? + JNZ Test1 ; If not, continue + Jmp Done ; Return value = false, go to end + +Test1: Mov AX,1 ; Prepare to check parameter #1 + Push AX ; Save parameter # on stack + Call __ParInfo ; Call parameter info routine + Add SP,2 ; Realign stack + Test AX,2 ; Is parameter numeric? + JNZ Get1 ; If so, continue +BadParam:Xor AX,AX ; Set return value to false + Jmp Done ; Go to end + +Get1: Mov AX,1 ; Prepare to retrieve parameter #1 + Push AX ; Save parameter # on stack + Call __ParNI ; Retrieve parameter + Add SP,2 ; Realign stack + + Cmp AX,385 ; Test highest inkey() + JG BadParam ; Bad INKEY() value + Cmp AX,-39 ; Test lowest INKEY() + JL BadParam ; Bad INKEY() value + +CtrlF1: Mov CL,0 ; Set ASCII value to null + Cmp AX,-10 ; Is Ctrl F1 thru Alt F10? + JG F2 ; If not, check next range + Neg AX ; Get absolute value of AX + Add AL,74 ; Translate INKEY() to scan code + Mov CH,AL ; Move scan code to CH + Jmp StuffIt ; Stuff the keystroke + +F2: Or AX,AX ; See if key is F2 thru F10 + JNS F1 ; If not, check next range + Neg AX ; Get absolute value of AX + Add AL,59 ; Translate INKEY() to scan code + Mov CH,AL ; Move scan code to CH + Jmp StuffIt ; Stuff the keystroke + +F1: Cmp AX,28 ; See if key is F1 + JNE CtrlF ; If not, check next key + Mov CH,59 ; Supply scan code for F1 + Jmp StuffIt ; Stuff the keystroke + +CtrlF: Cmp AX,6 ; See if key is Ctrl F or End + JNE CtrlW ; If not, check next key + Mov CH,79 ; Supply scan code for End + Jmp StuffIt ; Stuff the keystroke + +CtrlW: Cmp AX,23 ; See if key is Ctrl W or Ctrl End + JNE CtrlHome ; If not, check next key + Mov CH,117 ; Supply scan code for Ctrl End + Jmp StuffIt ; Stuff the keystroke + +CtrlHome:Cmp AX,29 ; See if key is Ctrl Home or Ctrl] + JNE CtrlV ; If not, check next key + Mov CH,119 ; Supply scan code for Ctrl Home + Jmp StuffIt ; Stuff the keystroke + +CtrlV: Cmp AX,22 ; See if key is Ins or Ctrl V + JNE ShiftTab ; If not, check next key + Mov CH,82 ; Supply scan code for Ctrl V + Jmp StuffIt ; Stuff the keystroke + +ShiftTab:Cmp AX,271 ; See if key is Shift Tab + JNE CtrlPgDn ; If not, check next key + Mov CH,15 ; Supply scan code for Shift Tab + Jmp StuffIt ; Stuff the keystroke + +CtrlPgDn:Cmp AX,30 ; See if key is Ctrl PgDn + JNE CtrlPgUp ; If not, check next key + Mov CH,118 ; Supply scan code for Ctrl PgDn + Jmp StuffIt ; Stuff the keystroke + +CtrlPgUp:Cmp AX,31 ; See if key is Ctrl PgUp + JNE AltQ ; If not, check next key + Mov CH,132 ; Supply scan code for Ctrl PgUp + Jmp StuffIt ; Stuff the keystroke + +AltQ: Cmp AX,272 ; See if key is Alt Q . . . + JL ASCII + Cmp AX,281 ; . . . thru Alt P + JG AltA + Mov CH,AL + Jmp StuffIt + +AltA: Cmp AX,286 ; See if key is Alt A . . . + JNL AltL + Jmp BadParam +AltL: Cmp AX,294 ; . . . thru Alt L + JG AltZ + Mov CH,AL + Jmp StuffIt + +AltZ: Cmp AX,300 ; See if key is Alt Z . . . + JNL AltM + Jmp BadParam +AltM: Cmp AX,306 ; . . . thru Alt M + JG Alt1 + Mov CH,AL + Mov CL,0 + Jmp StuffIt + +Alt1: Cmp AX,376 ; See if key is Alt 1 . . . + JNL AltNum + Jmp BadParam +AltNum: Mov CH,AL + Mov CL,0 + Jmp StuffIt + +ASCII: Or AH,AH ; See if key is plain ASCII + JZ Okay + Jmp BadParam +Okay: Mov CX,AX + +StuffIt: Push BP ; Save BP + Mov BP,SP ; Set up stack reference + Sub SP,10 ; Allocate local structure + Mov [Word Ptr BP - 10],5 ; Choose keystroke event + Mov [Word Ptr BP - 8],0 ; Init flag word to 0 + Mov [Word Ptr BP - 6],CX ; Store keystroke in structure + Mov [Word Ptr BP - 4],0 ; Init mouse row to 0 + Mov [Word Ptr BP - 2],0 ; Init mouse col to 0 + Push SS ; Put structure segment on stack + LEA AX,[BP - 10] ; Load structure offset + Push AX ; Put structure offset on stack + Mov AX,3 ; Post event subfunction code + Push AX ; Place onto stack + Call __evLow ; Call internal event handler + Dec AX ; Convert error code . . . + Neg AX ; . . . to a logical value + Mov SP,BP ; Restore stack alignment + Pop BP ; Restore BP + +Done: Push AX ; Save return value on stack + Call __RetL ; Return it to Clipper app + Add SP,2 ; Realign stack + Ret +Endp FT_PutKey +Ends _NanFor +End +*/ + +/* This is the New one Rewriten in C*/ + +#include "hbapi.h" +#include "hbapigt.h" + +HB_FUNC( FT_PUTKEY ) +{ + BOOL lSuccess = FALSE; + + if( ISNUM( 1 ) ) + { + int iKey = hb_parni(1); + + if( iKey >= -39 && iKey <= 385 ) + { + hb_inkeyPut( iKey ); + lSuccess = TRUE; + } + } + hb_retl( lSuccess ); +} diff --git a/harbour/contrib/libnf/sleep.prg b/harbour/contrib/libnf/sleep.prg index 448cfbdea9..ebed839828 100644 --- a/harbour/contrib/libnf/sleep.prg +++ b/harbour/contrib/libnf/sleep.prg @@ -105,4 +105,4 @@ FUNCTION FT_SLEEP( nSeconds, nInitial ) DO WHILE ( SECONDS() < nSeconds ) ENDDO - RETURN NIL + RETURN NIL diff --git a/harbour/contrib/libnf/sqzn.prg b/harbour/contrib/libnf/sqzn.prg index 06f132f02d..fcfd423d2b 100644 --- a/harbour/contrib/libnf/sqzn.prg +++ b/harbour/contrib/libnf/sqzn.prg @@ -131,4 +131,4 @@ function ft_unsqzn(cCompressed,nSize,nDecimals) tmp := strtran(tmp," ","0") cValue := substr(tmp,1,nSize-nDecimals)+"."+substr(tmp,nSize-nDecimals+1) - return val(cValue) * multi + return val(cValue) * multi diff --git a/harbour/contrib/libnf/stod.c b/harbour/contrib/libnf/stod.c index b6113a1f29..63f6b35d0d 100644 --- a/harbour/contrib/libnf/stod.c +++ b/harbour/contrib/libnf/stod.c @@ -53,12 +53,5 @@ HB_FUNC(FT_STOD) { -#if defined(HB_OS_DOS) || defined(HB_OS_WIN_32) - { - - hb_retds( hb_parc(1) ) ; - - return; - } -#endif + hb_retds( hb_parclen( 1 ) >= 8 ? hb_parc( 1 ) : NULL ); } diff --git a/harbour/contrib/libnf/sysmem.prg b/harbour/contrib/libnf/sysmem.prg index 3f54ce5385..efa79dbf3e 100644 --- a/harbour/contrib/libnf/sysmem.prg +++ b/harbour/contrib/libnf/sysmem.prg @@ -69,5 +69,5 @@ FUNCTION FT_SYSMEM() aRegs[ AX ] := 0 FT_INT86( MEMSIZE, aRegs ) -RETURN ( aRegs[ AX ] ) +RETURN ( aRegs[ AX ] ) diff --git a/harbour/contrib/libnf/tbwhile.prg b/harbour/contrib/libnf/tbwhile.prg index 98cd6d07dc..1784c42479 100644 --- a/harbour/contrib/libnf/tbwhile.prg +++ b/harbour/contrib/libnf/tbwhile.prg @@ -493,4 +493,4 @@ STATIC FUNCTION TbWhileBot(cKey) SEEK LEFT(cKey, LEN(cKey) -1) + CHR( ASC( RIGHT(cKey,1) ) +1) SET(_SET_SOFTSEEK, cSoftSave) SKIP -1 -RETURN NIL +RETURN NIL diff --git a/harbour/contrib/libnf/vertmenu.prg b/harbour/contrib/libnf/vertmenu.prg index 28ab8bcc58..d81fd1b01e 100644 --- a/harbour/contrib/libnf/vertmenu.prg +++ b/harbour/contrib/libnf/vertmenu.prg @@ -176,5 +176,3 @@ Set( _SET_WRAP, lOldwrap ) Set( _SET_COLOR, cOldcolor ) RETURN NIL - -* end of file: vertmenu.prg diff --git a/harbour/contrib/libnf/xbox.prg b/harbour/contrib/libnf/xbox.prg index ced5bb0ea2..927c90a871 100644 --- a/harbour/contrib/libnf/xbox.prg +++ b/harbour/contrib/libnf/xbox.prg @@ -220,4 +220,4 @@ FUNCTION FT_XBOX(cJustType,; // "L" = left, otherwise centered STATIC FUNCTION _FTSAY(nSayRow,nSayCol,cSayStr) @ nSayRow,nSayCol SAY cSayStr - RETURN NIL + RETURN NIL diff --git a/harbour/source/pp/ppcore.c b/harbour/source/pp/ppcore.c index 9b0962a3a9..ec2466413e 100644 --- a/harbour/source/pp/ppcore.c +++ b/harbour/source/pp/ppcore.c @@ -4422,6 +4422,12 @@ static PHB_PP_TOKEN hb_pp_calcValue( PHB_PP_TOKEN pToken, int iPrecedense, pToken = pToken->pNext; } } + else if( HB_PP_TOKEN_TYPE( pToken->type ) == HB_PP_TOKEN_LOGICAL ) + { + *plValue = HB_PP_ISTRUE( pToken->value[ 1 ] ) ? 1 : 0; + * pfError = FALSE; + pToken = pToken->pNext; + } else * pfError = TRUE;