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
48extern char	 GT;			/* Gtty indicates tabs. */
49extern char	 NONL;			/* Term can't hack LF doing a CR. */
50extern char	 UPPERCASE;		/* Terminal is uppercase only. */
51
52extern int	 My_term;		/* Use Def_term regardless. */
53extern char	*Def_term;		/* Default terminal type. */
54
55/* Termcap capabilities. */
56extern char	AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS,
57		PC, UL, XB, XN, XT, XS, XX;
58extern 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
73extern char	*__unctrl[256];	/* Control strings. */
74extern 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 */
86typedef 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
95typedef 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
106typedef 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. */
129extern WINDOW	*curscr;		/* Current screen. */
130extern WINDOW	*stdscr;		/* Standard screen. */
131
132extern struct termios __orig_termios;	/* Terminal state before curses */
133extern struct termios __baset;		/* Our base terminal state */
134extern int __tcaction;			/* If terminal hardware set. */
135
136extern int	 COLS;			/* Columns on the screen. */
137extern int	 LINES;			/* Lines on the screen. */
138
139extern 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
212int	 box(WINDOW *, int, int);
213int	 cbreak(void);
214int	 delwin(WINDOW *);
215int	 echo(void);
216int	 endwin(void);
217char	*fullname(char *, char *);
218char	*getcap(char *);
219int	 gettmode(void);
220void	 idlok(WINDOW *, int);
221WINDOW	*initscr(void);
222char	*longname(char *, char *);
223int	 mvcur(int, int, int, int);
224int	 mvprintw(int, int, const char *, ...);
225int	 mvscanw(int, int, const char *, ...);
226int	 mvwin(WINDOW *, int, int);
227int	 mvwprintw(WINDOW *, int, int, const char *, ...);
228int	 mvwscanw(WINDOW *, int, int, const char *, ...);
229WINDOW	*newwin(int, int, int, int);
230int	 nl(void);
231int	 nocbreak(void);
232int	 noecho(void);
233int	 nonl(void);
234int	 noraw(void);
235int	 overlay(WINDOW *, WINDOW *);
236int	 overwrite(WINDOW *, WINDOW *);
237int	 printw(const char *, ...);
238int	 raw(void);
239int	 resetty(void);
240int	 savetty(void);
241int	 scanw(const char *, ...);
242int	 scroll(WINDOW *);
243int	 setterm(char *);
244int	 sscans(WINDOW *, const char *, ...);
245WINDOW	*subwin(WINDOW *, int, int, int, int);
246int	 suspendwin(void);
247int	 touchline(WINDOW *, int, int, int);
248int	 touchoverlap(WINDOW *, WINDOW *);
249int	 touchwin(WINDOW *);
250int	 vwprintw(WINDOW *, const char *, __va_list);
251int      vwscanw(WINDOW *, const char *, __va_list);
252int	 waddch(WINDOW *, int);
253int	 waddnstr(WINDOW *, const char *, int);
254int	 wclear(WINDOW *);
255int	 wclrtobot(WINDOW *);
256int	 wclrtoeol(WINDOW *);
257int	 wdelch(WINDOW *);
258int	 wdeleteln(WINDOW *);
259int	 werase(WINDOW *);
260int	 wgetch(WINDOW *);
261int	 wgetstr(WINDOW *, char *);
262int	 winsch(WINDOW *, int);
263int	 winsertln(WINDOW *);
264int	 wmove(WINDOW *, int, int);
265int	 wprintw(WINDOW *, const char *, ...);
266int	 wrefresh(WINDOW *);
267int	 wscanw(WINDOW *, const char *, ...);
268int	 wstandend(WINDOW *);
269int	 wstandout(WINDOW *);
270int	 vwprintw(WINDOW *, const char *, __va_list);
271
272/* Private functions that are needed for user programs prototypes. */
273void	 __cputchar(int);
274int	 __waddbytes(WINDOW *, const char *, int, int);
275__END_DECLS
276
277/* Private functions. */
278void	 __CTRACE(const char *, ...);
279unsigned int	 __hash(char *, int);
280void	 __id_subwins(WINDOW *);
281int	 __mvcur(int, int, int, int, int);
282void	 __restore_stophandler(void);
283void	 __set_stophandler(void);
284void	 __set_subwin(WINDOW *, WINDOW *);
285void	 __startwin(void);
286void	 __stop_signal_handler(int);
287void	 __swflags(WINDOW *);
288int	 __touchline(WINDOW *, int, int, int, int);
289int	 __touchwin(WINDOW *);
290char	*__tscroll(const char *, int, int);
291int	 __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. */
298extern int	 __echoit;
299extern int	 __endwin;
300extern int	 __pfast;
301extern int	 __rawmode;
302extern int	 __noqch;
303
304/* Termcap functions. */
305__BEGIN_DECLS
306int	 tgetent(char *, char *);
307int	 tgetnum(char *);
308int	 tgetflag(char *);
309char	*tgetstr(char *, char **);
310char	*tgoto(char *, int, int);
311void	 tputs(char *, int, void (*)(int));
312__END_DECLS
313
314#endif /* !_OCURSES_H_ */
315