aboutsummaryrefslogtreecommitdiff
path: root/src/binlogcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/binlogcat.c')
-rw-r--r--src/binlogcat.c18
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
@@ -28,6 +28,7 @@ char *progname;
28char *timefmt = "%c"; 28char *timefmt = "%c";
29int number_option; 29int number_option;
30int verbose_option; 30int verbose_option;
31int timediff_option;
31 32
32void 33void
33catlog(const char *fname) 34catlog(const char *fname)
@@ -37,7 +38,8 @@ catlog(const char *fname)
37 struct binlog_record rec; 38 struct binlog_record rec;
38 char timebuf[128]; 39 char timebuf[128];
39 size_t i; 40 size_t i;
40 41 time_t start_ts;
42
41 if (strcmp(fname, "-") == 0) 43 if (strcmp(fname, "-") == 0)
42 fp = stdin; 44 fp = stdin;
43 else { 45 else {
@@ -83,6 +85,12 @@ catlog(const char *fname)
83 break; 85 break;
84 } 86 }
85 87
88 if (timediff_option) {
89 if (i == 0)
90 start_ts = rec.ts;
91 rec.ts -= start_ts;
92 }
93
86 strftime(timebuf, sizeof timebuf, timefmt, localtime(&rec.ts)); 94 strftime(timebuf, sizeof timebuf, timefmt, localtime(&rec.ts));
87 if (number_option) 95 if (number_option)
88 printf("%lu ", (unsigned long) i); 96 printf("%lu ", (unsigned long) i);
@@ -95,7 +103,7 @@ catlog(const char *fname)
95void 103void
96help() 104help()
97{ 105{
98 printf("usage: %s [-hnv] [t FORMAT] [FILE...]\n"); 106 printf("usage: %s [-dhnv] [t FORMAT] [FILE...]\n");
99} 107}
100 108
101int 109int
@@ -104,8 +112,12 @@ main(int argc, char **argv)
104 progname = argv[0]; 112 progname = argv[0];
105 int c; 113 int c;
106 114
107 while ((c = getopt(argc, argv, "ht:nv")) != EOF) 115 while ((c = getopt(argc, argv, "dht:nv")) != EOF)
108 switch (c) { 116 switch (c) {
117 case 'd':
118 timediff_option = 1;
119 timefmt = "%s";
120 break;
109 case 'h': 121 case 'h':
110 help(); 122 help();
111 return 0; 123 return 0;

Return to:

Send suggestions and report system problems to the System administrator.