From 2b2dee6586048e62d066a3ea7b761649828b3aff Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Thu, 28 Dec 2017 00:30:40 +0100 Subject: Add OpenVPN3 to build, change build system to cmake --- main/lzo/examples/dict.c | 274 ------------------- main/lzo/examples/lzopack.c | 628 ------------------------------------------- main/lzo/examples/overlap.c | 302 --------------------- main/lzo/examples/portab.h | 144 ---------- main/lzo/examples/portab_a.h | 61 ----- main/lzo/examples/precomp.c | 330 ----------------------- main/lzo/examples/precomp2.c | 382 -------------------------- main/lzo/examples/simple.c | 156 ----------- 8 files changed, 2277 deletions(-) delete mode 100644 main/lzo/examples/dict.c delete mode 100644 main/lzo/examples/lzopack.c delete mode 100644 main/lzo/examples/overlap.c delete mode 100644 main/lzo/examples/portab.h delete mode 100644 main/lzo/examples/portab_a.h delete mode 100644 main/lzo/examples/precomp.c delete mode 100644 main/lzo/examples/precomp2.c delete mode 100644 main/lzo/examples/simple.c (limited to 'main/lzo/examples') diff --git a/main/lzo/examples/dict.c b/main/lzo/examples/dict.c deleted file mode 100644 index 8945caf1..00000000 --- a/main/lzo/examples/dict.c +++ /dev/null @@ -1,274 +0,0 @@ -/* dict.c -- example program: how to use preset dictionaries - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -/************************************************************************* -// This program shows how to use preset dictionaries. -// -// Please study LZO.FAQ and simple.c first. -**************************************************************************/ - -#include -#include - -/* 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" - - -#define DICT_LEN 0xbfff -static lzo_bytep dict; -static lzo_uint dict_len = 0; -static lzo_uint32_t dict_adler32; - - -/************************************************************************* -// -**************************************************************************/ - -static lzo_uint total_n = 0; -static lzo_uint total_c_len = 0; -static lzo_uint total_d_len = 0; - -static void print_info(const char *name, lzo_uint d_len, lzo_uint c_len) -{ - double perc; - - perc = (d_len > 0) ? c_len * 100.0 / d_len : 0.0; - printf(" | %-30s %9ld -> %9ld %7.2f%% |\n", - name, (long) d_len, (long) c_len, perc); - - total_n++; - total_c_len += c_len; - total_d_len += d_len; -} - - -/************************************************************************* -// -**************************************************************************/ - -static int do_file(const char *in_name, int compression_level) -{ - int r; - lzo_bytep in; - lzo_bytep out; - lzo_bytep newb; - lzo_voidp wrkmem; - lzo_uint in_len; - lzo_uint out_len; - lzo_uint new_len; - long l; - FILE *fp; - -/* - * Step 1: open the input file - */ - fp = fopen(in_name,"rb"); - if (fp == NULL) - { - printf("%s: %s: cannot open file\n", progname, in_name); - return 0; /* no error */ - } - 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(fp); fp = NULL; - return 0; /* no error */ - } - in_len = (lzo_uint) l; - if ((long) in_len != l || l > 256L * 1024L * 1024L) - { - printf("%s: %s: file is too big -- skipping\n", progname, in_name); - fclose(fp); fp = NULL; - return 0; /* no error */ - } - -/* - * Step 2: allocate compression buffers and read the file - */ - 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(fp, in, in_len); - fclose(fp); fp = NULL; - -/* - * 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, compression_level); - if (r != LZO_E_OK) - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - return 1; - } - - print_info(in_name, in_len, out_len); - -/* - * 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); - if (r != LZO_E_OK) - { - /* this should NEVER happen */ - printf("internal error - decompression failed: %d\n", r); - return 1; - } - -/* - * Step 5: verify decompression - */ - if (new_len != in_len || lzo_memcmp(in, newb, in_len) != 0) - { - /* this should NEVER happen */ - printf("internal error - decompression data error\n"); - return 1; - } - - /* free buffers in reverse order to help malloc() */ - lzo_free(wrkmem); - lzo_free(newb); - lzo_free(out); - lzo_free(in); - return 0; -} - - -/************************************************************************* -// -**************************************************************************/ - -int __lzo_cdecl_main main(int argc, char *argv[]) -{ - int i = 1; - int r = 0; - const char *dict_name; - FILE *fp; - time_t t_total; - 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-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); - - progname = argv[0]; - - if (i < argc && argv[i][0] == '-' && isdigit(argv[i][1])) - compression_level = atoi(&argv[i++][1]); - - 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", compression_level); - -/* - * Step 1: initialize the LZO library - */ - 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"); - exit(1); - } - -/* - * Step 2: prepare the dictionary - */ - dict = (lzo_bytep) xmalloc(DICT_LEN); - if (dict == NULL) - { - printf("%s: out of memory\n", progname); - exit(1); - } - dict_name = argv[i++]; - if (strcmp(dict_name,"-n") == 0) - { - dict_name = "empty"; - dict_len = 0; - } - else - { - fp = fopen(dict_name,"rb"); - if (fp == NULL) - { - printf("%s: cannot open dictionary file %s\n", progname, dict_name); - exit(1); - } - dict_len = (lzo_uint) lzo_fread(fp, dict, DICT_LEN); - fclose(fp); fp = NULL; - } - - dict_adler32 = lzo_adler32(0, NULL, 0); - dict_adler32 = lzo_adler32(dict_adler32, dict, dict_len); - printf("Using dictionary '%s', %ld bytes, ID 0x%08lx.\n", - dict_name, (long) dict_len, (unsigned long) dict_adler32); - -/* - * Step 3: process files - */ - t_total = time(NULL); - for ( ; i < argc; i++) { - if (do_file(argv[i], compression_level) != 0) { - r = 1; - break; - } - } - t_total = time(NULL) - t_total; - - lzo_free(dict); - - if (total_n > 1) - print_info("***TOTALS***", total_d_len, total_c_len); - - printf("Dictionary compression test %s, execution time %lu seconds.\n", - r == 0 ? "passed" : "FAILED", (unsigned long) t_total); - return r; -} - - -/* vim:set ts=4 sw=4 et: */ diff --git a/main/lzo/examples/lzopack.c b/main/lzo/examples/lzopack.c deleted file mode 100644 index 91c0c1ab..00000000 --- a/main/lzo/examples/lzopack.c +++ /dev/null @@ -1,628 +0,0 @@ -/* lzopack.c -- LZO example program: a simple file packer - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -/************************************************************************* -// NOTE: this is an example program, so do not use to backup your data. -// -// This program lacks things like sophisticated file handling but is -// pretty complete regarding compression - it should provide a good -// starting point for adaption for your applications. -// -// Please study LZO.FAQ and simple.c first. -**************************************************************************/ - -#include -#include - -/* 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 unsigned long total_in = 0; -static unsigned long total_out = 0; -static lzo_bool opt_debug = 0; - -/* magic file header for lzopack-compressed files */ -static const unsigned char magic[7] = - { 0x00, 0xe9, 0x4c, 0x5a, 0x4f, 0xff, 0x1a }; - - -/************************************************************************* -// file IO -**************************************************************************/ - -static lzo_uint xread(FILE *fp, lzo_voidp buf, lzo_uint len, lzo_bool allow_eof) -{ - lzo_uint l; - - l = (lzo_uint) lzo_fread(fp, buf, len); - if (l > len) - { - fprintf(stderr, "\n%s: internal error - something is wrong with your C library !!!\n", progname); - exit(1); - } - if (l != len && !allow_eof) - { - fprintf(stderr, "\n%s: read error - premature end of file\n", progname); - exit(1); - } - total_in += (unsigned long) l; - return l; -} - -static lzo_uint xwrite(FILE *fp, const lzo_voidp buf, lzo_uint len) -{ - if (fp != NULL && lzo_fwrite(fp, buf, len) != len) - { - fprintf(stderr, "\n%s: write error (disk full ?)\n", progname); - exit(1); - } - total_out += (unsigned long) len; - return len; -} - - -static int xgetc(FILE *fp) -{ - unsigned char c; - xread(fp, (lzo_voidp) &c, 1, 0); - return c; -} - -static void xputc(FILE *fp, int c) -{ - unsigned char cc = (unsigned char) (c & 0xff); - xwrite(fp, (const lzo_voidp) &cc, 1); -} - -/* read and write portable 32-bit integers */ - -static lzo_uint32_t xread32(FILE *fp) -{ - unsigned char b[4]; - lzo_uint32_t v; - - xread(fp, b, 4, 0); - v = (lzo_uint32_t) b[3] << 0; - v |= (lzo_uint32_t) b[2] << 8; - v |= (lzo_uint32_t) b[1] << 16; - v |= (lzo_uint32_t) b[0] << 24; - return v; -} - -static void xwrite32(FILE *fp, lzo_uint v) -{ - unsigned char b[4]; - - b[3] = (unsigned char) ((v >> 0) & 0xff); - b[2] = (unsigned char) ((v >> 8) & 0xff); - b[1] = (unsigned char) ((v >> 16) & 0xff); - b[0] = (unsigned char) ((v >> 24) & 0xff); - xwrite(fp, b, 4); -} - - -/************************************************************************* -// compress -// -// possible improvement: we could use overlapping compression to -// save some memory - see overlap.c. This would require some minor -// changes in the decompression code as well, because if a block -// turns out to be incompressible we would still have to store it in its -// "compressed" (i.e. then slightly enlarged) form because the original -// (uncompressed) data would have been lost during the overlapping -// compression. -**************************************************************************/ - -static 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_voidp wrkmem = NULL; - lzo_uint in_len; - lzo_uint out_len; - lzo_uint wrkmem_size; - lzo_uint32_t flags = 1; /* do compute a checksum */ - int method = 1; /* compression method: LZO1X */ - lzo_uint32_t checksum; - - total_in = total_out = 0; - -/* - * Step 1: write magic header, flags & block size, init checksum - */ - xwrite(fo, magic, sizeof(magic)); - xwrite32(fo, flags); - 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) xmalloc(block_size); - out = (lzo_bytep) xmalloc(block_size + block_size / 16 + 64 + 3); - if (compression_level == 9) - wrkmem_size = LZO1X_999_MEM_COMPRESS; - else - wrkmem_size = LZO1X_1_MEM_COMPRESS; - wrkmem = (lzo_voidp) xmalloc(wrkmem_size); - if (in == NULL || out == NULL || wrkmem == NULL) - { - printf("%s: out of memory\n", progname); - r = 1; - goto err; - } - -/* - * Step 3: process blocks - */ - for (;;) - { - /* read block */ - in_len = xread(fi, in, block_size, 1); - if (in_len == 0) - break; - - /* update checksum */ - if (flags & 1) - checksum = lzo_adler32(checksum, in, in_len); - - /* clear wrkmem (not needed, only for debug/benchmark purposes) */ - if (opt_debug) - lzo_memset(wrkmem, 0xff, wrkmem_size); - - /* compress block */ - 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); - if (r != LZO_E_OK || out_len > in_len + in_len / 16 + 64 + 3) - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - r = 2; - goto err; - } - - /* write uncompressed block size */ - xwrite32(fo, in_len); - - if (out_len < in_len) - { - /* write compressed block */ - xwrite32(fo, out_len); - xwrite(fo, out, out_len); - } - else - { - /* not compressible - write uncompressed block */ - xwrite32(fo, in_len); - xwrite(fo, in, in_len); - } - } - - /* write EOF marker */ - xwrite32(fo, 0); - - /* write checksum */ - if (flags & 1) - xwrite32(fo, checksum); - - r = 0; -err: - lzo_free(wrkmem); - lzo_free(out); - lzo_free(in); - return r; -} - - -/************************************************************************* -// decompress / test -// -// We are using overlapping (in-place) decompression to save some -// memory - see overlap.c. -**************************************************************************/ - -static int do_decompress(FILE *fi, FILE *fo) -{ - int r = 0; - lzo_bytep buf = NULL; - lzo_uint buf_len; - unsigned char m [ sizeof(magic) ]; - lzo_uint32_t flags; - int method; - int compression_level; - lzo_uint block_size; - lzo_uint32_t checksum; - - total_in = total_out = 0; - -/* - * Step 1: check magic header, read flags & block size, init checksum - */ - if (xread(fi, m, sizeof(magic), 1) != sizeof(magic) || - memcmp(m, magic, sizeof(magic)) != 0) - { - printf("%s: header error - this file is not compressed by lzopack\n", progname); - r = 1; - goto err; - } - flags = xread32(fi); - method = xgetc(fi); - compression_level = xgetc(fi); - if (method != 1) - { - printf("%s: header error - invalid method %d (level %d)\n", - progname, method, compression_level); - r = 2; - goto err; - } - block_size = xread32(fi); - if (block_size < 1024 || block_size > 8L * 1024L * 1024L) - { - printf("%s: header error - invalid block size %ld\n", - progname, (long) block_size); - r = 3; - goto err; - } - checksum = lzo_adler32(0, NULL, 0); - -/* - * Step 2: allocate buffer for in-place decompression - */ - buf_len = block_size + block_size / 16 + 64 + 3; - buf = (lzo_bytep) xmalloc(buf_len); - if (buf == NULL) - { - printf("%s: out of memory\n", progname); - r = 4; - goto err; - } - -/* - * Step 3: process blocks - */ - for (;;) - { - lzo_bytep in; - lzo_bytep out; - lzo_uint in_len; - lzo_uint out_len; - - /* read uncompressed size */ - out_len = xread32(fi); - - /* exit if last block (EOF marker) */ - if (out_len == 0) - break; - - /* read compressed size */ - in_len = xread32(fi); - - /* sanity check of the size values */ - if (in_len > block_size || out_len > block_size || - in_len == 0 || in_len > out_len) - { - printf("%s: block size error - data corrupted\n", progname); - r = 5; - goto err; - } - - /* place compressed block at the top of the buffer */ - in = buf + buf_len - in_len; - out = buf; - - /* read compressed block data */ - xread(fi, in, in_len, 0); - - if (in_len < out_len) - { - /* decompress - use safe decompressor as data might be corrupted - * during a file transfer */ - lzo_uint new_len = out_len; - - r = lzo1x_decompress_safe(in, in_len, out, &new_len, NULL); - if (r != LZO_E_OK || new_len != out_len) - { - printf("%s: compressed data violation\n", progname); - r = 6; - goto err; - } - /* write decompressed block */ - xwrite(fo, out, out_len); - /* update checksum */ - if (flags & 1) - checksum = lzo_adler32(checksum, out, out_len); - } - else - { - /* write original (incompressible) block */ - xwrite(fo, in, in_len); - /* update checksum */ - if (flags & 1) - checksum = lzo_adler32(checksum, in, in_len); - } - } - - /* read and verify checksum */ - if (flags & 1) - { - lzo_uint32_t c = xread32(fi); - if (c != checksum) - { - printf("%s: checksum error - data corrupted\n", progname); - r = 7; - goto err; - } - } - - r = 0; -err: - lzo_free(buf); - return r; -} - - -/************************************************************************* -// -**************************************************************************/ - -static void usage(void) -{ - printf("usage: %s [-9] input-file output-file (compress)\n", progname); - printf("usage: %s -d input-file output-file (decompress)\n", progname); - printf("usage: %s -t input-file... (test)\n", progname); - exit(1); -} - - -/* open input file */ -static FILE *xopen_fi(const char *name) -{ - FILE *fp; - - fp = fopen(name, "rb"); - if (fp == NULL) - { - printf("%s: cannot open input file %s\n", progname, name); - exit(1); - } -#if defined(HAVE_STAT) && defined(S_ISREG) - { - struct stat st; - int is_regular = 1; - if (stat(name, &st) != 0 || !S_ISREG(st.st_mode)) - is_regular = 0; - if (!is_regular) - { - printf("%s: %s is not a regular file\n", progname, name); - fclose(fp); fp = NULL; - exit(1); - } - } -#endif - return fp; -} - - -/* open output file */ -static FILE *xopen_fo(const char *name) -{ - FILE *fp; - -#if 0 - /* this is an example program, so make sure we don't overwrite a file */ - fp = fopen(name, "rb"); - if (fp != NULL) - { - printf("%s: file %s already exists -- not overwritten\n", progname, name); - fclose(fp); fp = NULL; - exit(1); - } -#endif - fp = fopen(name, "wb"); - if (fp == NULL) - { - printf("%s: cannot open output file %s\n", progname, name); - exit(1); - } - return fp; -} - - -/* close file */ -static void xclose(FILE *fp) -{ - if (fp) - { - int err; - err = ferror(fp); - if (fclose(fp) != 0) - err = 1; - if (err) - { - printf("%s: error while closing file\n", progname); - exit(1); - } - } -} - - -/************************************************************************* -// -**************************************************************************/ - -int __lzo_cdecl_main main(int argc, char *argv[]) -{ - int i = 1; - int r = 0; - FILE *fi = NULL; - FILE *fo = NULL; - const char *in_name = NULL; - const char *out_name = NULL; - unsigned opt_decompress = 0; - unsigned opt_test = 0; - int opt_compression_level = 1; - lzo_uint opt_block_size; - const char *s; - - lzo_wildargv(&argc, &argv); - - progname = argv[0]; - for (s = progname; *s; s++) - if ((*s == '/' || *s == '\\') && s[1]) - progname = s + 1; - - printf("\nLZO real-time data compression library (v%s, %s).\n", - lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); - -#if 0 - printf( -"*** DISCLAIMER ***\n" -" This is an example program, do not use to backup your data !\n" -" Get LZOP if you're interested into a full-featured packer.\n" -" See http://www.oberhumer.com/opensource/lzop/\n" -"\n"); -#endif - - -/* - * Step 1: initialize the LZO library - */ - 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"); - exit(1); - } - - -/* - * Step 2: setup memory - */ - opt_block_size = 256 * 1024L; - -#if defined(LZO_MM_AHSHIFT) - /* reduce memory requirements for ancient 16-bit DOS 640kB real-mode */ - if (LZO_MM_AHSHIFT != 3) - opt_block_size = 16 * 1024L; -#endif - - -/* - * Step 3: get options - */ - - while (i < argc && argv[i][0] == '-') - { - if (strcmp(argv[i],"-d") == 0) - opt_decompress = 1; - else if (strcmp(argv[i],"-t") == 0) - opt_test = 1; - else if (strcmp(argv[i],"-9") == 0) - opt_compression_level = 9; - else if (argv[i][1] == 'b' && argv[i][2]) - { - long b = atol(&argv[i][2]); - if (b >= 1024L && b <= 8*1024*1024L) - opt_block_size = (lzo_uint) b; - else - { - printf("%s: invalid block_size in option '%s'.\n", progname, argv[i]); - usage(); - } - } - else if (strcmp(argv[i],"--debug") == 0) - opt_debug += 1; - else - usage(); - i++; - } - if (opt_test && i >= argc) - usage(); - if (!opt_test && i + 2 != argc) - usage(); - - -/* - * Step 4: process file(s) - */ - - if (opt_test) - { - while (i < argc && r == 0) - { - in_name = argv[i++]; - fi = xopen_fi(in_name); - r = do_decompress(fi, NULL); - if (r == 0) - printf("%s: %s tested ok (%lu -> %lu bytes)\n", - progname, in_name, total_in, total_out); - xclose(fi); fi = NULL; - } - } - else if (opt_decompress) - { - in_name = argv[i++]; - out_name = argv[i++]; - fi = xopen_fi(in_name); - fo = xopen_fo(out_name); - r = do_decompress(fi, fo); - if (r == 0) - printf("%s: decompressed %lu into %lu bytes\n", - progname, total_in, total_out); - } - else /* compress */ - { - in_name = argv[i++]; - out_name = argv[i++]; - fi = xopen_fi(in_name); - fo = xopen_fo(out_name); - 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); - } - - xclose(fi); fi = NULL; - xclose(fo); fo = NULL; - return r; -} - - -/* vim:set ts=4 sw=4 et: */ diff --git a/main/lzo/examples/overlap.c b/main/lzo/examples/overlap.c deleted file mode 100644 index 3ff4d180..00000000 --- a/main/lzo/examples/overlap.c +++ /dev/null @@ -1,302 +0,0 @@ -/* overlap.c -- example program: overlapping (de)compression - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -/************************************************************************* -// This program shows how to do overlapping compression and -// in-place decompression. -// -// Please study LZO.FAQ and simple.c first. -**************************************************************************/ - -#include -#include - -/* 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') - * - * Worst case (for files that are compressible by only a few bytes) - * is 'in_len / 16 + 64 + 3'. See step 5a) below. - * - * For overlapping compression '0xbfff + in_len / 16 + 64 + 3' bytes - * will be needed. See step 4a) below. - */ - -static long opt_overhead = 0; /* assume worst case */ - -static unsigned long total_files = 0; -static unsigned long total_in = 0; - - -/************************************************************************* -// -**************************************************************************/ - -static int do_file(const char *in_name) -{ - int r; - FILE *fp = NULL; - long l; - - lzo_voidp wrkmem = NULL; - - lzo_bytep in = NULL; - lzo_uint in_len; /* uncompressed length */ - - lzo_bytep out = NULL; - lzo_uint out_len; /* compressed length */ - - lzo_bytep overlap = NULL; - lzo_uint overhead; - lzo_uint offset; - - lzo_uint new_len = 0; - -/* - * Step 1: open the input file - */ - fp = fopen(in_name, "rb"); - if (fp == NULL) - { - printf("%s: %s: cannot open file\n", progname, in_name); - goto next_file; - } - 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); - goto next_file; - } - in_len = (lzo_uint) l; - if ((long) in_len != l || l > 256L * 1024L * 1024L) - { - printf("%s: %s: file is too big -- skipping\n", progname, in_name); - goto next_file; - } - -/* - * Step 2: allocate compression buffers and read the file - */ - 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 - */ - 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) - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - exit(1); - } - printf("%-25s %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 - */ - overhead = in_len > 0xbfff ? 0xbfff : in_len; - overhead += in_len / 16 + 64 + 3; - overlap = (lzo_bytep) xmalloc(in_len + overhead); - -/* - * Step 4b: prepare data in 'overlap' buffer. - * copy uncompressed data at the top of the overlap buffer - */ - /*** offset = in_len + overhead - in_len; ***/ - offset = overhead; - lzo_memcpy(overlap + offset, in, in_len); - -/* - * 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) - { - /* this should NEVER happen */ - printf("in-place compression failed: %d\n", r); - exit(1); - } - -/* - * Step 4d: verify overlapping compression - */ - if (new_len != out_len || lzo_memcmp(out, overlap, out_len) != 0) - { - /* As compression is non-deterministic there can be a difference - * in the representation of the compressed data (but this usually - * happens very seldom). So we have to verify the overlapping - * compression by doing a temporary decompression. - */ - 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("in-place compression data error\n"); - exit(1); - } - lzo_free(tmp); - } - - printf(" in-place compression: %8lu -> %8lu overhead: %7lu\n", - (unsigned long) in_len, (unsigned long) new_len, (unsigned long) overhead); - lzo_free(overlap); overlap = NULL; - - -/***** Step 5: 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 = (lzo_uint) opt_overhead; - overlap = (lzo_bytep) xmalloc(in_len + overhead); - -/* - * 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 - */ - new_len = in_len; - r = lzo1x_decompress_safe(overlap + offset, out_len, overlap, &new_len, NULL); - if (r != LZO_E_OK) - { - /* this may happen if overhead is too small */ - printf("in-place decompression failed: %d - increase 'opt_overhead'\n", r); - exit(1); - } - -/* - * Step 5d: verify decompression - */ - if (new_len != in_len || lzo_memcmp(in, overlap, in_len) != 0) - { - /* this may happen if overhead is too small */ - printf("in-place decompression data error - increase 'opt_overhead'\n"); - exit(1); - } - printf(" in-place decompression: %8lu -> %8lu overhead: %7lu\n", - (unsigned long) out_len, (unsigned long) new_len, (unsigned long) overhead); - lzo_free(overlap); overlap = NULL; - - -next_file: - lzo_free(overlap); - lzo_free(wrkmem); - lzo_free(out); - lzo_free(in); - if (fp) fclose(fp); - - return 0; -} - - -/************************************************************************* -// -**************************************************************************/ - -int __lzo_cdecl_main main(int argc, char *argv[]) -{ - int r; - int i = 1; - - 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-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); - - progname = argv[0]; - if (i < argc && argv[i][0] == '-') - opt_overhead = atol(&argv[i++][1]); -#if 1 - if (opt_overhead != 0 && opt_overhead < 4) - { - printf("%s: invalid overhead value %ld\n", progname, opt_overhead); - exit(1); - } -#endif - if (i >= argc) - { - printf("usage: %s [-overhead_in_bytes] file..\n", progname); - exit(1); - } - -/* - * Step 1: initialize the LZO library - */ - 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"); - exit(1); - } - -/* - * Step 2: process files - */ - for (r = 0; r == 0 && i < argc; i++) - r = do_file(argv[i]); - - printf("\nDone. Successfully processed %lu bytes in %lu files.\n", - total_in, total_files); - return r; -} - - -/* vim:set ts=4 sw=4 et: */ diff --git a/main/lzo/examples/portab.h b/main/lzo/examples/portab.h deleted file mode 100644 index 93db56a9..00000000 --- a/main/lzo/examples/portab.h +++ /dev/null @@ -1,144 +0,0 @@ -/* portab.h -- portability layer - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -#include - -#if (LZO_CC_MSC && (_MSC_VER >= 1000 && _MSC_VER < 1200)) - /* 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 */ -# pragma warning(disable: 4163 4255 4820) - /* avoid warnings about inlining */ -# pragma warning(disable: 4710 4711) -#endif -/* disable silly warnings about using "deprecated" POSIX functions like "fopen" */ -#if (LZO_CC_CLANG_MSC && LZO_CC_CLANG >= 0x030500) -# pragma clang diagnostic ignored "-Wdeprecated-declarations" -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1100)) -# pragma warning(disable: 1786) -#elif (LZO_CC_INTELC_MSC && (__INTEL_COMPILER >= 1000)) -# pragma warning(disable: 1478) -#elif (LZO_CC_MSC && (_MSC_VER >= 1400)) -# pragma warning(disable: 4996) -#endif -#if (LZO_CC_PELLESC && (__POCC__ >= 290)) -# pragma warn(disable:2002) -#endif - - -/************************************************************************* -// -**************************************************************************/ - -#if defined(LZO_WANT_ACCLIB_GETOPT) || !(defined(LZO_LIBC_ISOC90) || defined(LZO_LIBC_ISOC99)) - -#include "examples/portab_a.h" - -#else - -/* On any halfway modern machine we can use the following pure ANSI-C code. */ - -#include -#include -#include -#include -#include -#include -#if defined(CLK_TCK) && !defined(CLOCKS_PER_SEC) -# define CLOCKS_PER_SEC CLK_TCK -#endif - -#if defined(WANT_LZO_MALLOC) -# define lzo_malloc(a) (malloc(a)) -# define lzo_free(a) (free(a)) -#endif -#if defined(WANT_LZO_FREAD) -# define lzo_fread(f,b,s) (fread(b,1,s,f)) -# define lzo_fwrite(f,b,s) (fwrite(b,1,s,f)) -#endif -#if defined(WANT_LZO_PCLOCK) -# define lzo_pclock_handle_t int -# define lzo_pclock_t double -# define lzo_pclock_open_default(a) ((void)(a)) -# define lzo_pclock_close(a) ((void)(a)) -# define lzo_pclock_read(a,b) *(b) = (clock() / (double)(CLOCKS_PER_SEC)) -# define lzo_pclock_get_elapsed(a,b,c) (*(c) - *(b)) -# define lzo_pclock_flush_cpu_cache(a,b) ((void)(a)) -#endif -#if defined(WANT_LZO_WILDARGV) -# define lzo_wildargv(a,b) ((void)0) -#endif - -#endif - - -/************************************************************************* -// misc -**************************************************************************/ - -/* turn on assertions */ -#undef NDEBUG -#include - -/* just in case */ -#undef xmalloc -#undef xfree -#undef xread -#undef xwrite -#undef xputc -#undef xgetc -#undef xread32 -#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); - lzo_free(p); - exit(1); - } - return p; -} -#endif - - -/* vim:set ts=4 sw=4 et: */ diff --git a/main/lzo/examples/portab_a.h b/main/lzo/examples/portab_a.h deleted file mode 100644 index 64841971..00000000 --- a/main/lzo/examples/portab_a.h +++ /dev/null @@ -1,61 +0,0 @@ -/* portab_a.h -- advanced portability layer - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -/************************************************************************* -// -**************************************************************************/ - -#if defined(LZO_HAVE_CONFIG_H) -# define LZO_CFG_NO_CONFIG_HEADER 1 -#endif - -#define LZO_WANT_ACC_INCD_H 1 -#define LZO_WANT_ACC_INCE_H 1 -#if defined(LZO_WANT_ACCLIB_GETOPT) || defined(WANT_LZO_PCLOCK) || defined(WANT_LZO_WILDARGV) -# define LZO_WANT_ACC_INCI_H 1 -# define LZO_WANT_ACC_LIB_H 1 -#endif -#if defined(WANT_LZO_PCLOCK) -# define LZO_WANT_ACCLIB_PCLOCK 1 -#endif -#if defined(WANT_LZO_WILDARGV) -# define LZO_WANT_ACCLIB_WILDARGV 1 -#endif -#include "src/lzo_supp.h" - -#if defined(WANT_LZO_MALLOC) -# define lzo_malloc(a) (malloc(a)) -# define lzo_free(a) (free(a)) -#endif -#if defined(WANT_LZO_FREAD) -# define lzo_fread(f,b,s) (fread(b,1,s,f)) -# define lzo_fwrite(f,b,s) (fwrite(b,1,s,f)) -#endif - - -/* vim:set ts=4 sw=4 et: */ diff --git a/main/lzo/examples/precomp.c b/main/lzo/examples/precomp.c deleted file mode 100644 index e61b0c13..00000000 --- a/main/lzo/examples/precomp.c +++ /dev/null @@ -1,330 +0,0 @@ -/* precomp.c -- example program: how to generate pre-compressed data - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -/************************************************************************* -// This program shows how to generate pre-compressed data. -// -// Please study LZO.FAQ and simple.c first. -// -// We will be trying both LZO1X-999 and LZO1Y-999 and choose -// the algorithm that achieves the best compression ratio. -**************************************************************************/ - -#include -#include -#include - -#define USE_LZO1X 1 -#define USE_LZO1Y 1 - -#define PARANOID 1 - - -/* 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" - - -/************************************************************************* -// -**************************************************************************/ - -int __lzo_cdecl_main main(int argc, char *argv[]) -{ - int r; - - lzo_bytep in; - lzo_uint in_len; - - lzo_bytep out; - lzo_uint out_bufsize; - lzo_uint out_len = 0; - - lzo_voidp wrkmem; - lzo_uint wrkmem_size; - - lzo_uint best_len; - int best_compress = -1; - - lzo_uint orig_len; - lzo_uint32_t uncompressed_checksum; - lzo_uint32_t compressed_checksum; - - FILE *fp; - const char *in_name = NULL; - const char *out_name = NULL; - long l; - - - 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-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); - - progname = argv[0]; - if (argc < 2 || argc > 3) - { - printf("usage: %s file [output-file]\n", progname); - exit(1); - } - in_name = argv[1]; - if (argc > 2) out_name = argv[2]; - -/* - * Step 1: initialize the LZO library - */ - 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"); - exit(1); - } - -/* - * Step 2: allocate the work-memory - */ - wrkmem_size = 1; -#ifdef USE_LZO1X - wrkmem_size = (LZO1X_999_MEM_COMPRESS > wrkmem_size) ? LZO1X_999_MEM_COMPRESS : wrkmem_size; -#endif -#ifdef USE_LZO1Y - wrkmem_size = (LZO1Y_999_MEM_COMPRESS > wrkmem_size) ? LZO1Y_999_MEM_COMPRESS : wrkmem_size; -#endif - wrkmem = (lzo_voidp) xmalloc(wrkmem_size); - if (wrkmem == NULL) - { - printf("%s: out of memory\n", progname); - exit(1); - } - -/* - * Step 3: open the input file - */ - fp = fopen(in_name,"rb"); - if (fp == NULL) - { - printf("%s: cannot open file %s\n", progname, in_name); - exit(1); - } - 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(fp); fp = NULL; - exit(1); - } - in_len = (lzo_uint) l; - out_bufsize = in_len + in_len / 16 + 64 + 3; - best_len = in_len; - -/* - * Step 4: allocate compression buffers and read the file - */ - 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(fp, in, in_len); - printf("%s: loaded file %s: %ld bytes\n", progname, in_name, (long) in_len); - fclose(fp); fp = NULL; - -/* - * Step 5: compute a checksum of the uncompressed data - */ - uncompressed_checksum = lzo_adler32(0,NULL,0); - uncompressed_checksum = lzo_adler32(uncompressed_checksum,in,in_len); - -/* - * Step 6a: compress from 'in' to 'out' with LZO1X-999 - */ -#ifdef USE_LZO1X - out_len = out_bufsize; - r = lzo1x_999_compress(in,in_len,out,&out_len,wrkmem); - if (r != LZO_E_OK) - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - exit(1); - } - printf("LZO1X-999: %8lu -> %8lu\n", (unsigned long) in_len, (unsigned long) out_len); - if (out_len < best_len) - { - best_len = out_len; - best_compress = 1; /* LZO1X-999 */ - } -#endif /* USE_LZO1X */ - -/* - * Step 6b: compress from 'in' to 'out' with LZO1Y-999 - */ -#ifdef USE_LZO1Y - out_len = out_bufsize; - r = lzo1y_999_compress(in,in_len,out,&out_len,wrkmem); - if (r != LZO_E_OK) - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - exit(1); - } - printf("LZO1Y-999: %8lu -> %8lu\n", (unsigned long) in_len, (unsigned long) out_len); - if (out_len < best_len) - { - best_len = out_len; - best_compress = 2; /* LZO1Y-999 */ - } -#endif /* USE_LZO1Y */ - -/* - * Step 7: check if compressible - */ - if (best_len >= in_len) - { - printf("This file contains incompressible data.\n"); - return 0; - } - -/* - * Step 8: compress data again using the best compressor found - */ - out_len = out_bufsize; - if (best_compress == 1) - r = lzo1x_999_compress(in,in_len,out,&out_len,wrkmem); - else if (best_compress == 2) - r = lzo1y_999_compress(in,in_len,out,&out_len,wrkmem); - else - r = -100; - assert(r == LZO_E_OK); - assert(out_len == best_len); - -/* - * Step 9: optimize compressed data (compressed data is in 'out' buffer) - */ -#if 1 - /* Optimization does not require any data in the buffer that will - * hold the uncompressed data. To prove this, we clear the buffer. - */ - lzo_memset(in,0,in_len); -#endif - - orig_len = in_len; - r = -100; -#ifdef USE_LZO1X - if (best_compress == 1) - r = lzo1x_optimize(out,out_len,in,&orig_len,NULL); -#endif -#ifdef USE_LZO1Y - if (best_compress == 2) - r = lzo1y_optimize(out,out_len,in,&orig_len,NULL); -#endif - if (r != LZO_E_OK || orig_len != in_len) - { - /* this should NEVER happen */ - printf("internal error - optimization failed: %d\n", r); - exit(1); - } - -/* - * Step 10: compute a checksum of the compressed data - */ - compressed_checksum = lzo_adler32(0,NULL,0); - compressed_checksum = lzo_adler32(compressed_checksum,out,out_len); - -/* - * Step 11: write compressed data to a file - */ - printf("%s: %s: %ld -> %ld, checksum 0x%08lx 0x%08lx\n", - progname, in_name, (long) in_len, (long) out_len, - (long) uncompressed_checksum, (long) compressed_checksum); - - if (out_name && out_name[0]) - { - printf("%s: writing to file %s\n", progname, out_name); - fp = fopen(out_name,"wb"); - if (fp == NULL) - { - printf("%s: cannot open output file %s\n", progname, out_name); - exit(1); - } - if (lzo_fwrite(fp, out, out_len) != out_len || fclose(fp) != 0) - { - printf("%s: write error !!\n", progname); - exit(1); - } - } - -/* - * Step 12: verify decompression - */ -#ifdef PARANOID - lzo_memset(in,0,in_len); /* paranoia - clear output buffer */ - orig_len = in_len; - r = -100; -#ifdef USE_LZO1X - if (best_compress == 1) - r = lzo1x_decompress_safe(out,out_len,in,&orig_len,NULL); -#endif -#ifdef USE_LZO1Y - if (best_compress == 2) - r = lzo1y_decompress_safe(out,out_len,in,&orig_len,NULL); -#endif - if (r != LZO_E_OK || orig_len != in_len) - { - /* this should NEVER happen */ - printf("internal error - decompression failed: %d\n", r); - exit(1); - } - if (uncompressed_checksum != lzo_adler32(lzo_adler32(0,NULL,0),in,in_len)) - { - /* this should NEVER happen */ - printf("internal error - decompression data error\n"); - exit(1); - } - /* Now you could also verify decompression under similar conditions as in - * your application, e.g. overlapping assembler decompression etc. - */ -#endif - - lzo_free(in); - lzo_free(out); - lzo_free(wrkmem); - - return 0; -} - - -/* vim:set ts=4 sw=4 et: */ diff --git a/main/lzo/examples/precomp2.c b/main/lzo/examples/precomp2.c deleted file mode 100644 index 3216cd99..00000000 --- a/main/lzo/examples/precomp2.c +++ /dev/null @@ -1,382 +0,0 @@ -/* precomp2.c -- example program: how to generate pre-compressed data - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -/************************************************************************* -// This program shows how to generate pre-compressed data. -// -// Please study precomp.c first. -// -// We will be trying LZO1X-999 and LZO1Y-999, and we will be trying -// various parameters using the internal interface to squeeze out -// a little bit of extra compression. -// -// NOTE: this program can be quite slow for highly redundant files -**************************************************************************/ - -#include -#include -#include - -LZO_EXTERN(int) -lzo1x_999_compress_internal ( const lzo_bytep in , lzo_uint in_len, - lzo_bytep out, lzo_uintp out_len, - lzo_voidp wrkmem, - const lzo_bytep dict, lzo_uint dict_len, - lzo_callback_p cb, - int try_lazy, - lzo_uint good_length, - lzo_uint max_lazy, - lzo_uint nice_length, - lzo_uint max_chain, - lzo_uint32_t flags ); - -LZO_EXTERN(int) -lzo1y_999_compress_internal ( const lzo_bytep in , lzo_uint in_len, - lzo_bytep out, lzo_uintp out_len, - lzo_voidp wrkmem, - const lzo_bytep dict, lzo_uint dict_len, - lzo_callback_p cb, - int try_lazy, - lzo_uint good_length, - lzo_uint max_lazy, - lzo_uint nice_length, - lzo_uint max_chain, - lzo_uint32_t flags ); - -#define USE_LZO1X 1 -#define USE_LZO1Y 1 - -#define PARANOID 1 - - -/* 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" - - -/************************************************************************* -// -**************************************************************************/ - -int __lzo_cdecl_main main(int argc, char *argv[]) -{ - int r; - int lazy; - const int max_try_lazy = 5; - const lzo_uint big = 65536L; /* can result in very slow compression */ - const lzo_uint32_t flags = 0x1; - - lzo_bytep in; - lzo_uint in_len; - - lzo_bytep out; - lzo_uint out_bufsize; - lzo_uint out_len = 0; - - lzo_voidp wrkmem; - lzo_uint wrkmem_size; - - lzo_uint best_len; - int best_compress = -1; - int best_lazy = -1; - - lzo_uint orig_len; - lzo_uint32_t uncompressed_checksum; - lzo_uint32_t compressed_checksum; - - FILE *fp; - const char *in_name = NULL; - const char *out_name = NULL; - long l; - - - 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-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); - - progname = argv[0]; - if (argc < 2 || argc > 3) - { - printf("usage: %s file [output-file]\n", progname); - exit(1); - } - in_name = argv[1]; - if (argc > 2) out_name = argv[2]; - -/* - * Step 1: initialize the LZO library - */ - 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"); - exit(1); - } - -/* - * Step 2: allocate the work-memory - */ - wrkmem_size = 1; -#ifdef USE_LZO1X - wrkmem_size = (LZO1X_999_MEM_COMPRESS > wrkmem_size) ? LZO1X_999_MEM_COMPRESS : wrkmem_size; -#endif -#ifdef USE_LZO1Y - wrkmem_size = (LZO1Y_999_MEM_COMPRESS > wrkmem_size) ? LZO1Y_999_MEM_COMPRESS : wrkmem_size; -#endif - wrkmem = (lzo_voidp) xmalloc(wrkmem_size); - if (wrkmem == NULL) - { - printf("%s: out of memory\n", progname); - exit(1); - } - -/* - * Step 3: open the input file - */ - fp = fopen(in_name,"rb"); - if (fp == NULL) - { - printf("%s: cannot open file %s\n", progname, in_name); - exit(1); - } - 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(fp); fp = NULL; - exit(1); - } - in_len = (lzo_uint) l; - out_bufsize = in_len + in_len / 16 + 64 + 3; - best_len = in_len; - -/* - * Step 4: allocate compression buffers and read the file - */ - 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(fp, in, in_len); - printf("%s: loaded file %s: %ld bytes\n", progname, in_name, (long) in_len); - fclose(fp); fp = NULL; - -/* - * Step 5: compute a checksum of the uncompressed data - */ - uncompressed_checksum = lzo_adler32(0,NULL,0); - uncompressed_checksum = lzo_adler32(uncompressed_checksum,in,in_len); - -/* - * Step 6a: compress from 'in' to 'out' with LZO1X-999 - */ -#ifdef USE_LZO1X - for (lazy = 0; lazy <= max_try_lazy; lazy++) - { - out_len = out_bufsize; - r = lzo1x_999_compress_internal(in,in_len,out,&out_len,wrkmem, - NULL, 0, 0, - lazy, big, big, big, big, flags); - if (r != LZO_E_OK) - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - exit(1); - } - printf("LZO1X-999: lazy =%2d: %8lu -> %8lu\n", - lazy, (unsigned long) in_len, (unsigned long) out_len); - if (out_len < best_len) - { - best_len = out_len; - best_lazy = lazy; - best_compress = 1; /* LZO1X-999 */ - } - } -#endif /* USE_LZO1X */ - -/* - * Step 6b: compress from 'in' to 'out' with LZO1Y-999 - */ -#ifdef USE_LZO1Y - for (lazy = 0; lazy <= max_try_lazy; lazy++) - { - out_len = out_bufsize; - r = lzo1y_999_compress_internal(in,in_len,out,&out_len,wrkmem, - NULL, 0, 0, - lazy, big, big, big, big, flags); - if (r != LZO_E_OK) - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - exit(1); - } - printf("LZO1Y-999: lazy =%2d: %8lu -> %8lu\n", - lazy, (unsigned long) in_len, (unsigned long) out_len); - if (out_len < best_len) - { - best_len = out_len; - best_lazy = lazy; - best_compress = 2; /* LZO1Y-999 */ - } - } -#endif /* USE_LZO1Y */ - -/* - * Step 7: check if compressible - */ - if (best_len >= in_len) - { - printf("This file contains incompressible data.\n"); - return 0; - } - -/* - * Step 8: compress data again using the best compressor found - */ - out_len = out_bufsize; - if (best_compress == 1) - r = lzo1x_999_compress_internal(in,in_len,out,&out_len,wrkmem, - NULL, 0, 0, - best_lazy, big, big, big, big, flags); - else if (best_compress == 2) - r = lzo1y_999_compress_internal(in,in_len,out,&out_len,wrkmem, - NULL, 0, 0, - best_lazy, big, big, big, big, flags); - else - r = -100; - assert(r == LZO_E_OK); - assert(out_len == best_len); - -/* - * Step 9: optimize compressed data (compressed data is in 'out' buffer) - */ -#if 1 - /* Optimization does not require any data in the buffer that will - * hold the uncompressed data. To prove this, we clear the buffer. - */ - lzo_memset(in,0,in_len); -#endif - - orig_len = in_len; - r = -100; -#ifdef USE_LZO1X - if (best_compress == 1) - r = lzo1x_optimize(out,out_len,in,&orig_len,NULL); -#endif -#ifdef USE_LZO1Y - if (best_compress == 2) - r = lzo1y_optimize(out,out_len,in,&orig_len,NULL); -#endif - if (r != LZO_E_OK || orig_len != in_len) - { - /* this should NEVER happen */ - printf("internal error - optimization failed: %d\n", r); - exit(1); - } - -/* - * Step 10: compute a checksum of the compressed data - */ - compressed_checksum = lzo_adler32(0,NULL,0); - compressed_checksum = lzo_adler32(compressed_checksum,out,out_len); - -/* - * Step 11: write compressed data to a file - */ - printf("%s: %s: %ld -> %ld, checksum 0x%08lx 0x%08lx\n", - progname, in_name, (long) in_len, (long) out_len, - (long) uncompressed_checksum, (long) compressed_checksum); - - if (out_name && out_name[0]) - { - printf("%s: writing to file %s\n", progname, out_name); - fp = fopen(out_name,"wb"); - if (fp == NULL) - { - printf("%s: cannot open output file %s\n", progname, out_name); - exit(1); - } - if (lzo_fwrite(fp, out, out_len) != out_len || fclose(fp) != 0) - { - printf("%s: write error !!\n", progname); - exit(1); - } - } - -/* - * Step 12: verify decompression - */ -#ifdef PARANOID - lzo_memset(in,0,in_len); /* paranoia - clear output buffer */ - orig_len = in_len; - r = -100; -#ifdef USE_LZO1X - if (best_compress == 1) - r = lzo1x_decompress_safe(out,out_len,in,&orig_len,NULL); -#endif -#ifdef USE_LZO1Y - if (best_compress == 2) - r = lzo1y_decompress_safe(out,out_len,in,&orig_len,NULL); -#endif - if (r != LZO_E_OK || orig_len != in_len) - { - /* this should NEVER happen */ - printf("internal error - decompression failed: %d\n", r); - exit(1); - } - if (uncompressed_checksum != lzo_adler32(lzo_adler32(0,NULL,0),in,in_len)) - { - /* this should NEVER happen */ - printf("internal error - decompression data error\n"); - exit(1); - } - /* Now you could also verify decompression under similar conditions as in - * your application, e.g. overlapping assembler decompression etc. - */ -#endif - - lzo_free(in); - lzo_free(out); - lzo_free(wrkmem); - - return 0; -} - - -/* vim:set ts=4 sw=4 et: */ diff --git a/main/lzo/examples/simple.c b/main/lzo/examples/simple.c deleted file mode 100644 index 5757e0c1..00000000 --- a/main/lzo/examples/simple.c +++ /dev/null @@ -1,156 +0,0 @@ -/* simple.c -- the annotated simple example program for the LZO library - - This file is part of the LZO real-time data compression library. - - Copyright (C) 1996-2017 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., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Markus F.X.J. Oberhumer - - http://www.oberhumer.com/opensource/lzo/ - */ - - -/************************************************************************* -// This program shows the basic usage of the LZO library. -// We will compress a block of data and decompress again. -// -// See also LZO.FAQ -**************************************************************************/ - -/* We will be using the LZO1X-1 algorithm, so we have - * to include - */ - -#include -#include - -/* 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 must provide a little more output space in case that compression - * is not possible. - */ - -#ifndef IN_LEN -#define IN_LEN (128*1024L) -#endif -#define OUT_LEN (IN_LEN + IN_LEN / 16 + 64 + 3) - - -/************************************************************************* -// -**************************************************************************/ - -int __lzo_cdecl_main main(int argc, char *argv[]) -{ - int r; - lzo_bytep in; - lzo_bytep out; - lzo_voidp wrkmem; - lzo_uint in_len; - lzo_uint out_len; - lzo_uint new_len; - - if (argc < 0 && argv == NULL) /* avoid warning about unused args */ - return 0; - - printf("\nLZO real-time data compression library (v%s, %s).\n", - lzo_version_string(), lzo_version_date()); - printf("Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n"); - -/* - * Step 1: initialize the LZO library - */ - 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"); - return 4; - } - -/* - * Step 2: allocate blocks and the work-memory - */ - 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"); - return 3; - } - -/* - * Step 3: prepare the input block that will get compressed. - * We just fill it with zeros in this example program, - * but you would use your real-world data here. - */ - in_len = IN_LEN; - lzo_memset(in,0,in_len); - -/* - * 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) - printf("compressed %lu bytes into %lu bytes\n", - (unsigned long) in_len, (unsigned long) out_len); - else - { - /* this should NEVER happen */ - printf("internal error - compression failed: %d\n", r); - return 2; - } - /* check for an incompressible block */ - if (out_len >= in_len) - { - printf("This block contains incompressible data.\n"); - return 0; - } - -/* - * Step 5: decompress again, now going from 'out' to 'in' - */ - new_len = in_len; - r = lzo1x_decompress(out, out_len, in, &new_len, NULL); - if (r == LZO_E_OK && new_len == in_len) - printf("decompressed %lu bytes back into %lu bytes\n", - (unsigned long) out_len, (unsigned long) in_len); - else - { - /* this should NEVER happen */ - printf("internal error - decompression failed: %d\n", r); - return 1; - } - - lzo_free(wrkmem); - lzo_free(out); - lzo_free(in); - printf("Simple compression test passed.\n"); - return 0; -} - - -/* vim:set ts=4 sw=4 et: */ -- cgit v1.2.3