⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ltest.c

📁 lzo-1.08-src.zip 高效的压缩解压代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ltest.c -- very comprehensive test driver for the LZO library   This file is part of the LZO real-time data compression library.   Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer   All Rights Reserved.   The LZO library 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 of   the License, or (at your option) any later version.   The LZO library 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 the LZO library; see the file COPYING.   If not, write to the Free Software Foundation, Inc.,   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.   Markus F.X.J. Oberhumer   <markus@oberhumer.com> */#include <lzoconf.h>#if defined(LZO_HAVE_CONFIG_H)#  include <config.h>#  include <sys/types.h>#endif#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <ctype.h>#include <limits.h>#include <assert.h>#if defined(__DJGPP__) || defined(__BORLANDC__)#  include <dir.h>#endif#if defined(HAVE_UNISTD_H) || defined(__DJGPP__) || defined(__EMX__)#  include <unistd.h>#endif#include <lzoutil.h>#if defined(__LZO_DOS) || defined(__LZO_WIN)#  define HAVE_STRICMP 1#  define HAVE_STRNICMP 1#endif#if defined(HAVE_STRNICMP) && !defined(HAVE_STRNCASECMP)#  define strncasecmp	strnicmp#endif#if 0#  define is_digit(x)	(isdigit((unsigned char)(x)))#  define is_space(x)	(isspace((unsigned char)(x)))#else#  define is_digit(x)	((unsigned)(x) - '0' <= 9)#  define is_space(x)	((x)==' ' || (x)=='\t' || (x)=='\r' || (x)=='\n')#endif/*************************************************************************// getopt & high resolution timer**************************************************************************/#include "mygetopt.h"#include "mygetopt.ch"#include "timer.h"/*************************************************************************// compression include section**************************************************************************/#define HAVE_LZO1_H#define HAVE_LZO1A_H#define HAVE_LZO1B_H#define HAVE_LZO1C_H#define HAVE_LZO1F_H#define HAVE_LZO1X_H#define HAVE_LZO1Y_H#define HAVE_LZO1Z_H#define HAVE_LZO2A_H#if 1 && defined(MFX) && !defined(LZO_HAVE_CONFIG_H) && !defined(HAVE_ZLIB_H)#define HAVE_ZLIB_H#endif#if defined(NO_ZLIB_H)#undef HAVE_ZLIB_H#endif#if defined(__LZO_DOS16)/* don't make this test program too big */#undef HAVE_LZO1_H#undef HAVE_LZO1A_H#undef HAVE_LZO1C_H#undef HAVE_LZO1Z_H#undef HAVE_LZO2A_H#undef HAVE_LZO2B_H#undef HAVE_ZLIB_H#endif/* LZO algorithms */#if defined(HAVE_LZO1_H)#  include <lzo1.h>#endif#if defined(HAVE_LZO1A_H)#  include <lzo1a.h>#endif#if defined(HAVE_LZO1B_H)#  include <lzo1b.h>#endif#if defined(HAVE_LZO1C_H)#  include <lzo1c.h>#endif#if defined(HAVE_LZO1F_H)#  include <lzo1f.h>#endif#if defined(HAVE_LZO1X_H)#  include <lzo1x.h>#endif#if defined(HAVE_LZO1Y_H)#  include <lzo1y.h>#endif#if defined(HAVE_LZO1Z_H)#  include <lzo1z.h>#endif#if defined(HAVE_LZO2A_H)#  include <lzo2a.h>#endif#if defined(HAVE_LZO2B_H)#  include <lzo2b.h>#endif/* other compressors */#if defined(HAVE_ZLIB_H)#  include <zlib.h>#  define ALG_ZLIB#endif#if defined(MFX)#  include "maint/t_config.ch"#endif/*************************************************************************// enumerate all methods**************************************************************************/enum {/* compression algorithms */	M_LZO1B_1     =     1,	M_LZO1B_2, M_LZO1B_3, M_LZO1B_4, M_LZO1B_5,	M_LZO1B_6, M_LZO1B_7, M_LZO1B_8, M_LZO1B_9,	M_LZO1C_1     =    11,	M_LZO1C_2, M_LZO1C_3, M_LZO1C_4, M_LZO1C_5,	M_LZO1C_6, M_LZO1C_7, M_LZO1C_8, M_LZO1C_9,	M_LZO1        =    21,	M_LZO1A       =    31,	M_LZO1B_99    =   901,	M_LZO1B_999   =   902,	M_LZO1C_99    =   911,	M_LZO1C_999   =   912,	M_LZO1_99     =   921,	M_LZO1A_99    =   931,	M_LZO1F_1     =    61,	M_LZO1F_999   =   962,	M_LZO1X_1     =    71,	M_LZO1X_1_11  =   111,	M_LZO1X_1_12  =   112,	M_LZO1X_1_15  =   115,	M_LZO1XT_1    =   171,	M_LZO1X_999   =   972,	M_LZO1Y_1     =    81,	M_LZO1Y_999   =   982,	M_LZO1Z_999   =   992,	M_LZO2A_999   =   942,	M_LZO2B_999   =   952,	M_LAST_LZO_COMPRESSOR = 998,/* other compressors */#if defined(ALG_ZLIB)	M_ZLIB_8_1 =  1101,	M_ZLIB_8_2, M_ZLIB_8_3, M_ZLIB_8_4, M_ZLIB_8_5,	M_ZLIB_8_6, M_ZLIB_8_7, M_ZLIB_8_8, M_ZLIB_8_9,#endif/* dummy compressor - for speed comparision */	M_MEMCPY      =   999,	M_LAST_COMPRESSOR = 4999,/* dummy algorithms - for speed comparision */	M_MEMSET      =  5001,/* checksum algorithms - for speed comparision */	M_ADLER32     =  6001,	M_CRC32       =  6002,#if defined(ALG_ZLIB)	M_Z_ADLER32   =  6011,	M_Z_CRC32     =  6012,#endif	M_UNUSED};#if defined(LZO_99_UNSUPPORTED)#define M_LZO1_99		(-1)#define M_LZO1A_99		(-1)#define M_LZO1B_99		(-1)#define M_LZO1C_99		(-1)#endif#if defined(LZO_999_UNSUPPORTED)#define M_LZO1B_999		(-1)#define M_LZO1C_999		(-1)#define M_LZO1F_999		(-1)#define M_LZO1X_999		(-1)#define M_LZO1Y_999		(-1)#define M_LZO1Z_999		(-1)#define M_LZO2A_999		(-1)#define M_LZO2B_999		(-1)#endif/*************************************************************************// command line options**************************************************************************/#if defined(MAINT)int opt_verbose = 1;#elseint opt_verbose = 2;#endifint opt_c_loops = 0;int opt_d_loops = 0;const char *opt_calgary_corpus_path = NULL;const char *opt_dump_compressed_data = NULL;lzo_bool opt_use_safe_decompressor = 0;lzo_bool opt_use_asm_decompressor = 0;lzo_bool opt_use_asm_fast_decompressor = 0;lzo_bool opt_optimize_compressed_data = 0;int opt_dict = 0;lzo_int opt_max_dict_len = LZO_INT_MAX;const char *opt_dictionary_file = NULL;lzo_bool opt_read_from_stdin = 0;/* set these to 1 to measure the speed impact of a checksum */lzo_bool opt_compute_adler32 = 0;lzo_bool opt_compute_crc32 = 0;static lzo_uint32 adler_in, adler_out;static lzo_uint32 crc_in, crc_out;lzo_bool opt_execution_time = 0;lzo_bool opt_totals = 0;static unsigned long total_n = 0;static unsigned long total_c_len = 0;static unsigned long total_d_len = 0;static unsigned long total_blocks = 0;static double total_c_kbs = 0.0;static double total_d_kbs = 0.0;lzo_bool opt_query = 0;		/* query interface is not implemented yet */static const lzo_bool opt_try_to_compress_0_bytes = 1;static const char *argv0 = "";#if defined(HAVE_LZO1X_H)int default_method = M_LZO1X_1;#elif defined(HAVE_LZO1B_H)int default_method = M_LZO1B_1;#elif defined(HAVE_LZO1C_H)int default_method = M_LZO1C_1;#elif defined(HAVE_LZO1F_H)int default_method = M_LZO1F_1;#elif defined(HAVE_LZO1Y_H)int default_method = M_LZO1Y_1;#elseint default_method = M_MEMCPY;#endifstatic const int benchmark_methods[] = {	M_LZO1B_1, M_LZO1B_9,	M_LZO1C_1, M_LZO1C_9,	M_LZO1F_1,	M_LZO1X_1,	0};static const int x1_methods[] = {	M_LZO1, M_LZO1A, M_LZO1B_1, M_LZO1C_1, M_LZO1F_1, M_LZO1X_1, M_LZO1Y_1,	0};static const int x99_methods[] = {	M_LZO1_99, M_LZO1A_99, M_LZO1B_99, M_LZO1C_99,	0};static const int x999_methods[] = {	M_LZO1B_999, M_LZO1C_999, M_LZO1F_999, M_LZO1X_999, M_LZO1Y_999,	M_LZO1Z_999,	M_LZO2A_999,	0};/* exit codes of this test program */#define EXIT_OK			0#define EXIT_USAGE		1#define EXIT_FILE		2#define EXIT_MEM		3#define EXIT_ADLER		4#define EXIT_LZO_ERROR	5#define EXIT_LZO_INIT	6#define EXIT_INTERNAL	7/*************************************************************************// memory setup**************************************************************************/#if 0 && (UINT_MAX >= LZO_0xffffffffL)#define USE_MALLOC#endif#if defined(__LZO_STRICT_16BIT)#define BLOCK_SIZE		32000u#define MAX_BLOCK_SIZE	(55*1024u)#define DATA_LEN		(63*1024u)#define WRK_LEN			(32*1024u)#elif defined(__LZO_TOS) || defined(__LZO_WIN16)/* adjust memory so that it works on a 4 meg machine */#define BLOCK_SIZE		(256*1024l)#define MAX_BLOCK_SIZE	(1*BLOCK_SIZE)#define DATA_LEN		(1024*1024l)#define WRK_LEN			(768*1024l)#define USE_CORPUS#elif (UINT_MAX >= LZO_0xffffffffL)		/* 32 bit or more */#define BLOCK_SIZE		(256*1024l)#define MAX_BLOCK_SIZE	(5*256*1024l)#define DATA_LEN		(5*256*1024l)#ifndef WRK_LEN#define WRK_LEN			(768*1024l * ((sizeof(long)+3)/4))#endif#define DICT_LEN		0xbfff#define USE_DUMP#define USE_CORPUS#else/* DOS 16 bit - have to squeeze everything into ~600 kB  */#define BLOCK_SIZE		32000u#define MAX_BLOCK_SIZE	40000u#define DATA_LEN		(64*1024l)#define WRK_LEN			(64*1024l)#endifstatic lzo_uint opt_block_size = BLOCK_SIZE;static lzo_uint opt_max_data_len = 0;static lzo_byte _block1[MAX_BLOCK_SIZE * 9L / 8 + 256 + 1024];static lzo_byte _block2[MAX_BLOCK_SIZE * 9L / 8 + 256 + 1024];static lzo_byte _wrkmem[16 + WRK_LEN + 256 + 16];#ifdef USE_MALLOC#undef DATA_LENstatic lzo_byte *_data = NULL;#elsestatic lzo_byte _data[DATA_LEN + 256];#endif#ifdef DICT_LEN#define USE_DICTstatic lzo_byte _dict[DICT_LEN];static lzo_byte *dict = _dict;static lzo_uint32 dict_adler32;#elsestatic lzo_byte *dict = NULL;#endifstatic lzo_uint dict_len = 0;/* align memory blocks (cache issues) */static lzo_byte *block1 = NULL;static lzo_byte *block2 = NULL;static lzo_byte *wrkmem = NULL;static lzo_byte *data   = NULL;static void align_mem(void){	block1 = LZO_PTR_ALIGN_UP(_block1,256);	block2 = LZO_PTR_ALIGN_UP(_block2,256);	wrkmem = LZO_PTR_ALIGN_UP(_wrkmem+16,256);}/* lock all memory to avoid any swapping to disk */#if 0 && defined(__DJGPP__)#  include <crt0.h>   int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;#endif/*************************************************************************// dictionary support**************************************************************************/#ifdef USE_DICTstatic void init_default_dict(void){	lzo_uint i, j, d, dd;	dict_len = DICT_LEN;	lzo_memset(dict,0,dict_len);	/* this default dictionary does not provide good contexts... */	dd = dict_len;	if (dd >= 16 * 256)	{		dd -= 16 * 256;		for (i = 0, d = dd; i < 256; i++)			for (j = 0; j < 16; j++)				dict[d++] = (unsigned char) i;	}	dict_adler32 = lzo_adler32(0,NULL,0);	dict_adler32 = lzo_adler32(dict_adler32,dict,dict_len);}static void read_dict(const char *file_name){	FILE *f;	dict_len = 0;	f = fopen(file_name,"rb");	if (f)	{		dict_len = lzo_fread(f,dict,DICT_LEN);		fclose(f);		dict_adler32 = lzo_adler32(0,NULL,0);		dict_adler32 = lzo_adler32(dict_adler32,dict,dict_len);	}}#endif/*************************************************************************// compression database**************************************************************************/typedef struct{	const char *			name;	int 					id;	lzo_uint32				mem_compress;	lzo_uint32				mem_decompress;	lzo_compress_t			compress;	lzo_optimize_t			optimize;	lzo_decompress_t		decompress;	lzo_decompress_asm_t	decompress_safe;	lzo_decompress_asm_t	decompress_asm;	lzo_decompress_asm_t	decompress_asm_safe;	lzo_decompress_asm_t	decompress_asm_fast;	lzo_decompress_asm_t	decompress_asm_fast_safe;	lzo_compress_dict_t		compress_dict;	lzo_decompress_dict_t	decompress_dict_safe;}compress_t;#include "asm.h"#include "wrap.h"#define M_PRIVATE       LZO_PRIVATE#define m_uint          lzo_uint#define m_uint32        lzo_uint32#define m_voidp         lzo_voidp#define m_bytep         lzo_bytep#define m_uintp         lzo_uintp#include "wrapmisc.h"static const compress_t compress_database[] = {#include "db.h"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -