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 (c) 1995, by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 /*
28  * baudrate.c
29  *
30  * XCurses Library
31  *
32  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
33  *
34  */
35 
36 #include <private.h>
37 
38 typedef struct {
39 	speed_t speed;
40 	int value;
41 } t_baud;
42 
43 static t_baud speeds[] = {
44 	{ B0,		0 },
45 	{ B50,		50 },
46 	{ B75,		75 },
47 	{ B110,		110 },
48 	{ B134,		134 },
49 	{ B150,		150 },
50 	{ B200,		200 },
51 	{ B300,		300 },
52 	{ B600,		600 },
53 	{ B1200,	1200 },
54 	{ B1800,	1800 },
55 	{ B2400,	2400 },
56 	{ B4800,	4800 },
57 	{ B9600,	9600 },
58 	{ B19200,	19200 },
59 	{ B38400,	38400 },
60 	{ B57600,	57600 },
61 	{ B76800,	76800 },
62 	{ B115200,	115200 },
63 	{ B153600,	153600 },
64 	{ B230400,	230400 },
65 	{ B307200,	307200 },
66 	{ B460800,	460800 },
67 	{ B921600,	921600 },
68 	{ B1000000,	1000000 },
69 	{ B1152000,	1152000 },
70 	{ B1500000,	1500000 },
71 	{ B2000000,	2000000 },
72 	{ B2500000,	2500000 },
73 	{ B3000000,	3000000 },
74 	{ B3500000,	3500000 },
75 	{ B4000000,	4000000 },
76 	{ (speed_t)-1,	-1 }
77 };
78 
79 /*
80  * Return the output speed of the terminal.  The number returned is in
81  * bits per second and is an integer.
82  */
83 int
baudrate()84 baudrate()
85 {
86 	int i;
87 	speed_t value;
88 
89 #ifdef M_CURSES_TRACE
90 	__m_trace("baudrate(void)");
91 #endif
92 
93  	value = cfgetospeed(&cur_term->_prog);
94 
95 	for (i = 0; speeds[i].speed != (speed_t) -1; ++i) {
96 		if (speeds[i].speed == value) {
97 			break;
98 		}
99 	}
100 
101 	return __m_return_int("baudrate", speeds[i].value);
102 }
103