From 100289b2a5c5022da12a9b71b3de2a408eb061bf Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 15 Oct 2012 02:43:47 +0000 Subject: [PATCH] 2012-10-15 04:42 UTC+0200 Viktor Szakats (harbour syenar.net) * extras/guestbk/inifiles.prg * extras/guestbk/testcgi.prg * tests/inifiles.prg * tests/stripem.prg * tests/testhtml.prg + changed low-level class creation to hbclass.ch one * extras/guestbk/guestbk.hbp * minor --- harbour/ChangeLog | 11 +++ harbour/extras/guestbk/guestbk.hbp | 4 +- harbour/extras/guestbk/inifiles.prg | 92 +++++++----------- harbour/extras/guestbk/testcgi.prg | 140 ++++++++-------------------- harbour/tests/inifiles.prg | 92 +++++++----------- harbour/tests/stripem.prg | 65 +++++-------- harbour/tests/testhtml.prg | 73 ++++++--------- 7 files changed, 170 insertions(+), 307 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 6d240a012e..422355b2ca 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,17 @@ The license applies to all entries newer than 2009-04-28. */ +2012-10-15 04:42 UTC+0200 Viktor Szakats (harbour syenar.net) + * extras/guestbk/inifiles.prg + * extras/guestbk/testcgi.prg + * tests/inifiles.prg + * tests/stripem.prg + * tests/testhtml.prg + + changed low-level class creation to hbclass.ch one + + * extras/guestbk/guestbk.hbp + * minor + 2012-10-15 04:12 UTC+0200 Viktor Szakats (harbour syenar.net) * contrib/gtwvg/tests/activex.prg * contrib/gtwvg/tests/demowvg.prg diff --git a/harbour/extras/guestbk/guestbk.hbp b/harbour/extras/guestbk/guestbk.hbp index 34890fa05c..9e1ee7a35f 100644 --- a/harbour/extras/guestbk/guestbk.hbp +++ b/harbour/extras/guestbk/guestbk.hbp @@ -2,4 +2,6 @@ # $Id$ # -guestbk.prg inifiles.prg testcgi.prg +guestbk.prg +inifiles.prg +testcgi.prg diff --git a/harbour/extras/guestbk/inifiles.prg b/harbour/extras/guestbk/inifiles.prg index 299b57f0eb..d2d74afbc6 100644 --- a/harbour/extras/guestbk/inifiles.prg +++ b/harbour/extras/guestbk/inifiles.prg @@ -3,40 +3,32 @@ */ #include "fileio.ch" +#include "hbclass.ch" -FUNCTION TIniFile() +CREATE CLASS TIniFile - STATIC oClass + VAR FileName + VAR Contents - IF oClass == NIL - oClass := HBClass():New( "TINIFILE" ) // starts a new class definition + METHOD New( cFileName ) + METHOD ReadString( cSection, cIdent, cDefault ) + METHOD WriteString( cSection, cIdent, cString ) + METHOD ReadNumber( cSection, cIdent, nDefault ) + METHOD WriteNumber( cSection, cIdent, nNumber ) + METHOD ReadDate( cSection, cIdent, dDefault ) + METHOD WriteDate( cSection, cIdent, dDate ) + METHOD ReadBool( cSection, cIdent, lDefault ) + METHOD WriteBool( cSection, cIdent, lBool ) + METHOD DeleteKey( cSection, cIdent ) + METHOD EraseSection( cSection ) + METHOD ReadSection( cSection ) + METHOD ReadSections() + METHOD UpdateFile() - oClass:AddData( "FileName" ) // define this class objects datas - oClass:AddData( "Contents" ) +END CLASS - oClass:AddMethod( "New", @New() ) // define this class objects methods - oClass:AddMethod( "ReadString", @ReadString() ) - oClass:AddMethod( "WriteString", @WriteString() ) - oClass:AddMethod( "ReadNumber", @ReadNumber() ) - oClass:AddMethod( "WriteNumber", @WriteNumber() ) - oClass:AddMethod( "ReadDate", @ReadDate() ) - oClass:AddMethod( "WriteDate", @WriteDate() ) - oClass:AddMethod( "ReadBool", @ReadBool() ) - oClass:AddMethod( "WriteBool", @WriteBool() ) - oClass:AddMethod( "ReadSection", @ReadSection() ) - oClass:AddMethod( "ReadSections", @ReadSections() ) - oClass:AddMethod( "DeleteKey", @DeleteKey() ) - oClass:AddMethod( "EraseSection", @EraseSection() ) - oClass:AddMethod( "UpdateFile", @UpdateFile() ) +METHOD New( cFileName ) CLASS TIniFile - oClass:Create() // builds this class - ENDIF - - RETURN oClass:Instance() // builds an object of this class - -STATIC FUNCTION New( cFileName ) - - LOCAL Self := QSelf() LOCAL Done, hFile, cFile, cLine, cIdent, nPos LOCAL CurrArray @@ -111,9 +103,8 @@ STATIC FUNCTION New( cFileName ) RETURN Self -STATIC FUNCTION ReadString( cSection, cIdent, cDefault ) +METHOD ReadString( cSection, cIdent, cDefault ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL cResult := cDefault LOCAL i, j, cFind @@ -141,9 +132,8 @@ STATIC FUNCTION ReadString( cSection, cIdent, cDefault ) RETURN cResult -STATIC PROCEDURE WriteString( cSection, cIdent, cString ) +METHOD PROCEDURE WriteString( cSection, cIdent, cString ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j, cFind IF Empty( cIdent ) @@ -180,52 +170,40 @@ STATIC PROCEDURE WriteString( cSection, cIdent, cString ) RETURN -STATIC FUNCTION ReadNumber( cSection, cIdent, nDefault ) - - LOCAL Self := QSelf() +METHOD ReadNumber( cSection, cIdent, nDefault ) CLASS TIniFile RETURN Val( ::ReadString( cSection, cIdent, Str(nDefault ) ) ) -STATIC PROCEDURE WriteNumber( cSection, cIdent, nNumber ) - - LOCAL Self := QSelf() +METHOD PROCEDURE WriteNumber( cSection, cIdent, nNumber ) CLASS TIniFile ::WriteString( cSection, cIdent, hb_ntos( nNumber ) ) RETURN -STATIC FUNCTION ReadDate( cSection, cIdent, dDefault ) - - LOCAL Self := QSelf() +METHOD ReadDate( cSection, cIdent, dDefault ) CLASS TIniFile RETURN SToD( ::ReadString( cSection, cIdent, DToS( dDefault ) ) ) -STATIC PROCEDURE WriteDate( cSection, cIdent, dDate ) - - LOCAL Self := QSelf() +METHOD PROCEDURE WriteDate( cSection, cIdent, dDate ) CLASS TIniFile ::WriteString( cSection, cIdent, DToS( dDate ) ) RETURN -STATIC FUNCTION ReadBool( cSection, cIdent, lDefault ) +METHOD ReadBool( cSection, cIdent, lDefault ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL cDefault := iif( lDefault, ".t.", ".f." ) RETURN ::ReadString( cSection, cIdent, cDefault ) == ".t." -STATIC PROCEDURE WriteBool( cSection, cIdent, lBool ) - - LOCAL Self := QSelf() +METHOD PROCEDURE WriteBool( cSection, cIdent, lBool ) CLASS TIniFile ::WriteString( cSection, cIdent, iif( lBool, ".t.", ".f." ) ) RETURN -STATIC PROCEDURE DeleteKey( cSection, cIdent ) +METHOD PROCEDURE DeleteKey( cSection, cIdent ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j cSection := Lower( cSection ) @@ -240,9 +218,8 @@ STATIC PROCEDURE DeleteKey( cSection, cIdent ) RETURN -STATIC PROCEDURE EraseSection( cSection ) +METHOD PROCEDURE EraseSection( cSection ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i IF Empty( cSection ) @@ -259,9 +236,8 @@ STATIC PROCEDURE EraseSection( cSection ) RETURN -STATIC FUNCTION ReadSection( cSection ) +METHOD ReadSection( cSection ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j, aSection := {} IF Empty( cSection ) @@ -286,9 +262,8 @@ STATIC FUNCTION ReadSection( cSection ) RETURN aSection -STATIC FUNCTION ReadSections() +METHOD ReadSections() CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, aSections := {} FOR i := 1 TO Len( ::Contents ) @@ -300,9 +275,8 @@ STATIC FUNCTION ReadSections() RETURN aSections -STATIC PROCEDURE UpdateFile() +METHOD PROCEDURE UpdateFile() CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j, hFile hFile := FCreate( ::Filename ) diff --git a/harbour/extras/guestbk/testcgi.prg b/harbour/extras/guestbk/testcgi.prg index 6fb1c5269f..a564f8c771 100644 --- a/harbour/extras/guestbk/testcgi.prg +++ b/harbour/extras/guestbk/testcgi.prg @@ -22,6 +22,7 @@ **/ #include "fileio.ch" +#include "hbclass.ch" #include "cgi.ch" @@ -51,78 +52,37 @@ FUNCTION ParseString( cString, cDelim, nRet ) RETURN aElem[ nRet ] -FUNCTION Hex2Dec( cHex ) +CREATE CLASS THTML - LOCAL aHex := {; - { "0", 00 }, ; - { "1", 01 }, ; - { "2", 02 }, ; - { "3", 03 }, ; - { "4", 04 }, ; - { "5", 05 }, ; - { "6", 06 }, ; - { "7", 07 }, ; - { "8", 08 }, ; - { "9", 09 }, ; - { "A", 10 }, ; - { "B", 11 }, ; - { "C", 12 }, ; - { "D", 13 }, ; - { "E", 14 }, ; - { "F", 15 } } - LOCAL nRet - LOCAL nRes + VAR cTitle // Page Title + VAR cBody // HTML Body Handler + VAR cBGColor // Background Color + VAR cLinkColor // Link Color + VAR cvLinkColor // Visited Link Color + VAR cContent // Page Content Handler - nRet := AScan( aHex, {| x | Upper( x[ 1 ] ) == Upper( Left( cHex, 1 ) ) } ) - nRes := aHex[ nRet, 2 ] * 16 - nRet := AScan( aHex, {| x | Upper( x[ 1 ] ) == Upper( Right( cHex, 1 ) ) } ) - nRes += aHex[ nRet, 2 ] + VAR aCGIContents + VAR aQueryFields + VAR cHTMLFile + VAR aReplaceTags - RETURN nRes + METHOD New() + METHOD SetTitle( cTitle ) + METHOD AddLink( cLinkTo, cLinkName ) + METHOD AddHead( cDescr ) + METHOD AddPara( cPara, cAlign ) + METHOD Generate() + METHOD ShowResult() + METHOD SaveToFile( cFile ) + METHOD ProcessCGI() + METHOD GetCGIParam( nParam ) + METHOD QueryFields( cQueryName ) + METHOD SetHTMLFile( cFile ) + METHOD AddReplaceTag( cTag, cReplaceText ) -FUNCTION THTML() +END CLASS - STATIC oClass - - IF oClass == NIL - oClass := HBClass():New( "THTML" ) - - oClass:AddData( "cTitle" ) // Page Title - oClass:AddData( "cBody" ) // HTML Body Handler - oClass:AddData( "cBGColor" ) // Background Color - oClass:AddData( "cLinkColor" ) // Link Color - oClass:AddData( "cvLinkColor" ) // Visited Link Color - oClass:AddData( "cContent" ) // Page Content Handler - - oClass:AddData( "aCGIContents" ) - oClass:AddData( "aQueryFields" ) - oClass:AddData( "cHTMLFile" ) - oClass:AddData( "aReplaceTags" ) - - oClass:AddMethod( "New", @New() ) // New Method - oClass:AddMethod( "SetTitle", @SetTitle() ) // Set Page Title - oClass:AddMethod( "AddHead", @AddHead() ) // Add

