summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-07-10 12:47:24 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-07-10 12:47:24 +0000
commit602ccbf5d4f2fbfc7cb76196edf416ee39629434 (patch)
tree737f9823f3bb2930e8419cb4091ac5d24023cba3
parentba89989533bd55a701b857e20f5002ad0b3521f1 (diff)
Add ~R command to start recording output to a file.
-rw-r--r--usr.bin/cu/command.c25
-rw-r--r--usr.bin/cu/cu.16
-rw-r--r--usr.bin/cu/cu.c5
-rw-r--r--usr.bin/cu/cu.h3
4 files changed, 35 insertions, 4 deletions
diff --git a/usr.bin/cu/command.c b/usr.bin/cu/command.c
index d902748efdb..7a8980584ec 100644
--- a/usr.bin/cu/command.c
+++ b/usr.bin/cu/command.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: command.c,v 1.9 2012/07/10 12:20:23 nicm Exp $ */
+/* $OpenBSD: command.c,v 1.10 2012/07/10 12:47:23 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -195,6 +195,25 @@ set_speed(void)
}
void
+start_record(void)
+{
+ const char *file;
+
+ if (record_file != NULL) {
+ fclose(record_file);
+ record_file = NULL;
+ }
+
+ file = get_input("Record file?");
+ if (file == NULL || *file == '\0')
+ return;
+
+ record_file = fopen(file, "a");
+ if (record_file == NULL)
+ cu_warnx("%s", file);
+}
+
+void
do_command(char c)
{
switch (c) {
@@ -210,6 +229,9 @@ do_command(char c)
case 'C':
connect_command();
break;
+ case 'R':
+ start_record();
+ break;
case 'S':
set_speed();
break;
@@ -233,6 +255,7 @@ do_command(char c)
"~$ pipe local command to remote host\r\n"
"~> send file to remote host\r\n"
"~C connect program to remote host\r\n"
+ "~R start recording to file\r\n"
"~S set speed\r\n"
"~X send file with XMODEM\r\n"
"~? get this summary\r\n"
diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1
index e37cb2d7720..347af77180d 100644
--- a/usr.bin/cu/cu.1
+++ b/usr.bin/cu/cu.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cu.1,v 1.4 2012/07/10 11:42:02 nicm Exp $
+.\" $OpenBSD: cu.1,v 1.5 2012/07/10 12:47:23 nicm Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -123,6 +123,10 @@ file descriptors:
1 \*(Lt-\*(Gt remote tty out
2 \*(Lt-\*(Gt local tty stderr
.Ed
+.It Ic ~R
+Record all output from the remote system to a file.
+If the given file already exists, it is appended to.
+If no file is specified, any existing recording is stopped.
.It Ic ~S
Change the speed of the connection.
.It Ic ~X
diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c
index 587711dad47..4699afd397e 100644
--- a/usr.bin/cu/cu.c
+++ b/usr.bin/cu/cu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cu.c,v 1.5 2012/07/10 12:20:23 nicm Exp $ */
+/* $OpenBSD: cu.c,v 1.6 2012/07/10 12:47:23 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -36,6 +36,7 @@
extern char *__progname;
+FILE *record_file;
struct termios saved_tio;
struct bufferevent *input_ev;
struct bufferevent *output_ev;
@@ -283,6 +284,8 @@ line_read(struct bufferevent *bufev, void *data)
if (new_size == 0)
return;
+ if (record_file != NULL)
+ fwrite(new_data, 1, new_size, record_file);
bufferevent_write(output_ev, new_data, new_size);
evbuffer_drain(line_ev->input, new_size);
diff --git a/usr.bin/cu/cu.h b/usr.bin/cu/cu.h
index 8218478b6d6..70510d61c42 100644
--- a/usr.bin/cu/cu.h
+++ b/usr.bin/cu/cu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cu.h,v 1.5 2012/07/10 12:14:21 nicm Exp $ */
+/* $OpenBSD: cu.h,v 1.6 2012/07/10 12:47:23 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -23,6 +23,7 @@
void do_command(char);
/* cu.c */
+extern FILE *record_file;
extern struct termios saved_tio;
extern int line_fd;
extern struct bufferevent *line_ev;