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 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 /* LINTLIBRARY */
30
31 /*
32 * wadd_wch.c
33 *
34 * XCurses Library
35 *
36 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
37 *
38 */
39
40 #ifdef M_RCSID
41 #ifndef lint
42 static char rcsID[] =
43 "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
44 "libxcurses/src/libc/xcurses/rcs/wadd_wch.c 1.5 1998/06/01 14:26:53 "
45 "cbates Exp $";
46 #endif
47 #endif
48
49 #include <private.h>
50
51 /* Special for calls from string add functions */
52 int
__m_wadd_wch(WINDOW * w,const cchar_t * cc)53 __m_wadd_wch(WINDOW *w, const cchar_t *cc)
54 {
55 int xsave = w->_curx;
56 int ysave = w->_cury;
57 int code = wadd_wch(w, cc);
58
59 if (code == ERR) {
60 w->_curx = (short) xsave;
61 w->_cury = (short) ysave;
62 }
63 return (code);
64 }
65
66 /*
67 * Add a character (and attributes) to a window and advance the cursor.
68 * Automatic newline done at right margin, tabs are expanded every 8
69 * columns, backspaces are handled. Newline will clear the rest of the
70 * line; if nl() mode then the cursor is advanced to the start of the
71 * next line.
72 */
73 int
wadd_wch(WINDOW * w,const cchar_t * cc)74 wadd_wch(WINDOW *w, const cchar_t *cc)
75 {
76 cchar_t uc;
77 const wchar_t *p;
78 int code, x, y;
79 int oflags;
80
81 oflags = w->_flags & (W_FLUSH | W_SYNC_UP);
82
83 code = ERR;
84 x = w->_curx;
85 y = w->_cury;
86
87 if (x < 0 || w->_maxx <= x || y < 0 || w->_maxy <= y)
88 goto error;
89
90 if (iswprint(cc->_wc[0]) || cc->_wc[0] == L'\n' ||
91 cc->_wc[0] == L'\b' || cc->_wc[0] == L'\r') {
92 if (__m_cc_add(w, y, x, cc, 0, &y, &x) == ERR)
93 goto error;
94 } else if (cc->_wc[0] == L'\t') {
95 /*
96 * Experimental ...
97 * Maybe other cntrl chars should do this too ...
98 */
99 if (__m_cc_add(w, y, x, cc, 0, &y, &x) == ERR) {
100 w->_curx = (short) x;
101 w->_cury = (short) y;
102 WSYNC(w);
103 WFLUSH(w);
104 goto error;
105 }
106 } else {
107 /* Convert non-printables into printable representation. */
108 uc._n = 1;
109 uc._at = cc->_at;
110 uc._co = cc->_co;
111
112 if ((p = wunctrl((cchar_t *)cc)) == NULL)
113 goto error;
114
115 for (; *p != '\0'; ++p) {
116 uc._wc[0] = *p;
117 if (__m_cc_add(w, y, x, &uc, 0, &y, &x) == ERR)
118 goto error;
119 }
120 }
121
122 w->_curx = (short) x;
123 w->_cury = (short) y;
124
125 WSYNC(w);
126
127 code = WFLUSH(w);
128 error:
129 w->_flags = oflags | (w->_flags & ~(W_FLUSH | W_SYNC_UP));
130
131 return (code);
132 }
133