Header - oClass:AddMethod( "AddLink", @AddLink() ) // Add Hyperlink - oClass:AddMethod( "AddPara", @AddPara() ) // Add Paragraph - oClass:AddMethod( "SaveToFile", @SaveToFile() ) // Saves Content to File - oClass:AddMethod( "ShowResult", @ShowResult() ) // Show Result - SEE Fcn - oClass:AddMethod( "Generate", @Generate() ) // Generate HTML - oClass:AddMethod( "SetHTMLFile", @SetHTMLFile() ) // Sets source HTML file - - oClass:AddMethod( "ProcessCGI", @ProcessCGI() ) - oClass:AddMethod( "GetCGIParam", @GetCGIParam() ) - oClass:AddMethod( "QueryFields", @QueryFields() ) - oClass:AddMethod( "AddReplaceTag", @AddReplaceTag() ) - - oClass:Create() - - ENDIF - - RETURN oClass:Instance() - -STATIC FUNCTION New() - - LOCAL Self := QSelf() +METHOD New() CLASS THTML ::cTitle := "Untitled" ::cBGColor := "#FFFFFF" @@ -137,34 +97,26 @@ STATIC FUNCTION New() RETURN Self -STATIC FUNCTION SetTitle( cTitle ) - - LOCAL Self := QSelf() +METHOD SetTitle( cTitle ) CLASS THTML ::cTitle := cTitle RETURN Self -STATIC FUNCTION AddLink( cLinkTo, cLinkName ) - - LOCAL Self := QSelf() +METHOD AddLink( cLinkTo, cLinkName ) CLASS THTML ::cBody := ::cBody + ; "" + cLinkName + "" RETURN Self -STATIC FUNCTION AddHead( cDescr ) - - LOCAL Self := QSelf() +METHOD AddHead( cDescr ) CLASS THTML ::cBody += "

