date and time created 85/05/31 12:51:02 by bloom
[unix-history] / usr / src / usr.bin / ex / ex_vget.c
index 7ef7a3b..0bc7647 100644 (file)
@@ -1,5 +1,13 @@
-/* Copyright (c) 1980 Regents of the University of California */
-static char *sccsid = "@(#)ex_vget.c   6.1 %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)ex_vget.c  5.1.1.1 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
 #include "ex.h"
 #include "ex_tty.h"
 #include "ex_vis.h"
@@ -15,7 +23,7 @@ static char *sccsid = "@(#)ex_vget.c  6.1 %G%";
  * Return the key.
  */
 ungetkey(c)
  * Return the key.
  */
 ungetkey(c)
-       char c;
+       int c;          /* mjm: char --> int */
 {
 
        if (Peekkey != ATTN)
 {
 
        if (Peekkey != ATTN)
@@ -27,7 +35,7 @@ ungetkey(c)
  */
 getkey()
 {
  */
 getkey()
 {
-       register char c;
+       register int c;         /* mjm: char --> int */
 
        do {
                c = getbr();
 
        do {
                c = getbr();
@@ -48,6 +56,8 @@ peekbr()
 }
 
 short  precbksl;
 }
 
 short  precbksl;
+jmp_buf        readbuf;
+int    doingread = 0;
 
 /*
  * Get a keystroke, including a ^@.
 
 /*
  * Get a keystroke, including a ^@.
@@ -64,6 +74,7 @@ getbr()
        char ch;
        register int c, d;
        register char *colp;
        char ch;
        register int c, d;
        register char *colp;
+       int cnt;
 #define BEEHIVE
 #ifdef BEEHIVE
        static char Peek2key;
 #define BEEHIVE
 #ifdef BEEHIVE
        static char Peek2key;
@@ -101,7 +112,12 @@ getATTN:
        }
        flusho();
 again:
        }
        flusho();
 again:
-       if (read(slevel == 0 ? 0 : ttyindes, &ch, 1) != 1) {
+       if (setjmp(readbuf))
+               goto getATTN;
+       doingread = 1;
+       c = read(slevel == 0 ? 0 : ttyindes, &ch, 1);
+       doingread = 0;
+       if (c != 1) {
                if (errno == EINTR)
                        goto getATTN;
                error("Input read error");
                if (errno == EINTR)
                        goto getATTN;
                error("Input read error");
@@ -455,7 +471,7 @@ map(c,maps)
                                        if ((c=='#' ? peekkey() : fastpeekkey()) == 0) {
 #ifdef MDEBUG
                                                if (trace)
                                        if ((c=='#' ? peekkey() : fastpeekkey()) == 0) {
 #ifdef MDEBUG
                                                if (trace)
-                                                       fprintf(trace,"fpk=0: return '%c'",c);
+                                                       fprintf(trace,"fpk=0: will return '%c'",c);
 #endif
                                                /*
                                                 * Nothing waiting.  Push back
 #endif
                                                /*
                                                 * Nothing waiting.  Push back
@@ -467,7 +483,15 @@ map(c,maps)
                                                 * to undo part of an insertion
                                                 * so if in input mode don't.
                                                 */
                                                 * to undo part of an insertion
                                                 * so if in input mode don't.
                                                 */
+#ifdef MDEBUG
+                                               if (trace)
+                                                       fprintf(trace, "Call macpush, b %d %d %d\n", b[0], b[1], b[2]);
+#endif
                                                macpush(&b[1],maps == arrows);
                                                macpush(&b[1],maps == arrows);
+#ifdef MDEBUG
+                                               if (trace)
+                                                       fprintf(trace, "return %d\n", c);       
+#endif
                                                return(c);
                                        }
                                        *q = getkey();
                                                return(c);
                                        }
                                        *q = getkey();
@@ -511,11 +535,7 @@ int canundo;
 
        if (st==0 || *st==0)
                return;
 
        if (st==0 || *st==0)
                return;
-#ifdef notdef
-       if (!value(UNDOMACRO))
-               canundo = 0;
-#endif
-#ifdef TRACE
+#ifdef MDEBUG
        if (trace)
                fprintf(trace, "macpush(%s), canundo=%d\n",st,canundo);
 #endif
        if (trace)
                fprintf(trace, "macpush(%s), canundo=%d\n",st,canundo);
 #endif
@@ -565,6 +585,7 @@ vudump(s)
 char *s;
 {
        register line *p;
 char *s;
 {
        register line *p;
+       char savelb[1024];
 
        if (!trace) return;
 
 
        if (!trace) return;
 
@@ -572,10 +593,16 @@ char *s;
                s, undkind, vundkind, lineno(unddel), lineno(undap1), lineno(undap2));
        fprintf(trace, "  undadot=%d, dot=%d, dol=%d, unddol=%d, truedol=%d\n",
                lineno(undadot), lineno(dot), lineno(dol), lineno(unddol), lineno(truedol));
                s, undkind, vundkind, lineno(unddel), lineno(undap1), lineno(undap2));
        fprintf(trace, "  undadot=%d, dot=%d, dol=%d, unddol=%d, truedol=%d\n",
                lineno(undadot), lineno(dot), lineno(dol), lineno(unddol), lineno(truedol));
-       fprintf(trace, "  [");
-       for (p=zero+1; p<=truedol; p++)
+       fprintf(trace, "  [\n");
+       CP(savelb, linebuf);
+       fprintf(trace, "linebuf = '%s'\n", linebuf);
+       for (p=zero+1; p<=truedol; p++) {
                fprintf(trace, "%o ", *p);
                fprintf(trace, "%o ", *p);
+               getline(*p);
+               fprintf(trace, "'%s'\n", linebuf);
+       }
        fprintf(trace, "]\n");
        fprintf(trace, "]\n");
+       CP(linebuf, savelb);
 }
 #endif
 
 }
 #endif
 
