1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* LINTLIBRARY */
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate * wins_wch.c
31*7c478bd9Sstevel@tonic-gate *
32*7c478bd9Sstevel@tonic-gate * XCurses Library
33*7c478bd9Sstevel@tonic-gate *
34*7c478bd9Sstevel@tonic-gate * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
35*7c478bd9Sstevel@tonic-gate *
36*7c478bd9Sstevel@tonic-gate */
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate #ifdef M_RCSID
39*7c478bd9Sstevel@tonic-gate #ifndef lint
40*7c478bd9Sstevel@tonic-gate static char rcsID[] =
41*7c478bd9Sstevel@tonic-gate "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
42*7c478bd9Sstevel@tonic-gate "libxcurses/src/libc/xcurses/rcs/wins_wch.c 1.3 1998/06/04 17:54:38 "
43*7c478bd9Sstevel@tonic-gate "cbates Exp $";
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate #include <private.h>
48*7c478bd9Sstevel@tonic-gate #include <string.h>
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate /*
51*7c478bd9Sstevel@tonic-gate * Insert a character into a window line, shifting the line right
52*7c478bd9Sstevel@tonic-gate * the column width of the inserted character. The right most columns
53*7c478bd9Sstevel@tonic-gate * will be truncated according to the width of the character inserted.
54*7c478bd9Sstevel@tonic-gate */
55*7c478bd9Sstevel@tonic-gate int
__m_cc_ins(WINDOW * w,int y,int x,const cchar_t * cc)56*7c478bd9Sstevel@tonic-gate __m_cc_ins(WINDOW *w, int y, int x, const cchar_t *cc)
57*7c478bd9Sstevel@tonic-gate {
58*7c478bd9Sstevel@tonic-gate int width;
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate /* Determine the character width to insert. */
61*7c478bd9Sstevel@tonic-gate if ((width = __m_cc_width(cc)) <= 0 || w->_maxx < x + width)
62*7c478bd9Sstevel@tonic-gate return (-1);
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate x = __m_cc_first(w, y, x);
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate /*
67*7c478bd9Sstevel@tonic-gate * Use erase to remove possible multi-column chars
68*7c478bd9Sstevel@tonic-gate * before memmove clobbers them
69*7c478bd9Sstevel@tonic-gate */
70*7c478bd9Sstevel@tonic-gate (void) __m_cc_erase(w, y, w->_maxx - width, y, w->_maxx - 1);
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate /* Insert a "hole" into the line. */
73*7c478bd9Sstevel@tonic-gate (void) memmove(&w->_line[y][x + width], &w->_line[y][x],
74*7c478bd9Sstevel@tonic-gate (w->_maxx - x - width) * sizeof (**w->_line));
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate /* Write the character into the hole. */
77*7c478bd9Sstevel@tonic-gate if (__m_cc_replace(w, y, x, cc, 0) != width)
78*7c478bd9Sstevel@tonic-gate return (-1);
79*7c478bd9Sstevel@tonic-gate
80*7c478bd9Sstevel@tonic-gate /* Update dirty region markers. */
81*7c478bd9Sstevel@tonic-gate if (x < w->_first[y])
82*7c478bd9Sstevel@tonic-gate w->_first[y] = (short) x;
83*7c478bd9Sstevel@tonic-gate w->_last[y] = w->_maxx;
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate /*
86*7c478bd9Sstevel@tonic-gate * If the last character on the line is incomplete,
87*7c478bd9Sstevel@tonic-gate * blank it out.
88*7c478bd9Sstevel@tonic-gate */
89*7c478bd9Sstevel@tonic-gate x = __m_cc_first(w, y, w->_maxx-1);
90*7c478bd9Sstevel@tonic-gate if (w->_maxx < x + __m_cc_width(&w->_line[y][x]))
91*7c478bd9Sstevel@tonic-gate (void) __m_cc_erase(w, y, x, y, w->_maxx-1);
92*7c478bd9Sstevel@tonic-gate
93*7c478bd9Sstevel@tonic-gate return (width);
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gate /*
97*7c478bd9Sstevel@tonic-gate * Special internal version of wins_wch() that can track the cursor
98*7c478bd9Sstevel@tonic-gate * position to facilitate inserting strings containing special characters
99*7c478bd9Sstevel@tonic-gate * like \b, \n, \r, and \t.
100*7c478bd9Sstevel@tonic-gate */
101*7c478bd9Sstevel@tonic-gate int
__m_wins_wch(WINDOW * w,int y,int x,const cchar_t * cc,int * yp,int * xp)102*7c478bd9Sstevel@tonic-gate __m_wins_wch(WINDOW *w, int y, int x, const cchar_t *cc,
103*7c478bd9Sstevel@tonic-gate int *yp, int *xp)
104*7c478bd9Sstevel@tonic-gate {
105*7c478bd9Sstevel@tonic-gate cchar_t uc;
106*7c478bd9Sstevel@tonic-gate const wchar_t *p;
107*7c478bd9Sstevel@tonic-gate int code, nx, width;
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate code = ERR;
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate switch (cc->_wc[0]) {
112*7c478bd9Sstevel@tonic-gate case L'\r':
113*7c478bd9Sstevel@tonic-gate x = 0;
114*7c478bd9Sstevel@tonic-gate break;
115*7c478bd9Sstevel@tonic-gate case L'\b':
116*7c478bd9Sstevel@tonic-gate if (0 < x)
117*7c478bd9Sstevel@tonic-gate --x;
118*7c478bd9Sstevel@tonic-gate break;
119*7c478bd9Sstevel@tonic-gate case L'\t':
120*7c478bd9Sstevel@tonic-gate for (nx = x + (8 - (x & 07)); x < nx; x += width)
121*7c478bd9Sstevel@tonic-gate if ((width = __m_cc_ins(w, y, x, &w->_bg)) <= 0)
122*7c478bd9Sstevel@tonic-gate goto error;
123*7c478bd9Sstevel@tonic-gate break;
124*7c478bd9Sstevel@tonic-gate case L'\n':
125*7c478bd9Sstevel@tonic-gate /* Truncate the tail of the current line. */
126*7c478bd9Sstevel@tonic-gate if (__m_cc_erase(w, y, x, y, w->_maxx - 1) == -1)
127*7c478bd9Sstevel@tonic-gate goto error;
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate if (__m_do_scroll(w, y, x, &y, &x) == ERR)
130*7c478bd9Sstevel@tonic-gate goto error;
131*7c478bd9Sstevel@tonic-gate break;
132*7c478bd9Sstevel@tonic-gate default:
133*7c478bd9Sstevel@tonic-gate if (iswprint(cc->_wc[0])) {
134*7c478bd9Sstevel@tonic-gate if ((width = __m_cc_ins(w, y, x, cc)) <= 0)
135*7c478bd9Sstevel@tonic-gate goto error;
136*7c478bd9Sstevel@tonic-gate x += width;
137*7c478bd9Sstevel@tonic-gate break;
138*7c478bd9Sstevel@tonic-gate }
139*7c478bd9Sstevel@tonic-gate
140*7c478bd9Sstevel@tonic-gate /* Convert non-printables into printable representation. */
141*7c478bd9Sstevel@tonic-gate uc._n = 1;
142*7c478bd9Sstevel@tonic-gate uc._at = cc->_at;
143*7c478bd9Sstevel@tonic-gate uc._co = cc->_co;
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate if ((p = wunctrl((cchar_t *)cc)) == NULL)
146*7c478bd9Sstevel@tonic-gate goto error;
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate for (; *p != '\0'; ++p, x += width) {
149*7c478bd9Sstevel@tonic-gate uc._wc[0] = *p;
150*7c478bd9Sstevel@tonic-gate if ((width = __m_cc_ins(w, y, x, &uc)) < 0)
151*7c478bd9Sstevel@tonic-gate goto error;
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate if (yp != NULL)
156*7c478bd9Sstevel@tonic-gate *yp = y;
157*7c478bd9Sstevel@tonic-gate if (xp != NULL)
158*7c478bd9Sstevel@tonic-gate *xp = x;
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate WSYNC(w);
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gate code = WFLUSH(w);
163*7c478bd9Sstevel@tonic-gate error:
164*7c478bd9Sstevel@tonic-gate return (code);
165*7c478bd9Sstevel@tonic-gate }
166*7c478bd9Sstevel@tonic-gate
167*7c478bd9Sstevel@tonic-gate /*
168*7c478bd9Sstevel@tonic-gate * Insert a character (with attributes) before the cursor. All
169*7c478bd9Sstevel@tonic-gate * characters to the right of the cursor are moved one space to
170*7c478bd9Sstevel@tonic-gate * the right, with a possibility of the rightmost character on
171*7c478bd9Sstevel@tonic-gate * the line being lost. The cursor position does not change.
172*7c478bd9Sstevel@tonic-gate */
173*7c478bd9Sstevel@tonic-gate int
wins_wch(WINDOW * w,const cchar_t * cc)174*7c478bd9Sstevel@tonic-gate wins_wch(WINDOW *w, const cchar_t *cc)
175*7c478bd9Sstevel@tonic-gate {
176*7c478bd9Sstevel@tonic-gate int code;
177*7c478bd9Sstevel@tonic-gate
178*7c478bd9Sstevel@tonic-gate code = __m_wins_wch(w, w->_cury, w->_curx, cc, NULL, NULL);
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate return (code);
181*7c478bd9Sstevel@tonic-gate }
182