2012-07-17 10:03 UTC+0200 Viktor Szakats (harbour syenar.net)

* contrib/hbformat/hbfmtcls.prg
    ! iif() added to list of functions
    * minor formatting

  * tests/readhrb.prg
    * minor to prev
This commit is contained in:
Viktor Szakats
2012-07-17 08:04:35 +00:00
parent 5f22fe0d23
commit ba315e9544
3 changed files with 38 additions and 30 deletions

View File

@@ -16,6 +16,14 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-07-17 10:03 UTC+0200 Viktor Szakats (harbour syenar.net)
* contrib/hbformat/hbfmtcls.prg
! iif() added to list of functions
* minor formatting
* tests/readhrb.prg
* minor to prev
2012-07-17 09:51 UTC+0200 Viktor Szakats (harbour syenar.net)
* tests/readhrb.prg
+ updated by Vailton Renato to work on current .hrb format

View File

@@ -95,7 +95,7 @@ CREATE CLASS HBFORMATCODE
VAR nCaseUnk INIT -1 // Case of functions ( -1 - no change, 1 - upper, 2 - lower, 3 - title )
VAR nCaseDrt INIT 2 // Case of directives ( -1 - no change, 1 - upper, 2 - lower, 3 - title )
VAR nSpaceDrt INIT 0 // Number of spaces after # in directives ( -1 - no change )
VAR nLineFnc INIT 1 // -1 - no change, 1 - insert empty line before a function ( procedure,class ) declaration, 2 - remove it
VAR nLineFnc INIT 1 // -1 - no change, 1 - insert empty line before a function ( procedure, class ) declaration, 2 - remove it
VAR nLineRet INIT 1 // -1 - no change, 1 - insert empty line before return, 2 - remove it
VAR nLineVar INIT 1 // -1 - no change, 1 - insert empty line before variables declaration, 2 - remove it
VAR nLineCode INIT 1 // -1 - no change, 1 - insert empty line before code in function, 2 - remove it
@@ -103,7 +103,7 @@ CREATE CLASS HBFORMATCODE
VAR nBr4Brac INIT 2 // Max level of nesting in brackets, while space is added after/before a bracket
VAR cExtSave INIT "" // Extension for a formatted file ( "" - replace original )
VAR cExtBack INIT "bak" // Extension for a backup file
VAR cExtBack INIT ".bak" // Extension for a backup file
VAR cCommands INIT ","
VAR cClauses INIT ","
@@ -138,17 +138,17 @@ METHOD New( aParams, cIniName ) CLASS HBFORMATCODE
::nErr := 0
IF hb_isString( cIniName )
IF !::ReadIni( cIniName )
IF HB_ISSTRING( cIniName )
IF ! ::ReadIni( cIniName )
RETURN Self
ENDIF
FOR i := 1 TO Len( aParams )
IF Left( cParam := aParams[i], 1 ) == "@"
IF !::ReadIni( SubStr( cParam, 2 ) )
IF Left( cParam := aParams[ i ], 1 ) == "@"
IF ! ::ReadIni( SubStr( cParam, 2 ) )
RETURN Self
ENDIF
ELSEIF Left( cParam, 1 ) $ "-/"
IF !::SetOption( SubStr( cParam, 2 ), 0 )
IF ! ::SetOption( SubStr( cParam, 2 ), 0 )
RETURN Self
ENDIF
ENDIF
@@ -176,8 +176,8 @@ METHOD New( aParams, cIniName ) CLASS HBFORMATCODE
IF Right( ::cFunctions, 1 ) != ","
::cFunctions += ","
ENDIF
IF ! ( ",STR," $ Upper( ::cFunctions ) )
::cFunctions += "ISNIL,ISARRAY,ISBLOCK,ISCHARACTER,ISDATE,ISLOGICAL,ISMEMO,ISNUMBER,ISOBJECT"
IF !( ",STR," $ Upper( ::cFunctions ) )
::cFunctions += "iif,ISNIL,ISARRAY,ISBLOCK,ISCHARACTER,ISDATE,ISLOGICAL,ISMEMO,ISNUMBER,ISOBJECT"
FOR EACH cLine IN hb_ATokens( StrTran( __harbour_hbx(), Chr( 13 ) ), Chr( 10 ) )
IF Left( cLine, Len( "DYNAMIC " ) ) == "DYNAMIC "
::cFunctions += "," + SubStr( cLine, Len( "DYNAMIC " ) + 1 )
@@ -234,7 +234,7 @@ METHOD Reformat( aFile ) CLASS HBFORMATCODE
IF lComment
IF ( nPos := FindNotQuoted( "*/", aFile[ i ] ) ) != 0
lComment := .F.
IF !Empty( cToken1 := SubStr( aFile[ i ], nPos + 2 ) )
IF ! Empty( cToken1 := SubStr( aFile[ i ], nPos + 2 ) )
aFile[ i ] := Left( aFile[ i ], nPos + 1 )
nLen := rf_AINS( aFile, i + 1, cToken1 )
iDelta++
@@ -273,7 +273,7 @@ METHOD Reformat( aFile ) CLASS HBFORMATCODE
IF ( nPos := FindNotQuoted( "/*", cLineAll ) ) != 0 .AND. ( nPosComment == 0 .OR. nPosComment > nPos )
nPosComment := nPos
IF ( nPos := FindNotQuoted( "*/", cLineAll, nPos + 2 ) ) != 0
IF !Empty( cToken1 := SubStr( cLineAll, nPos + 2 ) )
IF ! Empty( cToken1 := SubStr( cLineAll, nPos + 2 ) )
cLineAll := Left( cLineAll, nPos + 1 )
nLen := rf_AINS( aFile, i + 1, cToken1 )
iDelta++
@@ -282,9 +282,9 @@ METHOD Reformat( aFile ) CLASS HBFORMATCODE
lComment := .T.
ENDIF
ENDIF
IF !lPragmaDump .AND. ::lIndent .AND. ( !lComment .OR. nPosComment > 1 )
IF ! lPragmaDump .AND. ::lIndent .AND. ( ! lComment .OR. nPosComment > 1 )
aFile[ i ] := cLineAll
IF !lContinue
IF ! lContinue
nPosSep := 1
nLineSegment := 1
DO WHILE .T.
@@ -315,8 +315,8 @@ METHOD Reformat( aFile ) CLASS HBFORMATCODE
ELSEIF nLenToken >= 4 .AND. ( ( LEFTEQUAL( "static", cToken1 ) .AND. ;
( LEFTEQUAL( "function", cToken2 ) .OR. LEFTEQUAL( "procedure", cToken2 ) ) ) .OR. ;
LEFTEQUAL( "function", cToken1 ) .OR. LEFTEQUAL( "procedure", cToken1 ) ;
.OR. ( "method" == cToken1 .AND. !lClass ) .OR. ;
( "class" == cToken1 .AND. !lClass ) )
.OR. ( "method" == cToken1 .AND. ! lClass ) .OR. ;
( "class" == cToken1 .AND. ! lClass ) )
IF nDeep == 0
nState := RF_STATE_FUNC
IF "class" == cToken1
@@ -382,11 +382,11 @@ METHOD Reformat( aFile ) CLASS HBFORMATCODE
ELSEIF nState == RF_STATE_VAR
nIndent := iif( ::lIndVar, ::nIndLeft, 0 )
ELSEIF nState == RF_STATE_RET
nIndent := iif( !lClass .AND. ::lIndRet, ::nIndLeft, 0 )
nIndent := iif( ! lClass .AND. ::lIndRet, ::nIndLeft, 0 )
ELSE
nIndent := ::nIndLeft + ::nIndNext * iif( nContrState == 0, nDeep, nDeep - 1 )
ENDIF
IF Left( cLine, 1 ) == "#" .AND. !::lIndDrt
IF Left( cLine, 1 ) == "#" .AND. ! ::lIndDrt
nIndent := 0
ENDIF
cLineAll := Space( nIndent ) + ::FormatLine( cLine )
@@ -400,7 +400,7 @@ METHOD Reformat( aFile ) CLASS HBFORMATCODE
( nState == RF_STATE_FUNC .AND. ::nLineFnc == 1 ) .OR. ;
( nState == RF_STATE_VAR .AND. ::nLineVar == 1 ) .OR. ;
( nState == RF_STATE_CODE .AND. ::nLineCode == 1 )
IF !Empty( aFile[ nPos ] )
IF ! Empty( aFile[ nPos ] )
nLen := rf_AINS( aFile, nPos + 1, "" )
iDelta++
i++
@@ -438,7 +438,7 @@ METHOD Reformat( aFile ) CLASS HBFORMATCODE
ELSE
lContinue := .F.
ENDIF
ELSEIF !lPragmaDump
ELSEIF ! lPragmaDump
aFile[ i ] := ::FormatLine( aFile[ i ] )
ENDIF
ENDIF
@@ -459,12 +459,12 @@ METHOD FormatLine( cLine, lContinued ) CLASS HBFORMATCODE
LOCAL lFirst, nBegin, nEnd, nB := 0, nA := 0, aBrackets[ 2 ]
LOCAL cOperators := "+-*/%#=~^<>$!"
IF !::lCase .AND. !::lSpaces
IF ! ::lCase .AND. ! ::lSpaces
RETURN cLine
ENDIF
hb_default( @lContinued, .F. )
lFirst := !lContinued
lFirst := ! lContinued
nLen := Len( cLine )
@@ -472,7 +472,7 @@ METHOD FormatLine( cLine, lContinued ) CLASS HBFORMATCODE
nPos++
ENDDO
IF !lContinued .AND. Left( cLine, 1 ) == "#"
IF ! lContinued .AND. Left( cLine, 1 ) == "#"
IF ::lSpaces .AND. ::nSpaceDrt != -1
cLine := Left( cLine, nPos ) + Space( ::nSpaceDrt ) + LTrim( SubStr( cLine, nPos + 1 ) )
ENDIF
@@ -543,7 +543,7 @@ METHOD FormatLine( cLine, lContinued ) CLASS HBFORMATCODE
IF nEnd == nBegin
nEnd := i
ENDIF
IF ( !lFirst .OR. !::ConvertCmd( @cLine, nBegin, nEnd, .T. ) ) .AND. c == "("
IF ( ! lFirst .OR. ! ::ConvertCmd( @cLine, nBegin, nEnd, .T. ) ) .AND. c == "("
::ConvertFnc( @cLine, nBegin, nEnd )
ENDIF
ENDIF
@@ -638,7 +638,7 @@ METHOD ConvertCmd( cLine, nBegin, nEnd, lFirstOnly ) CLASS HBFORMATCODE
IF ( ( nPos := At( "," + cToken, ::cCommands ) ) != 0 .AND. ( Len(cToken ) >= 4 ;
.OR. SubStr( ::cCommands, nPos + Len( cToken ) + 1, 1 ) == "," ) ) ;
.OR. ;
( !lFirstOnly .AND. ;
( ! lFirstOnly .AND. ;
( nPos := At( "," + cToken, ::cClauses ) ) != 0 .AND. ( Len( cToken ) >= 4 ;
.OR. SubStr( ::cClauses, nPos + Len( cToken ) + 1, 1 ) == "," ) )
IF ::nCaseCmd > 0
@@ -767,9 +767,9 @@ METHOD ReadIni( cIniName ) CLASS HBFORMATCODE
aIni := hb_ATokens( StrTran( MemoRead( cIniName ), Chr( 13 ) + Chr( 10 ), Chr( 10 ) ), Chr( 10 ) )
nLen := Len( aIni )
FOR i := 1 TO nLen
IF !Empty( aIni[ i ] := AllTrim( aIni[ i ] ) ) .AND. ;
IF ! Empty( aIni[ i ] := AllTrim( aIni[ i ] ) ) .AND. ;
( c := Left( aIni[ i ], 1 ) ) != ";" .AND. c != "#"
IF !::SetOption( aIni[ i ], @i, aIni )
IF ! ::SetOption( aIni[ i ], @i, aIni )
EXIT
ENDIF
ENDIF
@@ -807,7 +807,7 @@ METHOD Array2File( cFileName, aFile ) CLASS HBFORMATCODE
ENDIF
ENDIF
IF !Empty( ::cExtSave )
IF ! Empty( ::cExtSave )
cFileName := cName + iif( Left( ::cExtSave, 1 ) != ".", ".", "" ) + ::cExtSave
ENDIF
IF ::lFCaseLow
@@ -822,7 +822,7 @@ METHOD Array2File( cFileName, aFile ) CLASS HBFORMATCODE
IF aFile[ i ] == NIL
EXIT
ENDIF
IF i < nLen .OR. !Empty( aFile[ i ] )
IF i < nLen .OR. ! Empty( aFile[ i ] )
FWrite( handle, aFile[ i ] + ::cEol )
ENDIF
NEXT

View File

@@ -61,8 +61,8 @@ FUNCTION Main( cFrom )
LOCAL nIdx
LOCAL cSymbol
SET( _SET_ALTERNATE, "readhrb.out" )
SET( _SET_ALTERNATE, .T. )
Set( _SET_ALTERNATE, "readhrb.out" )
Set( _SET_ALTERNATE, .T. )
IF cFrom == NIL
cFrom := "default.hrb"