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
2N/A/*
2N/A * This routine prints the character in the current position.
2N/A * Think of it as putc.
2N/A */
2N/A
2N/Aint
2N/Awaddch(WINDOW *win, chtype c)
2N/A{
2N/A short x = win->_curx;
2N/A short y = win->_cury;
2N/A chtype rawc = _CHAR(c);
2N/A chtype rawattrs = _ATTR(c);
2N/A int rv = OK;
2N/A bool savimmed = win->_immed;
2N/A bool savsync = win->_sync;
2N/A
2N/A win->_immed = win->_sync = FALSE;
2N/A
2N/A#ifdef DEBUG
2N/A if (outf)
2N/A if (c == rawc)
2N/A fprintf(outf, "'%c'", rawc);
2N/A else
2N/A fprintf(outf, "'%c' %o, raw %o", c, c, rawc);
2N/A#endif /* DEBUG */
2N/A
2N/A win->_insmode = FALSE;
2N/A if (_scrmax > 1 && _mbvalid(win) == ERR)
2N/A goto next;
2N/A if (_mbtrue && ISMBIT(rawc)) {
2N/A rv = _mbaddch(win, rawattrs, RBYTE(rawc));
2N/A win->_immed = savimmed;
2N/A win->_sync = savsync;
2N/A goto nextw;
2N/A }
2N/A
2N/A switch (rawc) {
2N/A case '\n':
2N/A (void) wclrtoeol(win);
2N/A goto new_line;
2N/A case '\r':
2N/A goto move_to_begin_line;
2N/A case '\b':
2N/A if (--x < 0)
2N/Amove_to_begin_line:
2N/A x = 0;
2N/A win->_curx = x;
2N/A win->_flags |= _WINMOVED;
2N/A goto out_move_only;
2N/A default:
2N/A if (rawc < ' ' || rawc == _CTRL('?')) {
2N/A if (rawc == '\t') {
2N/A int newx;
2N/A chtype space = ' ' | rawattrs;
2N/A
2N/A if ((newx = x + (TABSIZE -
2N/A (x % TABSIZE))) > win->_maxx)
2N/A newx = win->_maxx;
2N/A for (; x < newx; x++)
2N/A if (waddch(win,
2N/A space) == ERR)
2N/A goto next;
2N/A } else {
2N/A if ((waddch(win, (chtype)
2N/A '^'|rawattrs) == ERR) ||
2N/A (waddch(win, (chtype)
2N/A _UNCTRL(rawc)|rawattrs) == ERR)) {
2N/Anext :
2N/A rv = ERR;
2N/A }
2N/A }
2N/A x = win->_curx;
2N/A y = win->_cury;
2N/A win->_immed = savimmed;
2N/A win->_sync = savsync;
2N/A break;
2N/A }
2N/A#ifdef DEBUG
2N/A if ((win->_attrs) && outf)
2N/A fprintf(outf, "(attrs %o, %o=>%o)", win->_attrs,
2N/A c, c | win->_attrs);
2N/A#endif /* DEBUG */
2N/A
2N/A /* clear any partial multi-column character */
2N/A if (_scrmax > 1 && ISMBIT(win->_y[y][x]) &&
2N/A (rv = _mbclrch(win, y, x)) == ERR) {
2N/A x = win->_curx;
2N/A y = win->_cury;
2N/A win->_immed = savimmed;
2N/A win->_sync = savsync;
2N/A break;
2N/A }
2N/A
2N/A if ((c = _WCHAR(win, c)|rawattrs) != win->_y[y][x]) {
2N/A if (x < win->_firstch[y])
2N/A win->_firstch[y] = x;
2N/A if (x > win->_lastch[y])
2N/A win->_lastch[y] = x;
2N/A win->_y[y][x] = c;
2N/A#ifdef _VR3_COMPAT_CODE
2N/A if (_y16update)
2N/A /* LINTED */
2N/A win->_y16[y][x] = _TO_OCHTYPE(c);
2N/A#endif /* _VR3_COMPAT_CODE */
2N/A }
2N/A if (++x == win->_maxx) {
2N/Anew_line:
2N/A if (y == win->_bmarg) {
2N/A if (wscrl(win, 1) == ERR) {
2N/A rv = ERR;
2N/A if (x == win->_maxx)
2N/A --x;
2N/A#ifdef DEBUG
2N/A if (outf) {
2N/A int i;
2N/A
2N/A fprintf(outf, "ERR because "
2N/A "(%d, %d) > (%d, %d)\n",
2N/A x, y, win->_maxx,
2N/A win->_maxy);
2N/A fprintf(outf, "line: '");
2N/A for (i = 0; i < win->_maxy;
2N/A i++)
2N/A fprintf(outf, "%c",
2N/A win->_y[y-1][i]);
2N/A fprintf(outf, "'\n");
2N/A }
2N/A#endif /* DEBUG */
2N/A break;
2N/A } else
2N/A savimmed = 1;
2N/A } else
2N/A y++;
2N/A x = 0;
2N/A } else
2N/A savimmed += 2;
2N/A#ifdef FULLDEBUG
2N/A if (outf)
2N/A fprintf(outf, "ADDCH: 2: y = %d, x = %d, "
2N/A "firstch = %d, lastch = %d\n", y, x,
2N/A win->_firstch[y], win->_lastch[y]);
2N/A#endif /* FULLDEBUG */
2N/A break;
2N/A }
2N/A win->_cury = y;
2N/A win->_curx = x;
2N/A
2N/Anextw:
2N/A /* sync with ancestor structures */
2N/A if (win->_sync)
2N/A wsyncup(win);
2N/A
2N/A if (savimmed == 3)
2N/A return ((*_quick_ptr)(win, c));
2N/A
2N/A win->_flags |= _WINCHANGED;
2N/A
2N/Aout_move_only:
2N/A
2N/A return ((savimmed == 1) ? wrefresh(win) : rv);
2N/A}