xref: /illumos-gate/usr/src/ucbhead/curses.h (revision 8c0b080c8ed055a259d8cd26b9f005211c6a9753)
1 /*
2  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved.  The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #ifndef	_CURSES_H
16 #define	_CURSES_H
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #ifndef WINDOW
23 
24 #include	<stdio.h>
25 #include	<sgtty.h>
26 
27 #undef		HZ		/* in case they've included <sys/param.h> */
28 
29 #if !(defined(__cplusplus) && defined(_BOOL))
30 #define	bool	char
31 #endif
32 
33 #define	reg	register
34 
35 #define	TRUE	(1)
36 #define	FALSE	(0)
37 #define	ERR	(0)
38 #define	OK	(1)
39 
40 #define	_ENDLINE	001
41 #define	_FULLWIN	002
42 #define	_SCROLLWIN	004
43 #define	_FLUSH		010
44 #define	_FULLLINE	020
45 #define	_IDLINE		040
46 #define	_STANDOUT	0200
47 #define	_NOCHANGE	-1
48 
49 #define	_puts(s)	tputs(s, 0, _putchar)
50 
51 typedef	struct sgttyb	SGTTY;
52 
53 /*
54  * Capabilities from termcap
55  */
56 
57 extern	bool	AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL,
58 		XB, XN, XT, XS, XX;
59 extern	char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
60 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
61 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
62 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
63 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
64 		*VE, *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM,
65 		*LEFT_PARM, *RIGHT_PARM;
66 extern char	PC;
67 
68 /*
69  * From the tty modes...
70  */
71 
72 extern bool	GT, NONL, UPPERCASE, normtty, _pfast;
73 
74 struct _win_st {
75 	short		_cury, _curx;
76 	short		_maxy, _maxx;
77 	short		_begy, _begx;
78 	short		_flags;
79 	short		_ch_off;
80 	bool		_clear;
81 	bool		_leave;
82 	bool		_scroll;
83 	char		**_y;
84 	short		*_firstch;
85 	short		*_lastch;
86 	struct _win_st	*_nextp, *_orig;
87 };
88 
89 #define	WINDOW	struct _win_st
90 
91 extern bool	My_term, _echoit, _rawmode, _endwin;
92 
93 extern char	*Def_term, ttytype[50];
94 
95 extern int	LINES, COLS, _tty_ch, _res_flg;
96 
97 extern SGTTY	_tty;
98 
99 extern WINDOW	*stdscr, *curscr;
100 
101 #define	VOID(x)	(x)
102 
103 /*
104  * pseudo functions for standard screen
105  */
106 #define	addch(ch)	VOID(waddch(stdscr, ch))
107 #define	getch()		VOID(wgetch(stdscr))
108 #define	addstr(str)	VOID(waddstr(stdscr, str))
109 #define	getstr(str)	VOID(wgetstr(stdscr, str))
110 #define	move(y, x)	VOID(wmove(stdscr, y, x))
111 #define	clear()		VOID(wclear(stdscr))
112 #define	erase()		VOID(werase(stdscr))
113 #define	clrtobot()	VOID(wclrtobot(stdscr))
114 #define	clrtoeol()	VOID(wclrtoeol(stdscr))
115 #define	insertln()	VOID(winsertln(stdscr))
116 #define	deleteln()	VOID(wdeleteln(stdscr))
117 #define	refresh()	VOID(wrefresh(stdscr))
118 #define	inch()		VOID(winch(stdscr))
119 #define	insch(c)	VOID(winsch(stdscr, c))
120 #define	delch()		VOID(wdelch(stdscr))
121 #define	standout()	VOID(wstandout(stdscr))
122 #define	standend()	VOID(wstandend(stdscr))
123 
124 /*
125  * mv functions
126  */
127 #define	mvwaddch(win, y, x, ch)	VOID(wmove(win, y, x) == ERR ? \
128 				ERR:waddch(win, ch))
129 #define	mvwgetch(win, y, x)	VOID(wmove(win, y, x) == ERR?ERR:wgetch(win))
130 #define	mvwaddstr(win, y, x, str)	VOID(wmove(win, y, x) == ERR? \
131 					ERR:waddstr(win, str))
132 #define	mvwgetstr(win, y, x, str)	VOID(wmove(win, y, x) == ERR? \
133 					ERR:wgetstr(win, str))
134 #define	mvwinch(win, y, x)	VOID(wmove(win, y, x) == ERR ? ERR : winch(win))
135 #define	mvwdelch(win, y, x)	VOID(wmove(win, y, x) == ERR ? \
136 				ERR : wdelch(win))
137 #define	mvwinsch(win, y, x, c)	VOID(wmove(win, y, x) == ERR ? \
138 				ERR:winsch(win, c))
139 #define	mvaddch(y, x, ch)	mvwaddch(stdscr, y, x, ch)
140 #define	mvgetch(y, x)		mvwgetch(stdscr, y, x)
141 #define	mvaddstr(y, x, str)	mvwaddstr(stdscr, y, x, str)
142 #define	mvgetstr(y, x, str)	mvwgetstr(stdscr, y, x, str)
143 #define	mvinch(y, x)		mvwinch(stdscr, y, x)
144 #define	mvdelch(y, x)		mvwdelch(stdscr, y, x)
145 #define	mvinsch(y, x, c)	mvwinsch(stdscr, y, x, c)
146 
147 /*
148  * pseudo functions
149  */
150 
151 #define	clearok(win, bf)	(win->_clear = bf)
152 #define	leaveok(win, bf)	(win->_leave = bf)
153 #define	scrollok(win, bf)	(win->_scroll = bf)
154 #define	flushok(win, bf)	(bf ? (win->_flags |= _FLUSH): \
155 				(win->_flags &= ~_FLUSH))
156 #define	getyx(win, y, x)	 y = win->_cury, x = win->_curx
157 #define	winch(win)		(win->_y[win->_cury][win->_curx] & 0177)
158 
159 #define	raw()	 (_tty.sg_flags |= RAW, _pfast = _rawmode = TRUE, \
160 		(void) stty(_tty_ch, &_tty))
161 #define	noraw()  (_tty.sg_flags &= ~RAW, _rawmode = FALSE, \
162 		_pfast = !(_tty.sg_flags & CRMOD), (void) stty(_tty_ch, &_tty))
163 #define	cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, \
164 		(void) stty(_tty_ch, &_tty))
165 #define	nocbreak() (_tty.sg_flags &= ~CBREAK, _rawmode = FALSE, \
166 		(void) stty(_tty_ch, &_tty))
167 #define	crmode() cbreak()	/* backwards compatability */
168 #define	nocrmode() nocbreak()	/* backwards compatability */
169 #define	echo()	 (_tty.sg_flags |= ECHO, _echoit = TRUE, \
170 		(void) stty(_tty_ch, &_tty))
171 #define	noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, \
172 		(void) stty(_tty_ch, &_tty))
173 #define	nl()	 (_tty.sg_flags |= CRMOD, _pfast = _rawmode, \
174 		(void) stty(_tty_ch, &_tty))
175 #define	nonl()	 (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, \
176 		(void) stty(_tty_ch, &_tty))
177 #define	savetty() ((void) gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
178 #define	resetty() (_tty.sg_flags = _res_flg, (void) stty(_tty_ch, &_tty))
179 
180 #define	erasechar()	(_tty.sg_erase)
181 #define	killchar()	(_tty.sg_kill)
182 #define	baudrate()	(_tty.sg_ospeed)
183 
184 /*
185  * chtype is the type used to store a character together with attributes.
186  * It can be set to "char" to save space, or "int" to get more attributes.
187  */
188 #ifdef CHTYPE
189 typedef CHTYPE chtype;
190 #else
191 typedef unsigned int chtype;
192 #endif
193 
194 #ifndef __STDC__
195 WINDOW	*initscr(), *newwin(), *subwin();
196 char	*longname(), *getcap();
197 #else
198 extern WINDOW *initscr(void);
199 extern WINDOW *newwin(int, int, int, int);
200 extern WINDOW *subwin(WINDOW *, int, int, int, int);
201 extern char *longname(char *, char *);
202 extern char *getcap(char *);
203 extern char *wstandout(WINDOW *);
204 extern char *wstandend(WINDOW *);
205 extern int gettmode(void);
206 extern int idlok(WINDOW *, bool);
207 extern int box(WINDOW *, char, char);
208 extern int touchwin(WINDOW *);
209 extern int touchline(WINDOW *, int, int, int);
210 extern int mvcur(int, int, int, int);
211 extern int wmove(WINDOW *, int, int);
212 extern int scroll(WINDOW *);
213 extern int werase(WINDOW *);
214 extern int wrefresh(WINDOW *);
215 extern int endwin(void);
216 extern int mvwin(WINDOW *, int, int);
217 extern int delwin(WINDOW *);
218 extern int overlay(WINDOW *, WINDOW *);
219 extern int overwrite(WINDOW *, WINDOW *);
220 extern int winsertln(WINDOW *);
221 extern int wdeleteln(WINDOW *);
222 extern int wgetstr(WINDOW *, char *);
223 extern int wgetch(WINDOW *);
224 extern int waddch(WINDOW *, char);
225 extern int waddstr(WINDOW *, char *);
226 extern int winsch(WINDOW *, char);
227 extern int wdelch(WINDOW *);
228 extern int wclear(WINDOW *);
229 extern int wclrtobot(WINDOW *);
230 extern int wclrtoeol(WINDOW *);
231 extern int printw(char *, ...);
232 extern int wprintw(WINDOW *, char *, ...);
233 extern int mvprintw(int, int, char *, ...);
234 extern int mvwprintw(WINDOW *, int, int, char *, ...);
235 extern int scanw(char *, ...);
236 extern int wscanw(WINDOW *, char *, ...);
237 extern int mvscanw(int, int, char *, ...);
238 extern int mvwscanw(WINDOW *, int, int, char *, ...);
239 extern int setterm(char *);
240 #endif	/* __STDC__ */
241 
242 /*
243  * Used to be in unctrl.h.
244  */
245 #define	unctrl(c)	_unctrl[(c) & 0177]
246 extern char *_unctrl[];
247 #endif
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 
253 #endif	/* _CURSES_H */
254