From 9edef1b7ddd2d3681aceabf6a310c04eed12ebcb Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 10 Dec 2010 14:16:07 +0000 Subject: [PATCH] 2010-12-10 15:14 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * contrib/hblzf/tests/test.prg * contrib/hblzf/hblzf.c * contrib/hblzf/hblzf.hbp + contrib/hblzf/hblzf.ch * Re-renamed HB_LZF_*() pure wrapper functions to LZF_*(). % Deleted unnecessary HB_SIZE casts. ! Fixed formatting to Harbour standard in new code. ! Added HB_ prefix to locally rolled macros. + Moved locally rolled macros to separate .ch file. ! Fixed test to use hblzf.ch instead of repeating macro definitions. ; TOFIX: errno.h. Replace with HB_LZF_* values? * tests/wvtext.prg ! Fixed -w3 warnings. --- harbour/ChangeLog | 18 +++++++- harbour/contrib/hblzf/hblzf.c | 35 +++++++--------- harbour/contrib/hblzf/hblzf.ch | 63 ++++++++++++++++++++++++++++ harbour/contrib/hblzf/hblzf.hbp | 2 + harbour/contrib/hblzf/tests/test.prg | 43 +++++++++---------- harbour/tests/wvtext.prg | 10 +++-- 6 files changed, 123 insertions(+), 48 deletions(-) create mode 100644 harbour/contrib/hblzf/hblzf.ch diff --git a/harbour/ChangeLog b/harbour/ChangeLog index a39160dfee..32e8f663cb 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,11 +16,27 @@ The license applies to all entries newer than 2009-04-28. */ +2010-12-10 15:14 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hblzf/tests/test.prg + * contrib/hblzf/hblzf.c + * contrib/hblzf/hblzf.hbp + + contrib/hblzf/hblzf.ch + * Re-renamed HB_LZF_*() pure wrapper functions to LZF_*(). + % Deleted unnecessary HB_SIZE casts. + ! Fixed formatting to Harbour standard in new code. + ! Added HB_ prefix to locally rolled macros. + + Moved locally rolled macros to separate .ch file. + ! Fixed test to use hblzf.ch instead of repeating macro definitions. + ; TOFIX: errno.h. Replace with HB_LZF_* values? + + * tests/wvtext.prg + ! Fixed -w3 warnings. + 2010-12-10 15:30 UTC+0200 Petr Chornyj (myorg63 at mail.ru) * contrib/hblzf/hblzf.c * contrib/hblzf/tests/test.prg * Renamed LZF_COMPRESS() to HB_LZF_COMPRESS() - ! Changed syntax of HB_LZF_COMPRESS() to + ! Changed syntax of HB_LZF_COMPRESS() to HB_LZF_COMPRESS( , [|<@cBuffer>], [<@nResult>] ) => or NIL on Error (suggested by Przemek) diff --git a/harbour/contrib/hblzf/hblzf.c b/harbour/contrib/hblzf/hblzf.c index 9a663a76f5..c3bbb2e6f8 100644 --- a/harbour/contrib/hblzf/hblzf.c +++ b/harbour/contrib/hblzf/hblzf.c @@ -60,9 +60,7 @@ #include "lzf.h" #include "lzfP.h" -#define LZF_OK 0 -#define LZF_BUF_ERROR 1 -#define LZF_MEM_ERROR 2 +#include "hblzf.ch" /** Return a LZF_VERSION, API version @@ -88,12 +86,11 @@ HB_FUNC( HB_LZF_OPTIMIZED_FOR_SPEED ) HB_FUNC( HB_LZF_COMPRESSBOUND ) { - if ( HB_ISCHAR(1) || HB_ISNUM(1) ) + if( HB_ISCHAR( 1 ) || HB_ISNUM( 1 ) ) { - HB_SIZE nLen = HB_ISCHAR(1) ? hb_parclen( 1 ) : (HB_SIZE) hb_parns(1); - nLen = (HB_SIZE) ( nLen * 1.04 + 1 ); - hb_retns( nLen ); - } + HB_SIZE nLen = HB_ISCHAR( 1 ) ? hb_parclen( 1 ) : hb_parns( 1 ); + hb_retns( ( HB_SIZE ) ( nLen * 1.04 + 1 ) ); + } else hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } @@ -102,7 +99,7 @@ HB_FUNC( HB_LZF_COMPRESSBOUND ) Return a string compressed with LZF */ -HB_FUNC( HB_LZF_COMPRESS ) +HB_FUNC( LZF_COMPRESS ) { PHB_ITEM pArg = hb_param( 1, HB_IT_STRING ); @@ -119,13 +116,13 @@ HB_FUNC( HB_LZF_COMPRESS ) if( pBuffer ) { - if( !hb_itemGetWriteCL( pBuffer, &out_data, &out_len ) ) + if( ! hb_itemGetWriteCL( pBuffer, &out_data, &out_len ) ) out_data = NULL; } else { - out_len = ( HB_ISNUM( 2 ) && hb_parns( 2 ) >= 0 ) ? - ( HB_SIZE ) hb_parns( 2 ) : + out_len = ( HB_ISNUM( 2 ) && hb_parns( 2 ) >= 0 ) ? + hb_parns( 2 ) : ( HB_SIZE ) ( in_len * 1.04 + 1 ); out_data = ( char * ) hb_xalloc( out_len + 1 ); @@ -142,23 +139,23 @@ HB_FUNC( HB_LZF_COMPRESS ) else hb_retclen( out_data, uiResult ); - hb_storni( LZF_OK, 3 ); + hb_storni( HB_LZF_OK, 3 ); } else { if( !pBuffer ) hb_xfree( out_data ); - hb_storni( LZF_BUF_ERROR, 3 ); - } + hb_storni( HB_LZF_BUF_ERROR, 3 ); + } } else - hb_storni( LZF_MEM_ERROR, 3 ); + hb_storni( HB_LZF_MEM_ERROR, 3 ); } else { hb_retc_null(); - hb_storni( LZF_OK, 3 ); + hb_storni( HB_LZF_OK, 3 ); } } else @@ -201,11 +198,7 @@ HB_FUNC( LZF_DECOMPRESS ) if( uiResult == 0 ) { if( errno == EINVAL ) - { - HB_TRACE( HB_TR_DEBUG, "LZF decompression failed, compressed data corrupted" ); - hb_storni( errno, 2 ); - } hb_xfree( buffer ); hb_retc_null(); diff --git a/harbour/contrib/hblzf/hblzf.ch b/harbour/contrib/hblzf/hblzf.ch new file mode 100644 index 0000000000..8a88d1ad86 --- /dev/null +++ b/harbour/contrib/hblzf/hblzf.ch @@ -0,0 +1,63 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * LZF API - Harbour header + * + * Copyright 2010 Viktor Szakats (harbour.01 syenar.hu) + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* NOTE: This file is also used by C code. */ + +#ifndef HBLZF_CH_ +#define HBLZF_CH_ + +#define HB_LZF_OK 0 +#define HB_LZF_BUF_ERROR 1 +#define HB_LZF_MEM_ERROR 2 +#define HB_LZF_DATA_CORRUPTED 22 + +#endif /* HBLZF_CH_ */ diff --git a/harbour/contrib/hblzf/hblzf.hbp b/harbour/contrib/hblzf/hblzf.hbp index 117b139eaa..e77a9cd8bb 100644 --- a/harbour/contrib/hblzf/hblzf.hbp +++ b/harbour/contrib/hblzf/hblzf.hbp @@ -16,6 +16,8 @@ -depincpathlocal=lzf:3rd/liblzf -depfinish=lzf +-instfile=inc:hblzf.ch + hblzf.c 3rd/liblzf/lzf.hbc{HBMK_HAS_LZF_LOCAL} diff --git a/harbour/contrib/hblzf/tests/test.prg b/harbour/contrib/hblzf/tests/test.prg index e73fea58f4..78095904ce 100644 --- a/harbour/contrib/hblzf/tests/test.prg +++ b/harbour/contrib/hblzf/tests/test.prg @@ -4,14 +4,11 @@ #include "simpleio.ch" +#include "hblzf.ch" + #define TEST_STRING "This is test of LZF extension" #define _NREPL_ 128 -#define LZF_OK 0 -#define LZF_BUF_ERROR 1 -#define LZF_MEM_ERROR 2 -#define LZF_DATA_CORRUPTED 22 - PROCEDURE Main() LOCAL cStr, str_compressed, str_decompressed LOCAL b64_expected_result := "BFRoaXMgIAIUdGVzdCBvZiBMWkYgZXh0ZW5zaW9u" @@ -24,43 +21,43 @@ PROCEDURE Main() ? "--- test 1 ---" /* If the output buffer is not large enough or any error occurs - hb_lzf_compress return NIL + lzf_compress return NIL */ cStr := TEST_STRING - str_compressed := hb_lzf_compress( cStr, 15, @nResult ) + str_compressed := lzf_compress( cStr, 15, @nResult ) - IF nResult == LZF_OK + IF nResult == HB_LZF_OK ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) ELSE - ? "hb_lzf_compress() return ", iif( nResult == LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) + ? "lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) ENDIF ? "--- test 2 ---" cStr := TEST_STRING str_compressed := Space( 15 ) - str_compressed := hb_lzf_compress( cStr, @str_compressed, @nResult ) + str_compressed := lzf_compress( cStr, @str_compressed, @nResult ) - IF nResult == LZF_OK + IF nResult == HB_LZF_OK ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) ELSE - ? "hb_lzf_compress() return ", iif( nResult == LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) + ? "lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) ENDIF ? "--- test 3 ---" nLen := hb_lzf_compressBound( cStr ) cStr := TEST_STRING - str_compressed := hb_lzf_compress( cStr, nLen, @nResult ) + str_compressed := lzf_compress( cStr, nLen, @nResult ) - IF nResult == LZF_OK + IF nResult == HB_LZF_OK ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) ? hb_base64encode( str_compressed ) == b64_expected_result ELSE - ? "hb_lzf_compress() return ", iif( nResult == LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) + ? "lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) ENDIF ? "--- test 4 ---" @@ -68,32 +65,32 @@ PROCEDURE Main() str_compressed := Space( nLen ) cStr := TEST_STRING - str_compressed := hb_lzf_compress( cStr, @str_compressed, @nResult ) + str_compressed := lzf_compress( cStr, @str_compressed, @nResult ) - IF nResult == LZF_OK + IF nResult == HB_LZF_OK ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) ? hb_base64encode( str_compressed ) == b64_expected_result ELSE - ? "hb_lzf_compress() return ", iif( nResult == LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) + ? "lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) ENDIF ? "--- test 5 ---" cStr := Replicate( TEST_STRING, _NREPL_ ) - str_compressed := hb_lzf_compress( cStr, NIL, @nResult ) + str_compressed := lzf_compress( cStr, NIL, @nResult ) - IF nResult == LZF_OK + IF nResult == HB_LZF_OK ? "Lenght of a string is", hb_ntos( Len( cStr ) ) ? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) ) ELSE - ? "hb_lzf_compress() return ", iif( nResult == LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) + ? "lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" ) ENDIF ? "--- test 6 ---" str_decompressed := lzf_decompress( str_compressed, @errno, NIL ) - IF errno == LZF_DATA_CORRUPTED + IF errno == HB_LZF_DATA_CORRUPTED ? "LZF decompression failed, compressed data corrupted" ELSE ? cStr == str_decompressed @@ -105,7 +102,7 @@ PROCEDURE Main() str_decompressed := lzf_decompress( str_compressed, @errno, NIL ) - IF errno == LZF_DATA_CORRUPTED + IF errno == HB_LZF_DATA_CORRUPTED ? "LZF decompression failed, compressed data corrupted !" ELSE ? cStr == str_decompressed diff --git a/harbour/tests/wvtext.prg b/harbour/tests/wvtext.prg index d9705c187f..bb615f382a 100644 --- a/harbour/tests/wvtext.prg +++ b/harbour/tests/wvtext.prg @@ -32,11 +32,11 @@ PROCEDURE Main() LOCAL nKey, lMark, lResize, lClose LOCAL nHeight := 20 LOCAL nWidth := Int( nHeight / 2 ) - LOCAL cFont +// LOCAL cFont LOCAL nMSec - Hb_GtInfo( HB_GTI_FONTNAME , cFont ) +// Hb_GtInfo( HB_GTI_FONTNAME , cFont ) Hb_GtInfo( HB_GTI_FONTWIDTH, nWidth ) Hb_GtInfo( HB_GTI_FONTSIZE , nHeight ) SetCursor( SC_NONE ) @@ -122,7 +122,7 @@ PROCEDURE Main() //----------------------------------------------------------------------// STATIC PROCEDURE DispScreen() - LOCAL nRow := 11, nCol := 28 + LOCAL nRow := 11 LOCAL cColor := "N/W" LOCAL nMaxCol := MaxCol() + 1 @@ -307,6 +307,8 @@ STATIC FUNCTION TBNext( oTbr ) LOCAL nSaveRecNum := recno() LOCAL lMoved := .T. + HB_SYMBOL_UNUSED( oTbr ) + if Eof() lMoved := .F. else @@ -323,6 +325,8 @@ STATIC FUNCTION TBPrev( oTbr ) LOCAL nSaveRecNum := Recno() LOCAL lMoved := .T. + HB_SYMBOL_UNUSED( oTbr ) + DBSkip( -1 ) if Bof()