From c9852a48761c99a86c8db42ab175ec4a922fa937 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 26 Jun 2012 22:11:08 +0000 Subject: [PATCH] 2012-06-27 00:09 UTC+0200 Viktor Szakats (harbour syenar.net) * examples/hbdoc/genhtml.prg * examples/hbdoc/gentpl.prg * examples/hbdoc/gentxt.prg * examples/hbdoc/genxml.prg * examples/hbdoc/hbdoc.prg * examples/hbdoc/tmplates.prg % cleanups and formatting + added support for UTF8 HVM CP + enabled UTF8 HVM CP. it means that now input files can really be UTF8 ones. --- harbour/ChangeLog | 12 +++++ harbour/examples/hbdoc/genhtml.prg | 20 ++++---- harbour/examples/hbdoc/gentpl.prg | 11 ++--- harbour/examples/hbdoc/gentxt.prg | 10 ++-- harbour/examples/hbdoc/genxml.prg | 14 +++--- harbour/examples/hbdoc/hbdoc.prg | 77 +++++++++++------------------ harbour/examples/hbdoc/tmplates.prg | 12 +++-- 7 files changed, 72 insertions(+), 84 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e7eff6578f..218706037f 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,18 @@ The license applies to all entries newer than 2009-04-28. */ +2012-06-27 00:09 UTC+0200 Viktor Szakats (harbour syenar.net) + * examples/hbdoc/genhtml.prg + * examples/hbdoc/gentpl.prg + * examples/hbdoc/gentxt.prg + * examples/hbdoc/genxml.prg + * examples/hbdoc/hbdoc.prg + * examples/hbdoc/tmplates.prg + % cleanups and formatting + + added support for UTF8 HVM CP + + enabled UTF8 HVM CP. it means that now input files + can really be UTF8 ones. + 2012-06-26 22:44 UTC+0200 Viktor Szakats (harbour syenar.net) * contrib/xhb/xhberr.prg ! typo in prev commit diff --git a/harbour/examples/hbdoc/genhtml.prg b/harbour/examples/hbdoc/genhtml.prg index f4193874b0..07240b6cd6 100644 --- a/harbour/examples/hbdoc/genhtml.prg +++ b/harbour/examples/hbdoc/genhtml.prg @@ -55,9 +55,6 @@ */ #include "hbclass.ch" -#include "common.ch" -#include "inkey.ch" -#include "fileio.ch" #include "hbdoc.ch" #ifdef __PLATFORM__DOS @@ -79,8 +76,8 @@ METHOD NewIndex( cFolder, cFilename, cTitle ) CLASS GenerateHTML2 super:NewIndex( cFolder, cFilename, cTitle, EXTENSION ) RETURN self -CLASS GenerateHTML FROM TPLGenerate -HIDDEN: +CREATE CLASS GenerateHTML FROM TPLGenerate + HIDDEN: METHOD RecreateStyleDocument( cStyleFile ) METHOD OpenTag( cText, ... ) METHOD Tagged( cText, cTag, ... ) @@ -91,7 +88,7 @@ HIDDEN: CLASSDATA lCreateStyleDocument AS LOGICAL INIT .T. DATA TargetFilename AS STRING INIT "" -EXPORTED: + EXPORTED: METHOD NewFile() HIDDEN METHOD NewIndex( cFolder, cFilename, cTitle ) METHOD NewDocument( cFolder, cFilename, cTitle ) @@ -201,10 +198,11 @@ METHOD PROCEDURE WriteEntry( cField, oEntry, lPreformatted, nIndent ) CLASS Gene LOCAL cTagClass := IIf( LOWER( cField ) + "|" $ "name|oneliner|examples|tests|", LOWER( cField ), "itemtext" ) IF ! Empty( cEntry ) - DEFAULT cCaption TO "" - DEFAULT nIndent TO 0 - //~ DEFAULT lPreformatted TO .F. - //~ DEFAULT cTagClass TO "itemtext" + + hb_default( @cCaption, "" ) + hb_default( @nIndent, 0 ) + //~ hb_default( @lPreformatted, .F. ) + //~ hb_default( @cTagClass, "itemtext" ) IF Len( cCaption ) > 0 /* .AND. nIndent > 0 */ ::Tagged( cCaption, "div", "class", "itemtitle" ) @@ -271,7 +269,7 @@ METHOD Append( cText, cFormat ) CLASS GenerateHTML IF Len( cResult ) > 0 - DEFAULT cFormat TO "" + hb_default( @cFormat, "" ) aFormat := p_aConversionList FOR idx := 1 TO Len( aFormat ) STEP 2 diff --git a/harbour/examples/hbdoc/gentpl.prg b/harbour/examples/hbdoc/gentpl.prg index 9e920e0b0d..3a2b76f394 100644 --- a/harbour/examples/hbdoc/gentpl.prg +++ b/harbour/examples/hbdoc/gentpl.prg @@ -54,18 +54,15 @@ * */ -#include "simpleio.ch" - #include "hbclass.ch" - #include "hbdoc.ch" #define DOCUMENT_ 1 #define INDEX_ 2 -CLASS TPLGenerate +CREATE CLASS TPLGenerate -EXPORTED: + EXPORTED: //~ PROTECTED: DATA nHandle AS NUMERIC DATA cFolder AS STRING @@ -82,7 +79,7 @@ EXPORTED: METHOD Generate() INLINE NIL METHOD IsIndex() INLINE ( ::nType == INDEX_ ) -PROTECTED: + PROTECTED: METHOD New( cFolder, cFilename, cTitle, cExtension, nType ) HIDDEN DATA nType AS INTEGER DATA Depth AS INTEGER INIT 0 @@ -106,7 +103,7 @@ METHOD New( cFolder, cFilename, cTitle, cExtension, nType ) CLASS TPLGenerate ::nType := nType IF ! hb_DirExists( ::cFolder ) - ? "Creating folder " + ::cFolder + OutStd( hb_eol(), "Creating folder " + ::cFolder ) hb_DirCreate( ::cFolder ) ENDIF diff --git a/harbour/examples/hbdoc/gentxt.prg b/harbour/examples/hbdoc/gentxt.prg index 209b07c8e3..738e9c2ce6 100644 --- a/harbour/examples/hbdoc/gentxt.prg +++ b/harbour/examples/hbdoc/gentxt.prg @@ -55,11 +55,9 @@ */ #include "hbclass.ch" -#include "inkey.ch" -#include "fileio.ch" #include "hbdoc.ch" -CLASS GenerateAscii FROM GenerateText +CREATE CLASS GenerateAscii FROM GenerateText METHOD NewIndex( cFolder, cFilename, cTitle, cDescription ) METHOD NewDocument( cFolder, cFilename, cTitle, cDescription ) ENDCLASS @@ -128,7 +126,7 @@ METHOD AddEntry( oEntry ) CLASS GenerateText NEXT IF ! ::lContinuous - FWrite( ::nHandle, Chr( K_CTRL_L ) + hb_eol() ) + FWrite( ::nHandle, hb_BChar( 12 ) + hb_eol() ) ENDIF ENDIF @@ -137,7 +135,7 @@ METHOD AddEntry( oEntry ) CLASS GenerateText METHOD PROCEDURE WriteEntry( cCaption, cEntry, lPreformatted ) CLASS GenerateText LOCAL nIndent IF ! Empty( cEntry ) - nIndent := IIf( Len( cCaption ) > 0, 6, 0 ) + nIndent := iif( Len( cCaption ) > 0, 6, 0 ) IF Len( cCaption ) > 0 .AND. nIndent > 0 FWrite( ::nHandle, Space( ::Depth * 6 ) + cCaption + ": " + hb_eol() ) ENDIF @@ -150,7 +148,7 @@ METHOD PROCEDURE WriteEntry( cCaption, cEntry, lPreformatted ) CLASS GenerateTex METHOD Generate() CLASS GenerateText IF ::IsIndex() IF ! ::lContinuous - FWrite( ::nHandle, Chr( K_CTRL_L ) + hb_eol() ) + FWrite( ::nHandle, hb_BChar( 12 ) + hb_eol() ) ENDIF ENDIF diff --git a/harbour/examples/hbdoc/genxml.prg b/harbour/examples/hbdoc/genxml.prg index 93f9edf26d..a05fe9569d 100644 --- a/harbour/examples/hbdoc/genxml.prg +++ b/harbour/examples/hbdoc/genxml.prg @@ -55,16 +55,14 @@ */ #include "hbclass.ch" -#include "inkey.ch" -#include "fileio.ch" #include "hbdoc.ch" -CLASS GenerateXML FROM TPLGenerate -HIDDEN: +CREATE CLASS GenerateXML FROM TPLGenerate + HIDDEN: -PROTECTED: + PROTECTED: -EXPORTED: + EXPORTED: METHOD NewIndex( cFolder, cFilename, cTitle ) METHOD NewDocument( cFolder, cFilename, cTitle ) METHOD AddEntry( oEntry ) @@ -98,8 +96,8 @@ METHOD BeginSection( cSection, cFilename ) CLASS GenerateXML RETURN self METHOD EndSection( cSection, cFilename ) CLASS GenerateXML -HB_SYMBOL_UNUSED( cSection ) -HB_SYMBOL_UNUSED( cFilename ) + HB_SYMBOL_UNUSED( cSection ) + HB_SYMBOL_UNUSED( cFilename ) ::Depth-- FWrite( ::nHandle, Replicate( Chr(9), ::Depth ) + [] + hb_eol() ) RETURN self diff --git a/harbour/examples/hbdoc/hbdoc.prg b/harbour/examples/hbdoc/hbdoc.prg index 4b0377d70b..d912708f18 100644 --- a/harbour/examples/hbdoc/hbdoc.prg +++ b/harbour/examples/hbdoc/hbdoc.prg @@ -96,7 +96,6 @@ done - build a list of 'categories' and validate against; see what 'classdoc' us done - validate sources against these templates */ -#include "common.ch" #include "directry.ch" #include "fileio.ch" #include "simpleio.ch" @@ -119,6 +118,13 @@ PROCEDURE Main( ... ) LOCAL oDocument, oIndex LOCAL aContent + /* Setup input CP of the translation */ + hb_cdpSelect( "UTF8EX" ) + + /* Configure terminal and OS codepage */ + hb_SetTermCP( hb_cdpTerm() ) + Set( _SET_OSCODEPAGE, hb_cdpOS() ) + init_Templates() PUBLIC p_hsSwitches := HB_Hash( ; @@ -219,9 +225,9 @@ PROCEDURE Main( ... ) ? ASort( aContent, , , {|oL,oR| ; - HB_NTOS( oL:CategoryIndex( oL:Category ) ) + Chr(1) + HB_NTOS( oL:SubcategoryIndex( oL:Category, oL:Subcategory ) ) + Chr(1) + oL:Name + Chr(1) ; + HB_NTOS( oL:CategoryIndex( oL:Category ) ) + " " + HB_NTOS( oL:SubcategoryIndex( oL:Category, oL:Subcategory ) ) + Chr(1) + oL:Name + " " ; <= ; - HB_NTOS( oR:CategoryIndex( oR:Category ) ) + Chr(1) + HB_NTOS( oR:SubcategoryIndex( oR:Category, oR:Subcategory ) ) + Chr(1) + oR:Name + Chr(1) ; + HB_NTOS( oR:CategoryIndex( oR:Category ) ) + " " + HB_NTOS( oR:SubcategoryIndex( oR:Category, oR:Subcategory ) ) + Chr(1) + oR:Name + " " ; } ) // TODO: what is this for? it is sorting the category sub-arrays and removing empty (?) sub-arrays, but why? @@ -232,9 +238,9 @@ PROCEDURE Main( ... ) IF ValType( p_aCategories[ idx ][ 3 ][ idx2 ] ) == "A" ASort( p_aCategories[ idx ][ 3 ][ idx2 ], , , ; {|oL,oR| ; - HB_NTOS( oL:CategoryIndex( oL:Category ) ) + Chr(1) + HB_NTOS( oL:SubcategoryIndex( oL:Category, oL:Subcategory ) ) + Chr(1) + oL:Name ; + HB_NTOS( oL:CategoryIndex( oL:Category ) ) + " " + HB_NTOS( oL:SubcategoryIndex( oL:Category, oL:Subcategory ) ) + " " + oL:Name ; <= ; - HB_NTOS( oR:CategoryIndex( oR:Category ) ) + Chr(1) + HB_NTOS( oR:SubcategoryIndex( oR:Category, oR:Subcategory ) ) + Chr(1) + oR:Name ; + HB_NTOS( oR:CategoryIndex( oR:Category ) ) + " " + HB_NTOS( oR:SubcategoryIndex( oR:Category, oR:Subcategory ) ) + " " + oR:Name ; } ) ELSE ASize( ADel( p_aCategories[ idx ][ 2 ], idx2 ), Len( p_aCategories[ idx ][ 2 ] ) - 1 ) @@ -459,11 +465,7 @@ STATIC PROCEDURE ProcessBlock( aHandle, aContent, cFile, cType, cVersion, o ) LOCAL idxSubCategory := -1 LOCAL cSourceFile -#ifdef __PLATFORM__UNIX - cSourceFile := "../" + cFile /* SubStr( cFile, Len( p_hsSwitches[ "basedir" ] + hb_ps() ) ) */ -#else - cSourceFile := StrTran( "../" + cFile /* SubStr( cFile, Len( p_hsSwitches[ "basedir" ] + hb_ps() ) ) */, "\", "/" ) -#endif + cSourceFile := StrTran( ".." + hb_ps() + cFile /* SubStr( cFile, Len( p_hsSwitches[ "basedir" ] + hb_ps() ) ) */, iif( hb_ps() == "\", "/", "\" ), hb_ps() ) o:type_ := cType o:sourcefile_ := cSourceFile @@ -708,7 +710,7 @@ STATIC PROCEDURE FileEval( acFile, bBlock, nMaxLine ) LOCAL lCloseFile := .F. LOCAL xResult - DEFAULT nMaxLine TO 256 + hb_default( @nMaxLine, 256 ) IF HB_ISSTRING( acFile ) lCloseFile := .T. @@ -734,48 +736,23 @@ STATIC PROCEDURE FileEval( acFile, bBlock, nMaxLine ) RETURN -STATIC FUNCTION FReadUntil( aHandle, cMatch, cResult ) - LOCAL cBuffer, nSavePos, nIdxMatch, nNumRead - - DEFAULT cResult TO "" - - DO WHILE nNumRead != 0 - nSavePos := FSeek( aHandle[ 1 ], 0, FS_RELATIVE ) - cBuffer := Space( 255 ) - IF ( nNumRead := FRead( aHandle[ 1 ], @cBuffer, Len( cBuffer ) ) ) == 0 - RETURN .F. - ENDIF - cBuffer := SubStr( cBuffer, 1, nNumRead ) - - IF ( nIdxMatch := At( cMatch, cBuffer ) ) > 0 - cResult += SubStr( cBuffer, 1, nIdxMatch + Len( cMatch ) - 1 ) - FSeek( aHandle[ 1 ], nSavePos + nIdxMatch + Len( cMatch ) - 1, FS_SET ) - RETURN nNumRead != 0 - ELSE - cResult += SubStr( cBuffer, 1, nNumRead - Len( cMatch ) ) - FSeek( aHandle[ 1 ], -Len( cMatch ), FS_RELATIVE ) - ENDIF - ENDDO - - RETURN nNumRead != 0 - STATIC FUNCTION FReadLn( aHandle, cBuffer, nMaxLine ) - STATIC s_aEOL := { chr(13) + chr(10), chr(10), chr(13) } + STATIC s_aEOL := { Chr( 13 ) + Chr( 10 ), Chr( 10 ), Chr( 13 ) } LOCAL cLine, nSavePos, nEol, nNumRead, nLenEol, idx - DEFAULT nMaxLine TO 256 + hb_default( @nMaxLine, 256 ) cBuffer := "" nSavePos := FSeek( aHandle[ 1 ], 0, FS_RELATIVE ) cLine := Space( nMaxLine ) - nNumRead := FRead( aHandle[ 1 ], @cLine, Len( cLine ) ) - cLine := SubStr( cLine, 1, nNumRead ) + nNumRead := FRead( aHandle[ 1 ], @cLine, hb_BLen( cLine ) ) + cLine := hb_BLeft( cLine, nNumRead ) nEol := 0 - FOR idx := 1 To Len(s_aEOL) + FOR idx := 1 To Len( s_aEOL ) IF ( nEol := At( s_aEOL[ idx ], cLine ) ) > 0 - nLenEol := Len( s_aEOL[ idx ] ) - 1 + nLenEol := hb_BLen( s_aEOL[ idx ] ) - 1 Exit ENDIF NEXT @@ -783,8 +760,8 @@ STATIC FUNCTION FReadLn( aHandle, cBuffer, nMaxLine ) IF nEol == 0 cBuffer := cLine ELSE - cBuffer := SubStr( cLine, 1, nEol - 1 ) - FSeek( aHandle[ 1 ], nSavePos + nEol + nLenEol, FS_SET ) + cBuffer := Left( cLine, nEol - 1 ) + FSeek( aHandle[ 1 ], nSavePos + hb_BLen( cBuffer ) + 1 + nLenEol, FS_SET ) ENDIF aHandle[ 2 ]++ @@ -1060,7 +1037,7 @@ FUNCTION Indent( cText, nLeftMargin, nWidth, lRaw ) LOCAL cLine LOCAL aText - DEFAULT lRaw TO .F. + hb_default( @lRaw, .F. ) IF nWidth == 0 .or. lRaw aText := Split( cText, hb_eol() ) @@ -1133,17 +1110,19 @@ FUNCTION Indent( cText, nLeftMargin, nWidth, lRaw ) RETURN cResult FUNCTION Filename( cFile, cFormat, nLength ) -STATIC s_Files := {} + + STATIC s_Files := {} + LOCAL cResult := "" LOCAL idx LOCAL char - DEFAULT cFormat TO "alnum" + hb_default( @cFormat, "alnum" ) #ifdef __PLATFORM__DOS - DEFAULT nLength TO 8 + hb_default( @nLength, 8 ) #else - DEFAULT nLength TO 0 + hb_default( @nLength, 0 ) #endif DO CASE diff --git a/harbour/examples/hbdoc/tmplates.prg b/harbour/examples/hbdoc/tmplates.prg index 96b63d66ca..4c60c10025 100644 --- a/harbour/examples/hbdoc/tmplates.prg +++ b/harbour/examples/hbdoc/tmplates.prg @@ -58,8 +58,10 @@ #include "hbclass.ch" /* a class that will hold one entry */ -CLASS Entry -EXPORTED: +CREATE CLASS Entry + + EXPORTED: + CLASSDATA Fields AS ARRAY INIT { ; { "DOC", "Doc" }, ; { "TEMPLATE", "Template" }, ; @@ -482,7 +484,7 @@ PROCEDURE init_Templates() 255, "yuml;" ; } -RETURN + RETURN PROCEDURE ShowTemplatesHelp( cTemplate ) @@ -537,6 +539,8 @@ PROCEDURE ShowComplianceHelp() ShowSubHelp( "", 1, 0 ) NEXT + RETURN + PROCEDURE ShowPlatformsHelp LOCAL idx @@ -545,3 +549,5 @@ PROCEDURE ShowPlatformsHelp ShowSubHelp( Decode( "PLATFORMS", NIL, p_aPlatforms[ idx ][ 1 ] ), 1, 6, idx ) ShowSubHelp( "", 1, 0 ) NEXT + + RETURN