-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrintInfo.cpp
More file actions
65 lines (50 loc) · 1.54 KB
/
PrintInfo.cpp
File metadata and controls
65 lines (50 loc) · 1.54 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
#include <cstdio>
#include <map>
const std::map<int, const char*> ERR_TO_STR = {
{ 0, "Type should be 2-32" },
{ 1, "Shift should be 1-7" },
{ 2, "Cannot read file" },
{ 3, "Cannot write file" },
{ 4, "Too many or too long arguments!\n\nCheck help!" },
{ 5, "Unable to parse table, stopped at element: %d" },
{ 6, "Cannot read table" },
{ 7, "Duplicate input character" },
{ 8, "No space or invalid character" },
{ 9, "More than 8 output bits" },
{ 10, "Invalid character" },
{ 11, "Input and Output are the same" },
{ 12, "Missing input file" },
{ 13, "Invalid output name" },
};
const std::map<int, const char*> INFO_TO_STR = {
{ 0, "Converting as: %d" },
{ 1, "Shift output by: %d" },
{ 2, "Table elements: %d" },
{ 3, "Table input,output,size (dec):" }
};
void PrintError(int n) {
printf("%s", "\033[1;31mERROR: ");
printf("%s", ERR_TO_STR.at(n));
printf("%s\n", "!\033[0m");
}
void PrintInfo(int n) {
printf("%s\n", INFO_TO_STR.at(n));
}
// type == 0 is for int, and 1 for char (not used here.. yet!)
void PrintErrWithVariable(int n, bool type, void* varA) {
if(type == 0) {
printf(ERR_TO_STR.at(n), *(int*)varA);
} else {
printf(ERR_TO_STR.at(n), *(char*)varA);
}
printf("\n");
}
// type == 0 is for int, and 1 for strings (not used here.. yet!)
void PrintInfoWithVariable(int n, bool type, void* varA) {
if(type == 0) {
printf(INFO_TO_STR.at(n), *(int*)varA);
} else {
printf(INFO_TO_STR.at(n), *(char*)varA);
}
printf("\n");
}