|
|
1.1 ! root 1: /* Copyright (c) 1979 Regents of the University of California */ ! 2: static char sccsid[] = "@(#)tputs.c 1.1 (1.9 3/6/83)"; ! 3: #include <ctype.h> ! 4: #include "curses.h" ! 5: #include "term.h" ! 6: #ifdef NONSTANDARD ! 7: # include "ns_curses.h" ! 8: #endif ! 9: ! 10: /* ! 11: * Put the character string cp out, with padding. ! 12: * The number of affected lines is affcnt, and the routine ! 13: * used to output one character is outc. ! 14: */ ! 15: tputs(cp, affcnt, outc) ! 16: register char *cp; ! 17: int affcnt; ! 18: int (*outc)(); ! 19: { ! 20: /* static (11 cc gripes) */ char *_tpad(); ! 21: ! 22: if (cp == 0) ! 23: return; ! 24: ! 25: /* ! 26: * The guts of the string. ! 27: */ ! 28: while (*cp) ! 29: if (*cp == '$' && cp[1] == '<') ! 30: cp = _tpad(cp, affcnt, outc); ! 31: else ! 32: (*outc)(*cp++); ! 33: } ! 34: ! 35: static char * ! 36: _tpad(cp, affcnt, outc) ! 37: register char *cp; ! 38: int affcnt; ! 39: int (*outc)(); ! 40: { ! 41: register int delay = 0; ! 42: register int mspc10; ! 43: register char *icp = cp; ! 44: ! 45: /* Eat initial $< */ ! 46: cp += 2; ! 47: ! 48: /* ! 49: * Convert the number representing the delay. ! 50: */ ! 51: if (isdigit(*cp)) { ! 52: do ! 53: delay = delay * 10 + *cp++ - '0'; ! 54: while (isdigit(*cp)); ! 55: } ! 56: delay *= 10; ! 57: if (*cp == '.') { ! 58: cp++; ! 59: if (isdigit(*cp)) ! 60: delay += *cp - '0'; ! 61: /* ! 62: * Only one digit to the right of the decimal point. ! 63: */ ! 64: while (isdigit(*cp)) ! 65: cp++; ! 66: } ! 67: ! 68: /* ! 69: * If the delay is followed by a `*', then ! 70: * multiply by the affected lines count. ! 71: */ ! 72: if (*cp == '*') ! 73: cp++, delay *= affcnt; ! 74: if (*cp == '>') ! 75: cp++; /* Eat trailing '>' */ ! 76: else { ! 77: /* ! 78: * We got a "$<" with no ">". This is usually caused by ! 79: * a cursor addressing sequence that happened to generate ! 80: * $<. To avoid an infinite loop, we output the $ here ! 81: * and pass back the rest. ! 82: */ ! 83: (*outc)(*icp++); ! 84: return icp; ! 85: } ! 86: ! 87: /* ! 88: * If no delay needed, or output speed is ! 89: * not comprehensible, then don't try to delay. ! 90: */ ! 91: if (delay == 0) ! 92: return cp; ! 93: /* ! 94: * Let handshaking take care of it - no extra cpu load from pads. ! 95: * Also, this will be more optimal since the pad info is usually ! 96: * worst case. We only use padding info for such terminals to ! 97: * estimate the cost of a capability in choosing the cheapest one. ! 98: */ ! 99: if (xon_xoff) ! 100: return cp; ! 101: (void) _delay(delay, outc); ! 102: return cp; ! 103: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.