summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--btimec.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/btimec.c b/btimec.c
index 02c29bc..bea87bb 100644
--- a/btimec.c
+++ b/btimec.c
@@ -6,23 +6,46 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
#include "btime.h"
+char usage[] = "USAGE: %s [-r] <host>\n";
+
int
main(int argc, char **argv)
{
unsigned int bt;
char *btimedhost;
+ int readable = 0;
+ int c;
- if (argc != 2) {
- fprintf(stderr, "USAGE: %s <host>\n", argv[0]);
- exit(2);
+ while ((c = getopt(argc, argv, "r")) != -1) {
+ switch (c) {
+ case 'r':
+ readable = 1;
+ break;
+ default:
+ fprintf(stderr, usage, argv[0]);
+ exit(2);
+ }
}
- btimedhost = argv[1];
- bt = btime(btimedhost);
- printf("%s: %u\n", btimedhost, bt);
-
+ if (optind >= argc) {
+ fprintf(stderr, usage, argv[0]);
+ exit(2);
+ }
+ for ( ; optind < argc; optind++) {
+ btimedhost = argv[optind];
+ bt = btime(btimedhost);
+ if (readable) {
+ time_t tt = bt;
+ time_t *ttp = &tt;
+ printf("%s: %s", btimedhost, bt ? ctime(ttp) : "down\n");
+ } else {
+ printf("%s: %u\n", btimedhost, bt);
+ }
+ }
exit(0);
}