Changed comment line recognition:
Everything without a '(' at the beginning of an input line is treated as comment.
Changed buffer size to allow long comment lines & added overflow handling.
pull/7/head
parent
ba037dcffa
commit
15ce202e60
29
canplayer.c
29
canplayer.c
|
|
@ -60,11 +60,10 @@
|
||||||
|
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
|
|
||||||
#define DEFAULT_GAP 1 /* ms */
|
#define DEFAULT_GAP 1 /* ms */
|
||||||
#define DEFAULT_LOOPS 1 /* only one replay */
|
#define DEFAULT_LOOPS 1 /* only one replay */
|
||||||
#define CHANNELS 20 /* anyone using more than 20 CAN interfaces at a time? */
|
#define CHANNELS 20 /* anyone using more than 20 CAN interfaces at a time? */
|
||||||
#define BUFSZ 100 /* for one line in the logfile */
|
#define BUFSZ 400 /* for one line in the logfile */
|
||||||
#define COMMENT '#'
|
|
||||||
|
|
||||||
struct assignment {
|
struct assignment {
|
||||||
char txif[IFNAMSIZ];
|
char txif[IFNAMSIZ];
|
||||||
|
|
@ -99,8 +98,8 @@ void print_usage(char *prg)
|
||||||
"vcan2 )\n");
|
"vcan2 )\n");
|
||||||
fprintf(stderr, "No assignments => send frames to the interface(s) they "
|
fprintf(stderr, "No assignments => send frames to the interface(s) they "
|
||||||
"had been received from.\n\n");
|
"had been received from.\n\n");
|
||||||
fprintf(stderr, "Lines in the logfile beginning with '%c' are ignored."
|
fprintf(stderr, "Lines in the logfile not beginning with '(' (start of "
|
||||||
"\n\n", COMMENT);
|
"timestamp) are ignored.\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copied from /usr/src/linux/include/linux/time.h ...
|
/* copied from /usr/src/linux/include/linux/time.h ...
|
||||||
|
|
@ -370,8 +369,12 @@ int main(int argc, char **argv)
|
||||||
printf (">>>>>>>>> start reading file. remaining loops = %d\n", loops);
|
printf (">>>>>>>>> start reading file. remaining loops = %d\n", loops);
|
||||||
|
|
||||||
/* read first non-comment frame from logfile */
|
/* read first non-comment frame from logfile */
|
||||||
while ((fret = fgets(buf, BUFSZ-1, infile)) != NULL && buf[0] == COMMENT)
|
while ((fret = fgets(buf, BUFSZ-1, infile)) != NULL && buf[0] != '(') {
|
||||||
;
|
if (strlen(buf) >= BUFSZ-2) {
|
||||||
|
fprintf(stderr, "comment line too long for input buffer\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!fret)
|
if (!fret)
|
||||||
goto out; /* nothing to read */
|
goto out; /* nothing to read */
|
||||||
|
|
@ -436,8 +439,12 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read next non-comment frame from logfile */
|
/* read next non-comment frame from logfile */
|
||||||
while ((fret = fgets(buf, BUFSZ-1, infile)) != NULL && buf[0] == COMMENT)
|
while ((fret = fgets(buf, BUFSZ-1, infile)) != NULL && buf[0] != '(') {
|
||||||
;
|
if (strlen(buf) >= BUFSZ-2) {
|
||||||
|
fprintf(stderr, "comment line too long for input buffer\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!fret) {
|
if (!fret) {
|
||||||
eof = 1; /* this file is completely processed */
|
eof = 1; /* this file is completely processed */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue