17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5de81e71eSTim Marsland  * Common Development and Distribution License (the "License").
6de81e71eSTim Marsland  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21de81e71eSTim Marsland 
227c478bd9Sstevel@tonic-gate /*
23de81e71eSTim Marsland  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include	<sys/types.h>
437c478bd9Sstevel@tonic-gate #include	"curses_inc.h"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * The following array gives the number of tens of milliseconds per
477c478bd9Sstevel@tonic-gate  * character for each speed as returned by gtty.  Thus since 300
487c478bd9Sstevel@tonic-gate  * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
497c478bd9Sstevel@tonic-gate  */
50*d9c3e05cSJoshua M. Clulow static short tmspc10[] = {
51*d9c3e05cSJoshua M. Clulow 	0,	/* 0 baud */
52*d9c3e05cSJoshua M. Clulow 	2000,	/* 50 baud */
53*d9c3e05cSJoshua M. Clulow 	1333,	/* 75 baud */
54*d9c3e05cSJoshua M. Clulow 	909,	/* 110 baud */
55*d9c3e05cSJoshua M. Clulow 	743,	/* 134 baud */
56*d9c3e05cSJoshua M. Clulow 	666,	/* 150 baud */
57*d9c3e05cSJoshua M. Clulow 	500,	/* 200 baud */
58*d9c3e05cSJoshua M. Clulow 	333,	/* 300 baud */
59*d9c3e05cSJoshua M. Clulow 	166,	/* 600 baud */
60*d9c3e05cSJoshua M. Clulow 	83,	/* 1200 baud */
61*d9c3e05cSJoshua M. Clulow 	55,	/* 1800 baud */
62*d9c3e05cSJoshua M. Clulow 	41,	/* 2400 baud */
63*d9c3e05cSJoshua M. Clulow 	20,	/* 4800 baud */
64*d9c3e05cSJoshua M. Clulow 	10,	/* 9600 baud */
65*d9c3e05cSJoshua M. Clulow 	5,	/* 19200 baud */
66*d9c3e05cSJoshua M. Clulow 	2,	/* 38400 baud */
67*d9c3e05cSJoshua M. Clulow 	2,	/* 57600 baud */
68*d9c3e05cSJoshua M. Clulow 	1,	/* 76800 baud */
69*d9c3e05cSJoshua M. Clulow 	1,	/* 115200 baud */
70*d9c3e05cSJoshua M. Clulow 	1,	/* 153600 baud */
71*d9c3e05cSJoshua M. Clulow 	1,	/* 230400 baud */
72*d9c3e05cSJoshua M. Clulow 	1,	/* 307200 baud */
73*d9c3e05cSJoshua M. Clulow 	1,	/* 460800 baud */
74*d9c3e05cSJoshua M. Clulow 	1,	/* 921600 baud */
75*d9c3e05cSJoshua M. Clulow 	1,	/* 1000000 baud */
76*d9c3e05cSJoshua M. Clulow 	1,	/* 1152000 baud */
77*d9c3e05cSJoshua M. Clulow 	1,	/* 1500000 baud */
78*d9c3e05cSJoshua M. Clulow 	1,	/* 2000000 baud */
79*d9c3e05cSJoshua M. Clulow 	1,	/* 2500000 baud */
80*d9c3e05cSJoshua M. Clulow 	1,	/* 3000000 baud */
81*d9c3e05cSJoshua M. Clulow 	1,	/* 3500000 baud */
82*d9c3e05cSJoshua M. Clulow 	1,	/* 4000000 baud */
83*d9c3e05cSJoshua M. Clulow };
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Insert a delay into the output stream for "delay/10" milliseconds.
877c478bd9Sstevel@tonic-gate  * Round up by a half a character frame, and then do the delay.
887c478bd9Sstevel@tonic-gate  * Too bad there are no user program accessible programmed delays.
897c478bd9Sstevel@tonic-gate  * Transmitting pad characters slows many terminals down and also
907c478bd9Sstevel@tonic-gate  * loads the system.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate int
_delay(int delay,int (* outc)(char))947c478bd9Sstevel@tonic-gate _delay(int delay, int (*outc)(char))
957c478bd9Sstevel@tonic-gate {
967c478bd9Sstevel@tonic-gate 	int	mspc10;
977c478bd9Sstevel@tonic-gate 	char	pc;
987c478bd9Sstevel@tonic-gate 	int	outspeed;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	/* if there is no pad character, then just return */
1017c478bd9Sstevel@tonic-gate 	if (no_pad_char)
1027c478bd9Sstevel@tonic-gate 		goto good;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #ifdef SYSV
1057c478bd9Sstevel@tonic-gate 	outspeed = _BRS(PROGTTYS);
1067c478bd9Sstevel@tonic-gate #else	/* SYSV */
1077c478bd9Sstevel@tonic-gate 	outspeed = _BR(PROGTTY);
1087c478bd9Sstevel@tonic-gate #endif	/* SYSV */
1097c478bd9Sstevel@tonic-gate 	if (outspeed <= 0 || outspeed >=
1107c478bd9Sstevel@tonic-gate 	    (sizeof (tmspc10) / sizeof (tmspc10[0])))
1117c478bd9Sstevel@tonic-gate 		return (ERR);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	mspc10 = tmspc10[outspeed];
1147c478bd9Sstevel@tonic-gate 	delay += mspc10 / 2;
1157c478bd9Sstevel@tonic-gate 	if (pad_char)
1167c478bd9Sstevel@tonic-gate 		pc = *pad_char;
1177c478bd9Sstevel@tonic-gate 	else
1187c478bd9Sstevel@tonic-gate 		pc = 0;
1197c478bd9Sstevel@tonic-gate 	for (delay /= mspc10; delay-- > 0; )
1207c478bd9Sstevel@tonic-gate 		(*outc)(pc);
1217c478bd9Sstevel@tonic-gate good:
1227c478bd9Sstevel@tonic-gate 	return (OK);
1237c478bd9Sstevel@tonic-gate }
124