00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004
00005 #include "nixsys.h"
00006 #include "minilzo.203/minilzo.h"
00007
00008 #if defined(__LZO_STRICT_16BIT)
00009 #define IN_LEN (8*1024u)
00010 #elif defined(LZO_ARCH_I086) && !defined(LZO_HAVE_MM_HUGE_ARRAY)
00011 #define IN_LEN (60*1024u)
00012 #else
00013
00014 #define IN_LEN (4*1024ul)
00015 #endif
00016 #define OUT_LEN (IN_LEN + IN_LEN / 16 + 64 + 3)
00017
00018 #define HEAP_ALLOC(var,size) \
00019 lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]
00020
00021
00022 unsigned char __LZO_MMODEL in [ IN_LEN ];
00023 unsigned char __LZO_MMODEL out [ OUT_LEN ];
00024 HEAP_ALLOC(wrkmem,LZO1X_1_MEM_COMPRESS);
00025
00026
00027
00028 int main(int argc, char *argv[]){
00029 void *buf = malloc(16000);
00030 void *buf2 = malloc(16000);
00031 char *str= "text data text data text data text data text data text data" ;
00032 int r;
00033 lzo_uint in_len;
00034 lzo_uint out_len;
00035 lzo_uint new_len;
00036
00037 std::cerr << "INLEN " << IN_LEN << std::endl ;
00038
00039 int outw,n ;
00040 if (lzo_init() != LZO_E_OK){
00041 fprintf(stderr,"internal error - lzo_init() failed !!!\n");
00042 fprintf(stderr,"(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable `-DLZO_DEBUG' for diagnostics)\n");
00043 return 3;
00044 }
00045
00046 if (argc < 2){
00047 std::cerr << "compressing" << std::endl ;
00048 outw = 0 ;
00049 while(n = ::read(0,buf,129)){
00050
00051
00052
00053 in_len = n;
00054 lzo_memcpy(in,buf,n);
00055
00056
00057
00058
00059 r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
00060 if (r == LZO_E_OK)
00061 fprintf(stderr,"compressed %lu bytes into %lu bytes\n",
00062 (unsigned long) in_len, (unsigned long) out_len);
00063 else
00064 {
00065
00066 fprintf(stderr,"internal error - compression failed: %d\n", r);
00067 return 2;
00068 }
00069
00070 ::write(1,out,out_len);
00071 std::cerr << "written " << out_len << "bytes" << std::endl ;
00072 }
00073 }else{
00074 outw = 0 ;
00075 std::cerr << "decompressing" << std::endl ;
00076 while(n = ::read(0,out,100)){
00077
00078
00079 out_len = n ;
00080
00081 r = lzo1x_decompress(out,out_len,in,&new_len,NULL);
00082 if (r == LZO_E_OK)
00083 fprintf(stderr,"decompressed %lu bytes back into %lu bytes\n",
00084 (unsigned long) out_len, (unsigned long) new_len);
00085 else
00086 {
00087
00088 fprintf(stderr,"internal error - decompression failed: %d\n", r);
00089 return 1;
00090 }
00091
00092 ::write(1,in,new_len);
00093
00094
00095
00096 std::cerr << "written" << outw << "bytes" << std::endl ;
00097
00098 }
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 return EXIT_SUCCESS;
00112 }
00113