Added optional filename argument to -l option
parent
ec6a573de1
commit
9b5dbdc430
16
candump.c
16
candump.c
|
|
@ -134,7 +134,7 @@ static void print_usage(char *prg)
|
||||||
fprintf(stderr, " -a (enable additional ASCII output)\n");
|
fprintf(stderr, " -a (enable additional ASCII output)\n");
|
||||||
fprintf(stderr, " -S (swap byte order in printed CAN data[] - marked with '%c' )\n", SWAP_DELIMITER);
|
fprintf(stderr, " -S (swap byte order in printed CAN data[] - marked with '%c' )\n", SWAP_DELIMITER);
|
||||||
fprintf(stderr, " -s <level> (silent mode - %d: off (default) %d: animation %d: silent)\n", SILENT_OFF, SILENT_ANI, SILENT_ON);
|
fprintf(stderr, " -s <level> (silent mode - %d: off (default) %d: animation %d: silent)\n", SILENT_OFF, SILENT_ANI, SILENT_ON);
|
||||||
fprintf(stderr, " -l (log CAN-frames into file. Sets '-s %d' by default)\n", SILENT_ON);
|
fprintf(stderr, " -l <fname> (log CAN-frames into file. Sets '-s %d' by default)\n", SILENT_ON);
|
||||||
fprintf(stderr, " -L (use log file format on stdout)\n");
|
fprintf(stderr, " -L (use log file format on stdout)\n");
|
||||||
fprintf(stderr, " -n <count> (terminate after reception of <count> CAN frames)\n");
|
fprintf(stderr, " -n <count> (terminate after reception of <count> CAN frames)\n");
|
||||||
fprintf(stderr, " -r <size> (set socket receive buffer to <size>)\n");
|
fprintf(stderr, " -r <size> (set socket receive buffer to <size>)\n");
|
||||||
|
|
@ -314,6 +314,7 @@ int main(int argc, char **argv)
|
||||||
struct timeval tv, last_tv;
|
struct timeval tv, last_tv;
|
||||||
int timeout_ms = -1; /* default to no timeout */
|
int timeout_ms = -1; /* default to no timeout */
|
||||||
FILE *logfile = NULL;
|
FILE *logfile = NULL;
|
||||||
|
const char *log_filename = NULL;
|
||||||
|
|
||||||
signal(SIGTERM, sigterm);
|
signal(SIGTERM, sigterm);
|
||||||
signal(SIGHUP, sigterm);
|
signal(SIGHUP, sigterm);
|
||||||
|
|
@ -322,7 +323,7 @@ int main(int argc, char **argv)
|
||||||
last_tv.tv_sec = 0;
|
last_tv.tv_sec = 0;
|
||||||
last_tv.tv_usec = 0;
|
last_tv.tv_usec = 0;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "t:HciaSs:lDdxLn:r:he8T:?")) != -1) {
|
while ((opt = getopt(argc, argv, "t:HciaSs:l::DdxLn:r:he8T:?")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 't':
|
case 't':
|
||||||
timestamp = optarg[0];
|
timestamp = optarg[0];
|
||||||
|
|
@ -376,6 +377,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
log = 1;
|
log = 1;
|
||||||
|
log_filename = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
|
|
@ -662,6 +664,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
localtime_r(&currtime, &now);
|
localtime_r(&currtime, &now);
|
||||||
|
|
||||||
|
if (!log_filename) {
|
||||||
sprintf(fname, "candump-%04d-%02d-%02d_%02d%02d%02d.log",
|
sprintf(fname, "candump-%04d-%02d-%02d_%02d%02d%02d.log",
|
||||||
now.tm_year + 1900,
|
now.tm_year + 1900,
|
||||||
now.tm_mon + 1,
|
now.tm_mon + 1,
|
||||||
|
|
@ -669,6 +672,15 @@ int main(int argc, char **argv)
|
||||||
now.tm_hour,
|
now.tm_hour,
|
||||||
now.tm_min,
|
now.tm_min,
|
||||||
now.tm_sec);
|
now.tm_sec);
|
||||||
|
} else {
|
||||||
|
int len = strlen(fname);
|
||||||
|
if (len > sizeof(fname) - 1) {
|
||||||
|
fprintf(stderr, "fname of -l argument must not exceed %d characters\n", sizeof(fname) - 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
memcpy(fname, log_filename, len);
|
||||||
|
fname[len] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (silent != SILENT_ON)
|
if (silent != SILENT_ON)
|
||||||
fprintf(stderr, "Warning: Console output active while logging!\n");
|
fprintf(stderr, "Warning: Console output active while logging!\n");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue