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
This commit is contained in:
Viktor Szakats
2012-10-15 02:43:47 +00:00
parent 6831364d2f
commit 100289b2a5
7 changed files with 170 additions and 307 deletions

View File

@@ -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

View File

@@ -2,4 +2,6 @@
# $Id$
#
guestbk.prg inifiles.prg testcgi.prg
guestbk.prg
inifiles.prg
testcgi.prg

View File

@@ -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 )

View File

@@ -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 <H1> 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 + ;
"<a href='" + cLinkTo + "'>" + cLinkName + "</a>"
RETURN Self
STATIC FUNCTION AddHead( cDescr )
LOCAL Self := QSelf()
METHOD AddHead( cDescr ) CLASS THTML
::cBody += "<h1>" + cDescr + "</h1>"
RETURN NIL
STATIC FUNCTION AddPara( cPara, cAlign )
LOCAL Self := QSelf()
METHOD AddPara( cPara, cAlign ) CLASS THTML
::cBody := ::cBody + ;
"<p align='" + cAlign + "'>" + 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 } )

View File

@@ -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 )

View File

@@ -4,6 +4,7 @@
#include "fileio.ch"
#include "set.ch"
#include "hbclass.ch"
#xtranslate Default( <Var>, <xVal> ) => iif( <Var> == NIL, <xVal>, <Var> )
@@ -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
// <nBlockSize> 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()
// <lCRLF> 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 )

View File

@@ -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 <H1> 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 <H1> 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 + ;
"<a href='" + cLinkTo + "'>" + cLinkName + "</a>"
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 := ;
"<html><head>" + 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 )