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