diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2011-06-03 06:10:34 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2011-06-03 06:10:34 +0000 |
commit | d0623598b772776507659254cf9b94adee6d9f4e (patch) | |
tree | e1a82fdfac579b40cd1bdff5894762c3c62bdd12 | |
parent | 3e1ba4676a0316815f76b1ca455f02f31969187b (diff) |
Make ^D behave: dont't echo it and make it work if the cursor is at
start of line after a ^C; ok okan@ deraadt@
-rw-r--r-- | usr.bin/bc/bc.y | 4 | ||||
-rw-r--r-- | usr.bin/bc/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/bc/scan.l | 19 |
3 files changed, 23 insertions, 3 deletions
diff --git a/usr.bin/bc/bc.y b/usr.bin/bc/bc.y index 22b850e6540..b1ee4e467df 100644 --- a/usr.bin/bc/bc.y +++ b/usr.bin/bc/bc.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: bc.y,v 1.35 2011/06/01 07:18:23 otto Exp $ */ +/* $OpenBSD: bc.y,v 1.36 2011/06/03 06:10:31 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -1145,6 +1145,8 @@ main(int argc, char *argv[]) el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_SIGNAL, 0); el_set(el, EL_PROMPT, dummy_prompt); + el_set(el, EL_ADDFN, "bc_eof", "", bc_eof); + el_set(el, EL_BIND, "^D", "bc_eof"); el_source(el, NULL); } } else { diff --git a/usr.bin/bc/extern.h b/usr.bin/bc/extern.h index 0f404065381..be03bd33a5f 100644 --- a/usr.bin/bc/extern.h +++ b/usr.bin/bc/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.7 2011/03/07 08:11:15 otto Exp $ */ +/* $OpenBSD: extern.h,v 1.8 2011/06/03 06:10:33 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -27,6 +27,7 @@ int yylex(void); void yyerror(char *); void fatal(const char *); void abort_line(int); +unsigned char bc_eof(EditLine *, int); extern int lineno; extern char *yytext; diff --git a/usr.bin/bc/scan.l b/usr.bin/bc/scan.l index 2a8e7caaeb2..8cef4b294f9 100644 --- a/usr.bin/bc/scan.l +++ b/usr.bin/bc/scan.l @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: scan.l,v 1.25 2011/06/01 07:18:23 otto Exp $ */ +/* $OpenBSD: scan.l,v 1.26 2011/06/03 06:10:33 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -253,6 +253,23 @@ abort_line(int 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 + * line after a ^C. + */ +unsigned char +bc_eof(EditLine *e, int ch) +{ + 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) { |