4556584 [rkeene@sledge /home/rkeene/devel/dact-0.8.37]$ cat -n comp_lzota.c
 1 /*
 2  * Copyright (C) 2001, 2002, and 2003  Roy Keene
 3  *
 4  * This program is free software; you can redistribute it and/or
 5  * modify it under the terms of the GNU General Public License
 6  * as published by the Free Software Foundation; either version 2
 7  * of the License, or (at your option) any later version.
 8  *
 9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  *      email: dact@rkeene.org
19  */
20 
21 
22 #include "dact.h"
23 #include "comp_lzota.h"
24 #ifndef comp_lzota_algo
25 #include <lzoconf.h>
26 #include <lzo2a.h>
27 #include <stdio.h>
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31 #ifdef HAVE_STDLIB_H
32 #include <stdlib.h>
33 #endif
34 
35 
36 /*
37     mode        - DACT_MODE_COMPR or DACT_MODE_DECMP
38                 Determine whether to compress or decompress.
39     prev_block  - Previous (uncompressed) block.
40     curr_block  - The data to be compressed.
41     out_block   - Where to put data after compression.
42     blk_size    - Size of prev_block and curr_block.
43 */
44 
45 #if defined(AS_MODULE) && defined(USE_MODULES)
46 #include "module.h"
47 uint32_t DC_NUM=15;
48 uint32_t DC_TYPE=DACT_MOD_TYPE_COMP;
49 void *DC_ALGO=comp_lzota_algo;
50 char *DC_NAME="LZO-2a Compression (MOD)";
51 /*
52 char *DC_SIGN="RGlnaXRhbFNpZ25hdHVyZQ==";
53 char *DC_URL_GET="http://www.rkeene.org/projects/compression/dact/@@OSNM@@-@@ARCH@@/comp_rle.dll";
54 char *DC_URL_VER="http://www.rkeene.org/projects/compression/dact/@@OSNM@@-@@ARCH@@/comp_rle.ver";
55 uint32_t DC_VER=0x00080d;
56 uint32_t DC_REQUIRE=DACT_MOD_REQ_ATLEAST|(0x00080d);
57 */
58 #endif
59 
60 int comp_lzota_algo(int mode, unsigned char *prev_block, unsigned char *curr_block, char *out_block, int blk_size, int
	bufsize) {
61     switch(mode) {
62         case DACT_MODE_COMPR:
63             return(comp_lzota_compress(prev_block, curr_block, out_block, blk_size, bufsize));
64             break; /* Heh */
65         case DACT_MODE_DECMP:
66             return(comp_lzota_decompress(prev_block, curr_block, out_block, blk_size, bufsize));
67             break;
68         default:
69             printf("Unsupported mode: %i\n", mode);
70             return(-1);
71     }
72 }
73 
74 int comp_lzota_compress(unsigned char *prev_block, unsigned char *curr_block, char *out_block, int blk_size, int
	bufsize) {
75     int retsize=0;
76     char *wrkmem;
77 
78     if ((wrkmem=malloc(LZO2A_999_MEM_COMPRESS))==NULL) return(-1);
79     if (lzo_init()!=LZO_E_OK) return(-1);
80     lzo2a_999_compress(curr_block, blk_size, out_block, &retsize, wrkmem);
81     free(wrkmem);
82     return(retsize);
83 }
84 
85 int comp_lzota_decompress(unsigned char *prev_block, unsigned char *curr_block, char *out_block, int blk_size, int
	bufsize) {
86     int retsize=0, retval;
87 
88     if (lzo_init()!=LZO_E_OK) return(-1);
89     retval=lzo2a_decompress(curr_block, blk_size, out_block, &retsize, NULL);
90     if (retval!=LZO_E_OK) return(-1);
91     return(retsize);
92 }
93 #endif
4556585 [rkeene@sledge /home/rkeene/devel/dact-0.8.37]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2004-04-04 07:01:50