2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1995, by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A * vid_puts.c
2N/A *
2N/A * XCurses Library
2N/A *
2N/A * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved.
2N/A *
2N/A */
2N/A
2N/A#ifdef M_RCSID
2N/A#ifndef lint
2N/Astatic char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/vid_puts.c 1.5 1995/07/19 16:38:26 ant Exp $";
2N/A#endif
2N/A#endif
2N/A
2N/A#include <private.h>
2N/A#include <limits.h>
2N/A
2N/ASTATIC attr_t turn_off(int (*)(int), attr_t);
2N/ASTATIC attr_t turn_on(int (*)(int), attr_t);
2N/A
2N/A/*
2N/A * Return true if attribute X a member of the attribute set A.
2N/A * no_color_video is the set of attributes that cannot be combined
2N/A * with colours.
2N/A */
2N/A#define ISATTR(a,x) (((a) & ~no_color_video & (x)) == (x))
2N/A
2N/A/*f
2N/A * Set the desired attribute state for a terminal screen.
2N/A *
2N/A * Using set_attributes is the prefered method but requires some care
2N/A * in writing the proper terminfo string. Using exit_attribute_mode and
2N/A * the assorted enter_ attribute mode capabilities is the next best method.
2N/A * Finally using the assorted exit_ and enter_ attribute mode capabilities
2N/A * is the last method available and is not necessarily efficent (or smart
2N/A * because of the needs of ceol_standout_glitch support).
2N/A */
2N/Aint
2N/Avid_puts(attr_t attr, short pair, void *opts, int (*putout)(int))
2N/A{
2N/A#ifdef M_CURSES_TRACE
2N/A __m_trace("vid_puts(%x, %d, %p, %p)", attr, pair, opts, putout);
2N/A#endif
2N/A
2N/A if (set_attributes != (char *) 0 && ATTR_STATE != attr) {
2N/A /* Assume that <set_attributes> disables attributes
2N/A * then re-enables attributes that are to be on.
2N/A */
2N/A (void) tputs(
2N/A tparm(
2N/A set_attributes,
2N/A (long) ISATTR(attr, WA_STANDOUT),
2N/A (long) ISATTR(attr, WA_UNDERLINE),
2N/A (long) ISATTR(attr, WA_REVERSE),
2N/A (long) ISATTR(attr, WA_BLINK),
2N/A (long) ISATTR(attr, WA_DIM),
2N/A (long) ISATTR(attr, WA_BOLD),
2N/A (long) ISATTR(attr, WA_INVIS),
2N/A (long) ISATTR(attr, WA_PROTECT),
2N/A (long) ISATTR(attr, WA_ALTCHARSET)
2N/A ),
2N/A 1, putout
2N/A );
2N/A
2N/A ATTR_STATE &= ~WA_SGR_MASK;
2N/A ATTR_STATE |= attr & WA_SGR_MASK;
2N/A
2N/A /* Only use <set_a_attributes> when <set_attributes>
2N/A * is defined. <set_a_attributes> should not disable
2N/A * attributes, as this will have been handled by
2N/A * <set_attributes>.
2N/A */
2N/A if (set_a_attributes != (char *) 0 && (attr & WA_SGR1_MASK)) {
2N/A (void) tputs(
2N/A tparm(
2N/A set_a_attributes,
2N/A (long) ISATTR(attr, WA_HORIZONTAL),
2N/A (long) ISATTR(attr, WA_LEFT),
2N/A (long) ISATTR(attr, WA_LOW),
2N/A (long) ISATTR(attr, WA_RIGHT),
2N/A (long) ISATTR(attr, WA_TOP),
2N/A (long) ISATTR(attr, WA_VERTICAL),
2N/A 0L, 0L, 0L
2N/A ),
2N/A 1, putout
2N/A );
2N/A
2N/A ATTR_STATE &= ~WA_SGR1_MASK;
2N/A ATTR_STATE |= attr & WA_SGR1_MASK;
2N/A }
2N/A } else if (ATTR_STATE != attr) {
2N/A /* Turn off only those attributes that are on. */
2N/A (void) turn_off(putout, ATTR_STATE);
2N/A
2N/A /* Turn on attributes regardless if they are already
2N/A * on, because terminals with ceol_standout_glitch, like
2N/A * HP terminals, will have to re-enforce the current
2N/A * attributes in order to change existing attribute
2N/A * cookies on the screen.
2N/A */
2N/A ATTR_STATE = turn_on(putout, attr);
2N/A }
2N/A
2N/A /* A_NORMAL equals 0, which is all attributes off and
2N/A * COLOR_PAIR(0). This implies that colour pair 0 is
2N/A * the orig_pair.
2N/A */
2N/A if (attr == WA_NORMAL) {
2N/A if (orig_pair != (char *) 0)
2N/A (void) tputs(orig_pair, 1, putout);
2N/A
2N/A pair = 0;
2N/A } else if (pair != cur_term->_co && 0 < max_colors) {
2N/A short fg, bg;
2N/A
2N/A if (set_color_pair != (char *) 0) {
2N/A (void) tputs(
2N/A tparm(
2N/A set_color_pair, (long) pair,
2N/A 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
2N/A ),
2N/A 1, putout
2N/A );
2N/A } else if (pair_content(pair, &fg, &bg) == OK) {
2N/A if (set_foreground != (char *) 0) {
2N/A (void) tputs(
2N/A tparm(set_foreground, (long) fg,
2N/A 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
2N/A ),
2N/A 1, putout
2N/A );
2N/A } else if (set_a_foreground != (char *) 0) {
2N/A (void) tputs(
2N/A tparm(
2N/A set_a_foreground, (long) fg,
2N/A 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
2N/A ),
2N/A 1, putout
2N/A );
2N/A }
2N/A
2N/A if (set_background != (char *) 0) {
2N/A (void) tputs(
2N/A tparm(set_background, (long) bg,
2N/A 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
2N/A ),
2N/A 1, putout
2N/A );
2N/A } else if (set_a_background != (char *) 0) {
2N/A (void) tputs(
2N/A tparm(
2N/A set_a_background, (long) bg,
2N/A 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
2N/A ),
2N/A 1, putout
2N/A );
2N/A }
2N/A }
2N/A }
2N/A
2N/A /* Remember the current attribute state for the terminal. */
2N/A ATTR_STATE = attr;
2N/A cur_term->_co = pair;
2N/A
2N/A return __m_return_code("vid_puts", OK);
2N/A}
2N/A
2N/ASTATIC attr_t
2N/Aturn_off(int (*putout)(int), attr_t attr)
2N/A{
2N/A attr_t new = attr;
2N/A
2N/A if (exit_attribute_mode != (char *) 0) {
2N/A (void) tputs(exit_attribute_mode, 1, putout);
2N/A new = WA_NORMAL;
2N/A } else {
2N/A if (ISATTR(attr, WA_UNDERLINE)
2N/A && exit_underline_mode != (char *) 0) {
2N/A (void) tputs(exit_underline_mode, 1, putout);
2N/A new &= ~WA_UNDERLINE;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_STANDOUT)
2N/A && exit_standout_mode != (char *) 0) {
2N/A (void) tputs(exit_standout_mode, 1, putout);
2N/A new &= ~WA_STANDOUT;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_ALTCHARSET)
2N/A && exit_alt_charset_mode != (char *) 0) {
2N/A (void) tputs(exit_alt_charset_mode, 1, putout);
2N/A new &= ~WA_ALTCHARSET;
2N/A }
2N/A }
2N/A
2N/A return new;
2N/A}
2N/A
2N/ASTATIC attr_t
2N/Aturn_on(int (*putout)(int), attr_t attr)
2N/A{
2N/A attr_t new = attr;
2N/A
2N/A if (ISATTR(attr, WA_ALTCHARSET)
2N/A && enter_alt_charset_mode != (char *) 0) {
2N/A (void) tputs(enter_alt_charset_mode, 1, putout);
2N/A new |= WA_ALTCHARSET;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_BLINK) && enter_blink_mode != (char *) 0) {
2N/A (void) tputs(enter_blink_mode, 1, putout);
2N/A new |= WA_BLINK;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_BOLD) && enter_bold_mode != (char *) 0) {
2N/A (void) tputs(enter_bold_mode, 1, putout);
2N/A new |= WA_BOLD;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_INVIS) && enter_secure_mode != (char *) 0) {
2N/A (void) tputs(enter_secure_mode, 1, putout);
2N/A new |= WA_INVIS;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_DIM) && enter_dim_mode != (char *) 0) {
2N/A (void) tputs(enter_dim_mode, 1, putout);
2N/A new |= WA_DIM;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_PROTECT) && enter_protected_mode != (char *) 0) {
2N/A (void) tputs(enter_protected_mode, 1, putout);
2N/A new |= WA_PROTECT;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_REVERSE) && enter_reverse_mode != (char *) 0) {
2N/A (void) tputs(enter_reverse_mode, 1, putout);
2N/A new |= WA_REVERSE;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_STANDOUT) && enter_standout_mode != (char *) 0) {
2N/A (void) tputs(enter_standout_mode, 1, putout);
2N/A new |= WA_STANDOUT;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_UNDERLINE) && enter_underline_mode != (char *) 0) {
2N/A (void) tputs(enter_underline_mode, 1, putout);
2N/A new |= WA_UNDERLINE;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_HORIZONTAL)
2N/A && enter_horizontal_hl_mode != (char *) 0) {
2N/A (void) tputs(enter_horizontal_hl_mode, 1, putout);
2N/A new |= WA_HORIZONTAL;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_LEFT) && enter_left_hl_mode != (char *) 0) {
2N/A (void) tputs(enter_left_hl_mode, 1, putout);
2N/A new |= WA_LEFT;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_LOW) && enter_low_hl_mode != (char *) 0) {
2N/A (void) tputs(enter_low_hl_mode, 1, putout);
2N/A new |= WA_LOW;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_RIGHT) && enter_right_hl_mode != (char *) 0) {
2N/A (void) tputs(enter_right_hl_mode, 1, putout);
2N/A new |= WA_RIGHT;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_TOP) && enter_top_hl_mode != (char *) 0) {
2N/A (void) tputs(enter_top_hl_mode, 1, putout);
2N/A new |= WA_TOP;
2N/A }
2N/A
2N/A if (ISATTR(attr, WA_VERTICAL) && enter_vertical_hl_mode != (char *) 0) {
2N/A (void) tputs(enter_vertical_hl_mode, 1, putout);
2N/A new |= WA_VERTICAL;
2N/A }
2N/A
2N/A return new;
2N/A}
2N/A