From da7de8dffdd1d2a171b709f9ea85f9d7928b7d42 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Fri, 23 Feb 2001 01:17:19 +0000 Subject: [PATCH] 2001-02-22 17:10 UTC-0800 Ron Pinkas * contrib/dot/pp.prg ! Fixed order of production in multi line result, where some of the resulting lines are re-processed + Added support for IF, ELSE, ELSEIF, ENDIF, DO CASE, CASE, OTHERWISE, ENDCASE ! Fixed cursor position in Dot prompt to simulate running program cursor position. * contrib/dot/rp_dot.ch ! Fixed literal coordinates to use MaxRow() and MaxCol() + Added #command CLS to only clean the work region. + Added #commands to "steal" handling of IF, ELSE, ELSEIF, ENDIF, DO CASE, CASE, OTHERWISE, ENDCASE --- harbour/ChangeLog | 11 ++ harbour/contrib/dot/pp.prg | 184 +++++++++++++++++++++++++++++----- harbour/contrib/dot/rp_dot.ch | 16 ++- 3 files changed, 184 insertions(+), 27 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index f92994e65e..b5a6d87931 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,14 @@ +2001-02-22 17:10 UTC-0800 Ron Pinkas + * contrib/dot/pp.prg + ! Fixed order of production in multi line result, where some of the resulting lines are re-processed + + Added support for IF, ELSE, ELSEIF, ENDIF, DO CASE, CASE, OTHERWISE, ENDCASE + ! Fixed cursor position in Dot prompt to simulate running program cursor position. + + * contrib/dot/rp_dot.ch + ! Fixed literal coordinates to use MaxRow() and MaxCol() + + Added #command CLS to only clean the work region. + + Added #commands to "steal" handling of IF, ELSE, ELSEIF, ENDIF, DO CASE, CASE, OTHERWISE, ENDCASE + 2001-02-22 15:45 GMT+3 Alexander Kresin * harbour/source/rdd/dbfntx/dbfntx1.c * fixed a bug while index opening, before ntxOrderListAdd have tried to diff --git a/harbour/contrib/dot/pp.prg b/harbour/contrib/dot/pp.prg index 89ca7e416d..c0477edfd9 100644 --- a/harbour/contrib/dot/pp.prg +++ b/harbour/contrib/dot/pp.prg @@ -30,6 +30,8 @@ #else #DEFINE CRLF Chr(13) + Chr(10) + EXTERNAL BROWSE + EXTERNAL ARRAY,ASIZE,ATAIL,AINS,ADEL,AFILL,ASCAN,AEVAL,ACOPY,ACLONE,ADIR, ASORT EXTERNAL MEMORY @@ -157,7 +159,7 @@ STATIC nPendingLines := 0, aPendingLines := {} STATIC bDbgMatch := .F., bDbgExp := .F., bDbgPPO := .F., bLoadRules := .T., bCount := .T., bCCH := .F., bPP := .F. -STATIC nIfDef := 0, abIfDef := {} +STATIC nIfDef := 0, abIfDef := {}, nIf := 0, abIf := {} STATIC hPP := NIL @@ -221,8 +223,9 @@ RETURN PROCEDURE RP_Dot() - LOCAL sLine := Space(256), bBlock, GetList := {}, sPPed, nNext, sBlock, sTemp + LOCAL sLine := Space(256), GetList := {}, sPPed, nNext, sBlock, sTemp LOCAL sTemp2, nLen, sLeft, sSymbol, nNextAssign + LOCAL nRow := 1, nCol := 0 bCount := .F. @@ -244,7 +247,7 @@ PROCEDURE RP_Dot() sLine := StrTran( sLine, Chr(9), " " ) - sPPed := ProcessLine( sLine, 1, '' ) + sPPed := ProcessLine( RTrim( sLine ), 1, '' ) ExtractLeadingWS( @sPPed ) DropTrailingWS( @sPPed ) @@ -252,7 +255,7 @@ PROCEDURE RP_Dot() @ 0,0 SAY "PP: " @ 0,4 SAY Pad( sPPed, 76 ) COLOR "N/R" - DevPos( 1, 0 ) + DevPos( nRow, nCol ) BEGIN SEQUENCE @@ -284,17 +287,24 @@ PROCEDURE RP_Dot() ENDIF ENDDO - bBlock := &( "{|| " + sBlock + " }" ) - Eval( bBlock ) + sSymbol := Upper( Left( sBlock, 14 ) ) // Len( "__SetOtherwise" ) + IF nIf == 0 .OR. ; + sSymbol = "__SETIF" .OR. sSymbol = "__SETELSE" .OR. sSymbol = "__SETELSEIF" .OR. sSymbol = "__SETEND" .OR. ; + sSymbol = "__SETDOCASE" .OR. sSymbol = "__SETCASE" .OR. sSymbol = "__SETOTHERWISE" .OR. sSymbol = "__SETENDCASE" .OR. ; + abIf[ nIf ] + + Eval( &( "{|| " + sBlock + " }" ) ) + ENDIF + sTemp := RTrim( SubStr( sTemp, nNext + 1 ) ) ExtractLeadingWS( @sTemp ) ENDDO - ExtractLeadingWS( @sTemp ) - DropTrailingWS( @sTemp ) + sBlock := sTemp + DropTrailingWS( @sBlock ) - IF ! ( sTemp == '' ) - sTemp2 := sTemp + IF ! ( sBlock == '' ) + sTemp2 := sBlock WHILE ( nNextAssign := At( ":=", sTemp2 ) ) > 0 sLeft := Left( sTemp2, nNextAssign - 1 ) sTemp2 := SubStr( sTemp2, nNextAssign + 2 ) @@ -317,12 +327,18 @@ PROCEDURE RP_Dot() ENDIF ENDDO - sTemp := "{|| " + sTemp + " }" - - bBlock := &sTemp - Eval( bBlock ) + sSymbol := Upper( Left( sBlock, 11 ) ) // Len( "__SetElseIf" ) + IF nIf == 0 .OR. ; + sSymbol = "__SETIF" .OR. sSymbol = "__SETELSE" .OR. sSymbol = "__SETELSEIF" .OR. sSymbol = "__SETEND" .OR. ; + sSymbol = "__SETDOCASE" .OR. sSymbol = "__SETCASE" .OR. sSymbol = "__SETOTHERWISE" .OR. sSymbol = "__SETENDCASE" .OR. ; + abIf[ nIf ] + Eval( &( "{|| " + sTemp + " }" ) ) + ENDIF ENDIF + nRow := Row() + nCol := Col() + @ 0,0 SAY "PP: " @ 0,4 SAY Pad( sPPed, 76 ) COLOR "N/R" @@ -830,6 +846,7 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) LOCAL nNewLineAt, nLines, Counter LOCAL sLeft, sPassed := '', asOutLines := {}, sOut := '', cChar LOCAL nLen, iCycles, aDefined := {}, aTranslated := {}, aCommanded := {} + LOCAL nPosition WHILE .T. @@ -837,11 +854,9 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) //? nPendingLines, nIfDef, IIF( nIfDef > 0, abIfDef[nIfDef] , ) //WAIT - IF ! sPassed == '' + IF ! ( sPassed == '' ) aAdd( asOutLines, ( sLeft + RTrim( sPassed ) ) ) sPassed := '' - //? "Pending Out: '" + aTail( asOutLines ) + "'" - //WAIT ENDIF IF sLine == NIL @@ -1054,7 +1069,7 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) ENDIF //? "Pending #", nPendingLines, Left( sLine, nNewLineAt - 1 ), aPendingLines[nPendingLines] - sLine := SubStr( sLine, nNewLineAt + 1 ) + sLine := LTrim( SubStr( sLine, nNewLineAt + 1 ) ) ENDDO IF ( sLine == '' ) @@ -1099,7 +1114,7 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) ENDIF //? "Pending #", nPendingLines, Left( sLine, nNewLineAt - 1 ), aPendingLines[nPendingLines] - sLine := SubStr( sLine, nNewLineAt + 1 ) + sLine := LTrim( SubStr( sLine, nNewLineAt + 1 ) ) ENDDO IF ( sLine == '' ) @@ -1113,10 +1128,13 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) aPendingLines[nPendingLines] := sLine ENDI + aAdd( asOutLines, NIL ) // Reserving place ordinal holder + //? "Pending #", nPendingLines, sLine, aPendingLines[nPendingLines] sLine := aPendingLines[1] aDel( aPendingLines, 1 ) nPendingLines-- + ENDIF LOOP @@ -1136,16 +1154,27 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) aAdd( aCommanded, nRule ) ENDIF + nPosition := 0 WHILE ( nNewLineAt := At( ';', sLine ) ) > 0 nPendingLines++ + /* IF nPendingLines > Len( aPendingLines ) aAdd( aPendingLines, Left( sLine, nNewLineAt - 1 ) ) ELSE aPendingLines[nPendingLines] := Left( sLine, nNewLineAt - 1 ) ENDIF + */ - //? "Pending #", nPendingLines, Left( sLine, nNewLineAt - 1 ), aPendingLines[nPendingLines] - sLine := SubStr( sLine, nNewLineAt + 1 ) + IF nPendingLines > Len( aPendingLines ) + aSize( aPendingLines, nPendingLines ) + ENDIF + + nPosition++ + aIns( aPendingLines, nPosition ) + aPendingLines[ nPosition ] := Left( sLine, nNewLineAt - 1 ) + + //? "Pending #", nPendingLines, Left( sLine, nNewLineAt - 1 ), aPendingLines[nPosition] + sLine := LTrim( SubStr( sLine, nNewLineAt + 1 ) ) ENDDO IF ( sLine == '' ) @@ -1153,13 +1182,25 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) ELSE IF nPendingLines > 0 nPendingLines++ + + /* IF nPendingLines > Len( aPendingLines ) aAdd( aPendingLines, sLine ) ELSE aPendingLines[nPendingLines] := sLine ENDI + */ + + IF nPendingLines > Len( aPendingLines ) + aSize( aPendingLines, nPendingLines ) + ENDIF + + nPosition++ + aIns( aPendingLines, nPosition ) + aPendingLines[ nPosition ] := sLine + + //? "Pending #", nPendingLines, sLine, aPendingLines[nPosition] - //? "Pending #", nPendingLines, sLine, aPendingLines[nPendingLines] sLine := aPendingLines[1] aDel( aPendingLines, 1 ) nPendingLines-- @@ -1178,7 +1219,10 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) sOut := '' nLines := Len( asOutLines ) - //@ Row(), 0 SAY nLines + + //? nLines + //WAIT + FOR Counter := 1 TO nLines sOut += asOutLines[Counter] IF Counter < nLines .OR. ! ( sPassed == '' ) @@ -1190,8 +1234,10 @@ FUNCTION ProcessLine( sLine, nLine, sSource ) sOut += ( sLeft + sPassed ) ENDIF - //? "Returning: " + sOut - //WAIT + IF ! Empty( sOut ) + //? "Returning: " + sOut + //WAIT + ENDIF RETURN sOut @@ -4302,6 +4348,94 @@ FUNCTION SetIfDef( sDefine, bExist ) RETURN nIfDef +FUNCTION __SetIf( bExp ) + + IF nIf > 0 .AND. ! abIf[nIf] + bExp := .F. + ENDIF + + nIf++ + aSize( abIf, nIf ) + abIf[nIf] := bExp + +RETURN abIf[nIf] + +FUNCTION __SetElseIf( bExp ) + + IF nIf > 1 .AND. ! abIf[nIf - 1] + RETURN .F. + ENDIF + + abIf[nIf] := ! abIf[nIf] + + IF abIf[nIf] + abIf[nIf] := bExp + ENDIF + +RETURN abIf[nIf] + +FUNCTION __SetElse() + + IF nIf > 1 .AND. ! abIf[nIf - 1] + RETURN .F. + ENDIF + + abIf[nIf] := ! abIf[nIf] + +RETURN abIf[nIf] + +FUNCTION __SetEnd() + + IF nIf > 0 + nIf-- + ELSE + Alert( "END with no IF in sight!" ) + ENDIF + +RETURN nIf + +FUNCTION __SetDoCase() + + nIf++ + aSize( abIf, nIf ) + abIf[nIf] := .F. + +RETURN abIf[nIf] + +FUNCTION __SetCase( bExp ) + + IF nIf > 1 .AND. ! abIf[nIf - 1] + RETURN .F. + ENDIF + + abIf[nIf] := ! abIf[nIf] + + IF abIf[nIf] + abIf[nIf] := bExp + ENDIF + +RETURN abIf[nIf] + +FUNCTION __SetOtherwise() + + IF nIf > 1 .AND. ! abIf[nIf - 1] + RETURN .F. + ENDIF + + abIf[nIf] := ! abIf[nIf] + +RETURN abIf[nIf] + +FUNCTION __SetEndCase() + + IF nIf > 0 + nIf-- + ELSE + Alert( "ENDCASE with no DO CASE in sight!" ) + ENDIF + +RETURN nIf + FUNCTION CompileToCCH( sSource ) LOCAL hCCH, Counter, aRules, nRules, nRule, aRule, nMatches, nMatch, aMatch, nWords, nWord, aWords diff --git a/harbour/contrib/dot/rp_dot.ch b/harbour/contrib/dot/rp_dot.ch index 3c37c49d5a..67b2e12194 100644 --- a/harbour/contrib/dot/rp_dot.ch +++ b/harbour/contrib/dot/rp_dot.ch @@ -1,4 +1,8 @@ -#COMMAND BROWSE => Browse( 1, 0, 23, 79 ) +#command CLS ; + => Scroll( 1, 0, MaxRow() - 1, MaxCol() ) ; + ; SetPos(1,0) + +#COMMAND BROWSE => Browse( 1, 0, MaxRow() - 1, MaxCol() ) #COMMAND EXIT => __QUIT() #ifdef __HARBOUR__ @@ -8,4 +12,12 @@ #TRANSLATE __GET( ):Display() => __GET() #endif -__get(1,2,3,4,5):display() +#COMMAND IF => __SetIf( ) +#COMMAND ELSEIF => __SetElseIf( ) +#COMMAND ELSE => __SetElse() +#COMMAND END [<*x*>] => __SetEnd() + +#COMMAND DO CASE => __SetDoCase() +#COMMAND CASE => __SetCase( ) +#COMMAND OTHERWISE => __SetOtherwise() +#COMMAND ENDCASE [<*x*>] => __SetEndCase()