-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
143 lines (132 loc) · 3.9 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "degree_convertions.h"
#include "distance_convertions.h"
#include "number_convertions.h"
#include "weight_convertions.h"
#define STREQ(a, b) (strcmp (a, b) == 0)
void usage_help () {
fprintf(stdout, "%s\n", "\n"
"rogconv [option] [value] convert from/to data types\n"
"\n"
"options:\n"
"\n"
"btd binary to decimal\n"
"dtb decimal to binary\n"
"htd hex to decimal\n"
"dth decimal to hex\n"
"bth binary to hex\n"
"htb hex to binary\n"
"\n"
"ftc fahrenheit to celsius\n"
"ctf celsius to fahrenheit\n"
"ftk fahrenheit to kelvin\n"
"ktf kelvin to fahrenheit\n"
"ctk celsius to kelvin\n"
"ktc kelvin to celsius\n"
"\n"
"otp ounces to pounds\n"
"pto pounds to ounces\n"
"ktp kilograms to pounds\n"
"ptk pounds to kilograms\n"
"kto kilograms to ounces\n"
"otk ounces to kilograms\n"
"\n"
"ktm kilometers to miles\n"
"mtk miles to kilometers\n"
"mtl miles to light years\n"
"ltm light years to miles\n"
"ktl kilometers to light years\n"
"ltk light years to kilometers\n"
"\n"
"flags:\n"
"\n"
"--help display help\n");
}
int main(int argc, char** argv) {
if (STREQ(argv[1], "--help"))
usage_help();
else if (argc != 3) {
printf("Wrong number of arguments");
return 1;
}
// Number bases
if (STREQ(argv[1], "btd")) {
btd(argv[2]);
}
else if (STREQ(argv[1], "dtb")) {
dtb(argv[2]);
}
else if (STREQ(argv[1], "htb")) {
htb(argv[2]);
}
else if (STREQ(argv[1], "dth")) {
dth(argv[2]);
}
else if (STREQ(argv[1], "bth")) {
bth(argv[2]);
}
else if (STREQ(argv[1], "htd")) {
htd(argv[2]);
}
// Degrees
else if (STREQ(argv[1], "ftc")) {
ftc(argv[2]);
}
else if (STREQ(argv[1], "ctf")) {
ctf(argv[2]);
}
else if (STREQ(argv[1], "ftk")) {
ftk(argv[2]);
}
else if (STREQ(argv[1], "ktf")) {
ktf(argv[2]);
}
else if (STREQ(argv[1], "ctk")) {
ctk(argv[2]);
}
else if (STREQ(argv[1], "ktc")) {
ktc(argv[2]);
}
// Weight
else if (STREQ(argv[1], "otp")) {
otp(argv[2]);
}
else if (STREQ(argv[1], "pto")) {
pto(argv[2]);
}
else if (STREQ(argv[1], "ktp")) {
ktp(argv[2]);
}
else if (STREQ(argv[1], "ptk")) {
ptk(argv[2]);
}
else if (STREQ(argv[1], "kto")) {
kto(argv[2]);
}
else if (STREQ(argv[1], "otk")) {
otk(argv[2]);
}
// Weight
else if (STREQ(argv[1], "ktm")) {
ktm(argv[2]);
}
else if (STREQ(argv[1], "mtk")) {
mtk(argv[2]);
}
else if (STREQ(argv[1], "mtl")) {
mtl(argv[2]);
}
else if (STREQ(argv[1], "ltm")) {
ltm(argv[2]);
}
else if (STREQ(argv[1], "ktl")) {
ktl(argv[2]);
}
else if (STREQ(argv[1], "ltk")) {
ltk(argv[2]);
}
return 0;
}