6429 SMB domain join doesn't work with libreSSL
[unleashed.git] / usr / src / lib / libcurses / screen / winsch.c
blobaa4ad13a245ed062d5608d565281e1c7d7c6c54b
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 /*LINTLIBRARY*/
44 #include <sys/types.h>
45 #include "curses_inc.h"
46 #include <ctype.h>
48 /* Insert a character at (curx, cury). */
50 int
51 winsch(WINDOW *win, chtype c)
53 short curx = win->_curx;
54 int n, cury = win->_cury;
55 chtype *wcp, a;
56 int rv;
58 a = _ATTR(c);
59 c &= A_CHARTEXT;
61 rv = OK;
62 win->_insmode = TRUE;
63 if (_scrmax > 1 && (rv = _mbvalid(win)) == ERR)
64 goto done;
65 /* take care of multi-byte characters */
66 if (_mbtrue && ISMBIT(c)) {
67 rv = _mbaddch(win, A_NORMAL, RBYTE(c));
68 goto done;
70 win->_nbyte = -1;
71 curx = win->_curx;
73 /* let waddch() worry about these */
74 if (c == '\r' || c == '\b')
75 return (waddch(win, c));
77 /* with \n, in contrast to waddch, we don't clear-to-eol */
78 if (c == '\n') {
79 if (cury >= (win->_maxy-1) || cury == win->_bmarg)
80 return (wscrl(win, 1));
81 else {
82 win->_cury++;
83 win->_curx = 0;
84 return (OK);
88 /* with tabs or control characters, we have to do more */
89 if (c == '\t') {
90 n = (TABSIZE - (curx % TABSIZE));
91 if ((curx + n) >= win->_maxx)
92 n = win->_maxx - curx;
93 c = ' ';
94 } else {
95 if (iscntrl((int) c) != 0) {
96 if (curx >= win->_maxx-1)
97 return (ERR);
98 n = 2;
99 } else
100 n = 1;
103 /* shift right */
104 wcp = win->_y[cury] + curx;
105 if ((rv = _mbinsshift(win, n)) == ERR)
106 goto done;
108 /* insert new control character */
109 if (c < ' ' || c == _CTRL('?')) {
110 *wcp++ = '^' | win->_attrs | a;
111 *wcp = _UNCTRL(c) | win->_attrs | a;
112 } else {
113 /* normal characters */
114 c = _WCHAR(win, c) | a;
115 for (; n > 0; --n)
116 *wcp++ = c;
119 done:
120 if (curx < win->_firstch[cury])
121 win->_firstch[cury] = curx;
122 win->_lastch[cury] = win->_maxx-1;
124 win->_flags |= _WINCHANGED;
126 if (win->_sync)
127 wsyncup(win);
129 return ((rv == OK && win->_immed) ? wrefresh(win) : rv);