Hi,

adding editline caused a regrssion in the handling of ^C.

Originally (and I mean the days of AT&T) bc used ^C as an abort line.
With editline, while appearing to work, the characters typed so far
remain in the input buffer. Try this: 1+^C2<enter>

Editline has no signal safe facility to accomodate that. So switch it
off (you can use ^U anyway). 

Also, honour the "edit off" command from .editrc or interactively. In
that case ^C works as before. 

        -Otto

Index: bc.y
===================================================================
RCS file: /cvs/src/usr.bin/bc/bc.y,v
retrieving revision 1.34
diff -u -p -r1.34 bc.y
--- bc.y        7 Mar 2011 08:11:15 -0000       1.34
+++ bc.y        26 May 2011 04:55:04 -0000
@@ -1143,7 +1143,7 @@ main(int argc, char *argv[])
                                history(hist, &he, H_SETSIZE, 100);
                                el_set(el, EL_HIST, history, hist);
                                el_set(el, EL_EDITOR, "emacs");
-                               el_set(el, EL_SIGNAL, 1);
+                               el_set(el, EL_SIGNAL, 0);
                                el_set(el, EL_PROMPT, dummy_prompt);
                                el_source(el, NULL);
                        }
Index: scan.l
===================================================================
RCS file: /cvs/src/usr.bin/bc/scan.l,v
retrieving revision 1.24
diff -u -p -r1.24 scan.l
--- scan.l      7 Mar 2011 08:11:15 -0000       1.24
+++ scan.l      26 May 2011 04:55:04 -0000
@@ -38,6 +38,7 @@ History               *hist;
 static char    *strbuf = NULL;
 static size_t  strbuf_sz = 1;
 static bool    dot_seen;
+static int     use_el;
 
 static void    init_strbuf(void);
 static void    add_str(const char *);
@@ -239,10 +240,11 @@ abort_line(int sig)
        static const char str[] = "[\n]P\n";
        int save_errno;
 
-       save_errno = errno;
-       YY_FLUSH_BUFFER;        /* XXX signal race? */
-       write(STDOUT_FILENO, str, sizeof(str) - 1);
-       errno = save_errno;
+       if (!use_el) {
+               save_errno = errno;
+               write(STDOUT_FILENO, str, sizeof(str) - 1);
+               errno = save_errno;
+       }
 }
 
 int
@@ -295,7 +297,10 @@ static int
 bc_yyinput(char *buf, int maxlen)
 {
        int num;
-       if (yyin == stdin && interactive) {
+
+       if (el != NULL)
+               el_get(el, EL_EDITMODE, &use_el);
+       if (use_el && yyin == stdin && interactive) {
                const char *bp;
 
                if ((bp = el_gets(el, &num)) == NULL || num == 0)
@@ -306,6 +311,7 @@ bc_yyinput(char *buf, int 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 &&

Reply via email to