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