xref: /titanic_52/usr/src/lib/libcurses/screen/delay.c (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 /*LINTLIBRARY*/
43 
44 #include	<sys/types.h>
45 #include	"curses_inc.h"
46 
47 /*
48  * The following array gives the number of tens of milliseconds per
49  * character for each speed as returned by gtty.  Thus since 300
50  * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
51  */
52 static	short	tmspc10[] =
53 		{
54 		    /* 0   50    75   110 134.5 150  200  300   baud */
55 			0, 2000, 1333, 909, 743, 666, 500, 333,
56 		    /* 600 1200 1800 2400 4800 9600 19200 38400 baud */
57 			166, 83,  55,  41,  20,  10,   5,    2,
58 		    /* 57600, 76800, 115200, 153600, 230400 307200 baud */
59 			2,	1,	1,	1,	1,	1,
60 		    /* 460800 baud */
61 			1
62 		};
63 
64 /*
65  * Insert a delay into the output stream for "delay/10" milliseconds.
66  * Round up by a half a character frame, and then do the delay.
67  * Too bad there are no user program accessible programmed delays.
68  * Transmitting pad characters slows many terminals down and also
69  * loads the system.
70  */
71 
72 int
73 _delay(int delay, int (*outc)(char))
74 {
75 	int	mspc10;
76 	char	pc;
77 	int	outspeed;
78 
79 	/* if there is no pad character, then just return */
80 	if (no_pad_char)
81 		goto good;
82 
83 #ifdef SYSV
84 	outspeed = _BRS(PROGTTYS);
85 #else	/* SYSV */
86 	outspeed = _BR(PROGTTY);
87 #endif	/* SYSV */
88 	if (outspeed <= 0 || outspeed >=
89 	    (sizeof (tmspc10) / sizeof (tmspc10[0])))
90 		return (ERR);
91 
92 	mspc10 = tmspc10[outspeed];
93 	delay += mspc10 / 2;
94 	if (pad_char)
95 		pc = *pad_char;
96 	else
97 		pc = 0;
98 	for (delay /= mspc10; delay-- > 0; )
99 		(*outc)(pc);
100 good:
101 	return (OK);
102 }
103