diff options
Diffstat (limited to 'src/binlogcat.c')
-rw-r--r-- | src/binlogcat.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/binlogcat.c b/src/binlogcat.c index c51125b..219f78c 100644 --- a/src/binlogcat.c +++ b/src/binlogcat.c @@ -25,22 +25,24 @@ #include "vmod-binlog.h" char *progname; char *timefmt = "%c"; int number_option; int verbose_option; +int timediff_option; void catlog(const char *fname) { FILE *fp; union binlog_header header; struct binlog_record rec; char timebuf[128]; size_t i; - + time_t start_ts; + if (strcmp(fname, "-") == 0) fp = stdin; else { fp = fopen(fname, "r"); if (!fp) { fprintf(stderr, "%s: cannot open %s: %s\n", @@ -80,35 +82,45 @@ catlog(const char *fname) if (fread(&rec, sizeof(rec), 1, fp) != 1) { fprintf(stderr, "%s: %s: unexpected eof\n", progname, fname); break; } + if (timediff_option) { + if (i == 0) + start_ts = rec.ts; + rec.ts -= start_ts; + } + strftime(timebuf, sizeof timebuf, timefmt, localtime(&rec.ts)); if (number_option) printf("%lu ", (unsigned long) i); printf("%s %ld %ld\n", timebuf, rec.nid, rec.aid); } fclose(fp); } void help() { - printf("usage: %s [-hnv] [t FORMAT] [FILE...]\n"); + printf("usage: %s [-dhnv] [t FORMAT] [FILE...]\n"); } int main(int argc, char **argv) { progname = argv[0]; int c; - while ((c = getopt(argc, argv, "ht:nv")) != EOF) + while ((c = getopt(argc, argv, "dht:nv")) != EOF) switch (c) { + case 'd': + timediff_option = 1; + timefmt = "%s"; + break; case 'h': help(); return 0; case 't': timefmt = optarg; break; |