|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)tputs.c 5.1 (Berkeley) 6/5/85"; ! 9: #endif not lint ! 10: ! 11: #ifndef vms ! 12: #include <sgtty.h> ! 13: #endif ! 14: #include <ctype.h> ! 15: ! 16: /* ! 17: * The following array gives the number of tens of milliseconds per ! 18: * character for each speed as returned by gtty. Thus since 300 ! 19: * baud returns a 7, there are 33.3 milliseconds per char at 300 baud. ! 20: */ ! 21: static ! 22: short tmspc10[] = { ! 23: 0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5 ! 24: }; ! 25: ! 26: short ospeed; ! 27: char PC; ! 28: ! 29: /* ! 30: * Put the character string cp out, with padding. ! 31: * The number of affected lines is affcnt, and the routine ! 32: * used to output one character is outc. ! 33: */ ! 34: tputs(cp, affcnt, outc) ! 35: register char *cp; ! 36: int affcnt; ! 37: int (*outc)(); ! 38: { ! 39: register int i = 0; ! 40: register int mspc10; ! 41: ! 42: if (cp == 0) ! 43: return; ! 44: ! 45: /* ! 46: * Convert the number representing the delay. ! 47: */ ! 48: if (isdigit(*cp)) { ! 49: do ! 50: i = i * 10 + *cp++ - '0'; ! 51: while (isdigit(*cp)); ! 52: } ! 53: i *= 10; ! 54: if (*cp == '.') { ! 55: cp++; ! 56: if (isdigit(*cp)) ! 57: i += *cp - '0'; ! 58: /* ! 59: * Only one digit to the right of the decimal point. ! 60: */ ! 61: while (isdigit(*cp)) ! 62: cp++; ! 63: } ! 64: ! 65: /* ! 66: * If the delay is followed by a `*', then ! 67: * multiply by the affected lines count. ! 68: */ ! 69: if (*cp == '*') ! 70: cp++, i *= affcnt; ! 71: ! 72: /* ! 73: * The guts of the string. ! 74: */ ! 75: while (*cp) ! 76: (*outc)(*cp++); ! 77: ! 78: /* ! 79: * If no delay needed, or output speed is ! 80: * not comprehensible, then don't try to delay. ! 81: */ ! 82: if (i == 0) ! 83: return; ! 84: if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0])) ! 85: return; ! 86: ! 87: /* ! 88: * Round up by a half a character frame, ! 89: * and then do the delay. ! 90: * Too bad there are no user program accessible programmed delays. ! 91: * Transmitting pad characters slows many ! 92: * terminals down and also loads the system. ! 93: */ ! 94: mspc10 = tmspc10[ospeed]; ! 95: i += mspc10 / 2; ! 96: for (i /= mspc10; i > 0; i--) ! 97: (*outc)(PC); ! 98: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.