2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * University Copyright- Copyright (c) 1982, 1986, 1988
2N/A * The Regents of the University of California
2N/A * All Rights Reserved
2N/A *
2N/A * University Acknowledgment- Portions of this document are derived from
2N/A * software developed by the University of California, Berkeley, and its
2N/A * contributors.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <sys/types.h>
2N/A#include "curses_inc.h"
2N/A#ifdef DEBUG
2N/A#include <ctype.h>
2N/A#endif /* DEBUG */
2N/A
2N/A/*
2N/A * This routine reads in a character from the window.
2N/A *
2N/A * wgetch MUST return an int, not a char, because it can return
2N/A * things like ERR, meta characters, and function keys > 256.
2N/A */
2N/A
2N/Aint
2N/Awgetch(WINDOW *win)
2N/A{
2N/A int inp;
2N/A bool weset = FALSE;
2N/A
2N/A#ifdef DEBUG
2N/A if (outf) {
2N/A fprintf(outf, "WGETCH: SP->fl_echoit = %c\n",
2N/A SP->fl_echoit ? 'T' : 'F');
2N/A fprintf(outf, "_use_keypad %d, kp_state %d\n",
2N/A win->_use_keypad, SP->kp_state);
2N/A fprintf(outf, "file %x fd %d\n", SP->input_file,
2N/A fileno(SP->input_file));
2N/A }
2N/A#endif /* DEBUG */
2N/A
2N/A if (SP->fl_echoit && cur_term->_fl_rawmode == 0) {
2N/A (void) cbreak();
2N/A weset++;
2N/A }
2N/A
2N/A /* Make sure we are in proper nodelay state and not */
2N/A /* in halfdelay state */
2N/A if (cur_term->_delay <= 0 && cur_term->_delay != win->_delay)
2N/A (void) ttimeout(win->_delay);
2N/A
2N/A if ((win->_flags & (_WINCHANGED | _WINMOVED)) && !(win->_flags &
2N/A _ISPAD))
2N/A (void) wrefresh(win);
2N/A
2N/A if ((cur_term->_ungotten == 0) && (req_for_input)) {
2N/A (void) tputs(req_for_input, 1, _outch);
2N/A (void) fflush(SP->term_file);
2N/A }
2N/A inp = (int)tgetch((int)(win->_use_keypad ? 1 + win->_notimeout : 0));
2N/A
2N/A /* echo the key out to the screen */
2N/A if (SP->fl_echoit && (inp < 0200) && (inp >= 0) && !(win->_flags &
2N/A _ISPAD))
2N/A (void) wechochar(win, (chtype) inp);
2N/A
2N/A /*
2N/A * Do nl() mapping. nl() affects both input and output. Since
2N/A * we turn off input mapping of CR->NL to not affect input
2N/A * virtualization, we do the mapping here in software.
2N/A */
2N/A if (inp == '\r' && !SP->fl_nonl)
2N/A inp = '\n';
2N/A
2N/A if (weset)
2N/A (void) nocbreak();
2N/A
2N/A return (inp);
2N/A}