* utils/hbmk2/hbmk2.*.po
* utils/hbmk2/hbmk2.prg
+ do not share plugin variables (hbmk[ "vars" ])
between different plugins. It avoids potentially nasty
issues with plugins stepping onto each other's toes.
[INCOMPATIBLE - though it's unlikely anyone is
affected. If you must communicate between plugins,
use public function or variable.]
+ clarified in help that -icon might not work on all
platforms/compilers and detailed Windows implementation
(in particular it's disabled on bcc/bcc64 and on
mingw it won't work when a manual .rc is specified,
also on some (old?) msvc versions. Consult your
C compiler's Windows resource handling limitations.)
+ clarified in help the syntax of filters
+ clarified in help that .hbp references are handled as
sub-projects
+ clarification to command substitution macro
+ clarification to filter syntax note
! strict parameter checks in all public shell APIs to
avoid RTEs inside hbmk2 due to faulty API usage by scripts
* utils/hbmk2/examples/plug_bis.hb
* updated according to latest plugin changes
* include/harbour.hbx
* include/hbapi.h
* src/vm/debug.c
* src/vm/hvm.c
+ added internal function hb_vmInternalsEnabled()
to query whether potentially sensitive internals
are allowed to be accessed by public Harbour APIs
+ added .prg level function __vmNoInternals()
to disable potentially sensitive internals
by default accessible via public APIs.
Intentionally a one-way function: once disabled,
it cannot be reenabled from .prg or .c level.
NOTE: It will break Harbour debug functionality,
so it'd will be useful for hbrun scripts and
release (non-debug) builds.
+ modified internal __dbg*() functions to return
dummy values when internals are disabled via
__vmNoInternals() functions. While the function
return types are kept, apps relying on their
specific values and certain relationships between
them might break.
; NOTE: In the future, some more internals might
be protected by this setting (f.e. low-level
object and class functions and some API from
hbdebug lib)
; Please review
* tests/debugtst.prg
! fixed to compile warning-free without lowering
warning level
! fixed to run RTE-free with internals disabled
* bin/3rdpatch.hb
* bin/commit.hb
* config/postinst.hb
* contrib/make.hb
* contrib/hbtest/hbtest.ch
* src/debug/*.prg
* src/rtl/tclass.prg
* utils/hbmk2/examples/plug_bis.hb
* utils/hbmk2/examples/plug_tpl.hb
* use short form #pragmas (the ones identical
to Harbour options)
; NOTE: Except -l which works reversed compared
to cmdline -l option. TOFIX? (I tried and failed)
* src/rtl/hbi18n2.prg
* contrib/xhb/tfile.prg
* use F_ERROR instead of -1 literal
* contrib/xhb/xhbtedit.prg
! replaced dirty xhb extension with std SubStr() call
Reported by Tony Quick
[pls report such bugs on Harbour devl list]
* contrib/hbodbc/todbc.prg
! Don't continue ::Open() when SQLExecDir() have error
Fix from xhb via Vicente Guerra, with cleanups.
* tests/multifnc/multifnc.hbp
+ added comment
+ support for watcom
* tests/multifnc/t1.prg
! missing file ending EOL
* tests/*.prg
* extras/gtwvw/tests/wvwtest9.prg
* formatting
317 lines
7.3 KiB
Plaintext
317 lines
7.3 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
#include "fileio.ch"
|
|
|
|
//
|
|
// Test of inheritance
|
|
//
|
|
|
|
/*
|
|
* Written by Eddie Runia <eddie@runia.comu>
|
|
* www - http://harbour-project.org
|
|
*
|
|
* Placed in the public domain
|
|
*/
|
|
|
|
PROCEDURE Main()
|
|
|
|
LOCAL oFrom
|
|
LOCAL oTo
|
|
LOCAL cOut
|
|
|
|
oFrom := TOnTop() :New( "hello.prg", "R" )
|
|
oTo := TTextFile():New( "hello.out", "W" )
|
|
|
|
? "What's in oFrom"
|
|
? hb_ValToExp( { oFrom, __objGetMethodList( oFrom ) } )
|
|
|
|
?
|
|
? "What's in oFrom:TEmpty"
|
|
? hb_ValToExp( { oFrom:TEmpty, __objGetMethodList( oFrom:TEmpty ) } )
|
|
|
|
?
|
|
? "Let's call Run() from TEmpty : "
|
|
oFrom:TEmpty:Run()
|
|
|
|
?
|
|
? "Let's call a method from TEmpty and one from TOnTop"
|
|
oFrom:Set( "Done !" )
|
|
oFrom:Say( "Out" )
|
|
|
|
?
|
|
? "Basic copy loop using the default Run() from TTextFile"
|
|
DO WHILE ! oFrom:lEoF
|
|
cOut := oFrom:Run()
|
|
? cOut
|
|
oTo:Run( cOut )
|
|
ENDDO
|
|
oFrom:Dispose()
|
|
oTo:Dispose()
|
|
|
|
// ? hb_ValToExp( __dbgVMStkGList() ) // Stack is OK!
|
|
|
|
RETURN
|
|
|
|
//
|
|
// Generic Empty Class
|
|
//
|
|
|
|
FUNCTION TEmpty()
|
|
|
|
STATIC oEmpty
|
|
|
|
IF oEmpty == NIL
|
|
oEmpty := HBClass():New( "TEmpty" ) // Create a new class def
|
|
|
|
oEmpty:AddInline( "New", {| self | self } )
|
|
|
|
oEmpty:AddInline( "Run", {|| QOut( "Run !" ) } ) // Test command
|
|
oEmpty:AddInline( "Set", {| self, xParam | ::Out := xParam } )
|
|
oEmpty:AddData( "Out", "Hi there" ) // Test command
|
|
oEmpty:AddVirtual( "Dispose" ) // Clean up code
|
|
|
|
oEmpty:Create()
|
|
ENDIF
|
|
|
|
RETURN oEmpty:Instance()
|
|
|
|
//
|
|
// Let's add another one on top
|
|
//
|
|
|
|
FUNCTION TOnTop()
|
|
|
|
STATIC oOnTop
|
|
|
|
IF oOnTop == NIL
|
|
oOnTop := HBClass():New( "TOnTop", "TTextFile" )
|
|
oOnTop:AddInline( "Say", {| self, cArg | QOut( __objSendMsg( self, cArg ) ) } )
|
|
oOnTop:Create()
|
|
ENDIF
|
|
|
|
RETURN oOnTop:Instance()
|
|
|
|
//
|
|
// Generic Text file handler
|
|
//
|
|
|
|
FUNCTION TTextFile()
|
|
|
|
STATIC oFile
|
|
|
|
IF oFile == NIL
|
|
oFile := HBClass():New( "TTextFile", "TEmpty" )
|
|
// Create a new class def
|
|
// from TEmpty class
|
|
|
|
oFile:AddData( "cFileName" ) // Filename spec. by user
|
|
oFile:AddData( "hFile" ) // File handle
|
|
oFile:AddData( "nLine" ) // Current linenumber
|
|
oFile:AddData( "nError" ) // Last error
|
|
oFile:AddData( "lEoF" ) // End of file
|
|
oFile:AddData( "cBlock" ) // Storage block
|
|
oFile:AddData( "nBlockSize" ) // Size of read-ahead buffer
|
|
oFile:AddData( "cMode" ) // Mode of file use
|
|
// R = read, W = write
|
|
|
|
oFile:AddMethod( "New" , @New() ) // Constructor
|
|
oFile:AddMethod( "Run" , @Run() ) // Get/set data
|
|
oFile:AddMethod( "Dispose", @Dispose() ) // Clean up code
|
|
oFile:AddMethod( "Read" , @Read() ) // Read line
|
|
oFile:AddMethod( "WriteLn", @WriteLn() ) // Write line
|
|
oFile:AddMethod( "Write" , @Write() ) // Write without CR
|
|
oFile:AddMethod( "Goto" , @Goto() ) // Go to line
|
|
|
|
oFile:Create()
|
|
ENDIF
|
|
|
|
RETURN oFile:Instance()
|
|
|
|
//
|
|
// Method TextFile:New -> Create a new text file
|
|
//
|
|
// <cFile> file name. No wild characters
|
|
// <cMode> mode for opening. Default "R"
|
|
// <nBlockSize> Optional maximum blocksize
|
|
//
|
|
|
|
FUNCTION New( cFileName, cMode, nBlock )
|
|
|
|
LOCAL self := QSelf() // Get self
|
|
|
|
hb_default( @cMode, "R" )
|
|
hb_default( @nBlock, 4096 )
|
|
|
|
::nLine := 0
|
|
::lEoF := .F.
|
|
::cBlock := ""
|
|
::cFileName := cFileName
|
|
::cMode := cMode
|
|
|
|
IF ::cMode == "R"
|
|
::hFile := FOpen( cFileName )
|
|
ELSEIF ::cMode == "W"
|
|
::hFile := FCreate( cFileName )
|
|
ELSE
|
|
? "DosFile Init: Unknown file mode:", ::cMode
|
|
ENDIF
|
|
|
|
::nError := FError()
|
|
IF ::nError != 0
|
|
::lEoF := .T.
|
|
? "Error ", ::nError
|
|
ENDIF
|
|
::nBlockSize := nBlock
|
|
|
|
RETURN self
|
|
|
|
FUNCTION RUN( xTxt, lCRLF )
|
|
|
|
LOCAL self := QSelf()
|
|
LOCAL xRet
|
|
|
|
IF ::cMode == "R"
|
|
xRet := ::Read()
|
|
ELSE
|
|
xRet := ::WriteLn( xTxt, lCRLF )
|
|
ENDIF
|
|
|
|
RETURN xRet
|
|
|
|
//
|
|
// Dispose -> Close the file handle
|
|
//
|
|
|
|
FUNCTION Dispose()
|
|
|
|
LOCAL self := QSelf()
|
|
|
|
::cBlock := NIL
|
|
IF ::hFile != F_ERROR
|
|
IF ! FClose( ::hFile )
|
|
::nError := FError()
|
|
? "Dos Error closing ", ::cFileName, " Code ", ::nError
|
|
ENDIF
|
|
ENDIF
|
|
|
|
RETURN self
|
|
|
|
//
|
|
// Read a single line
|
|
//
|
|
|
|
FUNCTION READ()
|
|
|
|
LOCAL self := QSelf()
|
|
LOCAL cRet := ""
|
|
LOCAL cBlock
|
|
LOCAL nCrPos
|
|
LOCAL nEoFPos
|
|
|
|
IF ::hFile == F_ERROR
|
|
? "DosFile:Read : No file open"
|
|
ELSEIF !( ::cMode == "R" )
|
|
? "File ", ::cFileName, " not open for reading"
|
|
ELSEIF ! ::lEoF
|
|
|
|
IF Len( ::cBlock ) == 0 // Read new block
|
|
cBlock := FReadStr( ::hFile, ::nBlockSize )
|
|
IF Len( cBlock ) == 0
|
|
::nError := FError() // Error or EOF
|
|
::lEoF := .T.
|
|
ELSE
|
|
::cBlock := cBlock
|
|
ENDIF
|
|
ENDIF
|
|
|
|
IF ! ::lEoF
|
|
::nLine++
|
|
nCRPos := At( Chr( 10 ), ::cBlock )
|
|
IF nCRPos != 0 // More than one line read
|
|
cRet := SubStr( ::cBlock, 1, nCRPos - 1 )
|
|
::cBlock := SubStr( ::cBlock, nCRPos + 1 )
|
|
ELSE // No complete line
|
|
cRet := ::cBlock
|
|
::cBlock := ""
|
|
cRet += ::Read() // Read the rest
|
|
IF ! ::lEoF
|
|
::nLine-- // Adjust erroneous line count
|
|
ENDIF
|
|
ENDIF
|
|
nEoFPos := hb_BAt( Chr( 26 ), cRet )
|
|
IF nEoFPos != 0 // End of file read
|
|
cRet := hb_BSubStr( cRet, 1, nEoFPos - 1 )
|
|
::lEoF := .T.
|
|
ENDIF
|
|
cRet := StrTran( cRet, Chr( 13 ) ) // Remove CR
|
|
ENDIF
|
|
ENDIF
|
|
|
|
RETURN cRet
|
|
|
|
//
|
|
// WriteLn -> Write a line to a file
|
|
//
|
|
// <xTxt> Text to write. May be any type. May also be an array containing
|
|
// one or more strings
|
|
// <lCRLF> End with Carriage Return/Line Feed (Default == TRUE)
|
|
//
|
|
|
|
FUNCTION WriteLn( xTxt, lCRLF )
|
|
|
|
LOCAL self := QSelf()
|
|
LOCAL cBlock
|
|
|
|
IF ::hFile == F_ERROR
|
|
? "DosFile:Write : No file open"
|
|
ELSEIF !( ::cMode == "W" )
|
|
? "File ", ::cFileName, " not opened for writing"
|
|
ELSE
|
|
hb_default( @lCRLF, .T. )
|
|
cBlock := hb_ValToExp( xTxt ) // Convert to string
|
|
IF lCRLF
|
|
cBlock += hb_eol()
|
|
ENDIF
|
|
FWrite( ::hFile, cBlock, Len( cBlock ) )
|
|
IF FError() != 0
|
|
::nError := FError() // Not completely written !
|
|
ENDIF
|
|
::nLine := ::nLine + 1
|
|
ENDIF
|
|
|
|
RETURN self
|
|
|
|
FUNCTION Write( xTxt )
|
|
|
|
LOCAL self := QSelf()
|
|
|
|
RETURN ::WriteLn( xTxt, .F. )
|
|
|
|
//
|
|
// Go to a specified line number
|
|
//
|
|
|
|
STATIC FUNCTION GOTO( nLine )
|
|
|
|
LOCAL self := QSelf()
|
|
LOCAL nWhere := 1
|
|
|
|
IF Empty( ::hFile )
|
|
? "DosFile:Goto : No file open"
|
|
ELSEIF !( ::cMode == "R" )
|
|
? "File ", ::cFileName, " not open for reading"
|
|
ELSE
|
|
::lEoF := .F. // Clear (old) End of file
|
|
::nLine := 0 // Start at beginning
|
|
::cBlock := ""
|
|
FSeek( ::hFile, 0 ) // Go top
|
|
DO WHILE ! ::lEoF .AND. nWhere < nLine
|
|
nWhere++
|
|
::Read()
|
|
ENDDO
|
|
ENDIF
|
|
|
|
RETURN ! ::lEoF
|