01483b966392023a26cf1000c3332966e579648b
11 #include "khatus_lib_log.h"
12 #include "khatus_lib_time.h"
14 #define usage(...) {print_usage(); fprintf(stderr, "Error:\n " __VA_ARGS__); exit(EXIT_FAILURE);}
17 #define END_OF_MESSAGE '\n'
21 double opt_interval
= 1.0;
22 char *opt_fmt
= "%a %b %d %H:%M:%S";
30 "OPT = -i int # interval\n"
31 " | -f string # format string\n"
32 " | -h # help message (i.e. what you're reading now :) )\n",
37 opt_parse(int argc
, char **argv
)
41 while ((c
= getopt(argc
, argv
, "f:i:h")) != -1)
44 opt_fmt
= calloc(strlen(optarg
), sizeof(char));
45 strcpy(opt_fmt
, optarg
);
48 opt_interval
= atof(optarg
);
54 if (optopt
== 'f' || optopt
== 'i')
56 "Option -%c requires an argument.\n",
58 else if (isprint(optopt
))
60 "Unknown option `-%c'.\n",
64 "Unknown option character `\\x%x'.\n",
73 main(int argc
, char **argv
)
81 opt_parse(argc
, argv
);
82 ti
= timespec_of_float(opt_interval
);
83 debug("opt_fmt: \"%s\"\n", opt_fmt
);
84 debug("opt_interval: %f\n", opt_interval
);
85 debug("ti: {tv_sec = %ld, tv_nsec = %ld}\n", ti
.tv_sec
, ti
.tv_nsec
);
86 memset(buf
, '\0', MAX_LEN
);
87 signal(SIGPIPE
, SIG_IGN
);
91 strftime(buf
, MAX_LEN
, opt_fmt
, localtime(&t
));
This page took 0.067837 seconds and 3 git commands to generate.