xref: /original-bsd/lib/libcurses/curses.h (revision 65d10654)
1 /*
2  * Copyright (c) 1981, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)curses.h	8.5 (Berkeley) 04/29/95
8  */
9 
10 #ifndef _CURSES_H_
11 #define	_CURSES_H_
12 
13 #include <stdio.h>
14 
15 /*
16  * The following #defines and #includes are present for backward
17  * compatibility only.  They should not be used in future code.
18  *
19  * START BACKWARD COMPATIBILITY ONLY.
20  */
21 #ifndef _CURSES_PRIVATE
22 #ifndef __cplusplus
23 #define	bool	char
24 #endif
25 #define	reg	register
26 
27 #ifndef TRUE
28 #define	TRUE	(1)
29 #endif
30 #ifndef FALSE
31 #define	FALSE	(0)
32 #endif
33 
34 #define	_puts(s)	tputs(s, 0, __cputchar)
35 #define	_putchar(c)	__cputchar(c)
36 
37 /* Old-style terminal modes access. */
38 #define	baudrate()	(cfgetospeed(&__baset))
39 #define	crmode()	cbreak()
40 #define	erasechar()	(__baset.c_cc[VERASE])
41 #define	killchar()	(__baset.c_cc[VKILL])
42 #define	nocrmode()	nocbreak()
43 #define	ospeed		(cfgetospeed(&__baset))
44 #endif /* _CURSES_PRIVATE */
45 
46 extern char	 GT;			/* Gtty indicates tabs. */
47 extern char	 NONL;			/* Term can't hack LF doing a CR. */
48 extern char	 UPPERCASE;		/* Terminal is uppercase only. */
49 
50 extern int	 My_term;		/* Use Def_term regardless. */
51 extern char	*Def_term;		/* Default terminal type. */
52 
53 /* Termcap capabilities. */
54 extern char	AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS,
55 		PC, UL, XB, XN, XT, XS, XX;
56 extern char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
57 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
58 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
59 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
60 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
61 		*VE, *al, *dl, *sf, *sr,
62 		*AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
63 		*RIGHT_PARM;
64 
65 /* END BACKWARD COMPATIBILITY ONLY. */
66 
67 /* 8-bit ASCII characters. */
68 #define	unctrl(c)		__unctrl[(c) & 0xff]
69 #define	unctrllen(ch)		__unctrllen[(ch) & 0xff]
70 
71 extern char	*__unctrl[256];	/* Control strings. */
72 extern char	 __unctrllen[256];	/* Control strings length. */
73 
74 /*
75  * A window an array of __LINE structures pointed to by the 'lines' pointer.
76  * A line is an array of __LDATA structures pointed to by the 'line' pointer.
77  *
78  * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
79  * fields are added -- padding fields with *constant values* should ensure
80  * that the compiler will not generate any padding when storing an array of
81  *  __LDATA structures.  This is to enable consistent use of memcmp, and memcpy
82  * for comparing and copying arrays.
83  */
84 typedef struct {
85 	char ch;			/* the actual character */
86 
87 #define	__STANDOUT	0x01  		/* Added characters are standout. */
88 	char attr;			/* attributes of character */
89 } __LDATA;
90 
91 #define __LDATASIZE	(sizeof(__LDATA))
92 
93 typedef struct {
94 #define	__ISDIRTY	0x01		/* Line is dirty. */
95 #define __ISPASTEOL	0x02		/* Cursor is past end of line */
96 #define __FORCEPAINT	0x04		/* Force a repaint of the line */
97 	u_int flags;
98 	u_int hash;			/* Hash value for the line. */
99 	size_t *firstchp, *lastchp;	/* First and last chngd columns ptrs */
100 	size_t firstch, lastch;		/* First and last changed columns. */
101 	__LDATA *line;			/* Pointer to the line text. */
102 } __LINE;
103 
104 typedef struct __window {		/* Window structure. */
105 	struct __window	*nextp, *orig;	/* Subwindows list and parent. */
106 	size_t begy, begx;		/* Window home. */
107 	size_t cury, curx;		/* Current x, y coordinates. */
108 	size_t maxy, maxx;		/* Maximum values for curx, cury. */
109 	short ch_off;			/* x offset for firstch/lastch. */
110 	__LINE **lines;			/* Array of pointers to the lines */
111 	__LINE  *lspace;		/* line space (for cleanup) */
112 	__LDATA *wspace;		/* window space (for cleanup) */
113 
114 #define	__ENDLINE	0x001		/* End of screen. */
115 #define	__FLUSH		0x002		/* Fflush(stdout) after refresh. */
116 #define	__FULLWIN	0x004		/* Window is a screen. */
117 #define	__IDLINE	0x008		/* Insert/delete sequences. */
118 #define	__SCROLLWIN	0x010		/* Last char will scroll window. */
119 #define	__SCROLLOK	0x020		/* Scrolling ok. */
120 #define	__CLEAROK	0x040		/* Clear on next refresh. */
121 #define __WSTANDOUT	0x080		/* Standout window */
122 #define __LEAVEOK	0x100		/* If curser left */
123 	u_int flags;
124 } WINDOW;
125 
126 /* Curses external declarations. */
127 extern WINDOW	*curscr;		/* Current screen. */
128 extern WINDOW	*stdscr;		/* Standard screen. */
129 
130 extern struct termios __orig_termios;	/* Terminal state before curses */
131 extern struct termios __baset;		/* Our base terminal state */
132 extern int __tcaction;			/* If terminal hardware set. */
133 
134 extern int	 COLS;			/* Columns on the screen. */
135 extern int	 LINES;			/* Lines on the screen. */
136 
137 extern char	*ttytype;		/* Full name of current terminal. */
138 
139 #define	ERR	(0)			/* Error return. */
140 #define	OK	(1)			/* Success return. */
141 
142 /* Standard screen pseudo functions. */
143 #define	addbytes(s, n)			__waddbytes(stdscr, s, n, 0)
144 #define	addch(ch)			waddch(stdscr, ch)
145 #define	addnstr(s, n)			waddnstr(stdscr, s, n)
146 #define	addstr(s)			__waddbytes(stdscr, s, strlen(s), 0)
147 #define	clear()				wclear(stdscr)
148 #define	clrtobot()			wclrtobot(stdscr)
149 #define	clrtoeol()			wclrtoeol(stdscr)
150 #define	delch()				wdelch(stdscr)
151 #define	deleteln()			wdeleteln(stdscr)
152 #define	erase()				werase(stdscr)
153 #define	getch()				wgetch(stdscr)
154 #define	getstr(s)			wgetstr(stdscr, s)
155 #define	inch()				winch(stdscr)
156 #define	insch(ch)			winsch(stdscr, ch)
157 #define	insertln()			winsertln(stdscr)
158 #define	move(y, x)			wmove(stdscr, y, x)
159 #define	refresh()			wrefresh(stdscr)
160 #define	standend()			wstandend(stdscr)
161 #define	standout()			wstandout(stdscr)
162 #define	waddbytes(w, s, n)		__waddbytes(w, s, n, 0)
163 #define	waddstr(w, s)			__waddbytes(w, s, strlen(s), 0)
164 
165 /* Standard screen plus movement pseudo functions. */
166 #define	mvaddbytes(y, x, s, n)		mvwaddbytes(stdscr, y, x, s, n)
167 #define	mvaddch(y, x, ch)		mvwaddch(stdscr, y, x, ch)
168 #define	mvaddnstr(y, x, s, n)		mvwaddnstr(stdscr, y, x, s, n)
169 #define	mvaddstr(y, x, s)		mvwaddstr(stdscr, y, x, s)
170 #define	mvdelch(y, x)			mvwdelch(stdscr, y, x)
171 #define	mvgetch(y, x)			mvwgetch(stdscr, y, x)
172 #define	mvgetstr(y, x, s)		mvwgetstr(stdscr, y, x, s)
173 #define	mvinch(y, x)			mvwinch(stdscr, y, x)
174 #define	mvinsch(y, x, c)		mvwinsch(stdscr, y, x, c)
175 #define	mvwaddbytes(w, y, x, s, n) \
176 	(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0))
177 #define	mvwaddch(w, y, x, ch) \
178 	(wmove(w, y, x) == ERR ? ERR : waddch(w, ch))
179 #define	mvwaddnstr(w, y, x, s, n) \
180 	(wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n))
181 #define	mvwaddstr(w, y, x, s) \
182 	(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0))
183 #define	mvwdelch(w, y, x) \
184 	(wmove(w, y, x) == ERR ? ERR : wdelch(w))
185 #define	mvwgetch(w, y, x) \
186 	(wmove(w, y, x) == ERR ? ERR : wgetch(w))
187 #define	mvwgetstr(w, y, x, s) \
188 	(wmove(w, y, x) == ERR ? ERR : wgetstr(w, s))
189 #define	mvwinch(w, y, x) \
190 	(wmove(w, y, x) == ERR ? ERR : winch(w))
191 #define	mvwinsch(w, y, x, c) \
192 	(wmove(w, y, x) == ERR ? ERR : winsch(w, c))
193 
194 /* Psuedo functions. */
195 #define	clearok(w, bf) \
196 	((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK))
197 #define	flushok(w, bf) \
198 	((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH))
199 #define	getyx(w, y, x) \
200 	(y) = (w)->cury, (x) = (w)->curx
201 #define	leaveok(w, bf) \
202 	((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK))
203 #define	scrollok(w, bf) \
204 	((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK))
205 #define	winch(w) \
206 	((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177)
207 
208 /* Public function prototypes. */
209 int	 box __P((WINDOW *, int, int));
210 int	 cbreak __P((void));
211 int	 delwin __P((WINDOW *));
212 int	 echo __P((void));
213 int	 endwin __P((void));
214 char	*fullname __P((char *, char *));
215 char	*getcap __P((char *));
216 int	 gettmode __P((void));
217 void	 idlok __P((WINDOW *, int));
218 WINDOW	*initscr __P((void));
219 char	*longname __P((char *, char *));
220 int	 mvcur __P((int, int, int, int));
221 int	 mvprintw __P((int, int, const char *, ...));
222 int	 mvscanw __P((int, int, const char *, ...));
223 int	 mvwin __P((WINDOW *, int, int));
224 int	 mvwprintw __P((WINDOW *, int, int, const char *, ...));
225 int	 mvwscanw __P((WINDOW *, int, int, const char *, ...));
226 WINDOW	*newwin __P((int, int, int, int));
227 int	 nl __P((void));
228 int	 nocbreak __P((void));
229 int	 noecho __P((void));
230 int	 nonl __P((void));
231 int	 noraw __P((void));
232 int	 overlay __P((WINDOW *, WINDOW *));
233 int	 overwrite __P((WINDOW *, WINDOW *));
234 int	 printw __P((const char *, ...));
235 int	 raw __P((void));
236 int	 resetty __P((void));
237 int	 savetty __P((void));
238 int	 scanw __P((const char *, ...));
239 int	 scroll __P((WINDOW *));
240 int	 setterm __P((char *));
241 int	 sscans __P((WINDOW *, const char *, ...));
242 WINDOW	*subwin __P((WINDOW *, int, int, int, int));
243 int	 suspendwin __P((void));
244 int	 touchline __P((WINDOW *, int, int, int));
245 int	 touchoverlap __P((WINDOW *, WINDOW *));
246 int	 touchwin __P((WINDOW *));
247 int 	 vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
248 int      vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_));
249 int	 waddch __P((WINDOW *, int));
250 int	 waddnstr __P((WINDOW *, const char *, int));
251 int	 wclear __P((WINDOW *));
252 int	 wclrtobot __P((WINDOW *));
253 int	 wclrtoeol __P((WINDOW *));
254 int	 wdelch __P((WINDOW *));
255 int	 wdeleteln __P((WINDOW *));
256 int	 werase __P((WINDOW *));
257 int	 wgetch __P((WINDOW *));
258 int	 wgetstr __P((WINDOW *, char *));
259 int	 winsch __P((WINDOW *, int));
260 int	 winsertln __P((WINDOW *));
261 int	 wmove __P((WINDOW *, int, int));
262 int	 wprintw __P((WINDOW *, const char *, ...));
263 int	 wrefresh __P((WINDOW *));
264 int	 wscanw __P((WINDOW *, const char *, ...));
265 int	 wstandend __P((WINDOW *));
266 int	 wstandout __P((WINDOW *));
267 int	 vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
268 
269 /* Private functions that are needed for user programs prototypes. */
270 void	 __cputchar __P((int));
271 int	 __waddbytes __P((WINDOW *, const char *, int, int));
272 
273 /* Private functions. */
274 #ifdef _CURSES_PRIVATE
275 void	 __CTRACE __P((const char *, ...));
276 u_int	 __hash __P((char *, int));
277 void	 __id_subwins __P((WINDOW *));
278 int	 __mvcur __P((int, int, int, int, int));
279 void	 __restore_stophandler __P((void));
280 void	 __set_stophandler __P((void));
281 void	 __set_subwin __P((WINDOW *, WINDOW *));
282 void	 __startwin __P((void));
283 void	 __stop_signal_handler __P((int));
284 void	 __swflags __P((WINDOW *));
285 int	 __touchline __P((WINDOW *, int, int, int, int));
286 int	 __touchwin __P((WINDOW *));
287 char	*__tscroll __P((const char *, int, int));
288 int	 __waddch __P((WINDOW *, __LDATA *));
289 
290 /* Private #defines. */
291 #define	min(a,b)	(a < b ? a : b)
292 #define	max(a,b)	(a > b ? a : b)
293 
294 /* Private externs. */
295 extern int	 __echoit;
296 extern int	 __endwin;
297 extern int	 __pfast;
298 extern int	 __rawmode;
299 extern int	 __noqch;
300 #endif
301 
302 /* Termcap functions. */
303 int	 tgetent __P((char *, char *));
304 int	 tgetnum __P((char *));
305 int	 tgetflag __P((char *));
306 char	*tgetstr __P((char *, char **));
307 char	*tgoto __P((char *, int, int));
308 int	 tputs __P((char *, int, void (*)(int)));
309 
310 #endif /* !_CURSES_H_ */
311