candump: reduce printf calls for logfile format

The creation of the logfile format was using fprint_canframe() and two other
fprintf() calls to produce a single logfile format line. Instead of using
fprint_canframe() use sprint_canframe() directly and reduce the printf() calls
from three to one.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
pull/1/head
Oliver Hartkopp 2014-05-05 21:29:56 +02:00
parent 67a2bdcd33
commit 31ccf45dc4
1 changed files with 12 additions and 7 deletions

View File

@ -698,18 +698,23 @@ int main(int argc, char **argv)
view |= CANLIB_VIEW_INDENT_SFF; view |= CANLIB_VIEW_INDENT_SFF;
if (log) { if (log) {
char buf[CL_CFSZ]; /* max length */
/* log CAN frame with absolute timestamp & device */ /* log CAN frame with absolute timestamp & device */
fprintf(logfile, "(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec); sprint_canframe(buf, &frame, 0, maxdlen);
fprintf(logfile, "%*s ", max_devname_len, devname[idx]); fprintf(logfile, "(%010ld.%06ld) %*s %s\n",
/* without separator as logfile use-case is parsing */ tv.tv_sec, tv.tv_usec,
fprint_canframe(logfile, &frame, "\n", 0, maxdlen); max_devname_len, devname[idx], buf);
} }
if (logfrmt) { if (logfrmt) {
char buf[CL_CFSZ]; /* max length */
/* print CAN frame in log file style to stdout */ /* print CAN frame in log file style to stdout */
printf("(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec); sprint_canframe(buf, &frame, 0, maxdlen);
printf("%*s ", max_devname_len, devname[idx]); printf("(%010ld.%06ld) %*s %s\n",
fprint_canframe(stdout, &frame, "\n", 0, maxdlen); tv.tv_sec, tv.tv_usec,
max_devname_len, devname[idx], buf);
goto out_fflush; /* no other output to stdout */ goto out_fflush; /* no other output to stdout */
} }