xref: /csrg-svn/lib/libcurses/curses.h (revision 57477)
122686Sdist /*
234677Sbostic  * Copyright (c) 1981 Regents of the University of California.
334677Sbostic  * All rights reserved.
422686Sdist  *
542653Sbostic  * %sccs.include.redist.c%
634677Sbostic  *
7*57477Sbostic  *	@(#)curses.h	5.23 (Berkeley) 01/11/93
822686Sdist  */
922686Sdist 
1055990Sbostic #ifndef _CURSES_H_
1155990Sbostic #define	_CURSES_H_
122244Sarnold 
1355990Sbostic #include <stdio.h>
142244Sarnold 
1555990Sbostic /*
1655990Sbostic  * The following #defines and #includes are present for backward
1755990Sbostic  * compatibility only.  They should not be used in future code.
1855990Sbostic  *
1955990Sbostic  * START BACKWARD COMPATIBILITY ONLY.
2055990Sbostic  */
2155990Sbostic #ifndef _CURSES_PRIVATE
2238839Skarels #define	bool	char
2338839Skarels #define	reg	register
242244Sarnold 
2555990Sbostic #ifndef TRUE
2638839Skarels #define	TRUE	(1)
2755990Sbostic #endif
2855990Sbostic #ifndef FALSE
2938839Skarels #define	FALSE	(0)
3055990Sbostic #endif
312244Sarnold 
3256116Selan #define	_puts(s)	tputs(s, 0, __cputchar)
3355990Sbostic #define	_putchar(c)	__cputchar(c)
342244Sarnold 
3555990Sbostic /* Old-style terminal modes access. */
3656116Selan #define	baudrate()	(cfgetospeed(&origtermio))
3755990Sbostic #define	crmode()	cbreak()
3855990Sbostic #define	erasechar()	(origtermio.c_cc[VERASE])
3955990Sbostic #define	killchar()	(origtermio.c_cc[VKILL])
4055990Sbostic #define	nocrmode()	nocbreak()
4156116Selan #define	ospeed		(cfgetospeed(&origtermio))
4255990Sbostic #endif /* _CURSES_PRIVATE */
432244Sarnold 
44*57477Sbostic extern char	 GT;			/* Gtty indicates tabs. */
45*57477Sbostic extern char	 NONL;			/* Term can't hack LF doing a CR. */
46*57477Sbostic extern char	 UPPERCASE;		/* Terminal is uppercase only. */
47*57477Sbostic 
4855990Sbostic extern int	 My_term;		/* Use Def_term regardless. */
4955990Sbostic extern char	*Def_term;		/* Default terminal type. */
5055990Sbostic 
51*57477Sbostic /* Termcap capabilities. */
52*57477Sbostic extern char	AM, BS, CA, DA, EO, HC, HZ, IN, MI, MS, NC, NS, OS,
53*57477Sbostic 		PC, UL, XB, XN, XT, XS, XX;
54*57477Sbostic extern char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
55*57477Sbostic 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
56*57477Sbostic 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
57*57477Sbostic 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
58*57477Sbostic 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
59*57477Sbostic 		*VE, *al, *dl, *sf, *sr,
60*57477Sbostic 		*AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
61*57477Sbostic 		*RIGHT_PARM;
62*57477Sbostic 
6355990Sbostic /* END BACKWARD COMPATIBILITY ONLY. */
6455990Sbostic 
6555990Sbostic /* 7-bit ASCII characters. */
6655990Sbostic #define	unctrl(c)		__unctrl[(c) & 0x7f]
6755990Sbostic #define	unctrllen(ch)		__unctrllen[(ch) & 0x7f]
6855990Sbostic 
69*57477Sbostic extern char	*__unctrl[0x80];	/* Control strings. */
70*57477Sbostic extern char	 __unctrllen[0x80];	/* Control strings length. */
71*57477Sbostic 
7256238Selan /*
7356647Selan  * A window an array of __LINE structures pointed to by the 'lines' pointer.
7456647Selan  * A line is an array of __LDATA structures pointed to by the 'line' pointer.
7556647Selan  *
7656647Selan  * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
7756647Selan  * fields are added -- padding fields with *constant values* should ensure
7856647Selan  * that the compiler will not generate any padding when storing an array of
7956647Selan  *  __LDATA structures.  This is to enable consistent use of bcmp, and bcopy
8056647Selan  * for comparing and copying arrays.
8156238Selan  */
8256647Selan typedef struct {
8356647Selan 	char ch;			/* the actual character */
8456647Selan 
8556647Selan #define	__STANDOUT	0x01  		/* Added characters are standout. */
8656647Selan 	char attr;			/* attributes of character */
8756647Selan } __LDATA;
8856647Selan 
8956647Selan #define __LDATASIZE	(sizeof(__LDATA))
9056647Selan 
9156647Selan typedef struct {
9256238Selan #define	__ISDIRTY	0x01		/* Line is dirty. */
9356300Selan #define __ISPASTEOL	0x02		/* Cursor is past end of line */
9456650Selan #define __FORCEPAINT	0x04		/* Force a repaint of the line */
9556238Selan 	u_int flags;
9656238Selan 	u_int hash;			/* Hash value for the line. */
9756715Selan 	size_t *firstchp, *lastchp;	/* First and last chngd columns ptrs */
9856238Selan 	size_t firstch, lastch;		/* First and last changed columns. */
9956647Selan 	__LDATA *line;			/* Pointer to the line text. */
10056647Selan } __LINE;
10156596Selan 
10256238Selan typedef struct __window {		/* Window structure. */
10356238Selan 	struct __window	*nextp, *orig;	/* Subwindows list and parent. */
10456238Selan 	size_t begy, begx;		/* Window home. */
10556238Selan 	size_t cury, curx;		/* Current x, y coordinates. */
10656238Selan 	size_t maxy, maxx;		/* Maximum values for curx, cury. */
10756238Selan 	short ch_off;			/* x offset for firstch/lastch. */
10856647Selan 	__LINE **lines;			/* Array of pointers to the lines */
10956647Selan 	__LINE  *lspace;		/* line space (for cleanup) */
11056647Selan 	__LDATA *wspace;		/* window space (for cleanup) */
11155990Sbostic 
11256238Selan #define	__ENDLINE	0x001		/* End of screen. */
11356238Selan #define	__FLUSH		0x002		/* Fflush(stdout) after refresh. */
11456238Selan #define	__FULLLINE	0x004		/* Line width = terminal width. */
11556238Selan #define	__FULLWIN	0x008		/* Window is a screen. */
11656238Selan #define	__IDLINE	0x010		/* Insert/delete sequences. */
11756238Selan #define	__SCROLLWIN	0x020		/* Last char will scroll window. */
11856238Selan #define	__SCROLLOK	0x040		/* Scrolling ok. */
11956238Selan #define	__CLEAROK	0x080		/* Clear on next refresh. */
12056238Selan #define __WSTANDOUT	0x100		/* Standout window */
12156238Selan #define __LEAVEOK	0x200		/* If curser left */
12256238Selan 	u_int flags;
12355990Sbostic } WINDOW;
12455990Sbostic 
12555990Sbostic /* Curses external declarations. */
12655990Sbostic extern WINDOW	*curscr;		/* Current screen. */
12755990Sbostic extern WINDOW	*stdscr;		/* Standard screen. */
1282244Sarnold 
12955990Sbostic extern struct termios origtermio;	/* Original terminal modes. */
1302244Sarnold 
13155990Sbostic extern int	 COLS;			/* Columns on the screen. */
13255990Sbostic extern int	 LINES;			/* Lines on the screen. */
1332244Sarnold 
13455990Sbostic extern char	*ttytype;		/* Full name of current terminal. */
1352244Sarnold 
13655990Sbostic #define	ERR	(0)			/* Error return. */
13755990Sbostic #define	OK	(1)			/* Success return. */
1382244Sarnold 
13955990Sbostic /* Standard screen pseudo functions. */
140*57477Sbostic #define	addbytes(da, co)		waddbytes(stdscr, da, co)
141*57477Sbostic #define	addch(ch)			waddch(stdscr, ch)
142*57477Sbostic #define	addstr(str)			waddbytes(stdscr, str, strlen(str))
143*57477Sbostic #define	clear()				wclear(stdscr)
144*57477Sbostic #define	clrtobot()			wclrtobot(stdscr)
145*57477Sbostic #define	clrtoeol()			wclrtoeol(stdscr)
146*57477Sbostic #define	delch()				wdelch(stdscr)
147*57477Sbostic #define	deleteln()			wdeleteln(stdscr)
148*57477Sbostic #define	erase()				werase(stdscr)
149*57477Sbostic #define	getch()				wgetch(stdscr)
150*57477Sbostic #define	getstr(str)			wgetstr(stdscr, str)
151*57477Sbostic #define	inch()				winch(stdscr)
152*57477Sbostic #define	insch(ch))			winsch(stdscr, ch)
153*57477Sbostic #define	insertln()			winsertln(stdscr)
154*57477Sbostic #define	move(y, x)			wmove(stdscr, y, x)
155*57477Sbostic #define	refresh()			wrefresh(stdscr)
156*57477Sbostic #define	standend()			wstandend(stdscr)
157*57477Sbostic #define	standout()			wstandout(stdscr)
1582244Sarnold 
15955990Sbostic /* Standard screen plus movement pseudo functions. */
160*57477Sbostic #define	mvaddbytes(y, x, da, co)	mvwaddbytes(stdscr, y, x, da, co)
161*57477Sbostic #define	mvaddch(y, x, ch)		mvwaddch(stdscr, y, x, ch)
162*57477Sbostic #define	mvaddstr(y, x, str)		mvwaddstr(stdscr, y, x, str)
163*57477Sbostic #define	mvdelch(y, x)			mvwdelch(stdscr, y, x)
164*57477Sbostic #define	mvgetch(y, x)			mvwgetch(stdscr, y, x)
165*57477Sbostic #define	mvgetstr(y, x, str)		mvwgetstr(stdscr, y, x, str)
166*57477Sbostic #define	mvinch(y, x)			mvwinch(stdscr, y, x)
167*57477Sbostic #define	mvinsch(y, x, c)		mvwinsch(stdscr, y, x, c)
16855990Sbostic #define	mvwaddbytes(win, y, x, da, co) \
169*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : waddbytes(win, da, co))
170*57477Sbostic #define	mvwaddch(win, y, x, ch) \
171*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : waddch(win, ch))
17255990Sbostic #define	mvwaddstr(win, y, x, str) \
173*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : waddbytes(win, str, strlen(str)))
174*57477Sbostic #define	mvwdelch(win, y, x) \
175*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : wdelch(win))
176*57477Sbostic #define	mvwgetch(win, y, x) \
177*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : wgetch(win))
17855990Sbostic #define	mvwgetstr(win, y, x, str) \
179*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : wgetstr(win, str))
180*57477Sbostic #define	mvwinch(win, y, x) \
181*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : winch(win))
182*57477Sbostic #define	mvwinsch(win, y, x, c) \
183*57477Sbostic 	(wmove(win, y, x) == ERR ? ERR : winsch(win, c))
1842244Sarnold 
185*57477Sbostic /* Psuedo functions. */
186*57477Sbostic #define	clearok(win, bf) \
187*57477Sbostic 	((bf) ? (win->flags |= __CLEAROK) : (win->flags &= ~__CLEAROK))
188*57477Sbostic #define	flushok(win, bf) \
189*57477Sbostic 	((bf) ? (win->flags |= __FLUSH) : (win->flags &= ~__FLUSH))
190*57477Sbostic #define	getyx(win, y, x) \
191*57477Sbostic 	(y) = win->cury, (x) = win->curx
192*57477Sbostic #define	leaveok(win, bf) \
193*57477Sbostic 	((bf) ? (win->flags |= __LEAVEOK) : (win->flags &= ~__LEAVEOK))
194*57477Sbostic #define	scrollok(win, bf) \
195*57477Sbostic 	((bf) ? (win->flags |= __SCROLLOK) : (win->flags &= ~__SCROLLOK))
196*57477Sbostic #define	winch(win) \
197*57477Sbostic 	(win->lines[win->cury]->line[win->curx].ch & 0177)
1982244Sarnold 
19955990Sbostic /* Public function prototypes. */
20055990Sbostic int	 box __P((WINDOW *, int, int));
20155990Sbostic int	 cbreak __P((void));
20255990Sbostic int	 delwin __P((WINDOW *));
20355990Sbostic int	 echo __P((void));
20455990Sbostic int	 endwin __P((void));
20555990Sbostic char	*fullname __P((char *, char *));
20655990Sbostic char	*getcap __P((char *));
20755990Sbostic int	 gettmode __P((void));
20855990Sbostic void	 idlok __P((WINDOW *, int));
20955990Sbostic WINDOW	*initscr __P((void));
21055990Sbostic char	*longname __P((char *, char *));
21155990Sbostic int	 mvcur __P((int, int, int, int));
21255990Sbostic int	 mvprintw __P((int, int, const char *, ...));
21355990Sbostic int	 mvscanw __P((int, int, const char *, ...));
21455990Sbostic int	 mvwin __P((WINDOW *, int, int));
21555990Sbostic int	 mvwprintw __P((WINDOW *, int, int, const char *, ...));
21655990Sbostic int	 mvwscanw __P((WINDOW *, int, int, const char *, ...));
21755990Sbostic WINDOW	*newwin __P((int, int, int, int));
21855990Sbostic int	 nl __P((void));
21955990Sbostic int	 nocbreak __P((void));
22055990Sbostic int	 noecho __P((void));
22155990Sbostic int	 nonl __P((void));
22255990Sbostic int	 noraw __P((void));
22355990Sbostic int	 overlay __P((WINDOW *, WINDOW *));
22455990Sbostic int	 overwrite __P((WINDOW *, WINDOW *));
22555990Sbostic int	 printw __P((const char *, ...));
22655990Sbostic int	 raw __P((void));
22755990Sbostic int	 resetty __P((void));
22855990Sbostic int	 savetty __P((void));
22955990Sbostic int	 scanw __P((const char *, ...));
23055990Sbostic int	 scroll __P((WINDOW *));
23155990Sbostic int	 setterm __P((char *));
23257362Selan int	 sscans __P((WINDOW *, const char *, ...));
23355990Sbostic WINDOW	*subwin __P((WINDOW *, int, int, int, int));
23455990Sbostic int	 suspendwin __P((void));
23555990Sbostic int	 touchline __P((WINDOW *, int, int, int));
23655990Sbostic int	 touchoverlap __P((WINDOW *, WINDOW *));
23755990Sbostic int	 touchwin __P((WINDOW *));
23855990Sbostic void	 tstp __P((int));
23957362Selan int 	 vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
24057362Selan int      vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_));
241*57477Sbostic int	 waddbytes __P((WINDOW *, char *, int));
24255990Sbostic int	 waddch __P((WINDOW *, int));
24355990Sbostic int	 waddstr __P((WINDOW *, char *));
24455990Sbostic int	 wclear __P((WINDOW *));
24555990Sbostic int	 wclrtobot __P((WINDOW *));
24655990Sbostic int	 wclrtoeol __P((WINDOW *));
24755990Sbostic int	 wdelch __P((WINDOW *));
24855990Sbostic int	 wdeleteln __P((WINDOW *));
24955990Sbostic int	 werase __P((WINDOW *));
25055990Sbostic int	 wgetch __P((WINDOW *));
25155990Sbostic int	 wgetstr __P((WINDOW *, char *));
25255990Sbostic int	 winsch __P((WINDOW *, int));
25355990Sbostic int	 winsertln __P((WINDOW *));
25455990Sbostic int	 wmove __P((WINDOW *, int, int));
25555990Sbostic int	 wprintw __P((WINDOW *, const char *, ...));
25655990Sbostic int	 wrefresh __P((WINDOW *));
25755990Sbostic int	 wscanw __P((WINDOW *, const char *, ...));
25855990Sbostic char	*wstandend __P((WINDOW *));
25955990Sbostic char	*wstandout __P((WINDOW *));
260*57477Sbostic int	 vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
2612244Sarnold 
26255990Sbostic #ifdef _CURSES_PRIVATE
26355990Sbostic /* Private function prototypes. */
264*57477Sbostic void	 __cputchar __P((int));
26556650Selan void	 __TRACE __P((const char *, ...));
26655990Sbostic void	 __id_subwins __P((WINDOW *));
26755990Sbostic void	 __set_subwin __P((WINDOW *, WINDOW *));
26855990Sbostic void	 __swflags __P((WINDOW *));
26956650Selan int	 __touchline __P((WINDOW *, int, int, int, int));
27056650Selan int	 __touchwin __P((WINDOW *));
271*57477Sbostic char	*__tscroll __P((const char *, int));
272*57477Sbostic int	 __waddbytes __P((WINDOW *, char *, int, int));
2732244Sarnold 
27455990Sbostic /* Private #defines. */
27555990Sbostic #define	min(a,b)	(a < b ? a : b)
27655990Sbostic #define	max(a,b)	(a > b ? a : b)
2772244Sarnold 
27855990Sbostic /* Private externs. */
27955990Sbostic extern int	 __echoit;
28055990Sbostic extern int	 __endwin;
28155990Sbostic extern int	 __pfast;
28255990Sbostic extern int	 __rawmode;
28356300Selan extern int	 __noqch;
28455990Sbostic #endif
2852244Sarnold 
28655990Sbostic /* Termcap functions. */
28755990Sbostic int	 tgetent __P((char *, char *));
28855990Sbostic int	 tgetnum __P((char *));
28955990Sbostic int	 tgetflag __P((char *));
29055990Sbostic char	*tgetstr __P((char *, char **));
29155990Sbostic char	*tgoto __P((char *, int, int));
29255990Sbostic int	 tputs __P((char *, int, void (*)(int)));
2932244Sarnold 
29455990Sbostic #endif /* !_CURSES_H_ */
295