33 lines
771 B
C
33 lines
771 B
C
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
#include "actions.h"
|
|
#include "duration.h"
|
|
#include "sleeptimer.h"
|
|
#include "stdio.h"
|
|
|
|
int main(int argc, char **argv) {
|
|
time_t start = time(NULL);
|
|
|
|
Duration duration = {.minutes = 30};
|
|
if (argc >= 2) {
|
|
duration = parseDuration(argv[1]);
|
|
}
|
|
|
|
enum Action action = ActionEcho;
|
|
if (argc >= 3) {
|
|
action = parseAction(argv[2]);
|
|
}
|
|
|
|
printf("Sleep timer set for \"%s\"\n", formatDuration(&duration));
|
|
|
|
unsigned long seconds = durationToSeconds(&duration);
|
|
actionCallback callback = getActionCallback(action);
|
|
if (!sleeptimer(seconds, callback)) {
|
|
return 1;
|
|
}
|
|
time_t end = time(NULL);
|
|
Duration runtime = secondsToDuration(end - start);
|
|
printf("Program ran for \"%s\"\n", formatDuration(&runtime));
|
|
}
|