printf(" -l (--log) <logfile> - file to store output in, defaults to stdout.\n");
printf(" -s (--speed) <speed> - baudrate to use, defaults to 9600 baud.\n");
printf(" -p (--port2) <port2> - serial port to use instead of pty.\n");
+ printf(" -i (--in-tee) <file> - write all input raw data also to this file(s).\n");
+ printf(" -o (--out-tee) <file> - write all output raw data also to this file(s).\n");
printf(" --color <color> - color to use for normal output.\n");
printf(" --timecolor <color> - color to use for timestamp.\n");
printf(" --bytescolor <color> - color to use for number of bytes transmitted.\n\n");
write(out, buffer, n);
write(aux, buffer, n);
} else {
+ struct tee_entry *entry;
+
/* print timestamp if necessary */
if (tty_data.tstamp) {
if (out == STDOUT_FILENO) setColor(out, tty_data.tclr);
if (out == STDOUT_FILENO) setColor(out, tty_data.bclr);
write (out, buffer, strlen(buffer));
}
+ for (entry = (aux ? tee_inputs : tee_outputs); entry; entry=entry->next)
+ if (n!=write(entry->fd, buffer, n))
+ fatalError(TEEWRTFAIL);
}
}
}
{"color", 1, NULL, 'x'},
{"timecolor", 1, NULL, 'y'},
{"bytescolor", 1, NULL, 'z'},
+ {"in-tee", 1, NULL, 'i'},
+ {"out-tee", 1, NULL, 'o'},
{NULL, 0, NULL, 0}
};
#endif
strcat(tty_data.bclr, ptr1);
}
break;
+ case 'i':
+ case 'o': {
+ int fd=open(optarg, O_WRONLY|O_NOCTTY|O_CREAT|O_TRUNC, 0644);
+ struct tee_entry *entry=malloc(sizeof(*entry));
+ struct tee_entry **entryp=(optret=='i' ? &tee_inputs : &tee_outputs);
+
+ if (fd == -1)
+ fatalError(TEEFAIL);
+ if (!entry)
+ fatalError(MEMFAIL);
+ entry->fd = fd;
+ entry->next = *entryp;
+ *entryp = entry;
+ } break;
case 'h':
case '?':
default :
#endif
#include "common.h"
-#define OPTSTR "bnhtp:l:s:" /* list of short options for getopt_long() */
+#define OPTSTR "bnhtp:l:s:i:o:" /* list of short options for getopt_long() */
#define PORT_OUT "\nHost --> "
#define PORT_IN "\nDevice --> "
#define DEFPTRNAME "/dev/pty??"
#define PTYFAIL "Failed to open a pty"
#define PORTFAIL "Failed to open port"
#define LOGFAIL "Failed to open log file, defaulting to stdout"
+#define TEEFAIL "Failed to create tee file"
+#define TEEWRTFAIL "Failed to write to tee file"
#define SELFAIL "`Select` failed"
#define RPORTFAIL "Error reading from port"
#define RPTYFAIL "Error reading from pty"
static tty_struct tty_data;
static pid_t pid = -1;
+static struct tee_entry {
+ struct tee_entry *next;
+ int fd;
+ } *tee_inputs,*tee_outputs;
+
/* baudrates */
typedef struct _spd_struct {
speed_t speed;