diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2013-09-19 16:12:02 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2013-09-19 16:12:02 +0000 |
commit | 9dcae335db31b109f2eeb4b6b63e0cab3328de65 (patch) | |
tree | b6bc771672ba0ddcf2316468407b77b264968c11 /usr.bin | |
parent | 6f3beff0ed61c4dd99f705958a5ae95ea659e832 (diff) |
separate termios.h out from scan.l, both have an ECHO define. Noted by
Joris Giovannangeli.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/bc/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/bc/bc.y | 4 | ||||
-rw-r--r-- | usr.bin/bc/extern.h | 5 | ||||
-rw-r--r-- | usr.bin/bc/scan.l | 44 | ||||
-rw-r--r-- | usr.bin/bc/tty.c | 64 |
5 files changed, 72 insertions, 49 deletions
diff --git a/usr.bin/bc/Makefile b/usr.bin/bc/Makefile index bc8b937791a..37acb194029 100644 --- a/usr.bin/bc/Makefile +++ b/usr.bin/bc/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.6 2011/03/07 08:11:15 otto Exp $ +# $OpenBSD: Makefile,v 1.7 2013/09/19 16:12:00 otto Exp $ PROG= bc -SRCS= bc.y scan.l +SRCS= bc.y scan.l tty.c CPPFLAGS+= -I. -I${.CURDIR} CFLAGS+= -Wall -Wno-unused YFLAGS+= diff --git a/usr.bin/bc/bc.y b/usr.bin/bc/bc.y index aabcbff4228..fe850368ae7 100644 --- a/usr.bin/bc/bc.y +++ b/usr.bin/bc/bc.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: bc.y,v 1.41 2012/03/08 08:20:08 otto Exp $ */ +/* $OpenBSD: bc.y,v 1.42 2013/09/19 16:12:01 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -41,9 +41,7 @@ #include <search.h> #include <signal.h> #include <stdarg.h> -#include <stdbool.h> #include <string.h> -#include <termios.h> #include <unistd.h> #include "extern.h" diff --git a/usr.bin/bc/extern.h b/usr.bin/bc/extern.h index 3fb7e318daa..7095941083b 100644 --- a/usr.bin/bc/extern.h +++ b/usr.bin/bc/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.9 2011/08/03 08:48:19 otto Exp $ */ +/* $OpenBSD: extern.h,v 1.10 2013/09/19 16:12:01 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <stdbool.h> #include <stdio.h> struct lvalue { @@ -27,7 +28,9 @@ int yylex(void); void yyerror(char *); void fatal(const char *); void abort_line(int); +struct termios; int gettty(struct termios *); +void tstpcont(int); unsigned char bc_eof(EditLine *, int); extern int lineno; diff --git a/usr.bin/bc/scan.l b/usr.bin/bc/scan.l index a49ef2cb38c..8372f540f60 100644 --- a/usr.bin/bc/scan.l +++ b/usr.bin/bc/scan.l @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: scan.l,v 1.27 2011/08/03 08:48:19 otto Exp $ */ +/* $OpenBSD: scan.l,v 1.28 2013/09/19 16:12:01 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -20,9 +20,7 @@ #include <err.h> #include <histedit.h> #include <signal.h> -#include <stdbool.h> #include <string.h> -#include <termios.h> #include <unistd.h> #include "extern.h" @@ -41,7 +39,6 @@ static size_t strbuf_sz = 1; static bool dot_seen; static int use_el; static volatile sig_atomic_t skipchars; -struct termios ttysaved, ttyedit; static void init_strbuf(void); static void add_str(const char *); @@ -255,45 +252,6 @@ abort_line(int sig) errno = save_errno; } -int -settty(struct termios *t) -{ - int ret; - - while ((ret = tcsetattr(0, TCSADRAIN, t) == -1) && errno == EINTR) - continue; - return ret; -} - -int -gettty(struct termios *t) -{ - int ret; - - while ((ret = tcgetattr(0, t) == -1) && errno == EINTR) - continue; - return ret; -} - -/* ARGSUSED */ -void -tstpcont(int sig) -{ - int save_errno = errno; - - if (sig == SIGTSTP) { - signal(SIGCONT, tstpcont); - gettty(&ttyedit); - settty(&ttysaved); - } else { - signal(SIGTSTP, tstpcont); - settty(&ttyedit); - } - signal(sig, SIG_DFL); - kill(0, sig); - errno = save_errno; -} - /* * Avoid the echo of ^D by the default code of editline and take * into account skipchars to make ^D work when the cursor is at start of diff --git a/usr.bin/bc/tty.c b/usr.bin/bc/tty.c new file mode 100644 index 00000000000..ffba1d5d18a --- /dev/null +++ b/usr.bin/bc/tty.c @@ -0,0 +1,64 @@ +/* $OpenBSD: tty.c,v 1.1 2013/09/19 16:12:01 otto Exp $ */ + +/* + * Copyright (c) 2013, Otto Moerbeek <otto@drijf.net> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <errno.h> +#include <signal.h> +#include <histedit.h> +#include <termios.h> +#include "extern.h" + +struct termios ttysaved, ttyedit; + +int +settty(struct termios *t) +{ + int ret; + + while ((ret = tcsetattr(0, TCSADRAIN, t) == -1) && errno == EINTR) + continue; + return ret; +} + +int +gettty(struct termios *t) +{ + int ret; + + while ((ret = tcgetattr(0, t) == -1) && errno == EINTR) + continue; + return ret; +} + +/* ARGSUSED */ +void +tstpcont(int sig) +{ + int save_errno = errno; + + if (sig == SIGTSTP) { + signal(SIGCONT, tstpcont); + gettty(&ttyedit); + settty(&ttysaved); + } else { + signal(SIGTSTP, tstpcont); + settty(&ttyedit); + } + signal(sig, SIG_DFL); + kill(0, sig); + errno = save_errno; +} |