-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.c
67 lines (61 loc) · 1.61 KB
/
main.c
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
#include <stdio.h>
#include <errno.h>
#include "giffy.h"
int main(int argc, char* argv[])
{
FILE* source = fopen(argv[2], "rb");
errno = 0;
FILE* giffy = fopen(argv[3], "wbx");
int overwrite_warning = errno;
char* secret_message = argv[4];
if (*argv[1] == 'm') {
write_header(giffy);
write_compressed_image_data(source, giffy);
write_entire_comment(giffy, secret_message);
return 0;
}
if (argc != 5) {
if (argc != 3) {
printf("\n");
printf("Please enter correct number of arguments. --\n");
print_directions();
return 1;
}
} else {
if (source == NULL) {
printf("\n");
printf("File %s doesn't seem to exist. Please check filepath and spelling. --\n", argv[2]);
print_directions();
return 3;
}
if (overwrite_warning != 0) {
printf("Looks like %s already exists. Please change output filename. --\n", argv[3]);
print_directions();
return 4;
}
}
if (*argv[1] != 'e') {
if (*argv[1] != 'd') {
printf("\n");
printf("Please enter `e` or `d` as second argument. --\n");
print_directions();
return 2;
}
}
if (*argv[1] == 'e') {
// encode secret message in file
copy_gif_file(source, giffy);
write_entire_comment(giffy, secret_message);
fclose(giffy);
// } else if (*argv[1] == 'm') {
// printf(" ^^^^ start m\n");
// write_header(giffy);
// write_compressed_image_data(source, giffy);
// write_entire_comment(giffy, secret_message);
} else {
// decode secret message in file
parse_out_secret_message(source);
fclose(source);
}
return 0;
}