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 0, /* 0 baud */
52 2000, /* 50 baud */
53 1333, /* 75 baud */
54 909, /* 110 baud */
55 743, /* 134 baud */
56 666, /* 150 baud */
57 500, /* 200 baud */
58 333, /* 300 baud */
59 166, /* 600 baud */
60 83, /* 1200 baud */
61 55, /* 1800 baud */
62 41, /* 2400 baud */
63 20, /* 4800 baud */
64 10, /* 9600 baud */
65 5, /* 19200 baud */
66 2, /* 38400 baud */
67 2, /* 57600 baud */
68 1, /* 76800 baud */
69 1, /* 115200 baud */
70 1, /* 153600 baud */
71 1, /* 230400 baud */
72 1, /* 307200 baud */
73 1, /* 460800 baud */
74 1, /* 921600 baud */
75 1, /* 1000000 baud */
76 1, /* 1152000 baud */
77 1, /* 1500000 baud */
78 1, /* 2000000 baud */
79 1, /* 2500000 baud */
80 1, /* 3000000 baud */
81 1, /* 3500000 baud */
82 1, /* 4000000 baud */
83 };
84
85 /*
86 * Insert a delay into the output stream for "delay/10" milliseconds.
87 * Round up by a half a character frame, and then do the delay.
88 * Too bad there are no user program accessible programmed delays.
89 * Transmitting pad characters slows many terminals down and also
90 * loads the system.
91 */
92
93 int
_delay(int delay,int (* outc)(char))94 _delay(int delay, int (*outc)(char))
95 {
96 int mspc10;
97 char pc;
98 int outspeed;
99
100 /* if there is no pad character, then just return */
101 if (no_pad_char)
102 goto good;
103
104 #ifdef SYSV
105 outspeed = _BRS(PROGTTYS);
106 #else /* SYSV */
107 outspeed = _BR(PROGTTY);
108 #endif /* SYSV */
109 if (outspeed <= 0 || outspeed >=
110 (sizeof (tmspc10) / sizeof (tmspc10[0])))
111 return (ERR);
112
113 mspc10 = tmspc10[outspeed];
114 delay += mspc10 / 2;
115 if (pad_char)
116 pc = *pad_char;
117 else
118 pc = 0;
119 for (delay /= mspc10; delay-- > 0; )
120 (*outc)(pc);
121 good:
122 return (OK);
123 }
124