|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)tputs.c 5.3 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include <sgtty.h> ! 25: #include <ctype.h> ! 26: ! 27: /* ! 28: * The following array gives the number of tens of milliseconds per ! 29: * character for each speed as returned by gtty. Thus since 300 ! 30: * baud returns a 7, there are 33.3 milliseconds per char at 300 baud. ! 31: */ ! 32: static ! 33: short tmspc10[] = { ! 34: 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5 ! 35: }; ! 36: ! 37: short ospeed; ! 38: char PC; ! 39: ! 40: /* ! 41: * Put the character string cp out, with padding. ! 42: * The number of affected lines is affcnt, and the routine ! 43: * used to output one character is outc. ! 44: */ ! 45: tputs(cp, affcnt, outc) ! 46: register char *cp; ! 47: int affcnt; ! 48: int (*outc)(); ! 49: { ! 50: register int i = 0; ! 51: register int mspc10; ! 52: ! 53: if (cp == 0) ! 54: return; ! 55: ! 56: /* ! 57: * Convert the number representing the delay. ! 58: */ ! 59: if (isdigit(*cp)) { ! 60: do ! 61: i = i * 10 + *cp++ - '0'; ! 62: while (isdigit(*cp)); ! 63: } ! 64: i *= 10; ! 65: if (*cp == '.') { ! 66: cp++; ! 67: if (isdigit(*cp)) ! 68: i += *cp - '0'; ! 69: /* ! 70: * Only one digit to the right of the decimal point. ! 71: */ ! 72: while (isdigit(*cp)) ! 73: cp++; ! 74: } ! 75: ! 76: /* ! 77: * If the delay is followed by a `*', then ! 78: * multiply by the affected lines count. ! 79: */ ! 80: if (*cp == '*') ! 81: cp++, i *= affcnt; ! 82: ! 83: /* ! 84: * The guts of the string. ! 85: */ ! 86: while (*cp) ! 87: (*outc)(*cp++); ! 88: ! 89: /* ! 90: * If no delay needed, or output speed is ! 91: * not comprehensible, then don't try to delay. ! 92: */ ! 93: if (i == 0) ! 94: return; ! 95: if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0])) ! 96: return; ! 97: ! 98: /* ! 99: * Round up by a half a character frame, ! 100: * and then do the delay. ! 101: * Too bad there are no user program accessible programmed delays. ! 102: * Transmitting pad characters slows many ! 103: * terminals down and also loads the system. ! 104: */ ! 105: mspc10 = tmspc10[ospeed]; ! 106: i += mspc10 / 2; ! 107: for (i /= mspc10; i > 0; i--) ! 108: (*outc)(PC); ! 109: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.