Hi, When quitting bc with EOF, it's unpleasing to see the ^D echoed by editline. Additionaly, after a ^C we want ^D to work as expected: only at the start of line. So take into account the position of the cursor and skipchars.
ok? -Otto Index: bc.y =================================================================== RCS file: /cvs/src/usr.bin/bc/bc.y,v retrieving revision 1.35 diff -u -p -r1.35 bc.y --- bc.y 1 Jun 2011 07:18:23 -0000 1.35 +++ bc.y 1 Jun 2011 07:29:00 -0000 @@ -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 { Index: extern.h =================================================================== RCS file: /cvs/src/usr.bin/bc/extern.h,v retrieving revision 1.7 diff -u -p -r1.7 extern.h --- extern.h 7 Mar 2011 08:11:15 -0000 1.7 +++ extern.h 1 Jun 2011 07:29:00 -0000 @@ -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; Index: scan.l =================================================================== RCS file: /cvs/src/usr.bin/bc/scan.l,v retrieving revision 1.25 diff -u -p -r1.25 scan.l --- scan.l 1 Jun 2011 07:18:23 -0000 1.25 +++ scan.l 1 Jun 2011 07:29:00 -0000 @@ -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) {