diff options
Diffstat (limited to 'lzo/examples')
-rw-r--r-- | lzo/examples/dict.c | 69 | ||||
-rw-r--r-- | lzo/examples/lzopack.c | 51 | ||||
-rw-r--r-- | lzo/examples/overlap.c | 99 | ||||
-rw-r--r-- | lzo/examples/portab.h | 31 | ||||
-rw-r--r-- | lzo/examples/portab_a.h | 48 | ||||
-rw-r--r-- | lzo/examples/precomp.c | 48 | ||||
-rw-r--r-- | lzo/examples/precomp2.c | 48 | ||||
-rw-r--r-- | lzo/examples/simple.c | 25 |
8 files changed, 230 insertions, 189 deletions
diff --git a/lzo/examples/dict.c b/lzo/examples/dict.c index eec76750..04db2453 100644 --- a/lzo/examples/dict.c +++ b/lzo/examples/dict.c @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -48,14 +51,14 @@ #include "lzo/lzo1x.h" /* portability layer */ +static const char *progname = NULL; #define WANT_LZO_MALLOC 1 #define WANT_LZO_FREAD 1 #define WANT_LZO_WILDARGV 1 +#define WANT_XMALLOC 1 #include "examples/portab.h" -static const char *progname = NULL; - #define DICT_LEN 0xbfff static lzo_bytep dict; static lzo_uint dict_len = 0; @@ -88,35 +91,35 @@ static void print_file ( const char *name, lzo_uint d_len, lzo_uint c_len ) // **************************************************************************/ -int do_file ( const char *in_name, int level ) +int do_file ( const char *in_name, int compression_level ) { int r; lzo_bytep in; lzo_bytep out; lzo_bytep newb; - lzo_bytep wrkmem; + lzo_voidp wrkmem; lzo_uint in_len; lzo_uint out_len; lzo_uint new_len; long l; - FILE *f; + FILE *fp; /* * Step 1: open the input file */ - f = fopen(in_name,"rb"); - if (f == 0) + fp = fopen(in_name,"rb"); + if (fp == 0) { printf("%s: cannot open file %s\n", progname, in_name); return 0; /* no error */ } - fseek(f,0,SEEK_END); - l = ftell(f); - fseek(f,0,SEEK_SET); + fseek(fp, 0, SEEK_END); + l = ftell(fp); + fseek(fp, 0, SEEK_SET); if (l <= 0) { printf("%s: %s: empty file -- skipping\n", progname, in_name); - fclose(f); + fclose(fp); fp = NULL; return 0; } in_len = (lzo_uint) l; @@ -124,23 +127,23 @@ int do_file ( const char *in_name, int level ) /* * Step 2: allocate compression buffers and read the file */ - in = (lzo_bytep) lzo_malloc(in_len); - out = (lzo_bytep) lzo_malloc(in_len + in_len / 16 + 64 + 3); - newb = (lzo_bytep) lzo_malloc(in_len); - wrkmem = (lzo_bytep) lzo_malloc(LZO1X_999_MEM_COMPRESS); + in = (lzo_bytep) xmalloc(in_len); + out = (lzo_bytep) xmalloc(in_len + in_len / 16 + 64 + 3); + newb = (lzo_bytep) xmalloc(in_len); + wrkmem = (lzo_voidp) xmalloc(LZO1X_999_MEM_COMPRESS); if (in == NULL || out == NULL || newb == NULL || wrkmem == NULL) { printf("%s: out of memory\n", progname); exit(1); } - in_len = (lzo_uint) lzo_fread(f,in,in_len); - fclose(f); + in_len = (lzo_uint) lzo_fread(fp, in, in_len); + fclose(fp); fp = NULL; /* - * Step 3: compress from `in' to `out' with LZO1X-999 + * Step 3: compress from 'in' to 'out' with LZO1X-999 */ r = lzo1x_999_compress_level(in,in_len,out,&out_len,wrkmem, - dict, dict_len, 0, level); + dict, dict_len, 0, compression_level); if (r != LZO_E_OK) { /* this should NEVER happen */ @@ -151,7 +154,7 @@ int do_file ( const char *in_name, int level ) print_file(in_name,in_len,out_len); /* - * Step 4: decompress again, now going from `out' to `newb' + * Step 4: decompress again, now going from 'out' to 'newb' */ new_len = in_len; r = lzo1x_decompress_dict_safe(out,out_len,newb,&new_len,NULL,dict,dict_len); @@ -190,27 +193,27 @@ int __lzo_cdecl_main main(int argc, char *argv[]) int i = 1; int r; const char *dict_name; - FILE *f; + FILE *fp; time_t t_total; - int level = 7; + int compression_level = 7; lzo_wildargv(&argc, &argv); printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); + printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); progname = argv[0]; if (i < argc && argv[i][0] == '-' && isdigit(argv[i][1])) - level = atoi(&argv[i++][1]); + compression_level = atoi(&argv[i++][1]); - if (i + 1 >= argc || level < 1 || level > 9) + if (i + 1 >= argc || compression_level < 1 || compression_level > 9) { printf("usage: %s [-level] [ dictionary-file | -n ] file...\n", progname); exit(1); } - printf("Compression level is LZO1X-999/%d\n", level); + printf("Compression level is LZO1X-999/%d\n", compression_level); /* * Step 1: initialize the LZO library @@ -218,14 +221,14 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); - printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n"); + printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); exit(1); } /* * Step 2: prepare the dictionary */ - dict = (lzo_bytep) lzo_malloc(DICT_LEN); + dict = (lzo_bytep) xmalloc(DICT_LEN); if (dict == NULL) { printf("%s: out of memory\n", progname); @@ -239,14 +242,14 @@ int __lzo_cdecl_main main(int argc, char *argv[]) } else { - f = fopen(dict_name,"rb"); - if (!f) + fp = fopen(dict_name,"rb"); + if (!fp) { printf("%s: cannot open dictionary file %s\n", progname, dict_name); exit(1); } - dict_len = (lzo_uint) lzo_fread(f,dict,DICT_LEN); - fclose(f); + dict_len = (lzo_uint) lzo_fread(fp, dict, DICT_LEN); + fclose(fp); fp = NULL; } dict_adler32 = lzo_adler32(0,NULL,0); @@ -259,7 +262,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) */ t_total = time(NULL); for (r = 0; r == 0 && i < argc; i++) - r = do_file(argv[i], level); + r = do_file(argv[i], compression_level); t_total = time(NULL) - t_total; lzo_free(dict); diff --git a/lzo/examples/lzopack.c b/lzo/examples/lzopack.c index 6a3d848a..e4e745df 100644 --- a/lzo/examples/lzopack.c +++ b/lzo/examples/lzopack.c @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -52,14 +55,14 @@ #include "lzo/lzo1x.h" /* portability layer */ +static const char *progname = NULL; #define WANT_LZO_MALLOC 1 #define WANT_LZO_FREAD 1 #define WANT_LZO_WILDARGV 1 +#define WANT_XMALLOC 1 #include "examples/portab.h" -static const char *progname = NULL; - static unsigned long total_in = 0; static unsigned long total_out = 0; static lzo_bool opt_debug = 0; @@ -156,12 +159,12 @@ void xwrite32(FILE *fp, lzo_xint v) // compression. **************************************************************************/ -int do_compress(FILE *fi, FILE *fo, int level, lzo_uint block_size) +int do_compress(FILE *fi, FILE *fo, int compression_level, lzo_uint block_size) { int r = 0; lzo_bytep in = NULL; lzo_bytep out = NULL; - lzo_bytep wrkmem = NULL; + lzo_voidp wrkmem = NULL; lzo_uint in_len; lzo_uint out_len; lzo_uint32 wrk_len = 0; @@ -176,21 +179,21 @@ int do_compress(FILE *fi, FILE *fo, int level, lzo_uint block_size) */ xwrite(fo, magic, sizeof(magic)); xwrite32(fo, flags); - xputc(fo, method); /* compression method */ - xputc(fo, level); /* compression level */ + xputc(fo, method); /* compression method */ + xputc(fo, compression_level); /* compression level */ xwrite32(fo, block_size); checksum = lzo_adler32(0, NULL, 0); /* * Step 2: allocate compression buffers and work-memory */ - in = (lzo_bytep) lzo_malloc(block_size); - out = (lzo_bytep) lzo_malloc(block_size + block_size / 16 + 64 + 3); - if (level == 9) + in = (lzo_bytep) xmalloc(block_size); + out = (lzo_bytep) xmalloc(block_size + block_size / 16 + 64 + 3); + if (compression_level == 9) wrk_len = LZO1X_999_MEM_COMPRESS; else wrk_len = LZO1X_1_MEM_COMPRESS; - wrkmem = (lzo_bytep) lzo_malloc(wrk_len); + wrkmem = (lzo_voidp) xmalloc(wrk_len); if (in == NULL || out == NULL || wrkmem == NULL) { printf("%s: out of memory\n", progname); @@ -205,7 +208,7 @@ int do_compress(FILE *fi, FILE *fo, int level, lzo_uint block_size) { /* read block */ in_len = xread(fi, in, block_size, 1); - if (in_len <= 0) + if (in_len == 0) break; /* update checksum */ @@ -217,7 +220,7 @@ int do_compress(FILE *fi, FILE *fo, int level, lzo_uint block_size) lzo_memset(wrkmem, 0xff, wrk_len); /* compress block */ - if (level == 9) + if (compression_level == 9) r = lzo1x_999_compress(in, in_len, out, &out_len, wrkmem); else r = lzo1x_1_compress(in, in_len, out, &out_len, wrkmem); @@ -277,7 +280,7 @@ int do_decompress(FILE *fi, FILE *fo) unsigned char m [ sizeof(magic) ]; lzo_uint32 flags; int method; - int level; + int compression_level; lzo_uint block_size; lzo_uint32 checksum; @@ -295,11 +298,11 @@ int do_decompress(FILE *fi, FILE *fo) } flags = xread32(fi); method = xgetc(fi); - level = xgetc(fi); + compression_level = xgetc(fi); if (method != 1) { printf("%s: header error - invalid method %d (level %d)\n", - progname, method, level); + progname, method, compression_level); r = 2; goto err; } @@ -317,7 +320,7 @@ int do_decompress(FILE *fi, FILE *fo) * Step 2: allocate buffer for in-place decompression */ buf_len = block_size + block_size / 16 + 64 + 3; - buf = (lzo_bytep) lzo_malloc(buf_len); + buf = (lzo_bytep) xmalloc(buf_len); if (buf == NULL) { printf("%s: out of memory\n", progname); @@ -506,9 +509,9 @@ int __lzo_cdecl_main main(int argc, char *argv[]) FILE *fo = NULL; const char *in_name = NULL; const char *out_name = NULL; - lzo_bool opt_decompress = 0; - lzo_bool opt_test = 0; - int opt_level = 1; + unsigned opt_decompress = 0; + unsigned opt_test = 0; + int opt_compression_level = 1; lzo_uint opt_block_size; const char *s; @@ -521,7 +524,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); + printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); #if 0 printf( @@ -539,7 +542,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); - printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n"); + printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); exit(1); } @@ -567,7 +570,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) else if (strcmp(argv[i],"-t") == 0) opt_test = 1; else if (strcmp(argv[i],"-9") == 0) - opt_level = 9; + opt_compression_level = 9; else if (argv[i][1] == 'b' && argv[i][2]) { long b = atol(&argv[i][2]); @@ -575,7 +578,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) opt_block_size = (lzo_uint) b; else { - printf("%s: invalid block_size in option `%s'.\n", progname, argv[i]); + printf("%s: invalid block_size in option '%s'.\n", progname, argv[i]); usage(); } } @@ -625,7 +628,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) out_name = argv[i++]; fi = xopen_fi(in_name); fo = xopen_fo(out_name); - r = do_compress(fi, fo, opt_level, opt_block_size); + r = do_compress(fi, fo, opt_compression_level, opt_block_size); if (r == 0) printf("%s: compressed %lu into %lu bytes\n", progname, total_in, total_out); diff --git a/lzo/examples/overlap.c b/lzo/examples/overlap.c index 7eeb52fc..b2337680 100644 --- a/lzo/examples/overlap.c +++ b/lzo/examples/overlap.c @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -49,15 +52,17 @@ #include "lzo/lzo1x.h" /* portability layer */ +static const char *progname = NULL; #define WANT_LZO_MALLOC 1 #define WANT_LZO_FREAD 1 #define WANT_LZO_WILDARGV 1 +#define WANT_XMALLOC 1 #include "examples/portab.h" /* Overhead (in bytes) for the in-place decompression buffer. * Most files need only 16 ! - * (try `overlap -16 file' or even `overlap -8 file') + * (try 'overlap -16 file' or even 'overlap -8 file') * * Worst case (for files that are compressible by only a few bytes) * is 'in_len / 16 + 64 + 3'. See step 5a) below. @@ -76,30 +81,10 @@ static lzo_uint opt_overhead = 0; /* assume worst case */ #endif -/************************************************************************* -// -**************************************************************************/ - -static const char *progname = NULL; - static unsigned long total_files = 0; static unsigned long total_in = 0; -static lzo_bytep xmalloc(lzo_uint len) -{ - lzo_bytep p; - - p = (lzo_bytep) lzo_malloc(len > 0 ? len : 1); - if (p == NULL) - { - printf("%s: out of memory\n", progname); - exit(1); - } - return p; -} - - /************************************************************************* // **************************************************************************/ @@ -107,10 +92,10 @@ static lzo_bytep xmalloc(lzo_uint len) int do_file ( const char *in_name ) { int r; - FILE *f = NULL; + FILE *fp = NULL; long l; - lzo_bytep wrkmem = NULL; + lzo_voidp wrkmem = NULL; lzo_bytep in = NULL; lzo_uint in_len; /* uncompressed length */ @@ -127,15 +112,15 @@ int do_file ( const char *in_name ) /* * Step 1: open the input file */ - f = fopen(in_name,"rb"); - if (f == NULL) + fp = fopen(in_name, "rb"); + if (fp == NULL) { printf("%s: %s: cannot open file\n", progname, in_name); goto next_file; } - fseek(f,0,SEEK_END); - l = ftell(f); - fseek(f,0,SEEK_SET); + fseek(fp, 0, SEEK_END); + l = ftell(fp); + fseek(fp, 0, SEEK_SET); if (l <= 0) { printf("%s: %s: empty file -- skipping\n", progname, in_name); @@ -146,18 +131,18 @@ int do_file ( const char *in_name ) /* * Step 2: allocate compression buffers and read the file */ - in = xmalloc(in_len); - out = xmalloc(in_len + in_len / 16 + 64 + 3); - wrkmem = xmalloc(LZO1X_1_MEM_COMPRESS); - in_len = (lzo_uint) lzo_fread(f,in,in_len); - fclose(f); f = NULL; - printf("%s: %s: read %ld bytes\n", progname, in_name, (long) in_len); + in = (lzo_bytep) xmalloc(in_len); + out = (lzo_bytep) xmalloc(in_len + in_len / 16 + 64 + 3); + wrkmem = (lzo_voidp) xmalloc(LZO1X_1_MEM_COMPRESS); + in_len = (lzo_uint) lzo_fread(fp, in, in_len); + fclose(fp); fp = NULL; + printf("%s: %s: read %lu bytes\n", progname, in_name, (unsigned long) in_len); total_files++; total_in += (unsigned long) in_len; /* - * Step 3: compress from `in' to `out' with LZO1X-1 + * Step 3: compress from 'in' to 'out' with LZO1X-1 */ r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem); if (r != LZO_E_OK || out_len > in_len + in_len / 16 + 64 + 3) @@ -166,20 +151,20 @@ int do_file ( const char *in_name ) printf("internal error - compression failed: %d\n", r); exit(1); } - printf("%-26s %8lu -> %8lu\n", "LZO1X-1:", (long) in_len, (long) out_len); + printf("%-26s %8lu -> %8lu\n", "LZO1X-1:", (unsigned long) in_len, (unsigned long) out_len); /***** Step 4: overlapping compression *****/ /* - * Step 4a: allocate the `overlap' buffer for overlapping compression + * Step 4a: allocate the 'overlap' buffer for overlapping compression */ overhead = in_len > 0xbfff ? 0xbfff : in_len; overhead += in_len / 16 + 64 + 3; - overlap = xmalloc(in_len + overhead); + overlap = (lzo_bytep) xmalloc(in_len + overhead); /* - * Step 4b: prepare data in `overlap' buffer. + * Step 4b: prepare data in 'overlap' buffer. * copy uncompressed data at the top of the overlap buffer */ /*** offset = in_len + overhead - in_len; ***/ @@ -187,7 +172,7 @@ int do_file ( const char *in_name ) lzo_memcpy(overlap + offset, in, in_len); /* - * Step 4c: do an in-place compression within the `overlap' buffer + * Step 4c: do an in-place compression within the 'overlap' buffer */ r = lzo1x_1_compress(overlap+offset,in_len,overlap,&new_len,wrkmem); if (r != LZO_E_OK) @@ -207,10 +192,10 @@ int do_file ( const char *in_name ) * happens very seldom). So we have to verify the overlapping * compression by doing a temporary decompression. */ - lzo_uint l = in_len; - lzo_bytep tmp = xmalloc(l); - r = lzo1x_decompress_safe(overlap,new_len,tmp,&l,NULL); - if (r != LZO_E_OK || l != in_len || lzo_memcmp(in,tmp,l) != 0) + lzo_uint ll = in_len; + lzo_bytep tmp = (lzo_bytep) xmalloc(ll); + r = lzo1x_decompress_safe(overlap, new_len, tmp, &ll, NULL); + if (r != LZO_E_OK || ll != in_len || lzo_memcmp(in, tmp, ll) != 0) { /* this should NEVER happen */ printf("overlapping compression data error\n"); @@ -219,38 +204,38 @@ int do_file ( const char *in_name ) lzo_free(tmp); } - printf("overlapping compression: %8lu -> %8lu overhead: %7ld\n", - (long) in_len, (long) new_len, (long) overhead); + printf("overlapping compression: %8lu -> %8lu overhead: %7lu\n", + (unsigned long) in_len, (unsigned long) new_len, (unsigned long) overhead); lzo_free(overlap); overlap = NULL; /***** Step 5: overlapping decompression *****/ /* - * Step 5a: allocate the `overlap' buffer for in-place decompression + * Step 5a: allocate the 'overlap' buffer for in-place decompression */ if (opt_overhead == 0 || out_len >= in_len) overhead = in_len / 16 + 64 + 3; else overhead = opt_overhead; - overlap = xmalloc(in_len + overhead); + overlap = (lzo_bytep) xmalloc(in_len + overhead); /* - * Step 5b: prepare data in `overlap' buffer. + * Step 5b: prepare data in 'overlap' buffer. * copy compressed data at the top of the overlap buffer */ offset = in_len + overhead - out_len; lzo_memcpy(overlap + offset, out, out_len); /* - * Step 5c: do an in-place decompression within the `overlap' buffer + * Step 5c: do an in-place decompression within the 'overlap' buffer */ new_len = in_len; r = lzo1x_decompress(overlap+offset,out_len,overlap,&new_len,NULL); if (r != LZO_E_OK) { /* this may happen if overhead is too small */ - printf("overlapping decompression failed: %d - increase `opt_overhead'\n", r); + printf("overlapping decompression failed: %d - increase 'opt_overhead'\n", r); exit(1); } @@ -260,11 +245,11 @@ int do_file ( const char *in_name ) if (new_len != in_len || lzo_memcmp(in,overlap,in_len) != 0) { /* this may happen if overhead is too small */ - printf("overlapping decompression data error - increase `opt_overhead'\n"); + printf("overlapping decompression data error - increase 'opt_overhead'\n"); exit(1); } - printf("overlapping decompression: %8lu -> %8lu overhead: %7ld\n", - (long) out_len, (long) new_len, (long) overhead); + printf("overlapping decompression: %8lu -> %8lu overhead: %7lu\n", + (unsigned long) out_len, (unsigned long) new_len, (unsigned long) overhead); lzo_free(overlap); overlap = NULL; @@ -273,7 +258,7 @@ next_file: lzo_free(wrkmem); lzo_free(out); lzo_free(in); - if (f) fclose(f); + if (fp) fclose(fp); return 0; } @@ -292,7 +277,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); + printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); progname = argv[0]; if (i < argc && argv[i][0] == '-') @@ -316,7 +301,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); - printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n"); + printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); exit(1); } diff --git a/lzo/examples/portab.h b/lzo/examples/portab.h index 1405b44b..b4b5a21a 100644 --- a/lzo/examples/portab.h +++ b/lzo/examples/portab.h @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -41,11 +44,11 @@ #include "lzo/lzoconf.h" #if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200)) - /* avoid `-W4' warnings in system header files */ + /* avoid '-W4' warnings in system header files */ # pragma warning(disable: 4201 4214 4514) #endif #if (LZO_CC_MSC && (_MSC_VER >= 1300)) - /* avoid `-Wall' warnings in system header files */ + /* avoid '-Wall' warnings in system header files */ # pragma warning(disable: 4163 4255 4820) /* avoid warnings about inlining */ # pragma warning(disable: 4710 4711) @@ -63,7 +66,7 @@ // **************************************************************************/ -#if defined(__LZO_MMODEL_HUGE) || !(defined(LZO_LIBC_ISOC90) || defined(LZO_LIBC_ISOC99)) +#if defined(__LZO_MMODEL_HUGE) || defined(ACC_WANT_ACCLIB_GETOPT) || !(defined(LZO_LIBC_ISOC90) || defined(LZO_LIBC_ISOC99)) #include "examples/portab_a.h" @@ -129,6 +132,28 @@ #undef xwrite32 +#if defined(WANT_XMALLOC) +static lzo_voidp xmalloc(lzo_uint len) +{ + lzo_voidp p; + lzo_uint align = (lzo_uint) sizeof(lzo_align_t); + + p = (lzo_voidp) lzo_malloc(len > 0 ? len : 1); + if (p == NULL) + { + printf("%s: out of memory\n", progname); + exit(1); + } + if (len >= align && __lzo_align_gap(p, align) != 0) + { + printf("%s: C library problem: malloc() returned misaligned pointer!\n", progname); + exit(1); + } + return p; +} +#endif + + #if defined(WANT_LZO_UCLOCK) /* High quality benchmarking. diff --git a/lzo/examples/portab_a.h b/lzo/examples/portab_a.h index a58ba99d..2706022d 100644 --- a/lzo/examples/portab_a.h +++ b/lzo/examples/portab_a.h @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -48,7 +51,7 @@ #define ACC_WANT_ACC_INCD_H 1 #define ACC_WANT_ACC_INCE_H 1 -#if defined(__LZO_MMODEL_HUGE) || defined(WANT_LZO_UCLOCK) || defined(WANT_LZO_WILDARGV) +#if defined(__LZO_MMODEL_HUGE) || defined(ACC_WANT_ACCLIB_GETOPT) || defined(WANT_LZO_UCLOCK) || defined(WANT_LZO_WILDARGV) # define ACC_WANT_ACC_INCI_H 1 # define ACC_WANT_ACC_LIB_H 1 #endif @@ -80,17 +83,10 @@ #if defined(WANT_LZO_WILDARGV) # define ACC_WANT_ACCLIB_WILDARGV 1 #endif -#if defined(__ACCLIB_PCLOCK_USE_PERFCTR) -# include "src/fullacc.h" -# define lzo_uclock_flush_cpu_cache(h,flags) acc_pclock_flush_cpu_cache(h,flags) -#else -# include "src/miniacc.h" -#endif - #if (__ACCLIB_REQUIRE_HMEMCPY_CH) && !defined(__ACCLIB_HMEMCPY_CH_INCLUDED) # define ACC_WANT_ACCLIB_HMEMCPY 1 -# include "src/miniacc.h" #endif +#include "src/miniacc.h" /************************************************************************* @@ -102,23 +98,39 @@ #undef lzo_fread #undef lzo_fwrite #if defined(WANT_LZO_MALLOC) -# define lzo_malloc(a) acc_halloc(a) -# define lzo_free(a) acc_hfree(a) +# if defined(acc_halloc) +# define lzo_malloc(a) acc_halloc(a) +# else +# define lzo_malloc(a) __ACCLIB_FUNCNAME(acc_halloc)(a) +# endif +# if defined(acc_hfree) +# define lzo_free(a) acc_hfree(a) +# else +# define lzo_free(a) __ACCLIB_FUNCNAME(acc_hfree)(a) +# endif #endif #if defined(WANT_LZO_FREAD) -# define lzo_fread(f,b,s) acc_hfread(f,b,s) -# define lzo_fwrite(f,b,s) acc_hfwrite(f,b,s) +# if defined(acc_hfread) +# define lzo_fread(f,b,s) acc_hfread(f,b,s) +# else +# define lzo_fread(f,b,s) __ACCLIB_FUNCNAME(acc_hfread)(f,b,s) +# endif +# if defined(acc_hfwrite) +# define lzo_fwrite(f,b,s) acc_hfwrite(f,b,s) +# else +# define lzo_fwrite(f,b,s) __ACCLIB_FUNCNAME(acc_hfwrite)(f,b,s) +# endif #endif #if defined(WANT_LZO_UCLOCK) # define lzo_uclock_handle_t acc_pclock_handle_t # define lzo_uclock_t acc_pclock_t -# define lzo_uclock_open(a) acc_pclock_open_default(a) -# define lzo_uclock_close(a) acc_pclock_close(a) -# define lzo_uclock_read(a,b) acc_pclock_read(a,b) -# define lzo_uclock_get_elapsed(a,b,c) acc_pclock_get_elapsed(a,b,c) +# define lzo_uclock_open(a) __ACCLIB_FUNCNAME(acc_pclock_open_default)(a) +# define lzo_uclock_close(a) __ACCLIB_FUNCNAME(acc_pclock_close)(a) +# define lzo_uclock_read(a,b) __ACCLIB_FUNCNAME(acc_pclock_read)(a,b) +# define lzo_uclock_get_elapsed(a,b,c) __ACCLIB_FUNCNAME(acc_pclock_get_elapsed)(a,b,c) #endif #if defined(WANT_LZO_WILDARGV) -# define lzo_wildargv(a,b) acc_wildargv(a,b) +# define lzo_wildargv(a,b) __ACCLIB_FUNCNAME(acc_wildargv)(a,b) #endif diff --git a/lzo/examples/precomp.c b/lzo/examples/precomp.c index 10f4e7fe..a953827b 100644 --- a/lzo/examples/precomp.c +++ b/lzo/examples/precomp.c @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -58,9 +61,11 @@ /* portability layer */ +static const char *progname = NULL; #define WANT_LZO_MALLOC 1 #define WANT_LZO_FREAD 1 #define WANT_LZO_WILDARGV 1 +#define WANT_XMALLOC 1 #include "examples/portab.h" @@ -79,7 +84,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) lzo_uint out_bufsize; lzo_uint out_len = 0; - lzo_bytep wrkmem; + lzo_voidp wrkmem; lzo_uint wrk_len; lzo_uint best_len; @@ -89,8 +94,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) lzo_uint32 uncompressed_checksum; lzo_uint32 compressed_checksum; - FILE *f; - const char *progname = NULL; + FILE *fp; const char *in_name = NULL; const char *out_name = NULL; long l; @@ -100,7 +104,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); + printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); progname = argv[0]; if (argc < 2 || argc > 3) @@ -117,7 +121,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); - printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n"); + printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); exit(1); } @@ -133,7 +137,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (wrk_len < LZO1Y_999_MEM_COMPRESS) wrk_len = LZO1Y_999_MEM_COMPRESS; #endif - wrkmem = (lzo_bytep) lzo_malloc(wrk_len); + wrkmem = (lzo_voidp) xmalloc(wrk_len); if (wrkmem == NULL) { printf("%s: out of memory\n", progname); @@ -143,19 +147,19 @@ int __lzo_cdecl_main main(int argc, char *argv[]) /* * Step 3: open the input file */ - f = fopen(in_name,"rb"); - if (f == NULL) + fp = fopen(in_name,"rb"); + if (fp == NULL) { printf("%s: cannot open file %s\n", progname, in_name); exit(1); } - fseek(f,0,SEEK_END); - l = ftell(f); - fseek(f,0,SEEK_SET); + fseek(fp, 0, SEEK_END); + l = ftell(fp); + fseek(fp, 0, SEEK_SET); if (l <= 0) { printf("%s: %s: empty file\n", progname, in_name); - fclose(f); + fclose(fp); fp = NULL; exit(1); } in_len = (lzo_uint) l; @@ -165,16 +169,16 @@ int __lzo_cdecl_main main(int argc, char *argv[]) /* * Step 4: allocate compression buffers and read the file */ - in = (lzo_bytep) lzo_malloc(in_len); - out = (lzo_bytep) lzo_malloc(out_bufsize); + in = (lzo_bytep) xmalloc(in_len); + out = (lzo_bytep) xmalloc(out_bufsize); if (in == NULL || out == NULL) { printf("%s: out of memory\n", progname); exit(1); } - in_len = (lzo_uint) lzo_fread(f,in,in_len); + in_len = (lzo_uint) lzo_fread(fp, in, in_len); printf("%s: loaded file %s: %ld bytes\n", progname, in_name, (long) in_len); - fclose(f); + fclose(fp); fp = NULL; /* * Step 5: compute a checksum of the uncompressed data @@ -183,7 +187,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) uncompressed_checksum = lzo_adler32(uncompressed_checksum,in,in_len); /* - * Step 6a: compress from `in' to `out' with LZO1X-999 + * Step 6a: compress from 'in' to 'out' with LZO1X-999 */ #ifdef USE_LZO1X out_len = out_bufsize; @@ -203,7 +207,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) #endif /* USE_LZO1X */ /* - * Step 6b: compress from `in' to `out' with LZO1Y-999 + * Step 6b: compress from 'in' to 'out' with LZO1Y-999 */ #ifdef USE_LZO1Y out_len = out_bufsize; @@ -245,7 +249,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) assert(out_len == best_len); /* - * Step 9: optimize compressed data (compressed data is in `out' buffer) + * Step 9: optimize compressed data (compressed data is in 'out' buffer) */ #if 1 /* Optimization does not require any data in the buffer that will @@ -287,13 +291,13 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (out_name && out_name[0]) { printf("%s: writing to file %s\n", progname, out_name); - f = fopen(out_name,"wb"); - if (f == NULL) + fp = fopen(out_name,"wb"); + if (fp == NULL) { printf("%s: cannot open output file %s\n", progname, out_name); exit(1); } - if (lzo_fwrite(f,out,out_len) != out_len || fclose(f) != 0) + if (lzo_fwrite(fp, out, out_len) != out_len || fclose(fp) != 0) { printf("%s: write error !!\n", progname); exit(1); diff --git a/lzo/examples/precomp2.c b/lzo/examples/precomp2.c index 44b066a5..d9e1b47b 100644 --- a/lzo/examples/precomp2.c +++ b/lzo/examples/precomp2.c @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -87,9 +90,11 @@ lzo1y_999_compress_internal ( const lzo_bytep in , lzo_uint in_len, /* portability layer */ +static const char *progname = NULL; #define WANT_LZO_MALLOC 1 #define WANT_LZO_FREAD 1 #define WANT_LZO_WILDARGV 1 +#define WANT_XMALLOC 1 #include "examples/portab.h" @@ -112,7 +117,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) lzo_uint out_bufsize; lzo_uint out_len = 0; - lzo_bytep wrkmem; + lzo_voidp wrkmem; lzo_uint wrk_len; lzo_uint best_len; @@ -123,8 +128,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) lzo_uint32 uncompressed_checksum; lzo_uint32 compressed_checksum; - FILE *f; - const char *progname = NULL; + FILE *fp; const char *in_name = NULL; const char *out_name = NULL; long l; @@ -134,7 +138,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); + printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); progname = argv[0]; if (argc < 2 || argc > 3) @@ -151,7 +155,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); - printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n"); + printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); exit(1); } @@ -167,7 +171,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (wrk_len < LZO1Y_999_MEM_COMPRESS) wrk_len = LZO1Y_999_MEM_COMPRESS; #endif - wrkmem = (lzo_bytep) lzo_malloc(wrk_len); + wrkmem = (lzo_voidp) xmalloc(wrk_len); if (wrkmem == NULL) { printf("%s: out of memory\n", progname); @@ -177,19 +181,19 @@ int __lzo_cdecl_main main(int argc, char *argv[]) /* * Step 3: open the input file */ - f = fopen(in_name,"rb"); - if (f == NULL) + fp = fopen(in_name,"rb"); + if (fp == NULL) { printf("%s: cannot open file %s\n", progname, in_name); exit(1); } - fseek(f,0,SEEK_END); - l = ftell(f); - fseek(f,0,SEEK_SET); + fseek(fp, 0, SEEK_END); + l = ftell(fp); + fseek(fp, 0, SEEK_SET); if (l <= 0) { printf("%s: %s: empty file\n", progname, in_name); - fclose(f); + fclose(fp); fp = NULL; exit(1); } in_len = (lzo_uint) l; @@ -199,16 +203,16 @@ int __lzo_cdecl_main main(int argc, char *argv[]) /* * Step 4: allocate compression buffers and read the file */ - in = (lzo_bytep) lzo_malloc(in_len); - out = (lzo_bytep) lzo_malloc(out_bufsize); + in = (lzo_bytep) xmalloc(in_len); + out = (lzo_bytep) xmalloc(out_bufsize); if (in == NULL || out == NULL) { printf("%s: out of memory\n", progname); exit(1); } - in_len = (lzo_uint) lzo_fread(f,in,in_len); + in_len = (lzo_uint) lzo_fread(fp, in, in_len); printf("%s: loaded file %s: %ld bytes\n", progname, in_name, (long) in_len); - fclose(f); + fclose(fp); fp = NULL; /* * Step 5: compute a checksum of the uncompressed data @@ -217,7 +221,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) uncompressed_checksum = lzo_adler32(uncompressed_checksum,in,in_len); /* - * Step 6a: compress from `in' to `out' with LZO1X-999 + * Step 6a: compress from 'in' to 'out' with LZO1X-999 */ #ifdef USE_LZO1X for (lazy = 0; lazy <= max_try_lazy; lazy++) @@ -244,7 +248,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) #endif /* USE_LZO1X */ /* - * Step 6b: compress from `in' to `out' with LZO1Y-999 + * Step 6b: compress from 'in' to 'out' with LZO1Y-999 */ #ifdef USE_LZO1Y for (lazy = 0; lazy <= max_try_lazy; lazy++) @@ -297,7 +301,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) assert(out_len == best_len); /* - * Step 9: optimize compressed data (compressed data is in `out' buffer) + * Step 9: optimize compressed data (compressed data is in 'out' buffer) */ #if 1 /* Optimization does not require any data in the buffer that will @@ -339,13 +343,13 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (out_name && out_name[0]) { printf("%s: writing to file %s\n", progname, out_name); - f = fopen(out_name,"wb"); - if (f == NULL) + fp = fopen(out_name,"wb"); + if (fp == NULL) { printf("%s: cannot open output file %s\n", progname, out_name); exit(1); } - if (lzo_fwrite(f,out,out_len) != out_len || fclose(f) != 0) + if (lzo_fwrite(fp, out, out_len) != out_len || fclose(fp) != 0) { printf("%s: write error !!\n", progname); exit(1); diff --git a/lzo/examples/simple.c b/lzo/examples/simple.c index 15611c92..9d06cb5c 100644 --- a/lzo/examples/simple.c +++ b/lzo/examples/simple.c @@ -2,6 +2,9 @@ This file is part of the LZO real-time data compression library. + Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer + Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer @@ -53,12 +56,14 @@ #include "lzo/lzo1x.h" /* portability layer */ +static const char *progname = NULL; #define WANT_LZO_MALLOC 1 +#define WANT_XMALLOC 1 #include "examples/portab.h" -/* We want to compress the data block at `in' with length `IN_LEN' to - * the block at `out'. Because the input block may be incompressible, +/* We want to compress the data block at 'in' with length 'IN_LEN' to + * the block at 'out'. Because the input block may be incompressible, * we must provide a little more output space in case that compression * is not possible. */ @@ -78,7 +83,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) int r; lzo_bytep in; lzo_bytep out; - lzo_bytep wrkmem; + lzo_voidp wrkmem; lzo_uint in_len; lzo_uint out_len; lzo_uint new_len; @@ -88,7 +93,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) printf("\nLZO real-time data compression library (v%s, %s).\n", lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2008 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); + printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); /* * Step 1: initialize the LZO library @@ -96,16 +101,16 @@ int __lzo_cdecl_main main(int argc, char *argv[]) if (lzo_init() != LZO_E_OK) { printf("internal error - lzo_init() failed !!!\n"); - printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n"); + printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n"); return 4; } /* * Step 2: allocate blocks and the work-memory */ - in = (lzo_bytep) lzo_malloc(IN_LEN); - out = (lzo_bytep) lzo_malloc(OUT_LEN); - wrkmem = (lzo_bytep) lzo_malloc(LZO1X_1_MEM_COMPRESS); + in = (lzo_bytep) xmalloc(IN_LEN); + out = (lzo_bytep) xmalloc(OUT_LEN); + wrkmem = (lzo_voidp) xmalloc(LZO1X_1_MEM_COMPRESS); if (in == NULL || out == NULL || wrkmem == NULL) { printf("out of memory\n"); @@ -121,7 +126,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) lzo_memset(in,0,in_len); /* - * Step 4: compress from `in' to `out' with LZO1X-1 + * Step 4: compress from 'in' to 'out' with LZO1X-1 */ r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem); if (r == LZO_E_OK) @@ -141,7 +146,7 @@ int __lzo_cdecl_main main(int argc, char *argv[]) } /* - * Step 5: decompress again, now going from `out' to `in' + * Step 5: decompress again, now going from 'out' to 'in' */ new_len = in_len; r = lzo1x_decompress(out,out_len,in,&new_len,NULL); |