|
|
1.1 ! root 1: # ! 2: ! 3: /* ! 4: * Mail -- a mail program ! 5: * ! 6: * Generally useful tty stuff. ! 7: */ ! 8: ! 9: #include "rcv.h" ! 10: #include <sgtty.h> ! 11: ! 12: static int c_erase; /* Current erase char */ ! 13: static int c_kill; /* Current kill char */ ! 14: ! 15: /* ! 16: * Read all relevant header fields. ! 17: */ ! 18: ! 19: grabh(hp, gflags) ! 20: struct header *hp; ! 21: { ! 22: struct sgttyb ttybuf; ! 23: register int s; ! 24: int (*savesigs[2])(), errs, set; ! 25: ! 26: errs = 0; ! 27: set = 0; ! 28: if (gtty(fileno(stdin), &ttybuf) < 0) { ! 29: perror("gtty"); ! 30: return(-1); ! 31: } ! 32: c_erase = ttybuf.sg_erase; ! 33: c_kill = ttybuf.sg_kill; ! 34: ttybuf.sg_erase = 0; ! 35: ttybuf.sg_kill = 0; ! 36: for (s = SIGINT; s <= SIGQUIT; s++) ! 37: if ((savesigs[s-SIGINT] = signal(s, SIG_IGN)) == SIG_DFL) ! 38: signal(s, SIG_DFL); ! 39: if (gflags & GTO) { ! 40: if (!set && hp->h_to != NOSTR) ! 41: set++, stty(fileno(stdin), &ttybuf); ! 42: hp->h_to = readtty("To: ", hp->h_to); ! 43: if (hp->h_to != NOSTR) ! 44: hp->h_seq++; ! 45: } ! 46: if (gflags & GSUBJECT) { ! 47: if (!set && hp->h_subject != NOSTR) ! 48: set++, stty(fileno(stdin), &ttybuf); ! 49: hp->h_subject = readtty("Subject: ", hp->h_subject); ! 50: if (hp->h_subject != NOSTR) ! 51: hp->h_seq++; ! 52: } ! 53: if (gflags & GCC) { ! 54: if (!set && hp->h_cc != NOSTR) ! 55: set++, stty(fileno(stdin), &ttybuf); ! 56: hp->h_cc = readtty("Cc: ", hp->h_cc); ! 57: if (hp->h_cc != NOSTR) ! 58: hp->h_seq++; ! 59: } ! 60: if (gflags & GBCC) { ! 61: if (!set && hp->h_bcc != NOSTR) ! 62: set++, stty(fileno(stdin), &ttybuf); ! 63: hp->h_bcc = readtty("Bcc: ", hp->h_bcc); ! 64: if (hp->h_bcc != NOSTR) ! 65: hp->h_seq++; ! 66: } ! 67: ttybuf.sg_erase = c_erase; ! 68: ttybuf.sg_kill = c_kill; ! 69: if (set) ! 70: stty(fileno(stdin), &ttybuf); ! 71: ! 72: out: ! 73: for (s = SIGINT; s <= SIGQUIT; s++) ! 74: signal(s, savesigs[s-SIGINT]); ! 75: return(errs); ! 76: } ! 77: ! 78: /* ! 79: * Read up a header from standard input. ! 80: * The source string has the preliminary contents to ! 81: * be read. ! 82: * ! 83: */ ! 84: ! 85: char * ! 86: readtty(pr, src) ! 87: char pr[], src[]; ! 88: { ! 89: char canonb[BUFSIZ]; ! 90: register int c; ! 91: register char *cp, *cp2; ! 92: ! 93: fputs(pr, stdout); ! 94: if (src != NOSTR && strlen(src) > BUFSIZ - 2) { ! 95: printf("too long to edit\n"); ! 96: return(src); ! 97: } ! 98: if (src != NOSTR) ! 99: cp = copy(src, canonb); ! 100: else ! 101: cp = copy("", canonb); ! 102: fputs(canonb, stdout); ! 103: fflush(stdout); ! 104: cp2 = fgets(cp, BUFSIZ - (cp - canonb), stdin); ! 105: canonb[strlen(canonb) - 1] = '\0'; ! 106: if (cp2 == NOSTR || *cp2 == '\0') ! 107: return(src); ! 108: cp = canonb; ! 109: cp2 = cp; ! 110: while (*cp != '\0') { ! 111: c = *cp++; ! 112: if (c == c_erase) { ! 113: if (cp2 == canonb) ! 114: continue; ! 115: if (cp2[-1] == '\\') { ! 116: cp2[-1] = c; ! 117: continue; ! 118: } ! 119: cp2--; ! 120: continue; ! 121: } ! 122: if (c == c_kill) { ! 123: if (cp2 == canonb) ! 124: continue; ! 125: if (cp2[-1] == '\\') { ! 126: cp2[-1] = c; ! 127: continue; ! 128: } ! 129: cp2 = canonb; ! 130: continue; ! 131: } ! 132: *cp2++ = c; ! 133: } ! 134: *cp2 = '\0'; ! 135: if (equal("", canonb)) ! 136: return(NOSTR); ! 137: return(savestr(canonb)); ! 138: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.