4577652 [rkeene@sledge /home/rkeene/devel/dact]$ cat -n comp_plain.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 /*
23     Example block compression routine for interfacing with DACT.
24 
25     This does no compression.
26 
27     (This is used as the minimum case, so block can be atmost blk_size
28     +3 bytes in size)
29 */
30 
31 
32 #include "dact.h"
33 #include "comp_plain.h"
34 #include <stdio.h>
35 #ifdef HAVE_UNISTD_H
36 #include <unistd.h>
37 #endif
38 #ifdef HAVE_STDLIB_H
39 #include <stdlib.h>
40 #endif
41 #ifdef HAVE_STRING_H
42 #include <string.h>
43 #endif
44 
45 
46 /*
47     mode        - DACT_MODE_COMPR or DACT_MODE_DECMP
48                 Determine whether to compress or decompress.
49     prev_block  - Previous (uncompressed) block.
50     curr_block  - The data to be compressed.
51     out_block   - Where to put data after compression.
52     blk_size    - Size of prev_block and curr_block.
53 */
54 int comp_plain_algo(int mode, unsigned char *prev_block, unsigned char *curr_block, char *out_block, int blk_size, int
	bufsize) {
55     switch(mode) {
56         case DACT_MODE_COMPR:
57             return(comp_plain_compress(prev_block, curr_block, out_block, blk_size, bufsize));
58             break; /* Heh */
59         case DACT_MODE_DECMP:
60             return(comp_plain_decompress(prev_block, curr_block, out_block, blk_size, bufsize));
61             break;
62         default:
63             printf("Unsupported mode: %i\n", mode);
64             return(-1);
65     }
66 }
67 
68 int comp_plain_compress(unsigned char *prev_block, unsigned char *curr_block, char *out_block, int blk_size, int
	bufsize) {
69     memcpy(out_block,curr_block,blk_size);
70     return(blk_size);
71 }
72 
73 int comp_plain_decompress(unsigned char *prev_block, unsigned char *curr_block, char *out_block, int blk_size, int
	bufsize) {
74     memcpy(out_block,curr_block,blk_size);
75     return(blk_size);
76 }
4577653 [rkeene@sledge /home/rkeene/devel/dact]$

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