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, by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 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[] = "$Header: /rd/src/libc/xcurses/rcs/wadd_wch.c 1.5 1995/07/26 17:43:19 ant Exp $"; 41 #endif 42 #endif 43 44 #include <private.h> 45 #include <wctype.h> 46 #include <string.h> 47 48 /*f 49 * Add a character (and attributes) to a window and advance the cursor. 50 * Automatic newline done at right margin, tabs are expanded every 8 51 * columns, backspaces are handled. Newline will clear the rest of the 52 * line; if nl() mode then the cursor is advanced to the start of the 53 * next line. 54 */ 55 int 56 wadd_wch(w, cc) 57 WINDOW *w; 58 const cchar_t *cc; 59 { 60 cchar_t uc; 61 const wchar_t *p; 62 int code, x, y, nx; 63 64 #ifdef M_CURSES_TRACE 65 __m_trace("wadd_wch(%p, %p) at (%d, %d)", w, cc, w->_cury, w->_curx); 66 #endif 67 68 code = ERR; 69 x = w->_curx; 70 y = w->_cury; 71 72 if (x < 0 || w->_maxx <= x || y < 0 || w->_maxy <= y) 73 goto error; 74 75 switch (cc->_wc[0]) { 76 default: 77 if (iswprint(cc->_wc[0])) { 78 case '\t': 79 case '\n': 80 case '\b': 81 case '\r': 82 if (__m_cc_add(w, y, x, cc, 0, &y, &x) == ERR) 83 goto error; 84 break; 85 } 86 87 /* Convert non-printables into printable representation. */ 88 uc._n = 1; 89 uc._at = cc->_at; 90 uc._co = cc->_co; 91 92 if ((p = wunctrl(cc)) == (wchar_t *) 0) 93 goto error; 94 95 for ( ; *p != '\0'; ++p) { 96 uc._wc[0] = *p; 97 if (__m_cc_add(w, y, x, &uc, 0, &y, &x) == ERR) 98 goto error; 99 } 100 break; 101 } 102 103 w->_curx = x; 104 w->_cury = y; 105 106 WSYNC(w); 107 108 code = WFLUSH(w); 109 error: 110 return __m_return_code("wadd_wch", code); 111 } 112 113