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#include <ctype.h>
2N/A
2N/A/* Insert a character at (curx, cury). */
2N/A
2N/Aint
2N/Awinsch(WINDOW *win, chtype c)
2N/A{
2N/A short curx = win->_curx;
2N/A int n, cury = win->_cury;
2N/A chtype *wcp, a;
2N/A int rv;
2N/A
2N/A a = _ATTR(c);
2N/A c &= A_CHARTEXT;
2N/A
2N/A rv = OK;
2N/A win->_insmode = TRUE;
2N/A if (_scrmax > 1 && (rv = _mbvalid(win)) == ERR)
2N/A goto done;
2N/A /* take care of multi-byte characters */
2N/A if (_mbtrue && ISMBIT(c)) {
2N/A rv = _mbaddch(win, A_NORMAL, RBYTE(c));
2N/A goto done;
2N/A }
2N/A win->_nbyte = -1;
2N/A curx = win->_curx;
2N/A
2N/A /* let waddch() worry about these */
2N/A if (c == '\r' || c == '\b')
2N/A return (waddch(win, c));
2N/A
2N/A /* with \n, in contrast to waddch, we don't clear-to-eol */
2N/A if (c == '\n') {
2N/A if (cury >= (win->_maxy-1) || cury == win->_bmarg)
2N/A return (wscrl(win, 1));
2N/A else {
2N/A win->_cury++;
2N/A win->_curx = 0;
2N/A return (OK);
2N/A }
2N/A }
2N/A
2N/A /* with tabs or control characters, we have to do more */
2N/A if (c == '\t') {
2N/A n = (TABSIZE - (curx % TABSIZE));
2N/A if ((curx + n) >= win->_maxx)
2N/A n = win->_maxx - curx;
2N/A c = ' ';
2N/A } else {
2N/A if (iscntrl((int) c) != 0) {
2N/A if (curx >= win->_maxx-1)
2N/A return (ERR);
2N/A n = 2;
2N/A } else
2N/A n = 1;
2N/A }
2N/A
2N/A /* shift right */
2N/A wcp = win->_y[cury] + curx;
2N/A if ((rv = _mbinsshift(win, n)) == ERR)
2N/A goto done;
2N/A
2N/A /* insert new control character */
2N/A if (c < ' ' || c == _CTRL('?')) {
2N/A *wcp++ = '^' | win->_attrs | a;
2N/A *wcp = _UNCTRL(c) | win->_attrs | a;
2N/A } else {
2N/A /* normal characters */
2N/A c = _WCHAR(win, c) | a;
2N/A for (; n > 0; --n)
2N/A *wcp++ = c;
2N/A }
2N/A
2N/Adone:
2N/A if (curx < win->_firstch[cury])
2N/A win->_firstch[cury] = curx;
2N/A win->_lastch[cury] = win->_maxx-1;
2N/A
2N/A win->_flags |= _WINCHANGED;
2N/A
2N/A if (win->_sync)
2N/A wsyncup(win);
2N/A
2N/A return ((rv == OK && win->_immed) ? wrefresh(win) : rv);
2N/A}