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