@@ -609,6 +636,7 @@ vgetcnt()
 fastpeekkey()
 {
        int trapalarm();
 fastpeekkey()
 {
        int trapalarm();
+       int (*Oint)();
        register int c;
 
        /*
        register int c;
 
        /*
@@ -622,9 +650,20 @@ fastpeekkey()
         * as separate.  notimeout is provided for people who dislike such
         * nondeterminism.
         */
         * as separate.  notimeout is provided for people who dislike such
         * nondeterminism.
         */
+#ifdef MDEBUG
+       if (trace)
+               fprintf(trace,"\nfastpeekkey: ",c);
+#endif
+       Oint = signal(SIGINT, trapalarm);
        if (value(TIMEOUT) && inopen >= 0) {
                signal(SIGALRM, trapalarm);
        if (value(TIMEOUT) && inopen >= 0) {
                signal(SIGALRM, trapalarm);
+#ifdef MDEBUG
+               alarm(10);
+               if (trace)
+                       fprintf(trace, "set alarm ");
+#else
                alarm(1);
                alarm(1);
+#endif
        }
        CATCH
                c = peekkey();
        }
        CATCH
                c = peekkey();
@@ -637,17 +676,19 @@ fastpeekkey()
                c = 0;
 #ifdef MDEBUG
        if (trace)
                c = 0;
 #ifdef MDEBUG
        if (trace)
-               fprintf(trace,"[TOUT]",c);
+               fprintf(trace,"[TIMEOUT]",c);
 #endif
        ENDCATCH
 #ifdef MDEBUG
        if (trace)
                fprintf(trace,"[fpk:%o]",c);
 #endif
 #endif
        ENDCATCH
 #ifdef MDEBUG
        if (trace)
                fprintf(trace,"[fpk:%o]",c);
 #endif
+       signal(SIGINT,Oint);
        return(c);
 }
 
 trapalarm() {
        alarm(0);
        return(c);
 }
 
 trapalarm() {
        alarm(0);
-       longjmp(vreslab,1);
+       if (vcatch)
+               longjmp(vreslab,1);
 }
 }