xref: /netbsd-src/lib/libcurses/curses.h (revision cda4f8f6ee55684e8d311b86c99ea59191e6b74f)
1 /*
2  * Copyright (c) 1981 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *	@(#)curses.h	5.9 (Berkeley) 7/1/90
34  */
35 
36 #ifndef WINDOW
37 
38 #include	<stdio.h>
39 
40 #define USE_OLD_TTY
41 #include	<sys/ioctl.h>
42 #undef USE_OLD_TTY
43 
44 #define	bool	char
45 #define	reg	register
46 
47 typedef unsigned short chtype;
48 
49 #define	TRUE	(1)
50 #define	FALSE	(0)
51 #define	ERR	(0)
52 #define	OK	(1)
53 
54 #define	_ENDLINE	001
55 #define	_FULLWIN	002
56 #define	_SCROLLWIN	004
57 #define	_FLUSH		010
58 #define	_FULLLINE	020
59 #define	_IDLINE		040
60 #define _STANDOUT       0400
61 #define	_NOCHANGE	-1
62 
63 #define	_puts(s)	tputs(s, 0, _putchar)
64 
65 typedef	struct sgttyb	SGTTY;
66 
67 /*
68  * Capabilities from termcap
69  */
70 
71 extern bool     AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL,
72 		XB, XN, XT, XS, XX;
73 extern char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
74 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
75 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
76 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
77 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
78 		*VE, *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM,
79 		*LEFT_PARM, *RIGHT_PARM;
80 extern char	PC;
81 
82 /*
83  * From the tty modes...
84  */
85 
86 extern bool	GT, NONL, UPPERCASE, normtty, _pfast;
87 
88 struct _win_st {
89 	short		_cury, _curx;
90 	short		_maxy, _maxx;
91 	short		_begy, _begx;
92 	short		_flags;
93 	short		_ch_off;
94 	bool		_clear;
95 	bool		_leave;
96 	bool		_scroll;
97 	chtype          **_y;
98 	short		*_firstch;
99 	short		*_lastch;
100 	struct _win_st	*_nextp, *_orig;
101 };
102 
103 #define	WINDOW	struct _win_st
104 
105 extern bool	My_term, _echoit, _rawmode, _endwin;
106 
107 extern char	*Def_term, ttytype[];
108 
109 extern int	LINES, COLS, _tty_ch, _res_flg;
110 
111 extern SGTTY	_tty;
112 
113 extern WINDOW	*stdscr, *curscr;
114 
115 /*
116  *	Define VOID to stop lint from generating "null effect"
117  * comments.
118  */
119 #ifdef lint
120 int	__void__;
121 #define	VOID(x)	(__void__ = (int) (x))
122 #else
123 #define	VOID(x)	(x)
124 #endif
125 
126 /*
127  * psuedo functions for standard screen
128  */
129 #define	addch(ch)	VOID(waddch(stdscr, ch))
130 #define	getch()		VOID(wgetch(stdscr))
131 #define	addbytes(da,co)	VOID(waddbytes(stdscr, da,co))
132 #define addstr(str)     VOID(waddstr(stdscr, str))
133 #define	getstr(str)	VOID(wgetstr(stdscr, str))
134 #define	move(y, x)	VOID(wmove(stdscr, y, x))
135 #define	clear()		VOID(wclear(stdscr))
136 #define	erase()		VOID(werase(stdscr))
137 #define	clrtobot()	VOID(wclrtobot(stdscr))
138 #define	clrtoeol()	VOID(wclrtoeol(stdscr))
139 #define	insertln()	VOID(winsertln(stdscr))
140 #define	deleteln()	VOID(wdeleteln(stdscr))
141 #define	refresh()	VOID(wrefresh(stdscr))
142 #define	inch()		VOID(winch(stdscr))
143 #define	insch(c)	VOID(winsch(stdscr,c))
144 #define	delch()		VOID(wdelch(stdscr))
145 #define	standout()	VOID(wstandout(stdscr))
146 #define	standend()	VOID(wstandend(stdscr))
147 
148 /*
149  * mv functions
150  */
151 #define	mvwaddch(win,y,x,ch)	VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
152 #define	mvwgetch(win,y,x)	VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
153 #define	mvwaddbytes(win,y,x,da,co) \
154 		VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co))
155 #define	mvwaddstr(win,y,x,str) \
156 		VOID(wmove(win,y,x)==ERR?ERR:waddstr(win,str))
157 #define mvwgetstr(win,y,x,str)  VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
158 #define	mvwinch(win,y,x)	VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
159 #define	mvwdelch(win,y,x)	VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
160 #define	mvwinsch(win,y,x,c)	VOID(wmove(win,y,x) == ERR ? ERR:winsch(win,c))
161 #define	mvaddch(y,x,ch)		mvwaddch(stdscr,y,x,ch)
162 #define	mvgetch(y,x)		mvwgetch(stdscr,y,x)
163 #define	mvaddbytes(y,x,da,co)	mvwaddbytes(stdscr,y,x,da,co)
164 #define	mvaddstr(y,x,str)	mvwaddstr(stdscr,y,x,str)
165 #define mvgetstr(y,x,str)       mvwgetstr(stdscr,y,x,str)
166 #define	mvinch(y,x)		mvwinch(stdscr,y,x)
167 #define	mvdelch(y,x)		mvwdelch(stdscr,y,x)
168 #define	mvinsch(y,x,c)		mvwinsch(stdscr,y,x,c)
169 
170 /*
171  * psuedo functions
172  */
173 
174 #define	clearok(win,bf)	 (win->_clear = bf)
175 #define	leaveok(win,bf)	 (win->_leave = bf)
176 #define	scrollok(win,bf) (win->_scroll = bf)
177 #define flushok(win,bf)	 (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
178 #define	getyx(win,y,x)	 y = win->_cury, x = win->_curx
179 #define winch(win)       (win->_y[win->_cury][win->_curx] & 0xFF)
180 
181 #define raw()	 (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, \
182 	ioctl(_tty_ch, TIOCSETP, &_tty))
183 #define noraw()	 (_tty.sg_flags&=~RAW,_rawmode=FALSE,\
184 	_pfast=!(_tty.sg_flags&CRMOD),ioctl(_tty_ch, TIOCSETP, &_tty))
185 #define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, \
186 	ioctl(_tty_ch, TIOCSETP, &_tty))
187 #define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE, \
188 	ioctl(_tty_ch, TIOCSETP, &_tty))
189 #define crmode() cbreak()	/* backwards compatability */
190 #define nocrmode() nocbreak()	/* backwards compatability */
191 #define echo()	 (_tty.sg_flags |= ECHO, _echoit = TRUE, \
192 	ioctl(_tty_ch, TIOCSETP, &_tty))
193 #define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, \
194 	ioctl(_tty_ch, TIOCSETP, &_tty))
195 #define nl()	 (_tty.sg_flags |= CRMOD,_pfast = _rawmode, \
196 	ioctl(_tty_ch, TIOCSETP, &_tty))
197 #define nonl()	 (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, \
198 	ioctl(_tty_ch, TIOCSETP, &_tty))
199 #define	savetty() ((void) ioctl(_tty_ch, TIOCGETP, &_tty), \
200 	_res_flg = _tty.sg_flags)
201 #define	resetty() (_tty.sg_flags = _res_flg, \
202 	_echoit = ((_res_flg & ECHO) == ECHO), \
203 	_rawmode = ((_res_flg & (CBREAK|RAW)) != 0), \
204 	_pfast = ((_res_flg & CRMOD) ? _rawmode : TRUE), \
205 	(void) ioctl(_tty_ch, TIOCSETP, &_tty))
206 
207 #define	erasechar()	(_tty.sg_erase)
208 #define	killchar()	(_tty.sg_kill)
209 #define baudrate()	(_tty.sg_ospeed)
210 
211 WINDOW	*initscr(), *newwin(), *subwin();
212 char	*longname(), *getcap();
213 
214 /*
215  * Used to be in unctrl.h.
216  */
217 #define	unctrl(c)	_unctrl[(c) & 0177]
218 extern char *_unctrl[];
219 #endif
220