diff --git a/canplayer.c b/canplayer.c index dd22560..dba5687 100644 --- a/canplayer.c +++ b/canplayer.c @@ -452,14 +452,20 @@ int main(int argc, char **argv) return 1; } log_tv.tv_sec = sec; - log_tv.tv_usec = usec; /* - * ensure the fractions of seconds are 6 decimal places long to catch + * ensure the fractions of seconds are 6 or 9 decimal places long to catch * 3rd party or handcrafted logfiles that treat the timestamp as float */ - if (strchr(buf, ')') - strchr(buf, '.') != 7) { - fprintf(stderr, "timestamp format in logfile requires 6 decimal places\n"); + switch (strchr(buf, ')') - strchr(buf, '.')) { + case 7: //6 + log_tv.tv_usec = usec; + break; + case 10: //9 + log_tv.tv_usec = usec / 1000; + break; + default: + fprintf(stderr, "timestamp format in logfile requires 6 or 9 decimal places\n"); return 1; } @@ -541,19 +547,25 @@ int main(int argc, char **argv) break; } - if (sscanf(buf, "(%llu.%llu) %s %s", &sec, &usec, device, afrbuf) != 4) { + if (sscanf(buf, "(%llu.%llu) %21s %6299s", &sec, &usec, device, afrbuf) != 4) { fprintf(stderr, "incorrect line format in logfile\n"); return 1; } log_tv.tv_sec = sec; - log_tv.tv_usec = usec; /* - * ensure the fractions of seconds are 6 decimal places long to catch + * ensure the fractions of seconds are 6 or 9 decimal places long to catch * 3rd party or handcrafted logfiles that treat the timestamp as float */ - if (strchr(buf, ')') - strchr(buf, '.') != 7) { - fprintf(stderr, "timestamp format in logfile requires 6 decimal places\n"); + switch (strchr(buf, ')') - strchr(buf, '.')) { + case 7: //6 + log_tv.tv_usec = usec; + break; + case 10: //9 + log_tv.tv_usec = usec / 1000; + break; + default: + fprintf(stderr, "timestamp format in logfile requires 6 or 9 decimal places\n"); return 1; } diff --git a/log2asc.c b/log2asc.c index 09e5abe..23a839b 100644 --- a/log2asc.c +++ b/log2asc.c @@ -407,7 +407,22 @@ int main(int argc, char **argv) } } tv.tv_sec = sec; - tv.tv_usec = usec; + + /* + * ensure the fractions of seconds are 6 or 9 decimal places long to catch + * 3rd party or handcrafted logfiles that treat the timestamp as float + */ + switch (strchr(buf, ')') - strchr(buf, '.')) { + case 7: //6 + tv.tv_usec = usec; + break; + case 10: //9 + tv.tv_usec = usec / 1000; + break; + default: + fprintf(stderr, "timestamp format in logfile requires 6 or 9 decimal places\n"); + return 1; + } if (print_banner) { /* print banner */ print_banner = 0; diff --git a/log2long.c b/log2long.c index 301f201..32c6b12 100644 --- a/log2long.c +++ b/log2long.c @@ -51,7 +51,7 @@ #include "lib.h" #define DEVSZ 22 -#define TIMESZ 22 /* sizeof("(1345212884.318850) ") */ +#define TIMESZ 25 /* sizeof("(1345212884.318850123) ") */ #define BUFSZ (DEVSZ + AFRSZ + TIMESZ) /* adapt sscanf() functions below on error */ @@ -61,7 +61,7 @@ #if (DEVSZ != 22) #error "DEVSZ value does not fit sscanf restrictions!" #endif -#if (TIMESZ != 22) +#if (TIMESZ != 25) #error "TIMESZ value does not fit sscanf restrictions!" #endif @@ -78,7 +78,7 @@ int main(void) return 1; } - if (sscanf(buf, "%21s %21s %6299s", timestamp, device, afrbuf) != 3) + if (sscanf(buf, "%24s %21s %6299s", timestamp, device, afrbuf) != 3) return 1; mtu = parse_canframe(afrbuf, &cu);