-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
58 lines (55 loc) · 2.13 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
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <float.h>
#include <string.h>
#include "bmparser.h"
// Driver program for the .bmp file parser
int main(int argc, char *argv[])
{
if (argc == 1) {
fprintf(stdout, "No file path provided\n");
return 1;
}
if (argc == 1 || argc > 4) {
fprintf(stdout, "Minimum 1 argument required - path to the bmp file to be parsed\n");
fprintf(stdout, "For greyscale creation, give 2 arguments: file path and path to out, greyscale file\n");
fprintf(stdout, "For message encoding, use the '-e' flag, specify path to the file to be encoded and write and the message (255 char max)\n");
fprintf(stdout, "For message decoding, use the '-d' flag and specify path to the file to be decoded\n");
exit(1);
}
Bmp *bmp;
if (argc == 2) {
// Only parse
bmp = bmpReadFile(argv[1]);
bmpDestroy(bmp);
} else if (argc == 4) {
// Message to be encoded
if (strcmp(argv[1], "-e") != 0) {
if (strcmp(argv[1], "-d") == 0) {
fprintf(stdout, "Too many arguments for decoding\n");
} else {
fprintf(stdout, "Unknown flag '%s'\n", argv[1]);
}
fprintf(stdout, "Minimum 1 argument required - path to the bmp file to be parsed\n");
fprintf(stdout, "For greyscale creation, give 2 arguments: file path and path to out, greyscale file\n");
fprintf(stdout, "For message encoding, use the '-e' flag, specify path to the file to be encoded and write and the message (255 char max)\n");
fprintf(stdout, "For message decoding, use the '-d' flag and specify path to the file to be decoded\n");
exit(1);
}
bmpEncode(argv[2], argv[3]);
} else {
if (strcmp(argv[1], "-d") == 0) {
// Message to be decoded
bmpDecode(argv[2]);
} else {
// Parse and create greyscale
bmp = bmpReadFile(argv[1]);
bmpCreateGreyscale(bmp, argv[2]);
bmpDestroy(bmp);
}
}
return 0;
}