[Midnightbsd-cvs] src [7104] trunk/usr.bin/bc/tty.c: update bc. sync with OpenBSD and FreeBSD 10 stable
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Jul 17 11:45:46 EDT 2015
Revision: 7104
http://svnweb.midnightbsd.org/src/?rev=7104
Author: laffer1
Date: 2015-07-17 11:45:45 -0400 (Fri, 17 Jul 2015)
Log Message:
-----------
update bc. sync with OpenBSD and FreeBSD 10 stable
Modified Paths:
--------------
trunk/usr.bin/bc/Makefile
trunk/usr.bin/bc/bc.1
trunk/usr.bin/bc/bc.library
trunk/usr.bin/bc/bc.y
trunk/usr.bin/bc/extern.h
trunk/usr.bin/bc/pathnames.h
trunk/usr.bin/bc/scan.l
Added Paths:
-----------
trunk/usr.bin/bc/tty.c
Property Changed:
----------------
trunk/usr.bin/bc/bc.1
trunk/usr.bin/bc/bc.y
trunk/usr.bin/bc/scan.l
Modified: trunk/usr.bin/bc/Makefile
===================================================================
--- trunk/usr.bin/bc/Makefile 2015-07-17 14:05:06 UTC (rev 7103)
+++ trunk/usr.bin/bc/Makefile 2015-07-17 15:45:45 UTC (rev 7104)
@@ -1,13 +1,15 @@
-# $MidnightBSD$
-# $OpenBSD: Makefile,v 1.4 2006/06/30 19:02:28 otto Exp $
+# $MidnightBSD$
+# $OpenBSD: Makefile,v 1.7 2013/09/19 16:12:00 otto Exp $
-PROG= bc
-SRCS= bc.y scan.l
-CFLAGS+= -I. -I${.CURDIR}
+PROG= bc
+SRCS= bc.y scan.l tty.c
+CFLAGS+= -I. -I${.CURDIR}
-DPADD= ${LIBEDIT} ${LIBTERMCAP}
-LDADD= -ledit -ltermcap
+DPADD+= ${LIBEDIT} ${LIBNCURSESW}
+LDADD+= -ledit -lncursesw
+NO_WMISSING_VARIABLE_DECLARATIONS=
+
FILES+= bc.library
FILESDIR=${SHAREDIR}/misc
Modified: trunk/usr.bin/bc/bc.1
===================================================================
--- trunk/usr.bin/bc/bc.1 2015-07-17 14:05:06 UTC (rev 7103)
+++ trunk/usr.bin/bc/bc.1 2015-07-17 15:45:45 UTC (rev 7104)
@@ -1,5 +1,6 @@
-.\" $MidnightBSD$
-.\" $OpenBSD: bc.1,v 1.25 2010/01/02 19:48:56 schwarze Exp $
+.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/bc/bc.1 265533 2014-05-07 08:06:54Z delphij $
+.\" $OpenBSD: bc.1,v 1.30 2014/01/14 07:42:42 jmc Exp $
.\"
.\" Copyright (C) Caldera International Inc. 2001-2002.
.\" All rights reserved.
@@ -35,7 +36,7 @@
.\"
.\" @(#)bc.1 6.8 (Berkeley) 8/8/91
.\"
-.Dd January 22, 2010
+.Dd April 16, 2014
.Dt BC 1
.Os
.Sh NAME
@@ -43,7 +44,7 @@
.Nd arbitrary-precision arithmetic language and calculator
.Sh SYNOPSIS
.Nm bc
-.Op Fl chlqv
+.Op Fl chlv
.Op Fl e Ar expression
.Op Ar file ...
.Sh DESCRIPTION
@@ -82,8 +83,6 @@
Allow specification of an arbitrary precision math library.
The definitions in the library are available to command line
expressions.
-Synonym for
-.Fl l .
.It Fl v , Fl Fl version
Prints version information.
.El
@@ -142,8 +141,7 @@
The semantics of the operators is the same as in the C language.
They are listed in order of decreasing precedence.
Operators in the same group have the same precedence.
-.Bl -column -offset indent "= += \-= *= /= %= ^=" "Associativity" \
-"multiply, divide, modulus"
+.Bl -column "= += \-= *= /= %= ^=" "Associativity" "multiply, divide, modulus" -offset indent
.It Sy "Operator" Ta Sy "Associativity" Ta Sy "Description"
.It "++ \-\-" Ta "none" Ta "increment, decrement"
.It "\-" Ta "none" Ta "unary minus"
@@ -162,7 +160,7 @@
.It
The relational operators may appear in any expression.
The
-.St -p1003.2
+.St -p1003.1-2008
standard only allows them in the conditional expression of an
.Sq if ,
.Sq while
@@ -344,6 +342,22 @@
.Ed
.Pp
prints an approximation of pi.
+.Sh COMMAND LINE EDITING
+.Nm
+supports interactive command line editing, via the
+.Xr editline 3
+library.
+It is enabled by default if input is from a tty.
+Previous lines can be recalled and edited with the arrow keys,
+and other GNU Emacs-style editing keys may be used as well.
+.Pp
+The
+.Xr editline 3
+library is configured with a
+.Pa .editrc
+file \- refer to
+.Xr editrc 5
+for more information.
.Sh FILES
.Bl -tag -width /usr/share/misc/bc.library -compact
.It Pa /usr/share/misc/bc.library
@@ -351,11 +365,16 @@
.Fl l
option is specified on the command line.
.El
+.Sh COMPATIBILITY
+The
+.Fl q
+and
+.Fl Fl quiet
+options are no-ops for compatibility with some other implementations of
+.Nm
+and their use is discouraged.
.Sh SEE ALSO
.Xr dc 1
-.Pp
-"BC \- An Arbitrary Precision Desk-Calculator Language",
-.Pa /usr/share/doc/usd/06.bc/ .
.Sh STANDARDS
The
.Nm
@@ -364,7 +383,8 @@
specification.
.Pp
The flags
-.Op Fl ce
+.Op Fl ce ,
+as well as the parts noted above,
are extensions to that specification.
.Sh HISTORY
The
Property changes on: trunk/usr.bin/bc/bc.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/bc/bc.library
===================================================================
--- trunk/usr.bin/bc/bc.library 2015-07-17 14:05:06 UTC (rev 7103)
+++ trunk/usr.bin/bc/bc.library 2015-07-17 15:45:45 UTC (rev 7104)
@@ -1,5 +1,6 @@
-/* $MidnightBSD$ */
-/* $OpenBSD: bc.library,v 1.3 2007/02/03 21:15:06 otto Exp $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.bin/bc/bc.library 265533 2014-05-07 08:06:54Z delphij $ */
+/* $OpenBSD: bc.library,v 1.4 2012/03/14 07:35:53 otto Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -100,13 +101,13 @@
if (x < 1) {
s = scale(x)
} else {
- s = length(x) - scale(x)
+ s = length(x)-scale(x)
}
scale = 0
a = (2.31*s)/1 /* estimated integer part of the answer */
s = t + length(a) + 2 /* estimated length of the answer */
while (x > 2) {
- scale=0
+ scale = 0
scale = (length(x) + scale(x))/2 + 1
if (scale < s) scale = s
x = sqrt(x)
Modified: trunk/usr.bin/bc/bc.y
===================================================================
--- trunk/usr.bin/bc/bc.y 2015-07-17 14:05:06 UTC (rev 7103)
+++ trunk/usr.bin/bc/bc.y 2015-07-17 15:45:45 UTC (rev 7104)
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: bc.y,v 1.33 2009/10/27 23:59:36 deraadt Exp $ */
+/* $OpenBSD: bc.y,v 1.44 2013/11/20 21:33:54 deraadt Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto at drijf.net>
@@ -45,7 +45,6 @@
#include <search.h>
#include <signal.h>
#include <stdarg.h>
-#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
@@ -53,7 +52,7 @@
#include "extern.h"
#include "pathnames.h"
-#define BC_VER "1.0-FreeBSD"
+#define BC_VER "1.1-MidnightBSD"
#define END_NODE ((ssize_t) -1)
#define CONST_STRING ((ssize_t) -2)
#define ALLOC_STRING ((ssize_t) -3)
@@ -69,7 +68,6 @@
ssize_t index;
};
-int yyparse(void);
int yywrap(void);
int fileindex;
@@ -972,8 +970,13 @@
if (yyin != NULL && feof(yyin))
n = asprintf(&str, "%s: %s:%d: %s: unexpected EOF",
__progname, filename, lineno, s);
- else if (isspace(yytext[0]) || !isprint(yytext[0]))
+ else if (yytext[0] == '\n')
n = asprintf(&str,
+ "%s: %s:%d: %s: newline unexpected",
+ __progname, filename, lineno, s);
+ else if (isspace((unsigned char)yytext[0]) ||
+ !isprint((unsigned char)yytext[0]))
+ n = asprintf(&str,
"%s: %s:%d: %s: ascii char 0x%02x unexpected",
__progname, filename, lineno, s, yytext[0]);
else
@@ -1024,7 +1027,7 @@
usage(void)
{
- fprintf(stderr, "usage: %s [-chlqv] [-e expression] [file ...]\n",
+ fprintf(stderr, "usage: %s [-chlv] [-e expression] [file ...]\n",
__progname);
exit(1);
}
@@ -1085,27 +1088,26 @@
}
/* ARGSUSED */
-void
-sigchld(int signo)
+static void
+sigchld(int signo __unused)
{
pid_t pid;
- int status;
+ int status, save_errno = errno;
- switch (signo) {
- default:
- for (;;) {
- pid = waitpid(dc, &status, WUNTRACED);
- if (pid == -1) {
- if (errno == EINTR)
- continue;
- _exit(0);
- }
- if (WIFEXITED(status) || WIFSIGNALED(status))
- _exit(0);
- else
- break;
- }
+ for (;;) {
+ pid = waitpid(dc, &status, WCONTINUED | WNOHANG);
+ if (pid == -1) {
+ if (errno == EINTR)
+ continue;
+ _exit(0);
+ } else if (pid == 0)
+ break;
+ if (WIFEXITED(status) || WIFSIGNALED(status))
+ _exit(0);
+ else
+ break;
}
+ errno = save_errno;
}
static const char *
@@ -1192,6 +1194,7 @@
}
}
if (interactive) {
+ gettty(&ttysaved);
el = el_init("bc", stdin, stderr, stderr);
hist = history_init();
history(hist, &he, H_SETSIZE, 100);
@@ -1199,6 +1202,8 @@
el_set(el, EL_EDITOR, "emacs");
el_set(el, EL_SIGNAL, 1);
el_set(el, EL_PROMPT, dummy_prompt);
+ el_set(el, EL_ADDFN, "bc_eof", "", bc_eof);
+ el_set(el, EL_BIND, "^D", "bc_eof", NULL);
el_source(el, NULL);
}
yywrap();
Property changes on: trunk/usr.bin/bc/bc.y
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/bc/extern.h
===================================================================
--- trunk/usr.bin/bc/extern.h 2015-07-17 14:05:06 UTC (rev 7103)
+++ trunk/usr.bin/bc/extern.h 2015-07-17 15:45:45 UTC (rev 7104)
@@ -1,5 +1,6 @@
-/* $MidnightBSD$ */
-/* $OpenBSD: extern.h,v 1.6 2006/03/18 20:44:43 otto Exp $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.bin/bc/extern.h 265533 2014-05-07 08:06:54Z delphij $ */
+/* $OpenBSD: extern.h,v 1.10 2013/09/19 16:12:01 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto at drijf.net>
@@ -17,26 +18,31 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <stdbool.h>
#include <stdio.h>
struct lvalue {
- ssize_t load;
- ssize_t store;
+ ssize_t load;
+ ssize_t store;
};
-int yylex(void);
-void yyerror(const char *);
-void fatal(const char *);
-void abort_line(int);
+int yylex(void);
+void yyerror(const 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;
-extern int fileindex;
-extern int sargc;
+extern int lineno;
+extern int fileindex;
+extern int sargc;
extern const char **sargv;
extern const char *filename;
-extern char *cmdexpr;
extern bool interactive;
extern EditLine *el;
extern History *hist;
extern HistEvent he;
-
+extern char *cmdexpr;
+extern struct termios ttysaved;
Modified: trunk/usr.bin/bc/pathnames.h
===================================================================
--- trunk/usr.bin/bc/pathnames.h 2015-07-17 14:05:06 UTC (rev 7103)
+++ trunk/usr.bin/bc/pathnames.h 2015-07-17 15:45:45 UTC (rev 7104)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.bin/bc/pathnames.h 202719 2010-01-20 21:30:52Z gabor $ */
/* $OpenBSD: pathnames.h,v 1.1 2003/09/25 19:32:44 otto Exp $ */
/*
Modified: trunk/usr.bin/bc/scan.l
===================================================================
--- trunk/usr.bin/bc/scan.l 2015-07-17 14:05:06 UTC (rev 7103)
+++ trunk/usr.bin/bc/scan.l 2015-07-17 15:45:45 UTC (rev 7104)
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: scan.l,v 1.23 2009/10/27 23:59:36 deraadt Exp $ */
+/* $OpenBSD: scan.l,v 1.28 2013/09/19 16:12:01 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto at drijf.net>
@@ -24,6 +24,7 @@
#include <errno.h>
#include <histedit.h>
#include <stdbool.h>
+#include <signal.h>
#include <string.h>
#include <unistd.h>
@@ -31,25 +32,30 @@
#include "bc.h"
#include "pathnames.h"
-int lineno;
+int lineno;
+bool interactive;
-bool interactive;
HistEvent he;
EditLine *el;
History *hist;
static char *strbuf = NULL;
-static size_t strbuf_sz = 1;
-static bool dot_seen;
+static size_t strbuf_sz = 1;
+static bool dot_seen;
+static int use_el;
+static volatile sig_atomic_t skipchars;
-static void init_strbuf(void);
-static void add_str(const char *);
+static void init_strbuf(void);
+static void add_str(const char *);
+
static int bc_yyinput(char *, int);
+#define YY_DECL int yylex(void)
#define YY_NO_INPUT
#undef YY_INPUT
#define YY_INPUT(buf,retval,max) \
(retval = bc_yyinput(buf, max))
+
%}
%option always-interactive
@@ -101,7 +107,7 @@
BEGIN(INITIAL);
yylval.str = strbuf;
unput('.');
- return (NUMBER);
+ return NUMBER;
} else {
dot_seen = true;
add_str(".");
@@ -112,73 +118,73 @@
BEGIN(INITIAL);
unput(yytext[0]);
if (strcmp(strbuf, ".") == 0)
- return (DOT);
+ return DOT;
else {
yylval.str = strbuf;
- return (NUMBER);
+ return NUMBER;
}
}
}
-"auto" return (AUTO);
-"break" return (BREAK);
-"continue" return (CONTINUE);
-"define" return (DEFINE);
-"else" return (ELSE);
-"ibase" return (IBASE);
-"if" return (IF);
-"last" return (DOT);
-"for" return (FOR);
-"length" return (LENGTH);
-"obase" return (OBASE);
-"print" return (PRINT);
-"quit" return (QUIT);
-"return" return (RETURN);
-"scale" return (SCALE);
-"sqrt" return (SQRT);
-"while" return (WHILE);
+"auto" return AUTO;
+"break" return BREAK;
+"continue" return CONTINUE;
+"define" return DEFINE;
+"else" return ELSE;
+"ibase" return IBASE;
+"if" return IF;
+"last" return DOT;
+"for" return FOR;
+"length" return LENGTH;
+"obase" return OBASE;
+"print" return PRINT;
+"quit" return QUIT;
+"return" return RETURN;
+"scale" return SCALE;
+"sqrt" return SQRT;
+"while" return WHILE;
-"^" return (EXPONENT);
-"*" return (MULTIPLY);
-"/" return (DIVIDE);
-"%" return (REMAINDER);
+"^" return EXPONENT;
+"*" return MULTIPLY;
+"/" return DIVIDE;
+"%" return REMAINDER;
-"!" return (BOOL_NOT);
-"&&" return (BOOL_AND);
-"||" return (BOOL_OR);
+"!" return BOOL_NOT;
+"&&" return BOOL_AND;
+"||" return BOOL_OR;
-"+" return (PLUS);
-"-" return (MINUS);
+"+" return PLUS;
+"-" return MINUS;
-"++" return (INCR);
-"--" return (DECR);
+"++" return INCR;
+"--" return DECR;
-"=" yylval.str = ""; return (ASSIGN_OP);
-"+=" yylval.str = "+"; return (ASSIGN_OP);
-"-=" yylval.str = "-"; return (ASSIGN_OP);
-"*=" yylval.str = "*"; return (ASSIGN_OP);
-"/=" yylval.str = "/"; return (ASSIGN_OP);
-"%=" yylval.str = "%"; return (ASSIGN_OP);
-"^=" yylval.str = "^"; return (ASSIGN_OP);
+"=" yylval.str = ""; return ASSIGN_OP;
+"+=" yylval.str = "+"; return ASSIGN_OP;
+"-=" yylval.str = "-"; return ASSIGN_OP;
+"*=" yylval.str = "*"; return ASSIGN_OP;
+"/=" yylval.str = "/"; return ASSIGN_OP;
+"%=" yylval.str = "%"; return ASSIGN_OP;
+"^=" yylval.str = "^"; return ASSIGN_OP;
-"==" return (EQUALS);
-"<=" return (LESS_EQ);
-">=" return (GREATER_EQ);
-"!=" return (UNEQUALS);
-"<" return (LESS);
-">" return (GREATER);
+"==" return EQUALS;
+"<=" return LESS_EQ;
+">=" return GREATER_EQ;
+"!=" return UNEQUALS;
+"<" return LESS;
+">" return GREATER;
-"," return (COMMA);
-";" return (SEMICOLON);
+"," return COMMA;
+";" return SEMICOLON;
-"(" return (LPAR);
-")" return (RPAR);
+"(" return LPAR;
+")" return RPAR;
-"[" return (LBRACKET);
-"]" return (RBRACKET);
+"[" return LBRACKET;
+"]" return RBRACKET;
-"{" return (LBRACE);
-"}" return (RBRACE);
+"{" return LBRACE;
+"}" return RBRACE;
{ALPHA}{ALPHANUM}* {
/* alloc an extra byte for the type marker */
@@ -187,15 +193,15 @@
err(1, NULL);
strlcpy(p, yytext, yyleng + 1);
yylval.astr = p;
- return (LETTER);
+ return LETTER;
}
\\\n lineno++;
-\n lineno++; return (NEWLINE);
+\n lineno++; return NEWLINE;
#[^\n]* ;
[ \t] ;
-<<EOF>> return (QUIT);
+<<EOF>> return QUIT;
. yyerror("illegal character");
%%
@@ -203,7 +209,6 @@
static void
init_strbuf(void)
{
-
if (strbuf == NULL) {
strbuf = malloc(strbuf_sz);
if (strbuf == NULL)
@@ -220,8 +225,8 @@
arglen = strlen(str);
if (strlen(strbuf) + arglen + 1 > strbuf_sz) {
- size_t newsize;
- char *p;
+ size_t newsize;
+ char *p;
newsize = strbuf_sz + arglen + 1;
p = realloc(strbuf, newsize);
@@ -235,11 +240,47 @@
strlcat(strbuf, str, strbuf_sz);
}
+/* ARGSUSED */
+void
+abort_line(int sig __unused)
+{
+ static const char str1[] = "[\n]P\n";
+ static const char str2[] = "[^C\n]P\n";
+ int save_errno;
+ const LineInfo *info;
+
+ save_errno = errno;
+ if (use_el) {
+ write(STDOUT_FILENO, str2, sizeof(str2) - 1);
+ info = el_line(el);
+ skipchars = info->lastchar - info->buffer;
+ } else
+ write(STDOUT_FILENO, str1, sizeof(str1) - 1);
+ 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
+ * line after a ^C.
+ */
+unsigned char
+bc_eof(EditLine *e, int ch __unused)
+{
+ const struct lineinfo *info = el_line(e);
+
+ if (info->buffer + skipchars == info->cursor &&
+ info->cursor == info->lastchar)
+ return (CC_EOF);
+ else
+ return (CC_ERROR);
+}
+
int
yywrap(void)
{
+ static int state;
static YY_BUFFER_STATE buf;
- static int state;
if (fileindex == 0 && sargc > 0 && strcmp(sargv[0], _PATH_LIBB) == 0) {
filename = sargv[fileindex++];
@@ -272,6 +313,10 @@
} else if (fileindex == sargc) {
fileindex++;
yyin = stdin;
+ if (interactive) {
+ signal(SIGINT, abort_line);
+ signal(SIGTSTP, tstpcont);
+ }
lineno = 1;
filename = "stdin";
return (0);
@@ -283,17 +328,32 @@
bc_yyinput(char *buf, int maxlen)
{
int num;
- if (yyin == stdin && interactive) {
+
+ if (el != NULL)
+ el_get(el, EL_EDITMODE, &use_el);
+
+ if (yyin == stdin && interactive && use_el) {
const char *bp;
+ sigset_t oset, nset;
if ((bp = el_gets(el, &num)) == NULL || num == 0)
return (0);
+ sigemptyset(&nset);
+ sigaddset(&nset, SIGINT);
+ sigprocmask(SIG_BLOCK, &nset, &oset);
+ if (skipchars < num) {
+ bp += skipchars;
+ num -= skipchars;
+ }
+ skipchars = 0;
+ sigprocmask(SIG_SETMASK, &oset, NULL);
if (num > maxlen) {
- el_push(el, (char *)(uintptr_t)(bp) + maxlen);
+ el_push(el, bp + maxlen);
num = maxlen;
}
memcpy(buf, bp, num);
history(hist, &he, H_ENTER, bp);
+ el_get(el, EL_EDITMODE, &use_el);
} else {
int c = '*';
for (num = 0; num < maxlen &&
@@ -307,3 +367,4 @@
return (num);
}
+
Property changes on: trunk/usr.bin/bc/scan.l
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: trunk/usr.bin/bc/tty.c
===================================================================
--- trunk/usr.bin/bc/tty.c (rev 0)
+++ trunk/usr.bin/bc/tty.c 2015-07-17 15:45:45 UTC (rev 7104)
@@ -0,0 +1,66 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.bin/bc/tty.c 265533 2014-05-07 08:06:54Z delphij $ */
+/* $OpenBSD: tty.c,v 1.2 2013/11/12 13:54:51 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2013, Otto Moerbeek <otto at 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;
+
+static 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;
+}
Property changes on: trunk/usr.bin/bc/tty.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
More information about the Midnightbsd-cvs
mailing list