xref: /titanic_41/usr/src/lib/libcurses/screen/delay.c (revision 726fad2a65f16c200a03969c29cb5c86c2d427db)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 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 /*LINTLIBRARY*/
41 
42 #include	<sys/types.h>
43 #include	"curses_inc.h"
44 
45 /*
46  * The following array gives the number of tens of milliseconds per
47  * character for each speed as returned by gtty.  Thus since 300
48  * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
49  */
50 static	short	tmspc10[] =
51 		{
52 		    /* 0   50    75   110 134.5 150  200  300   baud */
53 			0, 2000, 1333, 909, 743, 666, 500, 333,
54 		    /* 600 1200 1800 2400 4800 9600 19200 38400 baud */
55 			166, 83,  55,  41,  20,  10,   5,    2,
56 		    /* 57600, 76800, 115200, 153600, 230400, 307200 baud */
57 			2,	1,	1,	1,	1,	1,
58 		    /* 460800, 921600 baud */
59 			1,	1
60 		};
61 
62 /*
63  * Insert a delay into the output stream for "delay/10" milliseconds.
64  * Round up by a half a character frame, and then do the delay.
65  * Too bad there are no user program accessible programmed delays.
66  * Transmitting pad characters slows many terminals down and also
67  * loads the system.
68  */
69 
70 int
71 _delay(int delay, int (*outc)(char))
72 {
73 	int	mspc10;
74 	char	pc;
75 	int	outspeed;
76 
77 	/* if there is no pad character, then just return */
78 	if (no_pad_char)
79 		goto good;
80 
81 #ifdef SYSV
82 	outspeed = _BRS(PROGTTYS);
83 #else	/* SYSV */
84 	outspeed = _BR(PROGTTY);
85 #endif	/* SYSV */
86 	if (outspeed <= 0 || outspeed >=
87 	    (sizeof (tmspc10) / sizeof (tmspc10[0])))
88 		return (ERR);
89 
90 	mspc10 = tmspc10[outspeed];
91 	delay += mspc10 / 2;
92 	if (pad_char)
93 		pc = *pad_char;
94 	else
95 		pc = 0;
96 	for (delay /= mspc10; delay-- > 0; )
97 		(*outc)(pc);
98 good:
99 	return (OK);
100 }
101