calls to nonexistant fonts (from gbergman@cartan)
[unix-history] / usr / src / usr.bin / mail / tty.c
index a5e9a51..be56f74 100644 (file)
@@ -1,4 +1,12 @@
-#
+/*
+ * 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 = "@(#)tty.c       5.2 (Berkeley) %G%";
+#endif not lint
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
  */
 
 #include "rcv.h"
  */
 
 #include "rcv.h"
-#include <sgtty.h>
-
-static char *SccsId = "@(#)tty.c       1.1 %G%";
 
 static int     c_erase;                /* Current erase char */
 static int     c_kill;                 /* Current kill char */
 
 static int     c_erase;                /* Current erase char */
 static int     c_kill;                 /* Current kill char */
+static int     hadcont;                /* Saw continue signal */
+static jmp_buf rewrite;                /* Place to go when continued */
 #ifndef TIOCSTI
 static int     ttyset;                 /* We must now do erase/kill */
 #endif
 #ifndef TIOCSTI
 static int     ttyset;                 /* We must now do erase/kill */
 #endif
@@ -25,12 +32,17 @@ grabh(hp, gflags)
        struct header *hp;
 {
        struct sgttyb ttybuf;
        struct header *hp;
 {
        struct sgttyb ttybuf;
+       int ttycont(), signull();
 #ifndef TIOCSTI
        int (*savesigs[2])();
 #endif
 #ifndef TIOCSTI
        int (*savesigs[2])();
 #endif
+       int (*savecont)();
        register int s;
        int errs;
 
        register int s;
        int errs;
 
+# ifdef VMUNIX
+       savecont = sigset(SIGCONT, signull);
+# endif VMUNIX
        errs = 0;
 #ifndef TIOCSTI
        ttyset = 0;
        errs = 0;
 #ifndef TIOCSTI
        ttyset = 0;
@@ -45,8 +57,8 @@ grabh(hp, gflags)
        ttybuf.sg_erase = 0;
        ttybuf.sg_kill = 0;
        for (s = SIGINT; s <= SIGQUIT; s++)
        ttybuf.sg_erase = 0;
        ttybuf.sg_kill = 0;
        for (s = SIGINT; s <= SIGQUIT; s++)
-               if ((savesigs[s-SIGINT] = signal(s, SIG_IGN)) == SIG_DFL)
-                       signal(s, SIG_DFL);
+               if ((savesigs[s-SIGINT] = sigset(s, SIG_IGN)) == SIG_DFL)
+                       sigset(s, SIG_DFL);
 #endif
        if (gflags & GTO) {
 #ifndef TIOCSTI
 #endif
        if (gflags & GTO) {
 #ifndef TIOCSTI
@@ -84,13 +96,16 @@ grabh(hp, gflags)
                if (hp->h_bcc != NOSTR)
                        hp->h_seq++;
        }
                if (hp->h_bcc != NOSTR)
                        hp->h_seq++;
        }
+# ifdef VMUNIX
+       sigset(SIGCONT, savecont);
+# endif VMUNIX
 #ifndef TIOCSTI
        ttybuf.sg_erase = c_erase;
        ttybuf.sg_kill = c_kill;
        if (ttyset)
                stty(fileno(stdin), &ttybuf);
        for (s = SIGINT; s <= SIGQUIT; s++)
 #ifndef TIOCSTI
        ttybuf.sg_erase = c_erase;
        ttybuf.sg_kill = c_kill;
        if (ttyset)
                stty(fileno(stdin), &ttybuf);
        for (s = SIGINT; s <= SIGQUIT; s++)
-               signal(s, savesigs[s-SIGINT]);
+               sigset(s, savesigs[s-SIGINT]);
 #endif
        return(errs);
 }
 #endif
        return(errs);
 }
@@ -106,11 +121,12 @@ char *
 readtty(pr, src)
        char pr[], src[];
 {
 readtty(pr, src)
        char pr[], src[];
 {
-       char canonb[BUFSIZ];
-       int c, ch;
+       char ch, canonb[BUFSIZ];
+       int c, signull();
        register char *cp, *cp2;
 
        register char *cp, *cp2;
 
-       fputs(pr, stdout); fflush(stdout);
+       fputs(pr, stdout);
+       fflush(stdout);
        if (src != NOSTR && strlen(src) > BUFSIZ - 2) {
                printf("too long to edit\n");
                return(src);
        if (src != NOSTR && strlen(src) > BUFSIZ - 2) {
                printf("too long to edit\n");
                return(src);
@@ -123,21 +139,49 @@ readtty(pr, src)
        fputs(canonb, stdout);
        fflush(stdout);
 #else
        fputs(canonb, stdout);
        fflush(stdout);
 #else
-       for (cp = src; c = *cp; cp++) {
+       cp = src == NOSTR ? "" : src;
+       while (c = *cp++) {
                if (c == c_erase || c == c_kill) {
                        ch = '\\';
                        ioctl(0, TIOCSTI, &ch);
                }
                if (c == c_erase || c == c_kill) {
                        ch = '\\';
                        ioctl(0, TIOCSTI, &ch);
                }
-               ioctl(0, TIOCSTI, &c);
+               ch = c;
+               ioctl(0, TIOCSTI, &ch);
        }
        cp = canonb;
        }
        cp = canonb;
+       *cp = 0;
 #endif
 #endif
-       cp2 = fgets(cp, BUFSIZ - (cp - canonb), stdin);
-       canonb[strlen(canonb) - 1] = '\0';
+       cp2 = cp;
+       while (cp2 < canonb + BUFSIZ)
+               *cp2++ = 0;
+       cp2 = cp;
+       if (setjmp(rewrite))
+               goto redo;
+# ifdef VMUNIX
+       sigset(SIGCONT, ttycont);
+# endif VMUNIX
+       clearerr(stdin);
+       while (cp2 < canonb + BUFSIZ) {
+               c = getc(stdin);
+               if (c == EOF || c == '\n')
+                       break;
+               *cp2++ = c;
+       }
+       *cp2 = 0;
+# ifdef VMUNIX
+       sigset(SIGCONT, signull);
+# endif VMUNIX
+       if (c == EOF && ferror(stdin) && hadcont) {
+redo:
+               hadcont = 0;
+               cp = strlen(canonb) > 0 ? canonb : NOSTR;
+               clearerr(stdin);
+               return(readtty(pr, cp));
+       }
 #ifndef TIOCSTI
 #ifndef TIOCSTI
-       if (cp2 == NOSTR || *cp2 == '\0')
+       if (cp == NOSTR || *cp == '\0')
                return(src);
                return(src);
-       cp = cp2;
+       cp2 = cp;
        if (!ttyset)
                return(strlen(canonb) > 0 ? savestr(canonb) : NOSTR);
        while (*cp != '\0') {
        if (!ttyset)
                return(strlen(canonb) > 0 ? savestr(canonb) : NOSTR);
        while (*cp != '\0') {
@@ -170,3 +214,22 @@ readtty(pr, src)
                return(NOSTR);
        return(savestr(canonb));
 }
                return(NOSTR);
        return(savestr(canonb));
 }
+
+# ifdef VMUNIX
+/*
+ * Receipt continuation.
+ */
+ttycont(s)
+{
+
+       hadcont++;
+       longjmp(rewrite, 1);
+}
+# endif VMUNIX
+
+/*
+ * Null routine to satisfy
+ * silly system bug that denies us holding SIGCONT
+ */
+signull(s)
+{}