cc476770b691d179c39b583fec44fb3d6fcbbb6b
12 #include "khatus_lib_log.h"
13 #include "khatus_lib_sensor.h"
14 #include "khatus_lib_time.h"
16 #define usage(...) {print_usage(); fprintf(stderr, "Error:\n " __VA_ARGS__); exit(EXIT_FAILURE);}
19 #define END_OF_MESSAGE '\n'
23 double opt_interval
= 1.0;
24 char *opt_fmt
= "%a %b %d %H:%M:%S";
25 char *fifo_name
= NULL
;
31 "%s: [OPT ...] FIFO\n"
33 "FIFO = string # path to fifo file\n"
34 "OPT = -i int # interval\n"
35 " | -f string # format string\n"
36 " | -h # help message (i.e. what you're reading now :) )\n",
41 opt_parse(int argc
, char **argv
)
45 while ((c
= getopt(argc
, argv
, "f:i:h")) != -1)
48 opt_fmt
= calloc(strlen(optarg
), sizeof(char));
49 strcpy(opt_fmt
, optarg
);
52 opt_interval
= atof(optarg
);
58 if (optopt
== 'f' || optopt
== 'i')
60 "Option -%c requires an argument.\n",
62 else if (isprint(optopt
))
64 "Unknown option `-%c'.\n",
68 "Unknown option character `\\x%x'.\n",
74 fifo_name
= argv
[optind
];
75 debug("fifo_name: %s\n", fifo_name
);
77 usage("No filename was provided\n");
81 get_time(char *buf
, char *fmt
)
86 strftime(buf
, MAX_LEN
, fmt
, localtime(&t
));
91 main(int argc
, char **argv
)
98 opt_parse(argc
, argv
);
100 signal(SIGPIPE
, SIG_IGN
); /* Handled in loop */
102 memset(buf
, '\0', MAX_LEN
);
103 ti
= timespec_of_float(opt_interval
);
108 (SENSOR_FUN_T
) get_time
,
109 (SENSOR_PARAMS_T
) opt_fmt
This page took 0.083528 seconds and 3 git commands to generate.