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.
This commit is contained in:
Viktor Szakats
2010-12-10 14:16:07 +00:00
parent 5fa82b6bc6
commit 9edef1b7dd
6 changed files with 123 additions and 48 deletions

View File

@@ -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( <cData>, [<nDstBufLen>|<@cBuffer>], [<@nResult>] )
=> <cCompressedData> or NIL on Error
(suggested by Przemek)

View File

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

View File

@@ -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_ */

View File

@@ -16,6 +16,8 @@
-depincpathlocal=lzf:3rd/liblzf
-depfinish=lzf
-instfile=inc:hblzf.ch
hblzf.c
3rd/liblzf/lzf.hbc{HBMK_HAS_LZF_LOCAL}

View File

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

View File

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