From aec8ebcb8546740edb16fa790ddcf76276e16169 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Tue, 10 Nov 2009 18:32:19 +0000 Subject: [PATCH] 2009-11-10 19:31 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbcdpreg.h * use macro instead of direct value * harbour/tests/cpinfo.prg + generate .c files with CP definition in human readable form when it's can be safely use or with optional binary table when it should be verified if such form is acceptable. --- harbour/ChangeLog | 9 +++++ harbour/include/hbcdpreg.h | 2 +- harbour/tests/cpinfo.prg | 78 ++++++++++++++++++++++++++------------ 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4598513e0b..fec5181ad7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,15 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-11-10 19:31 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbcdpreg.h + * use macro instead of direct value + + * harbour/tests/cpinfo.prg + + generate .c files with CP definition in human readable form + when it's can be safely use or with optional binary table when + it should be verified if such form is acceptable. + 2009-11-10 18:54 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * tests/cpinfo.prg + Avoiding memowrit() since it will append a Chr(26) which diff --git a/harbour/include/hbcdpreg.h b/harbour/include/hbcdpreg.h index a2e97b224d..a76f8d9827 100644 --- a/harbour/include/hbcdpreg.h +++ b/harbour/include/hbcdpreg.h @@ -67,7 +67,7 @@ HB_CALL_ON_STARTUP_BEGIN( _hb_codepage_Init_ ) s_lower, s_sort, NULL, - 0, + HB_CDP_ACSORT_NONE, 0, 0, NULL, diff --git a/harbour/tests/cpinfo.prg b/harbour/tests/cpinfo.prg index 3d44025761..39ae504760 100644 --- a/harbour/tests/cpinfo.prg +++ b/harbour/tests/cpinfo.prg @@ -33,10 +33,6 @@ proc main( cdp, info, unicode ) lEqual := .f. #endif - if !empty( cdp ) - my_memowrit( "cp" + lower( cdp ) + ".c", genCP( cdp, info, unicode ) ) - endif - a := array( 256 ) for i := 1 to len( a ) a[ i ] := i - 1 @@ -246,6 +242,12 @@ proc main( cdp, info, unicode ) endif ? repl( "=", 50 ) ? + + if !empty( cdp ) + write_file( "cp" + lower( cdp ) + ".c", ; + genCP( cdp, info, unicode, lBin, lWarn, cUp, cLo ) ) + endif + return static function pad_letters( cUp, cLo ) @@ -315,7 +317,19 @@ return cInfo #define HB_CDP_LOWER 4 #define HB_CDP_UPPER 8 -static function genCP( id, info, unicode ) +static function write_file( cName, cBody ) + local lRet := .f. + local hFile + + hFile := fcreate( cName ) + if hFile != F_ERROR + lRet := fwrite( hFile, cBody, len( cBody ) ) == len( cBody ) + fclose( hFile ) + endif + +return lRet + +static function genCP( id, info, unicode, lBin, lWarn, cUp, cLo ) local flags[ 256 ], upper[ 256 ], lower[ 256 ], sort[ 256 ], tmp[ 256 ] local i, c @@ -366,10 +380,14 @@ static function genCP( id, info, unicode ) sort[ tmp[ i ] + 1 ] := i - 1 next - return genCPfile( id, info, unicode, flags, upper, lower, sort ) + return genCPfile( id, info, unicode, flags, upper, lower, sort, ; + lBin, lWarn, cUp, cLo ) -static function genCPfile( id, info, unicode, flags, upper, lower, sort ) - local cDef := ; +static function genCPfile( id, info, unicode, flags, upper, lower, sort, ; + lBin, lWarn, cUp, cLo ) + local cDef + + cDef := ; '/*' + EOL + ' * $Id$' + EOL + ' */' + EOL + EOL + ; '/*' + EOL + ; ' * Harbour Project source code:' + EOL + ; @@ -382,13 +400,34 @@ static function genCPfile( id, info, unicode, flags, upper, lower, sort ) ' */' + EOL + EOL + ; '#define HB_CP_ID $1' + EOL + ; '#define HB_CP_INFO "$2"' + EOL + ; - '#define HB_CP_UNITB HB_UNITB_$3' + EOL + EOL + ; - '#define HB_CP_RAW' + EOL + EOL + ; - 'static const unsigned char s_flags[ 256 ] = { $f };' + EOL + ; - 'static const unsigned char s_upper[ 256 ] = { $u };' + EOL + ; - 'static const unsigned char s_lower[ 256 ] = { $l };' + EOL + ; - 'static const unsigned char s_sort [ 256 ] = { $s };' + EOL + ; - EOL + ; + '#define HB_CP_UNITB HB_UNITB_$3' + EOL + if !lBin + cDef += ; + '#define HB_CP_ACSORT HB_CDP_ACSORT_NONE' + EOL + ; + '#define HB_CP_UPPER "' + cUp + '"' + EOL + ; + '#define HB_CP_LOWER "' + cLo + '"' + EOL + ; + EOL + if lWarn + cDef += ; + '#if 0 /* TOVERIFY: binary tables */' + EOL + endif + endif + if lBin .or. lWarn + cDef += ; + EOL + ; + '#define HB_CP_RAW' + EOL + EOL + ; + 'static const unsigned char s_flags[ 256 ] = { $f };' + EOL + ; + 'static const unsigned char s_upper[ 256 ] = { $u };' + EOL + ; + 'static const unsigned char s_lower[ 256 ] = { $l };' + EOL + ; + 'static const unsigned char s_sort [ 256 ] = { $s };' + EOL + ; + EOL + if !lBin + cDef += ; + '#endif' + EOL + EOL + EOL + endif + endif + cDef += ; '/* include CP registration code */' + EOL + ; '#include "hbcdpreg.h"' + EOL @@ -407,12 +446,3 @@ func a2def( a ) cData += iif( i == 1, "", "," ) + ltrim( str( a[ i ] ) ) next return cData - -static func my_memowrit( fname, data ) - local f := fcreate( fname ) - local r := .f. - if f != F_ERROR - r := ( fwrite( f, data ) == Len( data ) ) - fclose( f ) - endif -return r