-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsae_enc.c
More file actions
89 lines (77 loc) · 1.85 KB
/
sae_enc.c
File metadata and controls
89 lines (77 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ex: set tabstop=2 expandtab softtabstop=2 shiftwidth=2: */
/* SAE_ENC $(DATE)
* user interface for various compression algorithms
* @author esa karjalainen
* */
/*Testing version control*/
#include <stdio.h>
#include <string.h>
#include "compress.h"
void compress(FILE *, FILE*);
void extract(FILE *, FILE*);
void printBuffer(char *buf, int len);
int main(int argc, char *argv[]){
/*c/x [type] infile outfile*/
if (argc==4||argc==5){
FILE *infile;
FILE *outfile;
int nfilearg;
if(argc==4){
nfilearg=2;
}
else {
nfilearg=3;
}
infile = fopen(argv[nfilearg], "r");
if(infile==0){
printf("\nCouldn't open infile\n");
return -1;
}
outfile = fopen(argv[nfilearg+1], "w");
if(outfile==0){
printf("\nCouldn't open infile\n");
return -1;
}
/* Read data to buffer, compress, */
switch((int)*argv[1]){
int i;
case 'c':
compress(infile, outfile);
break;
case 'x':
extract(infile, outfile);
break;
default:
printf("DEBUG:");
for (i =0;i<argc;i++) {
printf("%d:%s ", i, argv[i]);
}
}
fclose(infile);
fclose(outfile);
}
else {
printf("\nInvalid command line arguments!\n");
printf("enc (c/x) infile outfile\n");
}
return 0;
}
/*
don't remember why I did it this way, probably to
wrap the compression-format specific file.
*/
void compress(FILE *infile, FILE* outfile){
compress_rle_ec(infile, outfile);
}
/* At least here we can call a diff'rent extractor based on filetype...
*
*/
void extract(FILE *infile, FILE* outfile){
extract_rle_ec(infile, outfile);
}
/* to check command parameters */
void printBuffer(char *buffer, int len){
char debug[100];
sprintf(debug, "%c%c%c", buffer[len-2],buffer[len-1], buffer[len]);
printf("|%s|\n", debug );
}