1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
28*0Sstevel@tonic-gate /* All Rights Reserved */
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
32*0Sstevel@tonic-gate * The Regents of the University of California
33*0Sstevel@tonic-gate * All Rights Reserved
34*0Sstevel@tonic-gate *
35*0Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
36*0Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
37*0Sstevel@tonic-gate * contributors.
38*0Sstevel@tonic-gate */
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate /*LINTLIBRARY*/
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate #include <sys/types.h>
45*0Sstevel@tonic-gate #include "curses_inc.h"
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate /*
48*0Sstevel@tonic-gate * This routine prints the character in the current position.
49*0Sstevel@tonic-gate * Think of it as putc.
50*0Sstevel@tonic-gate */
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate int
waddch(WINDOW * win,chtype c)53*0Sstevel@tonic-gate waddch(WINDOW *win, chtype c)
54*0Sstevel@tonic-gate {
55*0Sstevel@tonic-gate short x = win->_curx;
56*0Sstevel@tonic-gate short y = win->_cury;
57*0Sstevel@tonic-gate chtype rawc = _CHAR(c);
58*0Sstevel@tonic-gate chtype rawattrs = _ATTR(c);
59*0Sstevel@tonic-gate int rv = OK;
60*0Sstevel@tonic-gate bool savimmed = win->_immed;
61*0Sstevel@tonic-gate bool savsync = win->_sync;
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gate win->_immed = win->_sync = FALSE;
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate #ifdef DEBUG
66*0Sstevel@tonic-gate if (outf)
67*0Sstevel@tonic-gate if (c == rawc)
68*0Sstevel@tonic-gate fprintf(outf, "'%c'", rawc);
69*0Sstevel@tonic-gate else
70*0Sstevel@tonic-gate fprintf(outf, "'%c' %o, raw %o", c, c, rawc);
71*0Sstevel@tonic-gate #endif /* DEBUG */
72*0Sstevel@tonic-gate
73*0Sstevel@tonic-gate win->_insmode = FALSE;
74*0Sstevel@tonic-gate if (_scrmax > 1 && _mbvalid(win) == ERR)
75*0Sstevel@tonic-gate goto next;
76*0Sstevel@tonic-gate if (_mbtrue && ISMBIT(rawc)) {
77*0Sstevel@tonic-gate rv = _mbaddch(win, rawattrs, RBYTE(rawc));
78*0Sstevel@tonic-gate win->_immed = savimmed;
79*0Sstevel@tonic-gate win->_sync = savsync;
80*0Sstevel@tonic-gate goto nextw;
81*0Sstevel@tonic-gate }
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate switch (rawc) {
84*0Sstevel@tonic-gate case '\n':
85*0Sstevel@tonic-gate (void) wclrtoeol(win);
86*0Sstevel@tonic-gate goto new_line;
87*0Sstevel@tonic-gate case '\r':
88*0Sstevel@tonic-gate goto move_to_begin_line;
89*0Sstevel@tonic-gate case '\b':
90*0Sstevel@tonic-gate if (--x < 0)
91*0Sstevel@tonic-gate move_to_begin_line:
92*0Sstevel@tonic-gate x = 0;
93*0Sstevel@tonic-gate win->_curx = x;
94*0Sstevel@tonic-gate win->_flags |= _WINMOVED;
95*0Sstevel@tonic-gate goto out_move_only;
96*0Sstevel@tonic-gate default:
97*0Sstevel@tonic-gate if (rawc < ' ' || rawc == _CTRL('?')) {
98*0Sstevel@tonic-gate if (rawc == '\t') {
99*0Sstevel@tonic-gate int newx;
100*0Sstevel@tonic-gate chtype space = ' ' | rawattrs;
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate if ((newx = x + (TABSIZE -
103*0Sstevel@tonic-gate (x % TABSIZE))) > win->_maxx)
104*0Sstevel@tonic-gate newx = win->_maxx;
105*0Sstevel@tonic-gate for (; x < newx; x++)
106*0Sstevel@tonic-gate if (waddch(win,
107*0Sstevel@tonic-gate space) == ERR)
108*0Sstevel@tonic-gate goto next;
109*0Sstevel@tonic-gate } else {
110*0Sstevel@tonic-gate if ((waddch(win, (chtype)
111*0Sstevel@tonic-gate '^'|rawattrs) == ERR) ||
112*0Sstevel@tonic-gate (waddch(win, (chtype)
113*0Sstevel@tonic-gate _UNCTRL(rawc)|rawattrs) == ERR)) {
114*0Sstevel@tonic-gate next :
115*0Sstevel@tonic-gate rv = ERR;
116*0Sstevel@tonic-gate }
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate x = win->_curx;
119*0Sstevel@tonic-gate y = win->_cury;
120*0Sstevel@tonic-gate win->_immed = savimmed;
121*0Sstevel@tonic-gate win->_sync = savsync;
122*0Sstevel@tonic-gate break;
123*0Sstevel@tonic-gate }
124*0Sstevel@tonic-gate #ifdef DEBUG
125*0Sstevel@tonic-gate if ((win->_attrs) && outf)
126*0Sstevel@tonic-gate fprintf(outf, "(attrs %o, %o=>%o)", win->_attrs,
127*0Sstevel@tonic-gate c, c | win->_attrs);
128*0Sstevel@tonic-gate #endif /* DEBUG */
129*0Sstevel@tonic-gate
130*0Sstevel@tonic-gate /* clear any partial multi-column character */
131*0Sstevel@tonic-gate if (_scrmax > 1 && ISMBIT(win->_y[y][x]) &&
132*0Sstevel@tonic-gate (rv = _mbclrch(win, y, x)) == ERR) {
133*0Sstevel@tonic-gate x = win->_curx;
134*0Sstevel@tonic-gate y = win->_cury;
135*0Sstevel@tonic-gate win->_immed = savimmed;
136*0Sstevel@tonic-gate win->_sync = savsync;
137*0Sstevel@tonic-gate break;
138*0Sstevel@tonic-gate }
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate if ((c = _WCHAR(win, c)|rawattrs) != win->_y[y][x]) {
141*0Sstevel@tonic-gate if (x < win->_firstch[y])
142*0Sstevel@tonic-gate win->_firstch[y] = x;
143*0Sstevel@tonic-gate if (x > win->_lastch[y])
144*0Sstevel@tonic-gate win->_lastch[y] = x;
145*0Sstevel@tonic-gate win->_y[y][x] = c;
146*0Sstevel@tonic-gate #ifdef _VR3_COMPAT_CODE
147*0Sstevel@tonic-gate if (_y16update)
148*0Sstevel@tonic-gate /* LINTED */
149*0Sstevel@tonic-gate win->_y16[y][x] = _TO_OCHTYPE(c);
150*0Sstevel@tonic-gate #endif /* _VR3_COMPAT_CODE */
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate if (++x == win->_maxx) {
153*0Sstevel@tonic-gate new_line:
154*0Sstevel@tonic-gate if (y == win->_bmarg) {
155*0Sstevel@tonic-gate if (wscrl(win, 1) == ERR) {
156*0Sstevel@tonic-gate rv = ERR;
157*0Sstevel@tonic-gate if (x == win->_maxx)
158*0Sstevel@tonic-gate --x;
159*0Sstevel@tonic-gate #ifdef DEBUG
160*0Sstevel@tonic-gate if (outf) {
161*0Sstevel@tonic-gate int i;
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate fprintf(outf, "ERR because "
164*0Sstevel@tonic-gate "(%d, %d) > (%d, %d)\n",
165*0Sstevel@tonic-gate x, y, win->_maxx,
166*0Sstevel@tonic-gate win->_maxy);
167*0Sstevel@tonic-gate fprintf(outf, "line: '");
168*0Sstevel@tonic-gate for (i = 0; i < win->_maxy;
169*0Sstevel@tonic-gate i++)
170*0Sstevel@tonic-gate fprintf(outf, "%c",
171*0Sstevel@tonic-gate win->_y[y-1][i]);
172*0Sstevel@tonic-gate fprintf(outf, "'\n");
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate #endif /* DEBUG */
175*0Sstevel@tonic-gate break;
176*0Sstevel@tonic-gate } else
177*0Sstevel@tonic-gate savimmed = 1;
178*0Sstevel@tonic-gate } else
179*0Sstevel@tonic-gate y++;
180*0Sstevel@tonic-gate x = 0;
181*0Sstevel@tonic-gate } else
182*0Sstevel@tonic-gate savimmed += 2;
183*0Sstevel@tonic-gate #ifdef FULLDEBUG
184*0Sstevel@tonic-gate if (outf)
185*0Sstevel@tonic-gate fprintf(outf, "ADDCH: 2: y = %d, x = %d, "
186*0Sstevel@tonic-gate "firstch = %d, lastch = %d\n", y, x,
187*0Sstevel@tonic-gate win->_firstch[y], win->_lastch[y]);
188*0Sstevel@tonic-gate #endif /* FULLDEBUG */
189*0Sstevel@tonic-gate break;
190*0Sstevel@tonic-gate }
191*0Sstevel@tonic-gate win->_cury = y;
192*0Sstevel@tonic-gate win->_curx = x;
193*0Sstevel@tonic-gate
194*0Sstevel@tonic-gate nextw:
195*0Sstevel@tonic-gate /* sync with ancestor structures */
196*0Sstevel@tonic-gate if (win->_sync)
197*0Sstevel@tonic-gate wsyncup(win);
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate if (savimmed == 3)
200*0Sstevel@tonic-gate return ((*_quick_ptr)(win, c));
201*0Sstevel@tonic-gate
202*0Sstevel@tonic-gate win->_flags |= _WINCHANGED;
203*0Sstevel@tonic-gate
204*0Sstevel@tonic-gate out_move_only:
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate return ((savimmed == 1) ? wrefresh(win) : rv);
207*0Sstevel@tonic-gate }
208