|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * This code is derived from software contributed to Berkeley by ! 6: * Edward Wang at The University of California, Berkeley. ! 7: * ! 8: * Redistribution and use in source and binary forms are permitted provided ! 9: * that: (1) source distributions retain this entire copyright notice and ! 10: * comment, and (2) distributions including binaries display the following ! 11: * acknowledgement: ``This product includes software developed by the ! 12: * University of California, Berkeley and its contributors'' in the ! 13: * documentation or other materials provided with the distribution and in ! 14: * all advertising materials mentioning features or use of this software. ! 15: * Neither the name of the University nor the names of its contributors may ! 16: * be used to endorse or promote products derived from this software without ! 17: * specific prior written permission. ! 18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 19: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 20: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 21: */ ! 22: ! 23: #ifndef lint ! 24: static char sccsid[] = "@(#)ttoutput.c 3.9 (Berkeley) 6/6/90"; ! 25: #endif /* not lint */ ! 26: ! 27: #include "ww.h" ! 28: #include "tt.h" ! 29: #include <sys/errno.h> ! 30: ! 31: /* ! 32: * Buffered output package. ! 33: * We need this because stdio fails on non-blocking writes. ! 34: */ ! 35: ! 36: ttflush() ! 37: { ! 38: register char *p; ! 39: register n; ! 40: extern errno; ! 41: ! 42: wwnflush++; ! 43: for (p = tt_ob; p < tt_obp;) { ! 44: wwnwr++; ! 45: n = write(1, p, tt_obp - p); ! 46: if (n < 0) { ! 47: wwnwre++; ! 48: if (errno != EWOULDBLOCK) { ! 49: /* can't deal with this */ ! 50: p = tt_obp; ! 51: } ! 52: } else if (n == 0) { ! 53: /* what to do? */ ! 54: wwnwrz++; ! 55: } else { ! 56: wwnwrc += n; ! 57: p += n; ! 58: } ! 59: } ! 60: tt_obp = tt_ob; ! 61: } ! 62: ! 63: ttputs(s) ! 64: register char *s; ! 65: { ! 66: while (*s) ! 67: ttputc(*s++); ! 68: } ! 69: ! 70: ttwrite(s, n) ! 71: register char *s; ! 72: register n; ! 73: { ! 74: switch (n) { ! 75: case 0: ! 76: break; ! 77: case 1: ! 78: ttputc(*s); ! 79: break; ! 80: case 2: ! 81: if (tt_obe - tt_obp < 2) ! 82: (*tt.tt_flush)(); ! 83: *tt_obp++ = *s++; ! 84: *tt_obp++ = *s; ! 85: break; ! 86: case 3: ! 87: if (tt_obe - tt_obp < 3) ! 88: (*tt.tt_flush)(); ! 89: *tt_obp++ = *s++; ! 90: *tt_obp++ = *s++; ! 91: *tt_obp++ = *s; ! 92: break; ! 93: case 4: ! 94: if (tt_obe - tt_obp < 4) ! 95: (*tt.tt_flush)(); ! 96: *tt_obp++ = *s++; ! 97: *tt_obp++ = *s++; ! 98: *tt_obp++ = *s++; ! 99: *tt_obp++ = *s; ! 100: break; ! 101: case 5: ! 102: if (tt_obe - tt_obp < 5) ! 103: (*tt.tt_flush)(); ! 104: *tt_obp++ = *s++; ! 105: *tt_obp++ = *s++; ! 106: *tt_obp++ = *s++; ! 107: *tt_obp++ = *s++; ! 108: *tt_obp++ = *s; ! 109: break; ! 110: default: ! 111: while (n > 0) { ! 112: register m; ! 113: ! 114: while ((m = tt_obe - tt_obp) == 0) ! 115: (*tt.tt_flush)(); ! 116: if ((m = tt_obe - tt_obp) > n) ! 117: m = n; ! 118: bcopy(s, tt_obp, m); ! 119: tt_obp += m; ! 120: s += m; ! 121: n -= m; ! 122: } ! 123: } ! 124: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.