1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
40 #include <curses.priv.h>
41 #include <term.h> /* cur_term, pad_char */
42 #include <termcap.h> /* ospeed */
44 MODULE_ID("$Id: lib_baudrate.c,v 1.15 1999/01/31 03:05:25 tom Exp $")
50 * Returns the current terminal's baud rate.
59 static struct speed const speeds[] = {
102 int _nc_baudrate(int OSpeed)
104 static int last_OSpeed;
105 static int last_baudrate;
110 if (OSpeed == last_OSpeed) {
111 result = last_baudrate;
115 for (i = 0; i < SIZEOF(speeds); i++) {
116 if (speeds[i].s == (speed_t)OSpeed) {
117 result = speeds[i].sp;
122 last_baudrate = result;
128 int _nc_ospeed(int BaudRate)
134 for (i = 0; i < SIZEOF(speeds); i++) {
135 if (speeds[i].sp == BaudRate) {
136 result = speeds[i].s;
149 T((T_CALLED("baudrate()")));
152 * In debugging, allow the environment symbol to override when we're
153 * redirecting to a file, so we can construct repeatable test-cases
154 * that take into account costs that depend on baudrate.
157 if (SP && !isatty(fileno(SP->_ofp))
158 && getenv("BAUDRATE") != 0) {
160 if ((ret = _nc_getenv_num("BAUDRATE")) <= 0)
162 ospeed = _nc_ospeed(ret);
169 ospeed = cfgetospeed(&cur_term->Nttyb);
171 ospeed = cur_term->Nttyb.sg_ospeed;
173 result = _nc_baudrate(ospeed);
175 cur_term->_baudrate = result;