xref: /netbsd-src/lib/libcurses/addch.c (revision 2a780e62ed82cbe6862249cad03fe76de02d3db8)
1*2a780e62Sblymn /*	$NetBSD: addch.c,v 1.21 2019/06/09 07:40:14 blymn Exp $	*/
2716747aaSmikel 
361f28255Scgd /*
4d29088daScgd  * Copyright (c) 1981, 1993, 1994
5019bbd13Scgd  *	The Regents of the University of California.  All rights reserved.
661f28255Scgd  *
761f28255Scgd  * Redistribution and use in source and binary forms, with or without
861f28255Scgd  * modification, are permitted provided that the following conditions
961f28255Scgd  * are met:
1061f28255Scgd  * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd  *    notice, this list of conditions and the following disclaimer.
1261f28255Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd  *    notice, this list of conditions and the following disclaimer in the
1461f28255Scgd  *    documentation and/or other materials provided with the distribution.
15eb7c1594Sagc  * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd  *    may be used to endorse or promote products derived from this software
1761f28255Scgd  *    without specific prior written permission.
1861f28255Scgd  *
1961f28255Scgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd  * SUCH DAMAGE.
3061f28255Scgd  */
3161f28255Scgd 
32716747aaSmikel #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
34716747aaSmikel #if 0
35d29088daScgd static char sccsid[] = "@(#)addch.c	8.2 (Berkeley) 5/4/94";
36716747aaSmikel #else
37*2a780e62Sblymn __RCSID("$NetBSD: addch.c,v 1.21 2019/06/09 07:40:14 blymn Exp $");
38716747aaSmikel #endif
3961f28255Scgd #endif				/* not lint */
4061f28255Scgd 
41d29088daScgd #include "curses.h"
4223464ee5Sblymn #include "curses_private.h"
4361f28255Scgd 
44aaf74682Sblymn #ifndef _CURSES_USE_MACROS
45aaf74682Sblymn 
46aaf74682Sblymn /*
47aaf74682Sblymn  * addch --
48aaf74682Sblymn  *	Add the character to the current position in stdscr.
49aaf74682Sblymn  *
50aaf74682Sblymn  */
51aaf74682Sblymn int
52aaf74682Sblymn addch(chtype ch)
53aaf74682Sblymn {
5491804696Sroy 
55aaf74682Sblymn 	return waddch(stdscr, ch);
56aaf74682Sblymn }
57aaf74682Sblymn 
58aaf74682Sblymn /*
59aaf74682Sblymn  * mvaddch --
60aaf74682Sblymn  *      Add the character to stdscr at the given location.
61aaf74682Sblymn  */
62aaf74682Sblymn int
63aaf74682Sblymn mvaddch(int y, int x, chtype ch)
64aaf74682Sblymn {
6591804696Sroy 
66aaf74682Sblymn 	return mvwaddch(stdscr, y, x, ch);
67aaf74682Sblymn }
68aaf74682Sblymn 
69aaf74682Sblymn /*
70aaf74682Sblymn  * mvwaddch --
71aaf74682Sblymn  *      Add the character to the given window at the given location.
72aaf74682Sblymn  */
73aaf74682Sblymn int
74aaf74682Sblymn mvwaddch(WINDOW *win, int y, int x, chtype ch)
75aaf74682Sblymn {
7691804696Sroy 
77*2a780e62Sblymn 	if (wmove(win, y, x) == ERR)
78aaf74682Sblymn 		return ERR;
79aaf74682Sblymn 
80aaf74682Sblymn 	return waddch(win, ch);
81aaf74682Sblymn }
82aaf74682Sblymn 
83aaf74682Sblymn #endif
84aaf74682Sblymn 
8529dacce4Suwe #ifdef HAVE_WCHAR
8661f28255Scgd /*
8762a3457dSmycroft  * waddch --
8862a3457dSmycroft  *	Add the character to the current position in the given window.
8961f28255Scgd  */
9062a3457dSmycroft int
91aaf74682Sblymn waddch(WINDOW *win, chtype ch)
9261f28255Scgd {
93e124de36Sblymn 	cchar_t cc;
9462a3457dSmycroft 
95452834f2Sdrochner 	__cursesi_chtype_to_cchar(ch, &cc);
9623464ee5Sblymn #ifdef DEBUG
97e124de36Sblymn 	__CTRACE(__CTRACE_INPUT,
98e124de36Sblymn 		 "addch: %d : 0x%x (adding char as wide char)\n",
99e124de36Sblymn 		 cc.vals[0], cc.attributes);
100e124de36Sblymn #endif
101e124de36Sblymn 
10291804696Sroy 	return wadd_wch(win, &cc);
103019bbd13Scgd }
104019bbd13Scgd 
10529dacce4Suwe #else /* !HAVE_WCHAR */
10629dacce4Suwe 
10729dacce4Suwe /*
10829dacce4Suwe  * waddch --
10929dacce4Suwe  *	Add the character to the current position in the given window.
11029dacce4Suwe  */
11129dacce4Suwe int
11229dacce4Suwe waddch(WINDOW *win, chtype ch)
11329dacce4Suwe {
11429dacce4Suwe 	__LDATA buf;
11529dacce4Suwe 
11629dacce4Suwe 	buf.ch = (wchar_t)ch & __CHARTEXT;
11729dacce4Suwe 	buf.attr = (attr_t)ch & __ATTRIBUTES;
11829dacce4Suwe #ifdef DEBUG
11929dacce4Suwe 	__CTRACE(__CTRACE_INPUT, "addch: %d : 0x%x\n", buf.ch, buf.attr);
12029dacce4Suwe #endif
12129dacce4Suwe 	return __waddch(win, &buf);
12229dacce4Suwe }
12329dacce4Suwe #endif /* !HAVE_WCHAR */
12429dacce4Suwe 
125019bbd13Scgd int
126aaf74682Sblymn __waddch(WINDOW *win, __LDATA *dp)
127019bbd13Scgd {
128019bbd13Scgd 	char	buf[2];
129019bbd13Scgd 
130019bbd13Scgd 	buf[0] = dp->ch;
1318d259104Sblymn 	buf[1] = '\0';
13291804696Sroy 	return _cursesi_waddbytes(win, buf, 1, dp->attr, 1);
13361f28255Scgd }
134