17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include "curses_inc.h"
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * This routine prints the character in the current position.
477c478bd9Sstevel@tonic-gate * Think of it as putc.
487c478bd9Sstevel@tonic-gate */
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate int
waddch(WINDOW * win,chtype c)517c478bd9Sstevel@tonic-gate waddch(WINDOW *win, chtype c)
527c478bd9Sstevel@tonic-gate {
537c478bd9Sstevel@tonic-gate short x = win->_curx;
547c478bd9Sstevel@tonic-gate short y = win->_cury;
557c478bd9Sstevel@tonic-gate chtype rawc = _CHAR(c);
567c478bd9Sstevel@tonic-gate chtype rawattrs = _ATTR(c);
577c478bd9Sstevel@tonic-gate int rv = OK;
587c478bd9Sstevel@tonic-gate bool savimmed = win->_immed;
597c478bd9Sstevel@tonic-gate bool savsync = win->_sync;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate win->_immed = win->_sync = FALSE;
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate #ifdef DEBUG
647c478bd9Sstevel@tonic-gate if (outf)
657c478bd9Sstevel@tonic-gate if (c == rawc)
667c478bd9Sstevel@tonic-gate fprintf(outf, "'%c'", rawc);
677c478bd9Sstevel@tonic-gate else
687c478bd9Sstevel@tonic-gate fprintf(outf, "'%c' %o, raw %o", c, c, rawc);
697c478bd9Sstevel@tonic-gate #endif /* DEBUG */
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate win->_insmode = FALSE;
727c478bd9Sstevel@tonic-gate if (_scrmax > 1 && _mbvalid(win) == ERR)
737c478bd9Sstevel@tonic-gate goto next;
747c478bd9Sstevel@tonic-gate if (_mbtrue && ISMBIT(rawc)) {
757c478bd9Sstevel@tonic-gate rv = _mbaddch(win, rawattrs, RBYTE(rawc));
767c478bd9Sstevel@tonic-gate win->_immed = savimmed;
777c478bd9Sstevel@tonic-gate win->_sync = savsync;
787c478bd9Sstevel@tonic-gate goto nextw;
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate switch (rawc) {
827c478bd9Sstevel@tonic-gate case '\n':
837c478bd9Sstevel@tonic-gate (void) wclrtoeol(win);
847c478bd9Sstevel@tonic-gate goto new_line;
857c478bd9Sstevel@tonic-gate case '\r':
867c478bd9Sstevel@tonic-gate goto move_to_begin_line;
877c478bd9Sstevel@tonic-gate case '\b':
887c478bd9Sstevel@tonic-gate if (--x < 0)
897c478bd9Sstevel@tonic-gate move_to_begin_line:
907c478bd9Sstevel@tonic-gate x = 0;
917c478bd9Sstevel@tonic-gate win->_curx = x;
927c478bd9Sstevel@tonic-gate win->_flags |= _WINMOVED;
937c478bd9Sstevel@tonic-gate goto out_move_only;
947c478bd9Sstevel@tonic-gate default:
957c478bd9Sstevel@tonic-gate if (rawc < ' ' || rawc == _CTRL('?')) {
967c478bd9Sstevel@tonic-gate if (rawc == '\t') {
977c478bd9Sstevel@tonic-gate int newx;
987c478bd9Sstevel@tonic-gate chtype space = ' ' | rawattrs;
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate if ((newx = x + (TABSIZE -
101*e07d85f8SToomas Soome (x % TABSIZE))) > win->_maxx) {
1027c478bd9Sstevel@tonic-gate newx = win->_maxx;
103*e07d85f8SToomas Soome }
104*e07d85f8SToomas Soome for (; x < newx; x++) {
105*e07d85f8SToomas Soome if (waddch(win, space) == ERR)
106*e07d85f8SToomas Soome goto next;
107*e07d85f8SToomas Soome }
1087c478bd9Sstevel@tonic-gate } else {
1097c478bd9Sstevel@tonic-gate if ((waddch(win, (chtype)
1107c478bd9Sstevel@tonic-gate '^'|rawattrs) == ERR) ||
1117c478bd9Sstevel@tonic-gate (waddch(win, (chtype)
1127c478bd9Sstevel@tonic-gate _UNCTRL(rawc)|rawattrs) == ERR)) {
1137c478bd9Sstevel@tonic-gate next :
1147c478bd9Sstevel@tonic-gate rv = ERR;
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate x = win->_curx;
1187c478bd9Sstevel@tonic-gate y = win->_cury;
1197c478bd9Sstevel@tonic-gate win->_immed = savimmed;
1207c478bd9Sstevel@tonic-gate win->_sync = savsync;
1217c478bd9Sstevel@tonic-gate break;
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate #ifdef DEBUG
1247c478bd9Sstevel@tonic-gate if ((win->_attrs) && outf)
1257c478bd9Sstevel@tonic-gate fprintf(outf, "(attrs %o, %o=>%o)", win->_attrs,
1267c478bd9Sstevel@tonic-gate c, c | win->_attrs);
1277c478bd9Sstevel@tonic-gate #endif /* DEBUG */
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate /* clear any partial multi-column character */
1307c478bd9Sstevel@tonic-gate if (_scrmax > 1 && ISMBIT(win->_y[y][x]) &&
1317c478bd9Sstevel@tonic-gate (rv = _mbclrch(win, y, x)) == ERR) {
1327c478bd9Sstevel@tonic-gate x = win->_curx;
1337c478bd9Sstevel@tonic-gate y = win->_cury;
1347c478bd9Sstevel@tonic-gate win->_immed = savimmed;
1357c478bd9Sstevel@tonic-gate win->_sync = savsync;
1367c478bd9Sstevel@tonic-gate break;
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate if ((c = _WCHAR(win, c)|rawattrs) != win->_y[y][x]) {
1407c478bd9Sstevel@tonic-gate if (x < win->_firstch[y])
1417c478bd9Sstevel@tonic-gate win->_firstch[y] = x;
1427c478bd9Sstevel@tonic-gate if (x > win->_lastch[y])
1437c478bd9Sstevel@tonic-gate win->_lastch[y] = x;
1447c478bd9Sstevel@tonic-gate win->_y[y][x] = c;
1457c478bd9Sstevel@tonic-gate #ifdef _VR3_COMPAT_CODE
1467c478bd9Sstevel@tonic-gate if (_y16update)
1477c478bd9Sstevel@tonic-gate /* LINTED */
1487c478bd9Sstevel@tonic-gate win->_y16[y][x] = _TO_OCHTYPE(c);
1497c478bd9Sstevel@tonic-gate #endif /* _VR3_COMPAT_CODE */
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate if (++x == win->_maxx) {
1527c478bd9Sstevel@tonic-gate new_line:
1537c478bd9Sstevel@tonic-gate if (y == win->_bmarg) {
1547c478bd9Sstevel@tonic-gate if (wscrl(win, 1) == ERR) {
1557c478bd9Sstevel@tonic-gate rv = ERR;
1567c478bd9Sstevel@tonic-gate if (x == win->_maxx)
1577c478bd9Sstevel@tonic-gate --x;
1587c478bd9Sstevel@tonic-gate #ifdef DEBUG
1597c478bd9Sstevel@tonic-gate if (outf) {
1607c478bd9Sstevel@tonic-gate int i;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate fprintf(outf, "ERR because "
1637c478bd9Sstevel@tonic-gate "(%d, %d) > (%d, %d)\n",
1647c478bd9Sstevel@tonic-gate x, y, win->_maxx,
1657c478bd9Sstevel@tonic-gate win->_maxy);
1667c478bd9Sstevel@tonic-gate fprintf(outf, "line: '");
1677c478bd9Sstevel@tonic-gate for (i = 0; i < win->_maxy;
1687c478bd9Sstevel@tonic-gate i++)
1697c478bd9Sstevel@tonic-gate fprintf(outf, "%c",
1707c478bd9Sstevel@tonic-gate win->_y[y-1][i]);
1717c478bd9Sstevel@tonic-gate fprintf(outf, "'\n");
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate #endif /* DEBUG */
1747c478bd9Sstevel@tonic-gate break;
175*e07d85f8SToomas Soome } else {
1767c478bd9Sstevel@tonic-gate savimmed = 1;
177*e07d85f8SToomas Soome }
178*e07d85f8SToomas Soome } else {
1797c478bd9Sstevel@tonic-gate y++;
180*e07d85f8SToomas Soome }
181*e07d85f8SToomas Soome x = 0;
182*e07d85f8SToomas Soome } else {
1837c478bd9Sstevel@tonic-gate savimmed += 2;
184*e07d85f8SToomas Soome }
1857c478bd9Sstevel@tonic-gate #ifdef FULLDEBUG
186*e07d85f8SToomas Soome if (outf) {
1877c478bd9Sstevel@tonic-gate fprintf(outf, "ADDCH: 2: y = %d, x = %d, "
1887c478bd9Sstevel@tonic-gate "firstch = %d, lastch = %d\n", y, x,
1897c478bd9Sstevel@tonic-gate win->_firstch[y], win->_lastch[y]);
190*e07d85f8SToomas Soome }
1917c478bd9Sstevel@tonic-gate #endif /* FULLDEBUG */
1927c478bd9Sstevel@tonic-gate break;
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate win->_cury = y;
1957c478bd9Sstevel@tonic-gate win->_curx = x;
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate nextw:
1987c478bd9Sstevel@tonic-gate /* sync with ancestor structures */
1997c478bd9Sstevel@tonic-gate if (win->_sync)
2007c478bd9Sstevel@tonic-gate wsyncup(win);
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate if (savimmed == 3)
2037c478bd9Sstevel@tonic-gate return ((*_quick_ptr)(win, c));
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate win->_flags |= _WINCHANGED;
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate out_move_only:
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate return ((savimmed == 1) ? wrefresh(win) : rv);
2107c478bd9Sstevel@tonic-gate }
211