summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-07-10 08:16:28 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-07-10 08:16:28 +0000
commit322117d7596d6b7b5910afab1f88826c59556abe (patch)
tree25532f1c22b8faffd7f537422a55ab70f0cdd3c2
parent987bf588ac046de0e2a20e1f62985ac0fc03876a (diff)
Add a ~S escape to change the speed interactively (not using ~s since
may want to use it for variables later).
-rw-r--r--usr.bin/cu/command.c30
-rw-r--r--usr.bin/cu/cu.14
-rw-r--r--usr.bin/cu/cu.c35
-rw-r--r--usr.bin/cu/cu.h3
4 files changed, 55 insertions, 17 deletions
diff --git a/usr.bin/cu/command.c b/usr.bin/cu/command.c
index b63ccd08a46..6d17897d393 100644
--- a/usr.bin/cu/command.c
+++ b/usr.bin/cu/command.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: command.c,v 1.1 2012/07/10 08:02:27 nicm Exp $ */
+/* $OpenBSD: command.c,v 1.2 2012/07/10 08:16:27 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -101,6 +101,25 @@ send_file(void)
}
void
+set_speed(void)
+{
+ const char *s, *errstr;
+ int speed;
+
+ s = get_input("New speed?");
+ if (s == NULL || *s == '\0')
+ return;
+
+ speed = strtonum(s, 0, UINT_MAX, &errstr);
+ if (errstr != NULL) {
+ warnx("speed is %s: %s", errstr, s);
+ return;
+ }
+
+ set_line(speed);
+}
+
+void
do_command(char c)
{
switch (c) {
@@ -113,6 +132,9 @@ do_command(char c)
kill(getpid(), SIGTSTP);
set_termios();
break;
+ case 'S':
+ set_speed();
+ break;
case '$':
pipe_command();
break;
@@ -126,10 +148,12 @@ do_command(char c)
break;
case '?':
printf("\r\n"
- "~> send file to remote host\r\n"
+ "~# send break\r\n"
"~$ pipe local command to remote host\r\n"
+ "~> send file to remote host\r\n"
+ "~S set speed\r\n"
"~? get this summary\r\n"
- "~# send break\r\n");
+ );
break;
}
}
diff --git a/usr.bin/cu/cu.1 b/usr.bin/cu/cu.1
index b5568259e63..80b9fd29f22 100644
--- a/usr.bin/cu/cu.1
+++ b/usr.bin/cu/cu.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: cu.1,v 1.1 2012/07/10 08:02:27 nicm Exp $
+.\" $OpenBSD: cu.1,v 1.2 2012/07/10 08:16:27 nicm Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -113,6 +113,8 @@ to the remote system.
Stop
.Nm
(only available with job control).
+.It Ic ~S
+Change the speed of the connection.
.It Ic ~?
Get a summary of the tilde escapes.
.El
diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c
index ad60e9a1b26..13d4e5b1273 100644
--- a/usr.bin/cu/cu.c
+++ b/usr.bin/cu/cu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cu.c,v 1.1 2012/07/10 08:02:27 nicm Exp $ */
+/* $OpenBSD: cu.c,v 1.2 2012/07/10 08:16:27 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -68,7 +68,6 @@ main(int argc, char **argv)
const char *line, *errstr;
char *tmp;
int opt, speed, i, ch;
- struct termios tio;
static char sbuf[12];
line = "/dev/cua00";
@@ -132,16 +131,8 @@ getopt:
if (ioctl(line_fd, TIOCEXCL) != 0)
err(1, "ioctl(TIOCEXCL)");
- cfmakeraw(&tio);
- tio.c_iflag = 0;
- tio.c_oflag = 0;
- tio.c_lflag = 0;
- tio.c_cflag = CREAD|CS8;
- tio.c_cc[VMIN] = 1;
- tio.c_cc[VTIME] = 0;
- cfsetspeed(&tio, speed);
- if (tcsetattr(line_fd, TCSAFLUSH, &tio) != 0)
- err(1, "tcsetattr");
+ if (set_line(speed) != 0)
+ exit(1);
if (isatty(STDIN_FILENO) && tcgetattr(STDIN_FILENO, &saved_tio) != 0)
err(1, "tcgetattr");
@@ -218,6 +209,26 @@ restore_termios(void)
err(1, "tcsetattr");
}
+int
+set_line(int speed)
+{
+ struct termios tio;
+
+ cfmakeraw(&tio);
+ tio.c_iflag = 0;
+ tio.c_oflag = 0;
+ tio.c_lflag = 0;
+ tio.c_cflag = CREAD|CS8;
+ tio.c_cc[VMIN] = 1;
+ tio.c_cc[VTIME] = 0;
+ cfsetspeed(&tio, speed);
+ if (tcsetattr(line_fd, TCSAFLUSH, &tio) != 0) {
+ warn("tcsetattr");
+ return (-1);
+ }
+ return (0);
+}
+
void
stream_read(struct bufferevent *bufev, void *data)
{
diff --git a/usr.bin/cu/cu.h b/usr.bin/cu/cu.h
index db669becf31..ef7f888a235 100644
--- a/usr.bin/cu/cu.h
+++ b/usr.bin/cu/cu.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cu.h,v 1.1 2012/07/10 08:02:27 nicm Exp $ */
+/* $OpenBSD: cu.h,v 1.2 2012/07/10 08:16:27 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@openbsd.org>
@@ -27,6 +27,7 @@ extern struct bufferevent *input_ev;
extern struct bufferevent *output_ev;
extern int line_fd;
extern struct bufferevent *line_ev;
+int set_line(int);
void set_termios(void);
void restore_termios(void);
char *tilde_expand(const char *);