mirror of
https://github.com/linux-can/can-utils.git
synced 2026-09-22 08:06:34 +02:00
log: finalize unified buffer handling
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
+26
-7
@@ -43,26 +43,45 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <linux/can.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include "lib.h"
|
||||
|
||||
#define COMMENTSZ 200
|
||||
#define BUFSZ (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 + CL_CFSZ + COMMENTSZ) /* for one line in the logfile */
|
||||
#define DEVSZ 22
|
||||
#define TIMESZ 22 /* sizeof("(1345212884.318850) ") */
|
||||
#define BUFSZ (DEVSZ + AFRSZ + TIMESZ)
|
||||
|
||||
/* adapt sscanf() functions below on error */
|
||||
#if (AFRSZ != 6300)
|
||||
#error "AFRSZ value does not fit sscanf restrictions!"
|
||||
#endif
|
||||
#if (DEVSZ != 22)
|
||||
#error "DEVSZ value does not fit sscanf restrictions!"
|
||||
#endif
|
||||
#if (TIMESZ != 22)
|
||||
#error "TIMESZ value does not fit sscanf restrictions!"
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[BUFSZ], timestamp[BUFSZ], device[BUFSZ], ascframe[BUFSZ];
|
||||
char buf[BUFSZ], timestamp[TIMESZ], device[DEVSZ], afrbuf[AFRSZ];
|
||||
static cu_t cu;
|
||||
int mtu;
|
||||
|
||||
while (fgets(buf, BUFSZ-1, stdin)) {
|
||||
if (sscanf(buf, "%s %s %s", timestamp, device, ascframe) != 3)
|
||||
|
||||
if (strlen(buf) >= BUFSZ-2) {
|
||||
fprintf(stderr, "line too long for input buffer\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sscanf(buf, "%21s %21s %6299s", timestamp, device, afrbuf) != 3)
|
||||
return 1;
|
||||
|
||||
mtu = parse_canframe(ascframe, &cu);
|
||||
mtu = parse_canframe(afrbuf, &cu);
|
||||
|
||||
/* mark dual-use struct canfd_frame - no CAN_XL support */
|
||||
if (mtu == CAN_MTU)
|
||||
@@ -75,10 +94,10 @@ int main(void)
|
||||
}
|
||||
|
||||
/* with ASCII output */
|
||||
sprint_long_canframe(ascframe, &cu,
|
||||
sprint_long_canframe(afrbuf, &cu,
|
||||
(CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII));
|
||||
|
||||
printf("%s %s %s\n", timestamp, device, ascframe);
|
||||
printf("%s %s %s\n", timestamp, device, afrbuf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user