X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=x5%2Fkhatus_sensor_time.c;fp=x5%2Fkhatus_sensor_time.c;h=f156f455d40ab4db874c3a5100418f3434ece3d2;hb=8345f2b388e0986829ceeae50ecf186d5d540a9c;hp=0000000000000000000000000000000000000000;hpb=17a27e4866eb3e245e17dc211b4469f1c5aa3f1e;p=khatus.git diff --git a/x5/khatus_sensor_time.c b/x5/khatus_sensor_time.c new file mode 100644 index 0000000..f156f45 --- /dev/null +++ b/x5/khatus_sensor_time.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "khatus_lib_log.h" +#include "khatus_lib_time.h" + +char *argv0; + +void +usage() +{ + printf( + "%s: [OPT ...]\n" + "\n" + "OPT = -i int # interval\n" + " | -f string # format string\n" + " | -h # help message (i.e. what you're reading now :) )\n", + argv0); + fatal("usage\n"); +} + +int +main(int argc, char **argv) +{ + argv0 = argv[0]; + + double opt_interval = 1.0; + char *opt_fmt = "%a %b %d %H:%M:%S"; + + time_t t; + struct timespec ti; + char buf[128]; + char c; + + memset(buf, '\0', 128); + while ((c = getopt(argc, argv, "f:i:h")) != -1) + switch (c) { + case 'f': + opt_fmt = calloc(strlen(optarg), sizeof(char)); + strcpy(opt_fmt, optarg); + break; + case 'i': + opt_interval = atof(optarg); + break; + case 'h': + usage(); + break; + default: + usage(); + } + ti = timespec_of_float(opt_interval); + for (;;) { + t = time(NULL); + strftime(buf, sizeof(buf), opt_fmt, localtime(&t)); + puts(buf); + fflush(stdout); + snooze(&ti); + } + return EXIT_SUCCESS; +}