" + cDescr + "

" RETURN NIL -STATIC FUNCTION AddPara( cPara, cAlign ) - - LOCAL Self := QSelf() +METHOD AddPara( cPara, cAlign ) CLASS THTML ::cBody := ::cBody + ; "

" + hb_eol() + ; @@ -173,9 +125,8 @@ STATIC FUNCTION AddPara( cPara, cAlign ) RETURN Self -STATIC FUNCTION Generate() +METHOD Generate() CLASS THTML - LOCAL Self := QSelf() LOCAL cFile, i, hFile, nPos, cRes := "" LOCAL lFlag := .F. @@ -241,9 +192,7 @@ STATIC FUNCTION Generate() RETURN Self -STATIC FUNCTION ShowResult() - - LOCAL Self := QSelf() +METHOD ShowResult() CLASS THTML OutStd( ; "HTTP/1.0 200 OK" + hb_eol() + ; @@ -252,9 +201,8 @@ STATIC FUNCTION ShowResult() RETURN Self -STATIC FUNCTION SaveToFile( cFile ) +METHOD SaveToFile( cFile ) CLASS THTML - LOCAL Self := QSelf() LOCAL hFile := FCreate( cFile ) FWrite( hFile, ::cContent ) @@ -262,9 +210,8 @@ STATIC FUNCTION SaveToFile( cFile ) RETURN Self -STATIC FUNCTION ProcessCGI() +METHOD ProcessCGI() CLASS THTML - LOCAL Self := QSelf() LOCAL cQuery := "" LOCAL cBuff := "" LOCAL nBuff := 0 @@ -311,7 +258,7 @@ STATIC FUNCTION ProcessCGI() cBuff := "" ELSE IF SubStr( cQuery, i, 1 ) == "%" - cBuff += Chr( Hex2Dec( SubStr( cQuery, i + 1, 2 ) ) ) + cBuff += Chr( hb_HexToNum( SubStr( cQuery, i + 1, 2 ) ) ) nBuff := 3 ENDIF @@ -330,9 +277,7 @@ STATIC FUNCTION ProcessCGI() RETURN Self -STATIC FUNCTION GetCGIParam( nParam ) - - LOCAL Self := QSelf() +METHOD GetCGIParam( nParam ) CLASS THTML ::ProcessCGI() @@ -343,9 +288,8 @@ STATIC FUNCTION GetCGIParam( nParam ) RETURN ::aCGIContents[nParam] -STATIC FUNCTION QueryFields( cQueryName ) +METHOD QueryFields( cQueryName ) CLASS THTML - LOCAL Self := QSelf() LOCAL cRet := "" LOCAL nRet @@ -360,17 +304,13 @@ STATIC FUNCTION QueryFields( cQueryName ) RETURN cRet -STATIC FUNCTION SetHTMLFile( cFile ) - - LOCAL Self := QSelf() +METHOD SetHTMLFile( cFile ) CLASS THTML ::cHTMLFile := cFile RETURN Self -STATIC FUNCTION AddReplaceTag( cTag, cReplaceText ) - - LOCAL Self := QSelf() +METHOD AddReplaceTag( cTag, cReplaceText ) CLASS THTML AAdd( ::aReplaceTags, { cTag, cReplaceText } ) diff --git a/harbour/tests/inifiles.prg b/harbour/tests/inifiles.prg index 8dd1ce13ac..d67e89fa34 100644 --- a/harbour/tests/inifiles.prg +++ b/harbour/tests/inifiles.prg @@ -3,6 +3,7 @@ */ #include "fileio.ch" +#include "hbclass.ch" PROCEDURE Main( cFilename, cSection ) @@ -33,39 +34,30 @@ PROCEDURE Main( cFilename, cSection ) RETURN -FUNCTION TIniFile() +CREATE CLASS TIniFile - STATIC oClass + VAR FileName + VAR Contents - IF oClass == NIL - oClass := HBClass():New( "TINIFILE" ) // starts a new class definition + METHOD New( cFileName ) + METHOD ReadString( cSection, cIdent, cDefault ) + METHOD WriteString( cSection, cIdent, cString ) + METHOD ReadNumber( cSection, cIdent, nDefault ) + METHOD WriteNumber( cSection, cIdent, nNumber ) + METHOD ReadDate( cSection, cIdent, dDefault ) + METHOD WriteDate( cSection, cIdent, dDate ) + METHOD ReadBool( cSection, cIdent, lDefault ) + METHOD WriteBool( cSection, cIdent, lBool ) + METHOD DeleteKey( cSection, cIdent ) + METHOD EraseSection( cSection ) + METHOD ReadSection( cSection ) + METHOD ReadSections() + METHOD UpdateFile() - oClass:AddData( "FileName" ) // define this class objects datas - oClass:AddData( "Contents" ) +END CLASS - oClass:AddMethod( "New", @New() ) // define this class objects methods - oClass:AddMethod( "ReadString", @ReadString() ) - oClass:AddMethod( "WriteString", @WriteString() ) - oClass:AddMethod( "ReadNumber", @ReadNumber() ) - oClass:AddMethod( "WriteNumber", @WriteNumber() ) - oClass:AddMethod( "ReadDate", @ReadDate() ) - oClass:AddMethod( "WriteDate", @WriteDate() ) - oClass:AddMethod( "ReadBool", @ReadBool() ) - oClass:AddMethod( "WriteBool", @WriteBool() ) - oClass:AddMethod( "ReadSection", @ReadSection() ) - oClass:AddMethod( "ReadSections", @ReadSections() ) - oClass:AddMethod( "DeleteKey", @DeleteKey() ) - oClass:AddMethod( "EraseSection", @EraseSection() ) - oClass:AddMethod( "UpdateFile", @UpdateFile() ) +METHOD New( cFileName ) CLASS TIniFile - oClass:Create() // builds this class - ENDIF - - RETURN oClass:Instance() // builds an object of this class - -STATIC FUNCTION New( cFileName ) - - LOCAL Self := QSelf() LOCAL Done, hFile, cFile, cLine, cIdent, nPos LOCAL CurrArray @@ -140,9 +132,8 @@ STATIC FUNCTION New( cFileName ) RETURN Self -STATIC FUNCTION ReadString( cSection, cIdent, cDefault ) +METHOD ReadString( cSection, cIdent, cDefault ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL cResult := cDefault LOCAL i, j, cFind @@ -170,9 +161,8 @@ STATIC FUNCTION ReadString( cSection, cIdent, cDefault ) RETURN cResult -STATIC PROCEDURE WriteString( cSection, cIdent, cString ) +METHOD PROCEDURE WriteString( cSection, cIdent, cString ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j, cFind IF Empty( cIdent ) @@ -211,52 +201,40 @@ STATIC PROCEDURE WriteString( cSection, cIdent, cString ) RETURN -STATIC FUNCTION ReadNumber( cSection, cIdent, nDefault ) - - LOCAL Self := QSelf() +METHOD ReadNumber( cSection, cIdent, nDefault ) CLASS TIniFile RETURN Val( ::ReadString( cSection, cIdent, Str( nDefault ) ) ) -STATIC PROCEDURE WriteNumber( cSection, cIdent, nNumber ) - - LOCAL Self := QSelf() +METHOD PROCEDURE WriteNumber( cSection, cIdent, nNumber ) CLASS TIniFile ::WriteString( cSection, cIdent, hb_ntos( nNumber ) ) RETURN -STATIC FUNCTION ReadDate( cSection, cIdent, dDefault ) - - LOCAL Self := QSelf() +METHOD ReadDate( cSection, cIdent, dDefault ) CLASS TIniFile RETURN SToD( ::ReadString( cSection, cIdent, DToS( dDefault ) ) ) -STATIC PROCEDURE WriteDate( cSection, cIdent, dDate ) - - LOCAL Self := QSelf() +METHOD PROCEDURE WriteDate( cSection, cIdent, dDate ) CLASS TIniFile ::WriteString( cSection, cIdent, DToS( dDate ) ) RETURN -STATIC FUNCTION ReadBool( cSection, cIdent, lDefault ) +METHOD ReadBool( cSection, cIdent, lDefault ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL cDefault := iif( lDefault, ".T.", ".F." ) return ::ReadString( cSection, cIdent, cDefault ) == ".T." -STATIC PROCEDURE WriteBool( cSection, cIdent, lBool ) - - LOCAL Self := QSelf() +METHOD PROCEDURE WriteBool( cSection, cIdent, lBool ) CLASS TIniFile ::WriteString( cSection, cIdent, iif( lBool, ".T.", ".F." ) ) RETURN -STATIC PROCEDURE DeleteKey( cSection, cIdent ) +METHOD PROCEDURE DeleteKey( cSection, cIdent ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j cSection := Lower( cSection ) @@ -271,9 +249,8 @@ STATIC PROCEDURE DeleteKey( cSection, cIdent ) RETURN -STATIC PROCEDURE EraseSection( cSection ) +METHOD PROCEDURE EraseSection( cSection ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i IF Empty( cSection ) @@ -290,9 +267,8 @@ STATIC PROCEDURE EraseSection( cSection ) RETURN -STATIC FUNCTION ReadSection( cSection ) +METHOD ReadSection( cSection ) CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j, aSection := {} IF Empty( cSection ) @@ -317,9 +293,8 @@ STATIC FUNCTION ReadSection( cSection ) RETURN aSection -STATIC FUNCTION ReadSections() +METHOD ReadSections() CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, aSections := {} FOR i := 1 TO Len( ::Contents ) @@ -331,9 +306,8 @@ STATIC FUNCTION ReadSections() RETURN aSections -STATIC PROCEDURE UpdateFile() +METHOD PROCEDURE UpdateFile() CLASS TIniFile - LOCAL Self := QSelf() LOCAL i, j, hFile hFile := FCreate( ::Filename ) diff --git a/harbour/tests/stripem.prg b/harbour/tests/stripem.prg index ad82d5d9d5..37baff4206 100644 --- a/harbour/tests/stripem.prg +++ b/harbour/tests/stripem.prg @@ -4,6 +4,7 @@ #include "fileio.ch" #include "set.ch" +#include "hbclass.ch" #xtranslate Default( , ) => iif( == NIL, , ) @@ -56,39 +57,28 @@ PROCEDURE Main( cFrom, cTo ) // Generic DOS file handler // -FUNCTION TTextFile() // Parameter = dirty +CREATE CLASS TTextFile - STATIC oFile := NIL + VAR cFileName // Filename spec. by user + VAR hFile // File handle + VAR nLine // Current linenumber + VAR nError // Last error + VAR lEoF // End of file + VAR cBlock // Storage block + VAR nBlockSize // Size of read-ahead buffer + VAR cMode // Mode of file use R = read, W = write - IF oFile == NIL - oFile := HBClass():New( "TTEXTFILE" ) // Create a new class def + METHOD New( cFileName, cMode, nBlock ) // Constructor + METHOD Dispose() // Clean up code + METHOD Read() // Read line + METHOD WriteLn( xTxt, lCRLF ) // Write line + METHOD Goto( nLine ) // Go to line - 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 + METHOD Run( xTxt, lCRLF ) INLINE iif( ::cMode == "R", ::Read(), ::WriteLn( xTxt, lCRLF ) ) + METHOD Write( xTxt ) INLINE ::WriteLn( xTxt, .F. ) // Write without CR + METHOD Eof() INLINE ::lEoF - oFile:AddMethod( "New" , @New() ) // Constructor - oFile:AddMethod( "Dispose", @Dispose() ) // Clean up code - oFile:AddMethod( "Read" , @Read() ) // Read line - oFile:AddMethod( "WriteLn", @WriteLn() ) // Write line - oFile:AddMethod( "Goto" , @Goto() ) // Go to line - - oFile:AddInline( "Run" , ; // Get/set data - {| self, xTxt, lCRLF | iif( ::cMode == "R", ::Read(), ::WriteLn( xTxt, lCRLF ) ) } ) - oFile:AddInline( "Write" , {| self, xTxt | ::WriteLn( xTxt, .F. ) } ) - // Write without CR - oFile:AddInline( "EoF" , {| self | ::lEoF } ) - // End of file as function - oFile:Create() - ENDIF - - RETURN oFile:Instance() +END CLASS // // Method TextFile:New -> Create a new text file @@ -98,9 +88,7 @@ FUNCTION TTextFile() // Parameter = dirty // Optional maximum blocksize // -FUNCTION New( cFileName, cMode, nBlock ) - - LOCAL self := QSelf() // Get self +METHOD New( cFileName, cMode, nBlock ) CLASS TTextFile ::nLine := 0 ::lEoF := .F. @@ -129,9 +117,7 @@ FUNCTION New( cFileName, cMode, nBlock ) // Dispose -> Close the file handle // -FUNCTION Dispose() - - LOCAL self := QSelf() +METHOD Dispose() CLASS TTextFile ::cBlock := NIL IF ::hFile != F_ERROR @@ -147,9 +133,8 @@ FUNCTION Dispose() // Read a single line // -FUNCTION READ() +METHOD Read() CLASS TTextFile - LOCAL self := QSelf() LOCAL cRet := "" LOCAL cBlock LOCAL nCrPos @@ -204,9 +189,8 @@ FUNCTION READ() // End with Carriage Return/Line Feed (Default == TRUE) // -FUNCTION WriteLn( xTxt, lCRLF ) +METHOD WriteLn( xTxt, lCRLF ) CLASS TTextFile - LOCAL self := QSelf() LOCAL cBlock IF ::hFile == F_ERROR @@ -231,9 +215,8 @@ FUNCTION WriteLn( xTxt, lCRLF ) // Go to a specified line number // -STATIC FUNCTION GOTO( nLine ) +METHOD Goto( nLine ) CLASS TTextFile - LOCAL self := QSelf() LOCAL nWhere := 1 IF Empty( ::hFile ) diff --git a/harbour/tests/testhtml.prg b/harbour/tests/testhtml.prg index f5cf7e8933..c0d595ab0b 100644 --- a/harbour/tests/testhtml.prg +++ b/harbour/tests/testhtml.prg @@ -12,6 +12,8 @@ * **/ +#include "hbclass.ch" + PROCEDURE Main() LOCAL oHTML := THTML():New() @@ -34,37 +36,27 @@ PROCEDURE Main() RETURN -FUNCTION THTML() +CREATE CLASS THTML - STATIC oClass + VAR cTitle // Page Title + VAR cBody // HTML Body Handler + VAR cBGColor // Background Color + VAR cLinkColor // Link Color + VAR cvLinkColor // Visited Link Color + VAR cContent // Page Content Handler - IF oClass == NIL - oClass := HBClass():New( "THTML" ) + METHOD New() // New Method + METHOD SetTitle( cTitle ) // Set Page Title + METHOD AddLink( cLinkTo, cLinkName ) // Add

