-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
45 lines (41 loc) · 984 Bytes
/
main.c
File metadata and controls
45 lines (41 loc) · 984 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "adhuff_compress.h"
#include "adhuff_decompress.h"
#include "log.h"
/**
* Print usage
*/
void printUsage() {
puts("Usage:");
puts("\tto compress a file : ./adaptive_huffman -c <input_file> <output_file>");
puts("\tto decompress a file : ./adaptive_huffman -d <input_file> <output_file>");
}
/**
* Main function of the application
* @param argc
* @param argv
* @return 0 OK, otherwise FAILURE
*/
int main(int argc, char* argv[])
{
int rc = 0;
if (argc < 4) {
log_error("main", "Not enough parameters.\n");
printUsage();
rc = 1;
}
else if (strcmp(argv[1], "-c") == 0) {
rc = adh_compress_file(argv[2], argv[3]);
}
else if (strcmp(argv[1], "-d") == 0) {
rc = adh_decompress_file(argv[2], argv[3]);
}
else {
log_error("main", "Unexpected argument\n");
printUsage();
rc = 2;
}
return rc;
}