Flush out the last dregs in the terminal before quitting when
[unix-history] / usr / src / usr.bin / ex / ex_get.c
index 6713be3..29e0039 100644 (file)
@@ -1,5 +1,13 @@
-/* Copyright (c) 1981 Regents of the University of California */
-static char *sccsid = "@(#)ex_get.c    5.1.1.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_get.c    7.9 (Berkeley) %G%";
+#endif not lint
+
 #include "ex.h"
 #include "ex_tty.h"
 
 #include "ex.h"
 #include "ex_tty.h"
 
@@ -13,16 +21,16 @@ short       lastc = '\n';
 
 ignchar()
 {
 
 ignchar()
 {
-       ignore(getchar());
+       ignore(ex_getchar());
 }
 
 }
 
-getchar()
+ex_getchar()
 {
        register int c;
 
        do
                c = getcd();
 {
        register int c;
 
        do
                c = getcd();
-       while (!globp && c == CTRL(d));
+       while (!globp && c == CTRL('d'));
        return (c);
 }
 
        return (c);
 }
 
@@ -36,7 +44,7 @@ again:
                return (c);
        c &= TRIM;
        if (!inopen)
                return (c);
        c &= TRIM;
        if (!inopen)
-               if (!globp && c == CTRL(d))
+               if (!globp && c == CTRL('d'))
                        setlastchar('\n');
                else if (junk(c)) {
                        checkjunk(c);
                        setlastchar('\n');
                else if (junk(c)) {
                        checkjunk(c);
@@ -49,7 +57,7 @@ peekchar()
 {
 
        if (peekc == 0)
 {
 
        if (peekc == 0)
-               peekc = getchar();
+               peekc = ex_getchar();
        return (peekc);
 }
 
        return (peekc);
 }
 
@@ -63,8 +71,7 @@ peekcd()
 getach()
 {
        register int c;
 getach()
 {
        register int c;
-       static char inline[BUFSIZ];
-       struct stat statb;
+       static char inputline[BUFSIZ];
 
        c = peekc;
        if (c != 0) {
 
        c = peekc;
        if (c != 0) {
@@ -88,25 +95,25 @@ top:
        }
        flush();
        if (intty) {
        }
        flush();
        if (intty) {
-               c = read(0, inline, sizeof inline - 4);
+               c = read(0, inputline, sizeof inputline - 4);
                if (c < 0)
                        return (lastc = EOF);
                if (c < 0)
                        return (lastc = EOF);
-               if (c == 0 || inline[c-1] != '\n')
-                       inline[c++] = CTRL(d);
-               if (inline[c-1] == '\n')
+               if (c == 0 || inputline[c-1] != '\n')
+                       inputline[c++] = CTRL('d');
+               if (inputline[c-1] == '\n')
                        noteinp();
                        noteinp();
-               inline[c] = 0;
+               inputline[c] = 0;
                for (c--; c >= 0; c--)
                for (c--; c >= 0; c--)
-                       if (inline[c] == 0)
-                               inline[c] = QUOTE;
-               input = inline;
+                       if (inputline[c] == 0)
+                               inputline[c] = QUOTE;
+               input = inputline;
                goto top;
        }
                goto top;
        }
-       c = read(0, inline, sizeof inline - 1);
+       c = read(0, inputline, sizeof inputline - 1);
        if(c <= 0)
                return(lastc = EOF);
        if(c <= 0)
                return(lastc = EOF);
-       inline[c] = '\0';
-       input = inline;
+       inputline[c] = '\0';
+       input = inputline;
        goto top;
 }
 
        goto top;
 }
 
@@ -129,7 +136,7 @@ gettty()
        if (intty && !inglobal) {
                if (offset) {
                        holdcm = 1;
        if (intty && !inglobal) {
                if (offset) {
                        holdcm = 1;
-                       printf("  %4d  ", lineDOT() + 1);
+                       ex_printf("  %4d  ", lineDOT() + 1);
                        flush();
                        holdcm = 0;
                }
                        flush();
                        holdcm = 0;
                }
@@ -140,7 +147,7 @@ gettty()
                                lastin = lindent(dot + 1);
 #endif
                        tab(lastin + offset);
                                lastin = lindent(dot + 1);
 #endif
                        tab(lastin + offset);
-                       while ((c = getcd()) == CTRL(d)) {
+                       while ((c = getcd()) == CTRL('d')) {
                                if (lastin == 0 && isatty(0) == -1) {
                                        holdcm = 0;
                                        return (EOF);
                                if (lastin == 0 && isatty(0) == -1) {
                                        holdcm = 0;
                                        return (EOF);
@@ -153,17 +160,17 @@ gettty()
                        case '^':
                        case '0':
                                ch = getcd();
                        case '^':
                        case '0':
                                ch = getcd();
-                               if (ch == CTRL(d)) {
+                               if (ch == CTRL('d')) {
                                        if (c == '0')
                                                lastin = 0;
                                        if (!OS) {
                                        if (c == '0')
                                                lastin = 0;
                                        if (!OS) {
-                                               putchar('\b' | QUOTE);
-                                               putchar(' ' | QUOTE);
-                                               putchar('\b' | QUOTE);
+                                               ex_putchar('\b' | QUOTE);
+                                               ex_putchar(' ' | QUOTE);
+                                               ex_putchar('\b' | QUOTE);
                                        }
                                        tab(offset);
                                        hadup = 1;
                                        }
                                        tab(offset);
                                        hadup = 1;
-                                       c = getchar();
+                                       c = ex_getchar();
                                } else
                                        ungetchar(ch);
                                break;
                                } else
                                        ungetchar(ch);
                                break;
@@ -186,12 +193,12 @@ gettty()
                holdcm = 0;
        }
        if (c == 0)
                holdcm = 0;
        }
        if (c == 0)
-               c = getchar();
+               c = ex_getchar();
        while (c != EOF && c != '\n') {
                if (cp > &genbuf[LBSIZE - 2])
                        error("Input line too long");
                *cp++ = c;
        while (c != EOF && c != '\n') {
                if (cp > &genbuf[LBSIZE - 2])
                        error("Input line too long");
                *cp++ = c;
-               c = getchar();
+               c = ex_getchar();
        }
        if (c == EOF) {
                if (inglobal)
        }
        if (c == EOF) {
                if (inglobal)