]> rtime.felk.cvut.cz Git - socketcan-devel.git/blobdiff - can-utils/canplayer.c
Changed comment line recognition:
[socketcan-devel.git] / can-utils / canplayer.c
index 799a64a797b18ce761166bdd9e772351f3a74510..e8a1356c208a4ebc3a427a3fe8a47a8f5aeca79b 100644 (file)
 
 #include "lib.h"
 
-#define DEFAULT_GAP 1 /* ms */
-#define DEFAULT_LOOPS 1 /* only one replay */
-#define CHANNELS 20   /* anyone using more than 20 CAN interfaces at a time? */
-#define BUFSZ 100     /* for one line in the logfile */
+#define DEFAULT_GAP    1       /* ms */
+#define DEFAULT_LOOPS  1       /* only one replay */
+#define CHANNELS       20      /* anyone using more than 20 CAN interfaces at a time? */
+#define BUFSZ          400     /* for one line in the logfile */
 
 struct assignment {
        char txif[IFNAMSIZ];
@@ -98,6 +98,8 @@ void print_usage(char *prg)
                "vcan2 )\n");
        fprintf(stderr, "No assignments => send frames to the interface(s) they "
                "had been received from.\n\n");
+       fprintf(stderr, "Lines in the logfile not beginning with '(' (start of "
+               "timestamp) are ignored.\n\n");
 }
 
 /* copied from /usr/src/linux/include/linux/time.h ...
@@ -241,6 +243,7 @@ int main(int argc, char **argv)
        int assignments; /* assignments defined on the commandline */
        int txidx;       /* sendto() interface index */
        int eof, nbytes, i, j;
+       char *fret;
 
        while ((opt = getopt(argc, argv, "I:l:tg:s:xv")) != -1) {
                switch (opt) {
@@ -365,7 +368,15 @@ int main(int argc, char **argv)
                if (verbose > 1) /* use -v -v to see this */
                        printf (">>>>>>>>> start reading file. remaining loops = %d\n", loops);
 
-               if (!fgets(buf, BUFSZ-1, infile)) /* read first frame from logfile */
+               /* read first non-comment frame from logfile */
+               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)
                        goto out; /* nothing to read */
 
                eof = 0;
@@ -427,8 +438,15 @@ int main(int argc, char **argv)
                                        }
                                }
 
-                               /* read next frame from logfile */
-                               if (!fgets(buf, BUFSZ-1, infile)) {
+                               /* read next non-comment frame from logfile */
+                               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) {
                                        eof = 1; /* this file is completely processed */
                                        break;
                                }