-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
110 lines (88 loc) · 2.82 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
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <ncurses.h>
#include "timer.h"
#include "stopwatch.h"
int main(int argc, char* argv[]) {
int hours; // argv[1]
int minutes; // argv[2], argv[1];
int seconds; // argv[3], argv[2], argv[1];
int time_in_seconds;
tea teas[4];
char *tea_type;
if (!strcmp(argv[1], "stopwatch")) {
if (argc == 5) {
hours = atoi(argv[2]);
minutes = atoi(argv[3]);
seconds = atoi(argv[4]);
time_in_seconds = (hours * 3600) + (minutes * 60) + seconds;
stopwatch_start(time_in_seconds);
} else if (argc == 4) {
minutes = atoi(argv[2]);
seconds = atoi(argv[3]);
time_in_seconds = (minutes * 60) + seconds;
stopwatch_start(time_in_seconds);
} else if (argc == 3) {
seconds = atoi(argv[2]);
time_in_seconds = seconds;
stopwatch_start(time_in_seconds);
} else {
stopwatch_start(0);
}
}
if (argc > 4) {
printf("Too many arguments provided. Timer only takes one argument: time\n");
exit(1);
}
if (argc < 2) {
printf("Too few arguments provided. Timer takes one argument: time\n");
exit(1);
}
if (argc == 2) {
// returns 0 if argv[1] is not an int
seconds = atoi(argv[1]);
// Do tea timer stuff
if (seconds == 0) {
tea_type = argv[1];
printf("%s", tea_type);
char *gs = "green";
char *bs = "black";
char *gl = "greenlong";
char *bl = "blacklong";
timer_init_tea(teas, gs, 1, 30, 0);
timer_init_tea(teas, bs, 3, 0, 1);
timer_init_tea(teas, gl, 2, 0, 2);
timer_init_tea(teas, bl, 5, 0, 3);
for (size_t i = 0; i < sizeof(teas)/sizeof(teas[0]); i++) {
if (strcmp(argv[1], teas[i].key) == 0) {
minutes = teas[i].minutes;
seconds = teas[i].seconds;
time_in_seconds = (minutes * 60) + seconds;
timer_start(time_in_seconds, 2, 1);
}
}
printf("Not a tea.\n");
exit(1);
}
minutes = 0;
hours = 0;
timer_start(seconds, 1, 0);
}
if (argc == 3) {
seconds = atoi(argv[2]);
minutes = atoi(argv[1]);
hours = 0;
time_in_seconds = (minutes * 60) + seconds;
timer_start(time_in_seconds, 2, 0);
}
if (argc == 4) {
seconds = atoi(argv[3]);
minutes = atoi(argv[2]);
hours = atoi(argv[1]);
time_in_seconds = (hours * 3600) + (minutes * 60) + seconds;
timer_start(time_in_seconds, 3, 0);
}
return 0;
}