-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
63 lines (56 loc) · 1.5 KB
/
Copy pathmain.c
File metadata and controls
63 lines (56 loc) · 1.5 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
#include "flowtime.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#define VERSION "2.0.0"
void print_help() {
printf("flowtime - Display time in flowtime format\n\n");
printf("Usage:\n");
printf(" flowtime [options]\n\n");
printf("Options:\n");
printf(" -h, --help Show this help message\n");
printf(" -v, --version Show version information\n");
printf(" -c, --clock Run in continuous clock mode\n");
}
void print_version() {
printf("flowtime version %s\n", VERSION);
}
void print_flowtime(bool continuous) {
time_t t;
struct tm date;
time(&t);
date = *localtime(&t);
flowtime_t result = date_to_flowtime(&date);
printf(continuous ? "\r%02d:%02d:%02d" : "%02d:%02d:%02d\n",
result.hour, result.minute, result.second);
}
void print_flowtime_continuous() {
while (1) {
print_flowtime(true);
fflush(stdout);
sleep(1);
}
}
int main(int argc, char *argv[]) {
if (argc > 1) {
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
print_help();
return 0;
}
if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
print_version();
return 0;
}
if (strcmp(argv[1], "-c") == 0 || strcmp(argv[1], "--clock") == 0) {
print_flowtime_continuous();
return 0;
}
// Invalid parameter
printf("Unknown option: %s\n", argv[1]);
printf("Try 'flowtime --help' for more information.\n");
return 1;
}
print_flowtime(false);
return 0;
}