Header + METHOD AddHead( cDescr ) // Add Hyperlink + METHOD AddPara( cPara, cAlign ) // Add Paragraph + METHOD Generate() // Generate HTML + METHOD ShowResult() // Saves Content to File + METHOD SaveToFile( cFile ) // Show Result - oClass:AddData( "cTitle" ) // Page Title - oClass:AddData( "cBody" ) // HTML Body Handler - oClass:AddData( "cBGColor" ) // Background Color - oClass:AddData( "cLinkColor" ) // Link Color - oClass:AddData( "cvLinkColor" ) // Visited Link Color - oClass:AddData( "cContent" ) // Page Content Handler +END CLASS - oClass:AddMethod( "New", @New() ) // New Method - oClass:AddMethod( "SetTitle", @SetTitle() ) // Set Page Title - oClass:AddMethod( "AddHead", @AddHead() ) // Add

Header - oClass:AddMethod( "AddLink", @AddLink() ) // Add Hyperlink - oClass:AddMethod( "AddPara", @AddPara() ) // Add Paragraph - oClass:AddMethod( "Generate", @Generate() ) // Generate HTML - oClass:AddMethod( "SaveToFile", @SaveToFile() ) // Saves Content to File - oClass:AddMethod( "ShowResult", @ShowResult() ) // Show Result - SEE Fcn - - oClass:Create() - ENDIF - - RETURN oClass:Instance() - -STATIC FUNCTION New() - - LOCAL Self := QSelf() +METHOD New() CLASS THTML ::cTitle := "Untitled" ::cBGColor := "#FFFFFF" @@ -75,26 +67,20 @@ STATIC FUNCTION New() RETURN Self -STATIC FUNCTION SetTitle( cTitle ) - - LOCAL Self := QSelf() +METHOD SetTitle( cTitle ) CLASS THTML ::cTitle := cTitle RETURN Self -STATIC FUNCTION AddLink( cLinkTo, cLinkName ) - - LOCAL Self := QSelf() +METHOD AddLink( cLinkTo, cLinkName ) CLASS THTML ::cBody := ::cBody + ; "" + cLinkName + "" RETURN Self -STATIC FUNCTION AddHead( cDescr ) - - LOCAL Self := QSelf() +METHOD AddHead( cDescr ) CLASS THTML // Why this doesn't work? // ::cBody += ... @@ -105,9 +91,7 @@ STATIC FUNCTION AddHead( cDescr ) RETURN NIL -STATIC FUNCTION AddPara( cPara, cAlign ) - - LOCAL Self := QSelf() +METHOD AddPara( cPara, cAlign ) CLASS THTML cAlign := iif( cAlign == NIL, "Left", cAlign ) // Added Patrick Mast 2000-06-17 @@ -118,9 +102,7 @@ STATIC FUNCTION AddPara( cPara, cAlign ) RETURN Self -STATIC FUNCTION Generate() - - LOCAL Self := QSelf() +METHOD Generate() CLASS THTML ::cContent := ; "" + hb_eol() + ; @@ -132,9 +114,7 @@ STATIC FUNCTION Generate() RETURN Self -STATIC FUNCTION ShowResult() - - LOCAL Self := QSelf() +METHOD ShowResult() CLASS THTML OutStd( ; ;// "HTTP/1.0 200 OK" + hb_eol() + ; @@ -143,9 +123,8 @@ STATIC FUNCTION ShowResult() RETURN Self -STATIC FUNCTION SaveToFile( cFile ) +METHOD SaveToFile( cFile ) CLASS THTML - LOCAL Self := QSelf() LOCAL hFile := FCreate( cFile ) FWrite( hFile, ::cContent )