17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright (c) 1995, by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate * All rights reserved.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * vid_puts.c
297c478bd9Sstevel@tonic-gate *
307c478bd9Sstevel@tonic-gate * XCurses Library
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
337c478bd9Sstevel@tonic-gate *
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #ifdef M_RCSID
377c478bd9Sstevel@tonic-gate #ifndef lint
387c478bd9Sstevel@tonic-gate static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/vid_puts.c 1.5 1995/07/19 16:38:26 ant Exp $";
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include <private.h>
437c478bd9Sstevel@tonic-gate #include <limits.h>
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate STATIC attr_t turn_off(int (*)(int), attr_t);
467c478bd9Sstevel@tonic-gate STATIC attr_t turn_on(int (*)(int), attr_t);
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate * Return true if attribute X a member of the attribute set A.
507c478bd9Sstevel@tonic-gate * no_color_video is the set of attributes that cannot be combined
517c478bd9Sstevel@tonic-gate * with colours.
527c478bd9Sstevel@tonic-gate */
537c478bd9Sstevel@tonic-gate #define ISATTR(a,x) (((a) & ~no_color_video & (x)) == (x))
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate /*f
56*1da57d55SToomas Soome * Set the desired attribute state for a terminal screen.
577c478bd9Sstevel@tonic-gate *
58*1da57d55SToomas Soome * Using set_attributes is the prefered method but requires some care
59*1da57d55SToomas Soome * in writing the proper terminfo string. Using exit_attribute_mode and
607c478bd9Sstevel@tonic-gate * the assorted enter_ attribute mode capabilities is the next best method.
617c478bd9Sstevel@tonic-gate * Finally using the assorted exit_ and enter_ attribute mode capabilities
627c478bd9Sstevel@tonic-gate * is the last method available and is not necessarily efficent (or smart
637c478bd9Sstevel@tonic-gate * because of the needs of ceol_standout_glitch support).
647c478bd9Sstevel@tonic-gate */
657c478bd9Sstevel@tonic-gate int
vid_puts(attr_t attr,short pair,void * opts,int (* putout)(int))667c478bd9Sstevel@tonic-gate vid_puts(attr_t attr, short pair, void *opts, int (*putout)(int))
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate #ifdef M_CURSES_TRACE
697c478bd9Sstevel@tonic-gate __m_trace("vid_puts(%x, %d, %p, %p)", attr, pair, opts, putout);
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate if (set_attributes != (char *) 0 && ATTR_STATE != attr) {
737c478bd9Sstevel@tonic-gate /* Assume that <set_attributes> disables attributes
747c478bd9Sstevel@tonic-gate * then re-enables attributes that are to be on.
757c478bd9Sstevel@tonic-gate */
767c478bd9Sstevel@tonic-gate (void) tputs(
777c478bd9Sstevel@tonic-gate tparm(
787c478bd9Sstevel@tonic-gate set_attributes,
797c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_STANDOUT),
807c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_UNDERLINE),
817c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_REVERSE),
827c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_BLINK),
837c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_DIM),
847c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_BOLD),
857c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_INVIS),
867c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_PROTECT),
877c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_ALTCHARSET)
88*1da57d55SToomas Soome ),
897c478bd9Sstevel@tonic-gate 1, putout
907c478bd9Sstevel@tonic-gate );
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate ATTR_STATE &= ~WA_SGR_MASK;
937c478bd9Sstevel@tonic-gate ATTR_STATE |= attr & WA_SGR_MASK;
947c478bd9Sstevel@tonic-gate
95*1da57d55SToomas Soome /* Only use <set_a_attributes> when <set_attributes>
967c478bd9Sstevel@tonic-gate * is defined. <set_a_attributes> should not disable
977c478bd9Sstevel@tonic-gate * attributes, as this will have been handled by
987c478bd9Sstevel@tonic-gate * <set_attributes>.
997c478bd9Sstevel@tonic-gate */
1007c478bd9Sstevel@tonic-gate if (set_a_attributes != (char *) 0 && (attr & WA_SGR1_MASK)) {
1017c478bd9Sstevel@tonic-gate (void) tputs(
1027c478bd9Sstevel@tonic-gate tparm(
1037c478bd9Sstevel@tonic-gate set_a_attributes,
1047c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_HORIZONTAL),
1057c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_LEFT),
1067c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_LOW),
1077c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_RIGHT),
1087c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_TOP),
1097c478bd9Sstevel@tonic-gate (long) ISATTR(attr, WA_VERTICAL),
1107c478bd9Sstevel@tonic-gate 0L, 0L, 0L
111*1da57d55SToomas Soome ),
1127c478bd9Sstevel@tonic-gate 1, putout
1137c478bd9Sstevel@tonic-gate );
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate ATTR_STATE &= ~WA_SGR1_MASK;
1167c478bd9Sstevel@tonic-gate ATTR_STATE |= attr & WA_SGR1_MASK;
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate } else if (ATTR_STATE != attr) {
1197c478bd9Sstevel@tonic-gate /* Turn off only those attributes that are on. */
120*1da57d55SToomas Soome (void) turn_off(putout, ATTR_STATE);
1217c478bd9Sstevel@tonic-gate
122*1da57d55SToomas Soome /* Turn on attributes regardless if they are already
1237c478bd9Sstevel@tonic-gate * on, because terminals with ceol_standout_glitch, like
124*1da57d55SToomas Soome * HP terminals, will have to re-enforce the current
125*1da57d55SToomas Soome * attributes in order to change existing attribute
1267c478bd9Sstevel@tonic-gate * cookies on the screen.
1277c478bd9Sstevel@tonic-gate */
1287c478bd9Sstevel@tonic-gate ATTR_STATE = turn_on(putout, attr);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate
131*1da57d55SToomas Soome /* A_NORMAL equals 0, which is all attributes off and
1327c478bd9Sstevel@tonic-gate * COLOR_PAIR(0). This implies that colour pair 0 is
1337c478bd9Sstevel@tonic-gate * the orig_pair.
1347c478bd9Sstevel@tonic-gate */
1357c478bd9Sstevel@tonic-gate if (attr == WA_NORMAL) {
1367c478bd9Sstevel@tonic-gate if (orig_pair != (char *) 0)
1377c478bd9Sstevel@tonic-gate (void) tputs(orig_pair, 1, putout);
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate pair = 0;
1407c478bd9Sstevel@tonic-gate } else if (pair != cur_term->_co && 0 < max_colors) {
1417c478bd9Sstevel@tonic-gate short fg, bg;
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate if (set_color_pair != (char *) 0) {
1447c478bd9Sstevel@tonic-gate (void) tputs(
1457c478bd9Sstevel@tonic-gate tparm(
1467c478bd9Sstevel@tonic-gate set_color_pair, (long) pair,
147*1da57d55SToomas Soome 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
148*1da57d55SToomas Soome ),
1497c478bd9Sstevel@tonic-gate 1, putout
1507c478bd9Sstevel@tonic-gate );
1517c478bd9Sstevel@tonic-gate } else if (pair_content(pair, &fg, &bg) == OK) {
1527c478bd9Sstevel@tonic-gate if (set_foreground != (char *) 0) {
1537c478bd9Sstevel@tonic-gate (void) tputs(
1547c478bd9Sstevel@tonic-gate tparm(set_foreground, (long) fg,
155*1da57d55SToomas Soome 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
156*1da57d55SToomas Soome ),
1577c478bd9Sstevel@tonic-gate 1, putout
1587c478bd9Sstevel@tonic-gate );
1597c478bd9Sstevel@tonic-gate } else if (set_a_foreground != (char *) 0) {
1607c478bd9Sstevel@tonic-gate (void) tputs(
1617c478bd9Sstevel@tonic-gate tparm(
1627c478bd9Sstevel@tonic-gate set_a_foreground, (long) fg,
163*1da57d55SToomas Soome 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
164*1da57d55SToomas Soome ),
1657c478bd9Sstevel@tonic-gate 1, putout
1667c478bd9Sstevel@tonic-gate );
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate if (set_background != (char *) 0) {
1707c478bd9Sstevel@tonic-gate (void) tputs(
1717c478bd9Sstevel@tonic-gate tparm(set_background, (long) bg,
172*1da57d55SToomas Soome 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
173*1da57d55SToomas Soome ),
1747c478bd9Sstevel@tonic-gate 1, putout
1757c478bd9Sstevel@tonic-gate );
1767c478bd9Sstevel@tonic-gate } else if (set_a_background != (char *) 0) {
1777c478bd9Sstevel@tonic-gate (void) tputs(
1787c478bd9Sstevel@tonic-gate tparm(
1797c478bd9Sstevel@tonic-gate set_a_background, (long) bg,
180*1da57d55SToomas Soome 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
181*1da57d55SToomas Soome ),
1827c478bd9Sstevel@tonic-gate 1, putout
1837c478bd9Sstevel@tonic-gate );
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate /* Remember the current attribute state for the terminal. */
1897c478bd9Sstevel@tonic-gate ATTR_STATE = attr;
1907c478bd9Sstevel@tonic-gate cur_term->_co = pair;
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate return __m_return_code("vid_puts", OK);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate STATIC attr_t
turn_off(int (* putout)(int),attr_t attr)1967c478bd9Sstevel@tonic-gate turn_off(int (*putout)(int), attr_t attr)
1977c478bd9Sstevel@tonic-gate {
1987c478bd9Sstevel@tonic-gate attr_t new = attr;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate if (exit_attribute_mode != (char *) 0) {
2017c478bd9Sstevel@tonic-gate (void) tputs(exit_attribute_mode, 1, putout);
2027c478bd9Sstevel@tonic-gate new = WA_NORMAL;
2037c478bd9Sstevel@tonic-gate } else {
204*1da57d55SToomas Soome if (ISATTR(attr, WA_UNDERLINE)
2057c478bd9Sstevel@tonic-gate && exit_underline_mode != (char *) 0) {
2067c478bd9Sstevel@tonic-gate (void) tputs(exit_underline_mode, 1, putout);
2077c478bd9Sstevel@tonic-gate new &= ~WA_UNDERLINE;
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate
210*1da57d55SToomas Soome if (ISATTR(attr, WA_STANDOUT)
2117c478bd9Sstevel@tonic-gate && exit_standout_mode != (char *) 0) {
2127c478bd9Sstevel@tonic-gate (void) tputs(exit_standout_mode, 1, putout);
2137c478bd9Sstevel@tonic-gate new &= ~WA_STANDOUT;
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate
216*1da57d55SToomas Soome if (ISATTR(attr, WA_ALTCHARSET)
2177c478bd9Sstevel@tonic-gate && exit_alt_charset_mode != (char *) 0) {
2187c478bd9Sstevel@tonic-gate (void) tputs(exit_alt_charset_mode, 1, putout);
2197c478bd9Sstevel@tonic-gate new &= ~WA_ALTCHARSET;
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate return new;
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate STATIC attr_t
turn_on(int (* putout)(int),attr_t attr)2277c478bd9Sstevel@tonic-gate turn_on(int (*putout)(int), attr_t attr)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate attr_t new = attr;
2307c478bd9Sstevel@tonic-gate
231*1da57d55SToomas Soome if (ISATTR(attr, WA_ALTCHARSET)
2327c478bd9Sstevel@tonic-gate && enter_alt_charset_mode != (char *) 0) {
2337c478bd9Sstevel@tonic-gate (void) tputs(enter_alt_charset_mode, 1, putout);
2347c478bd9Sstevel@tonic-gate new |= WA_ALTCHARSET;
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_BLINK) && enter_blink_mode != (char *) 0) {
2387c478bd9Sstevel@tonic-gate (void) tputs(enter_blink_mode, 1, putout);
2397c478bd9Sstevel@tonic-gate new |= WA_BLINK;
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_BOLD) && enter_bold_mode != (char *) 0) {
2437c478bd9Sstevel@tonic-gate (void) tputs(enter_bold_mode, 1, putout);
2447c478bd9Sstevel@tonic-gate new |= WA_BOLD;
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_INVIS) && enter_secure_mode != (char *) 0) {
2487c478bd9Sstevel@tonic-gate (void) tputs(enter_secure_mode, 1, putout);
2497c478bd9Sstevel@tonic-gate new |= WA_INVIS;
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_DIM) && enter_dim_mode != (char *) 0) {
2537c478bd9Sstevel@tonic-gate (void) tputs(enter_dim_mode, 1, putout);
2547c478bd9Sstevel@tonic-gate new |= WA_DIM;
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_PROTECT) && enter_protected_mode != (char *) 0) {
2587c478bd9Sstevel@tonic-gate (void) tputs(enter_protected_mode, 1, putout);
2597c478bd9Sstevel@tonic-gate new |= WA_PROTECT;
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_REVERSE) && enter_reverse_mode != (char *) 0) {
2637c478bd9Sstevel@tonic-gate (void) tputs(enter_reverse_mode, 1, putout);
2647c478bd9Sstevel@tonic-gate new |= WA_REVERSE;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_STANDOUT) && enter_standout_mode != (char *) 0) {
2687c478bd9Sstevel@tonic-gate (void) tputs(enter_standout_mode, 1, putout);
2697c478bd9Sstevel@tonic-gate new |= WA_STANDOUT;
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_UNDERLINE) && enter_underline_mode != (char *) 0) {
2737c478bd9Sstevel@tonic-gate (void) tputs(enter_underline_mode, 1, putout);
2747c478bd9Sstevel@tonic-gate new |= WA_UNDERLINE;
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate
277*1da57d55SToomas Soome if (ISATTR(attr, WA_HORIZONTAL)
2787c478bd9Sstevel@tonic-gate && enter_horizontal_hl_mode != (char *) 0) {
2797c478bd9Sstevel@tonic-gate (void) tputs(enter_horizontal_hl_mode, 1, putout);
2807c478bd9Sstevel@tonic-gate new |= WA_HORIZONTAL;
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_LEFT) && enter_left_hl_mode != (char *) 0) {
2847c478bd9Sstevel@tonic-gate (void) tputs(enter_left_hl_mode, 1, putout);
2857c478bd9Sstevel@tonic-gate new |= WA_LEFT;
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_LOW) && enter_low_hl_mode != (char *) 0) {
2897c478bd9Sstevel@tonic-gate (void) tputs(enter_low_hl_mode, 1, putout);
2907c478bd9Sstevel@tonic-gate new |= WA_LOW;
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_RIGHT) && enter_right_hl_mode != (char *) 0) {
2947c478bd9Sstevel@tonic-gate (void) tputs(enter_right_hl_mode, 1, putout);
2957c478bd9Sstevel@tonic-gate new |= WA_RIGHT;
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_TOP) && enter_top_hl_mode != (char *) 0) {
2997c478bd9Sstevel@tonic-gate (void) tputs(enter_top_hl_mode, 1, putout);
3007c478bd9Sstevel@tonic-gate new |= WA_TOP;
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate if (ISATTR(attr, WA_VERTICAL) && enter_vertical_hl_mode != (char *) 0) {
3047c478bd9Sstevel@tonic-gate (void) tputs(enter_vertical_hl_mode, 1, putout);
3057c478bd9Sstevel@tonic-gate new |= WA_VERTICAL;
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate return new;
3097c478bd9Sstevel@tonic-gate }
3107c478bd9Sstevel@tonic-gate
311