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

📄 ltest.c

📁 lzo-1.08-src.zip 高效的压缩解压代码
💻 C
📖 第 1 页 / 共 4 页
字号:
"\n""   Markus F.X.J. Oberhumer\n""   <markus.oberhumer@jk.uni-linz.ac.at>\n""   http://www.oberhumer.com/opensource/lzo/\n""\n"	);	fflush(f);	exit(EXIT_OK);}/*************************************************************************// parse method option '-m'**************************************************************************/static int methods[256+1];static int methods_n = 0;static void add_method(int m){	int i;	if (m > 0)	{		if (!info(m,NULL))			info(m,stdout);		for (i = 0; i < methods_n; i++)			if (methods[i] == m)				return;		if (methods_n >= 256)		{			fprintf(stderr,"%s: too many methods\n",argv0);			exit(EXIT_USAGE);		}		methods[methods_n++] = m;		methods[methods_n] = 0;	}}static void add_methods(const int *ml){	while (*ml != 0)		add_method(*ml++);}static void add_all_methods(int first, int last){	int m;	for (m = first; m <= last; m++)		if (info(m,NULL) != NULL)			add_method(m);}static int m_strcmp(const char *a, const char *b){	size_t n;	if (a[0] == 0 || b[0] == 0)		return 1;	n = strlen(b);	if (strncmp(a,b,n) == 0 && (a[n] == 0 || a[n] == ','))		return 0;	return 1;}static lzo_bool m_strisdigit(const char *s){	for (;;)	{		if (!is_digit(*s))			return 0;		s++;		if (*s == 0 || *s == ',')			return 1;	}}static void parse_methods(const char *p){	const compress_t *c;	for (;;)	{		if (p == NULL || p[0] == 0)			usage(argv0,-1,1);		else if ((c = find_method(p)) != NULL)			add_method(c->id);		else if (m_strcmp(p,"all") == 0 || m_strcmp(p,"avail") == 0)			add_all_methods(1,M_LAST_COMPRESSOR);		else if (m_strcmp(p,"ALL") == 0)		{			add_all_methods(1,M_LAST_COMPRESSOR);			add_all_methods(9721,9729);			add_all_methods(9781,9789);		}		else if (m_strcmp(p,"lzo") == 0)			add_all_methods(1,M_MEMCPY);		else if (m_strcmp(p,"bench") == 0)			add_methods(benchmark_methods);		else if (m_strcmp(p,"m1") == 0)			add_methods(x1_methods);		else if (m_strcmp(p,"m99") == 0)			add_methods(x99_methods);		else if (m_strcmp(p,"m999") == 0)			add_methods(x999_methods);		else if (m_strcmp(p,"1x999") == 0)			add_all_methods(9721,9729);		else if (m_strcmp(p,"1y999") == 0)			add_all_methods(9821,9829);#if defined(ALG_ZLIB)		else if (m_strcmp(p,"zlib") == 0)			add_all_methods(M_ZLIB_8_1,M_ZLIB_8_9);#endif#if defined(MFX)#  include "maint/t_opt_m.ch"#endif		else if (m_strisdigit(p))			add_method(atoi(p));		else		{			printf("%s: invalid method '%s'\n\n",argv0,p);			exit(EXIT_USAGE);		}		while (*p && *p != ',')			p++;		while (*p == ',')			p++;		if (*p == 0)			return;	}}/*************************************************************************// options**************************************************************************/enum {	OPT_LONGOPT_ONLY = 512,	OPT_ADLER32,	OPT_CALGARY_CORPUS,	OPT_CRC32,	OPT_DICT,	OPT_DUMP,	OPT_EXECUTION_TIME,	OPT_MAX_DATA_LEN,	OPT_MAX_DICT_LEN,	OPT_QUERY,	OPT_UNUSED};static const struct mfx_option longopts[] ={ /* { name  has_arg  *flag  val } */    {"help",             0, 0, 'h'+256}, /* give help */    {"license",          0, 0, 'L'},     /* display software license */    {"quiet",            0, 0, 'q'},     /* quiet mode */    {"verbose",          0, 0, 'v'},     /* verbose mode */    {"version",          0, 0, 'V'+256}, /* display version number */    {"adler32",          0, 0, OPT_ADLER32},#ifdef USE_CORPUS    {"calgary-corpus",   1, 0, OPT_CALGARY_CORPUS},    {"corpus",           1, 0, OPT_CALGARY_CORPUS},#endif    {"crc32",            0, 0, OPT_CRC32},#ifdef USE_DICT    {"dict",             1, 0, OPT_DICT},#endif#ifdef USE_DUMP    {"dump-compressed",  1, 0, OPT_DUMP},#endif    {"execution-time",   0, 0, OPT_EXECUTION_TIME},    {"max-data-length",  1, 0, OPT_MAX_DATA_LEN},#ifdef USE_DICT    {"max-dict-length",  1, 0, OPT_MAX_DICT_LEN},#endif    {"methods",          1, 0, 'm'},    {"query",            0, 0, OPT_QUERY},    {"totals",           0, 0, 'T'},    { 0, 0, 0, 0 }};static int do_option(int optc){	switch (optc)	{	case 'A':		opt_use_asm_decompressor = 1;		break;	case 'b':		opt_block_size = MAX_BLOCK_SIZE;		if (mfx_optarg)		{			if (!mfx_optarg || !is_digit(mfx_optarg[0]))				return optc;			opt_block_size = atoi(mfx_optarg);		}		break;	case 'c':	case 'C':		if (!mfx_optarg || !is_digit(mfx_optarg[0]))			return optc;		opt_c_loops = atoi(mfx_optarg);		break;	case 'd':	case 'D':		if (!mfx_optarg || !is_digit(mfx_optarg[0]))			return optc;		opt_d_loops = atoi(mfx_optarg);		break;	case 'F':		opt_use_asm_fast_decompressor = 1;		break;	case 'h':	case 'H':	case '?':	case 'h'+256:		usage(argv0,EXIT_OK,0);		break;	case 'L':		license();		break;	case 'm':		parse_methods(mfx_optarg);		break;	case 'n':		if (!mfx_optarg || !is_digit(mfx_optarg[0]))			return optc;		opt_c_loops = opt_d_loops = atoi(mfx_optarg);		break;	case 'O':		opt_optimize_compressed_data = 1;		break;	case 'q':		opt_verbose = (opt_verbose > 1) ? opt_verbose - 1 : 1;		break;	case 'Q':		opt_verbose = 0;		break;#ifdef USE_CORPUS	case 's':	case OPT_CALGARY_CORPUS:		if (!mfx_optarg || !mfx_optarg[0])			return optc;		opt_calgary_corpus_path = mfx_optarg;		break;#endif	case 'S':		opt_use_safe_decompressor = 1;		break;	case 'T':		opt_totals = 1;		break;	case 'v':		opt_verbose = (opt_verbose < 2) ? 2 : opt_verbose + 1;		break;	case 'V':	case 'V'+256:		exit(EXIT_OK);		break;	case '@':		opt_read_from_stdin = 1;		break;	case '1': case '2': case '3': case '4': case '5':	case '6': case '7': case '8': case '9':		/* this is a dirty hack... */		parse_methods(nextchar-1);		if (nextchar[0])		{			nextchar = NULL;			mfx_optind++;		}		break;	case OPT_ADLER32:		opt_compute_adler32 = 1;		break;	case OPT_CRC32:		opt_compute_crc32 = 1;		break;#ifdef USE_DICT	case OPT_DICT:		opt_dict = 1;		opt_dictionary_file = mfx_optarg;		break;#endif	case OPT_EXECUTION_TIME:		opt_execution_time = 1;		break;#ifdef USE_DUMP	case OPT_DUMP:		opt_dump_compressed_data = mfx_optarg;		break;#endif	case OPT_MAX_DATA_LEN:		if (!mfx_optarg || !is_digit(mfx_optarg[0]))			return optc;		opt_max_data_len = atoi(mfx_optarg);		break;#ifdef USE_DICT	case OPT_MAX_DICT_LEN:		if (!mfx_optarg || !(is_digit(mfx_optarg[0]) || mfx_optarg[0] == '-'))			return optc;		opt_max_dict_len = atoi(mfx_optarg);		break;#endif	case OPT_QUERY:		opt_query = 1;		break;	case '\0':		return -1;	case ':':		return -2;	default:		fprintf(stderr,"%s: internal error in getopt (%d)\n",argv0,optc);		return -3;	}	return 0;}static int get_options(int argc, char **argv){	int optc;	mfx_optind = 0;	mfx_opterr = 1;	while ((optc = mfx_getopt_long (argc, argv,#ifdef USE_CORPUS	                  "Ab::c:C:d:D:FhHLm::n:OqQs:STvV@123456789",#else	                  "Ab::c:C:d:D:FhHLm::n:OqQSTvV@123456789",#endif	                  longopts, (int *)0)) >= 0)	{		if (do_option(optc) != 0)			exit(EXIT_USAGE);	}	return mfx_optind;}/*************************************************************************// main**************************************************************************/int main(int argc, char *argv[]){	int r = EXIT_OK;	int i, ii;	int m;	time_t t_total;#if defined(__EMX__)	_response(&argc,&argv);	_wildcard(&argc,&argv);#endif	if (argv[0])		argv0 = argv[0];	align_mem();	(void) my_clock();	printf("\nLZO real-time data compression library (v%s, %s).\n",	        LZO_VERSION_STRING, LZO_VERSION_DATE);	printf("Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer\n\n");	if (lzo_init() != LZO_E_OK)	{		printf("lzo_init() failed !!!\n");		exit(EXIT_LZO_INIT);	}	if (argc < 2)		usage(argv0,-1,0);	i = get_options(argc,argv);	if (methods_n == 0)		add_method(default_method);	if (methods_n > 1 && opt_read_from_stdin)	{		printf("%s: cannot use multiple methods and '-@'\n", argv0);		exit(EXIT_USAGE);	}	if (opt_block_size < 16)		opt_block_size = 16;	if (opt_block_size > MAX_BLOCK_SIZE)		opt_block_size = MAX_BLOCK_SIZE;	dict_len = 0;#ifndef USE_DICT	opt_dict = 0;#else	if (opt_dict)	{		opt_optimize_compressed_data = 0;		if (opt_dictionary_file)		{			read_dict(opt_dictionary_file);			if (opt_max_dict_len > 0 && dict_len > (lzo_uint) opt_max_dict_len)				dict_len = opt_max_dict_len;			if (dict_len > 0)				printf("Using dictionary '%s', %ld bytes, ID 0x%08lx.\n",				        opt_dictionary_file,			            (long) dict_len, (long) dict_adler32);		}		if (dict_len <= 0)		{			init_default_dict();			if (opt_max_dict_len > 0 && dict_len > (lzo_uint) opt_max_dict_len)				dict_len = opt_max_dict_len;			printf("Using default dictionary, %ld bytes, ID 0x%08lx.\n",			        (long) dict_len, (long) dict_adler32);		}		if (opt_max_dict_len == -1)			printf("Dictionary size will be adjusted to file size.\n");		else if (opt_max_dict_len <= 0)			printf("Dictionary size will be adjusted to file size.\n");	}#endif	t_total = time(NULL);	(void) my_clock();	ii = i;	for (m = 0; m < methods_n && r == EXIT_OK; m++)	{		int method = methods[m];		i = ii;		if (i >= argc && opt_calgary_corpus_path == NULL && !opt_read_from_stdin)			usage(argv0,-1,0);		if (m == 0 && opt_verbose >= 1)			printf("%lu block-size\n\n", (long) opt_block_size);		if (!info(method,NULL))			info(method,stdout);#ifdef USE_CORPUS		if (opt_calgary_corpus_path != NULL)			r = do_corpus(calgary_corpus,method,opt_calgary_corpus_path,			              opt_c_loops,opt_d_loops);		else#endif		{			for ( ; i < argc && r == EXIT_OK; i++)			{				r = do_file(method,argv[i],opt_c_loops,opt_d_loops,NULL,NULL);				if (r == EXIT_FILE)		/* ignore file errors */					r = EXIT_OK;			}			if (opt_read_from_stdin)			{				char buf[512], *p;				while (r == EXIT_OK && fgets(buf,sizeof(buf)-1,stdin) != NULL)				{					buf[sizeof(buf)-1] = 0;					p = buf + strlen(buf);					while (p > buf && is_space(p[-1]))							*--p = 0;					p = buf;					while (*p && is_space(*p))						p++;					if (*p)						r = do_file(method,p,opt_c_loops,opt_d_loops,NULL,NULL);					if (r == EXIT_FILE)		/* ignore file errors */						r = EXIT_OK;				}				opt_read_from_stdin = 0;			}		}	}	t_total = time(NULL) - t_total;	if (opt_totals)		print_totals();	if (opt_execution_time || (methods_n > 1 && opt_verbose >= 1))		printf("\n%s: execution time: %lu seconds\n", argv0, (long) t_total);	if (r != EXIT_OK)		printf("\n%s: exit code: %d\n", argv0, r);	return r;}/*vi:ts=4:et*/

⌨️ 快捷键说明

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