1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 1995-1998 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 /* LINTLIBRARY */
28
29 /*
30 * wadd_wch.c
31 *
32 * XCurses Library
33 *
34 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
35 *
36 */
37
38 #ifdef M_RCSID
39 #ifndef lint
40 static char rcsID[] =
41 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
42 "libxcurses/src/libc/xcurses/rcs/wadd_wch.c 1.5 1998/06/01 14:26:53 "
43 "cbates Exp $";
44 #endif
45 #endif
46
47 #include <private.h>
48
49 /* Special for calls from string add functions */
50 int
__m_wadd_wch(WINDOW * w,const cchar_t * cc)51 __m_wadd_wch(WINDOW *w, const cchar_t *cc)
52 {
53 int xsave = w->_curx;
54 int ysave = w->_cury;
55 int code = wadd_wch(w, cc);
56
57 if (code == ERR) {
58 w->_curx = (short) xsave;
59 w->_cury = (short) ysave;
60 }
61 return (code);
62 }
63
64 /*
65 * Add a character (and attributes) to a window and advance the cursor.
66 * Automatic newline done at right margin, tabs are expanded every 8
67 * columns, backspaces are handled. Newline will clear the rest of the
68 * line; if nl() mode then the cursor is advanced to the start of the
69 * next line.
70 */
71 int
wadd_wch(WINDOW * w,const cchar_t * cc)72 wadd_wch(WINDOW *w, const cchar_t *cc)
73 {
74 cchar_t uc;
75 const wchar_t *p;
76 int code, x, y;
77 int oflags;
78
79 oflags = w->_flags & (W_FLUSH | W_SYNC_UP);
80
81 code = ERR;
82 x = w->_curx;
83 y = w->_cury;
84
85 if (x < 0 || w->_maxx <= x || y < 0 || w->_maxy <= y)
86 goto error;
87
88 if (iswprint(cc->_wc[0]) || cc->_wc[0] == L'\n' ||
89 cc->_wc[0] == L'\b' || cc->_wc[0] == L'\r') {
90 if (__m_cc_add(w, y, x, cc, 0, &y, &x) == ERR)
91 goto error;
92 } else if (cc->_wc[0] == L'\t') {
93 /*
94 * Experimental ...
95 * Maybe other cntrl chars should do this too ...
96 */
97 if (__m_cc_add(w, y, x, cc, 0, &y, &x) == ERR) {
98 w->_curx = (short) x;
99 w->_cury = (short) y;
100 WSYNC(w);
101 WFLUSH(w);
102 goto error;
103 }
104 } else {
105 /* Convert non-printables into printable representation. */
106 uc._n = 1;
107 uc._at = cc->_at;
108 uc._co = cc->_co;
109
110 if ((p = wunctrl((cchar_t *)cc)) == NULL)
111 goto error;
112
113 for (; *p != '\0'; ++p) {
114 uc._wc[0] = *p;
115 if (__m_cc_add(w, y, x, &uc, 0, &y, &x) == ERR)
116 goto error;
117 }
118 }
119
120 w->_curx = (short) x;
121 w->_cury = (short) y;
122
123 WSYNC(w);
124
125 code = WFLUSH(w);
126 error:
127 w->_flags = oflags | (w->_flags & ~(W_FLUSH | W_SYNC_UP));
128
129 return (code);
130 }
131