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