inch.c revision 1.15
11.15Sblymn/*	$NetBSD: inch.c,v 1.15 2024/12/23 02:58:03 blymn Exp $	*/
21.2Sblymn
31.2Sblymn/*-
41.2Sblymn * Copyright (c) 1999 The NetBSD Foundation, Inc.
51.2Sblymn * All rights reserved.
61.2Sblymn *
71.2Sblymn * This code is derived from software contributed to The NetBSD Foundation
81.2Sblymn * by Julian Coleman.
91.2Sblymn *
101.2Sblymn * Redistribution and use in source and binary forms, with or without
111.2Sblymn * modification, are permitted provided that the following conditions
121.2Sblymn * are met:
131.2Sblymn * 1. Redistributions of source code must retain the above copyright
141.2Sblymn *    notice, this list of conditions and the following disclaimer.
151.2Sblymn * 2. Redistributions in binary form must reproduce the above copyright
161.2Sblymn *    notice, this list of conditions and the following disclaimer in the
171.2Sblymn *    documentation and/or other materials provided with the distribution.
181.2Sblymn *
191.2Sblymn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.2Sblymn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.2Sblymn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.2Sblymn * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.2Sblymn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.2Sblymn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.2Sblymn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.2Sblymn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.2Sblymn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.2Sblymn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.2Sblymn * POSSIBILITY OF SUCH DAMAGE.
301.2Sblymn */
311.4Sblymn
321.4Sblymn#include <sys/cdefs.h>
331.4Sblymn#ifndef lint
341.15Sblymn__RCSID("$NetBSD: inch.c,v 1.15 2024/12/23 02:58:03 blymn Exp $");
351.4Sblymn#endif				/* not lint */
361.2Sblymn
371.2Sblymn#include "curses.h"
381.2Sblymn#include "curses_private.h"
391.2Sblymn
401.3Sblymn#ifndef _CURSES_USE_MACROS
411.3Sblymn
421.3Sblymn/*
431.3Sblymn * inch --
441.3Sblymn *	Return character at cursor position from stdscr.
451.3Sblymn */
461.3Sblymnchtype
471.3Sblymninch(void)
481.3Sblymn{
491.11Sroy
501.3Sblymn	return winch(stdscr);
511.3Sblymn}
521.3Sblymn
531.3Sblymn/*
541.3Sblymn * mvinch --
551.3Sblymn *      Return character at position (y, x) from stdscr.
561.3Sblymn */
571.3Sblymnchtype
581.3Sblymnmvinch(int y, int x)
591.3Sblymn{
601.11Sroy
611.3Sblymn	return mvwinch(stdscr, y, x);
621.3Sblymn}
631.3Sblymn
641.3Sblymn/*
651.3Sblymn * mvwinch --
661.3Sblymn *      Return character at position (y, x) from the given window.
671.3Sblymn */
681.3Sblymnchtype
691.3Sblymnmvwinch(WINDOW *win, int y, int x)
701.3Sblymn{
711.11Sroy
721.14Sblymn	if (wmove(win, y, x) == ERR)
731.3Sblymn		return ERR;
741.5Sblymn
751.3Sblymn	return winch(win);
761.3Sblymn}
771.3Sblymn
781.3Sblymn#endif
791.3Sblymn
801.2Sblymn/*
811.2Sblymn * winch --
821.2Sblymn *	Return character at cursor position.
831.2Sblymn */
841.2Sblymnchtype
851.3Sblymnwinch(WINDOW *win)
861.2Sblymn{
871.10Sjdc	chtype	ch;
881.10Sjdc	attr_t	attr;
891.2Sblymn
901.15Sblymn	if (__predict_false(win == NULL))
911.15Sblymn		return ERR;
921.15Sblymn
931.10Sjdc	ch = (chtype) ((win)->alines[(win)->cury]->line[(win)->curx].ch &
941.10Sjdc	    __CHARTEXT);
951.10Sjdc	attr = (attr_t) ((win)->alines[(win)->cury]->line[(win)->curx].attr &
961.10Sjdc	    __ATTRIBUTES);
971.10Sjdc	if (__using_color && ((attr & __COLOR) == __default_color))
981.12Suwe		attr &= ~__COLOR;
991.10Sjdc	return (ch | attr);
1001.2Sblymn}
101