xref: /csrg-svn/lib/libcurses/curses.h (revision 69111)
122686Sdist /*
267569Sbostic  * Copyright (c) 1981, 1993, 1994
362542Sbostic  *	The Regents of the University of California.  All rights reserved.
422686Sdist  *
542653Sbostic  * %sccs.include.redist.c%
634677Sbostic  *
7*69111Sbostic  *	@(#)curses.h	8.5 (Berkeley) 04/29/95
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
22*69111Sbostic #ifndef __cplusplus
2338839Skarels #define	bool	char
24*69111Sbostic #endif
2538839Skarels #define	reg	register
262244Sarnold 
2755990Sbostic #ifndef TRUE
2838839Skarels #define	TRUE	(1)
2955990Sbostic #endif
3055990Sbostic #ifndef FALSE
3138839Skarels #define	FALSE	(0)
3255990Sbostic #endif
332244Sarnold 
3456116Selan #define	_puts(s)	tputs(s, 0, __cputchar)
3555990Sbostic #define	_putchar(c)	__cputchar(c)
362244Sarnold 
3755990Sbostic /* Old-style terminal modes access. */
3861229Smarc #define	baudrate()	(cfgetospeed(&__baset))
3955990Sbostic #define	crmode()	cbreak()
4061229Smarc #define	erasechar()	(__baset.c_cc[VERASE])
4161229Smarc #define	killchar()	(__baset.c_cc[VKILL])
4255990Sbostic #define	nocrmode()	nocbreak()
4361229Smarc #define	ospeed		(cfgetospeed(&__baset))
4455990Sbostic #endif /* _CURSES_PRIVATE */
452244Sarnold 
4657477Sbostic extern char	 GT;			/* Gtty indicates tabs. */
4757477Sbostic extern char	 NONL;			/* Term can't hack LF doing a CR. */
4857477Sbostic extern char	 UPPERCASE;		/* Terminal is uppercase only. */
4957477Sbostic 
5055990Sbostic extern int	 My_term;		/* Use Def_term regardless. */
5155990Sbostic extern char	*Def_term;		/* Default terminal type. */
5255990Sbostic 
5357477Sbostic /* Termcap capabilities. */
5465310Sbostic extern char	AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS,
5557477Sbostic 		PC, UL, XB, XN, XT, XS, XX;
5657477Sbostic extern char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
5757477Sbostic 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
5857477Sbostic 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
5957477Sbostic 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
6057477Sbostic 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
6157477Sbostic 		*VE, *al, *dl, *sf, *sr,
6257477Sbostic 		*AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
6357477Sbostic 		*RIGHT_PARM;
6457477Sbostic 
6555990Sbostic /* END BACKWARD COMPATIBILITY ONLY. */
6655990Sbostic 
6757830Selan /* 8-bit ASCII characters. */
6857830Selan #define	unctrl(c)		__unctrl[(c) & 0xff]
6957830Selan #define	unctrllen(ch)		__unctrllen[(ch) & 0xff]
7055990Sbostic 
7157479Selan extern char	*__unctrl[256];	/* Control strings. */
7257479Selan extern char	 __unctrllen[256];	/* Control strings length. */
7357477Sbostic 
7456238Selan /*
7556647Selan  * A window an array of __LINE structures pointed to by the 'lines' pointer.
7656647Selan  * A line is an array of __LDATA structures pointed to by the 'line' pointer.
7756647Selan  *
7856647Selan  * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
7956647Selan  * fields are added -- padding fields with *constant values* should ensure
8056647Selan  * that the compiler will not generate any padding when storing an array of
8158042Selan  *  __LDATA structures.  This is to enable consistent use of memcmp, and memcpy
8256647Selan  * for comparing and copying arrays.
8356238Selan  */
8456647Selan typedef struct {
8556647Selan 	char ch;			/* the actual character */
8656647Selan 
8756647Selan #define	__STANDOUT	0x01  		/* Added characters are standout. */
8856647Selan 	char attr;			/* attributes of character */
8956647Selan } __LDATA;
9056647Selan 
9156647Selan #define __LDATASIZE	(sizeof(__LDATA))
9256647Selan 
9356647Selan typedef struct {
9456238Selan #define	__ISDIRTY	0x01		/* Line is dirty. */
9556300Selan #define __ISPASTEOL	0x02		/* Cursor is past end of line */
9656650Selan #define __FORCEPAINT	0x04		/* Force a repaint of the line */
9756238Selan 	u_int flags;
9856238Selan 	u_int hash;			/* Hash value for the line. */
9956715Selan 	size_t *firstchp, *lastchp;	/* First and last chngd columns ptrs */
10056238Selan 	size_t firstch, lastch;		/* First and last changed columns. */
10156647Selan 	__LDATA *line;			/* Pointer to the line text. */
10256647Selan } __LINE;
10356596Selan 
10456238Selan typedef struct __window {		/* Window structure. */
10556238Selan 	struct __window	*nextp, *orig;	/* Subwindows list and parent. */
10656238Selan 	size_t begy, begx;		/* Window home. */
10756238Selan 	size_t cury, curx;		/* Current x, y coordinates. */
10856238Selan 	size_t maxy, maxx;		/* Maximum values for curx, cury. */
10956238Selan 	short ch_off;			/* x offset for firstch/lastch. */
11056647Selan 	__LINE **lines;			/* Array of pointers to the lines */
11156647Selan 	__LINE  *lspace;		/* line space (for cleanup) */
11256647Selan 	__LDATA *wspace;		/* window space (for cleanup) */
11355990Sbostic 
11456238Selan #define	__ENDLINE	0x001		/* End of screen. */
11556238Selan #define	__FLUSH		0x002		/* Fflush(stdout) after refresh. */
11667569Sbostic #define	__FULLWIN	0x004		/* Window is a screen. */
11767569Sbostic #define	__IDLINE	0x008		/* Insert/delete sequences. */
11867569Sbostic #define	__SCROLLWIN	0x010		/* Last char will scroll window. */
11967569Sbostic #define	__SCROLLOK	0x020		/* Scrolling ok. */
12067569Sbostic #define	__CLEAROK	0x040		/* Clear on next refresh. */
12167569Sbostic #define __WSTANDOUT	0x080		/* Standout window */
12267569Sbostic #define __LEAVEOK	0x100		/* If curser left */
12356238Selan 	u_int flags;
12455990Sbostic } WINDOW;
12555990Sbostic 
12655990Sbostic /* Curses external declarations. */
12755990Sbostic extern WINDOW	*curscr;		/* Current screen. */
12855990Sbostic extern WINDOW	*stdscr;		/* Standard screen. */
1292244Sarnold 
13061229Smarc extern struct termios __orig_termios;	/* Terminal state before curses */
13161229Smarc extern struct termios __baset;		/* Our base terminal state */
13262541Sbostic extern int __tcaction;			/* If terminal hardware set. */
1332244Sarnold 
13455990Sbostic extern int	 COLS;			/* Columns on the screen. */
13555990Sbostic extern int	 LINES;			/* Lines on the screen. */
1362244Sarnold 
13755990Sbostic extern char	*ttytype;		/* Full name of current terminal. */
1382244Sarnold 
13955990Sbostic #define	ERR	(0)			/* Error return. */
14055990Sbostic #define	OK	(1)			/* Success return. */
1412244Sarnold 
14255990Sbostic /* Standard screen pseudo functions. */
14357972Sbostic #define	addbytes(s, n)			__waddbytes(stdscr, s, n, 0)
14457477Sbostic #define	addch(ch)			waddch(stdscr, ch)
14557972Sbostic #define	addnstr(s, n)			waddnstr(stdscr, s, n)
14657972Sbostic #define	addstr(s)			__waddbytes(stdscr, s, strlen(s), 0)
14757477Sbostic #define	clear()				wclear(stdscr)
14857477Sbostic #define	clrtobot()			wclrtobot(stdscr)
14957477Sbostic #define	clrtoeol()			wclrtoeol(stdscr)
15057477Sbostic #define	delch()				wdelch(stdscr)
15157477Sbostic #define	deleteln()			wdeleteln(stdscr)
15257477Sbostic #define	erase()				werase(stdscr)
15357477Sbostic #define	getch()				wgetch(stdscr)
15457972Sbostic #define	getstr(s)			wgetstr(stdscr, s)
15557477Sbostic #define	inch()				winch(stdscr)
15658191Selan #define	insch(ch)			winsch(stdscr, ch)
15757477Sbostic #define	insertln()			winsertln(stdscr)
15857477Sbostic #define	move(y, x)			wmove(stdscr, y, x)
15957477Sbostic #define	refresh()			wrefresh(stdscr)
16057477Sbostic #define	standend()			wstandend(stdscr)
16157477Sbostic #define	standout()			wstandout(stdscr)
16257972Sbostic #define	waddbytes(w, s, n)		__waddbytes(w, s, n, 0)
16357972Sbostic #define	waddstr(w, s)			__waddbytes(w, s, strlen(s), 0)
1642244Sarnold 
16555990Sbostic /* Standard screen plus movement pseudo functions. */
16657972Sbostic #define	mvaddbytes(y, x, s, n)		mvwaddbytes(stdscr, y, x, s, n)
16757477Sbostic #define	mvaddch(y, x, ch)		mvwaddch(stdscr, y, x, ch)
16857972Sbostic #define	mvaddnstr(y, x, s, n)		mvwaddnstr(stdscr, y, x, s, n)
16957972Sbostic #define	mvaddstr(y, x, s)		mvwaddstr(stdscr, y, x, s)
17057477Sbostic #define	mvdelch(y, x)			mvwdelch(stdscr, y, x)
17157477Sbostic #define	mvgetch(y, x)			mvwgetch(stdscr, y, x)
17257972Sbostic #define	mvgetstr(y, x, s)		mvwgetstr(stdscr, y, x, s)
17357477Sbostic #define	mvinch(y, x)			mvwinch(stdscr, y, x)
17457477Sbostic #define	mvinsch(y, x, c)		mvwinsch(stdscr, y, x, c)
17557972Sbostic #define	mvwaddbytes(w, y, x, s, n) \
17657972Sbostic 	(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0))
17757972Sbostic #define	mvwaddch(w, y, x, ch) \
17857972Sbostic 	(wmove(w, y, x) == ERR ? ERR : waddch(w, ch))
17957972Sbostic #define	mvwaddnstr(w, y, x, s, n) \
18057972Sbostic 	(wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n))
18157972Sbostic #define	mvwaddstr(w, y, x, s) \
18257972Sbostic 	(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0))
18357972Sbostic #define	mvwdelch(w, y, x) \
18457972Sbostic 	(wmove(w, y, x) == ERR ? ERR : wdelch(w))
18557972Sbostic #define	mvwgetch(w, y, x) \
18657972Sbostic 	(wmove(w, y, x) == ERR ? ERR : wgetch(w))
18757972Sbostic #define	mvwgetstr(w, y, x, s) \
18857972Sbostic 	(wmove(w, y, x) == ERR ? ERR : wgetstr(w, s))
18957972Sbostic #define	mvwinch(w, y, x) \
19057972Sbostic 	(wmove(w, y, x) == ERR ? ERR : winch(w))
19157972Sbostic #define	mvwinsch(w, y, x, c) \
19257972Sbostic 	(wmove(w, y, x) == ERR ? ERR : winsch(w, c))
1932244Sarnold 
19457477Sbostic /* Psuedo functions. */
19557972Sbostic #define	clearok(w, bf) \
19657972Sbostic 	((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK))
19757972Sbostic #define	flushok(w, bf) \
19857972Sbostic 	((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH))
19957972Sbostic #define	getyx(w, y, x) \
20057972Sbostic 	(y) = (w)->cury, (x) = (w)->curx
20157972Sbostic #define	leaveok(w, bf) \
20257972Sbostic 	((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK))
20357972Sbostic #define	scrollok(w, bf) \
20457972Sbostic 	((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK))
20557972Sbostic #define	winch(w) \
20657972Sbostic 	((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177)
2072244Sarnold 
20855990Sbostic /* Public function prototypes. */
20955990Sbostic int	 box __P((WINDOW *, int, int));
21055990Sbostic int	 cbreak __P((void));
21155990Sbostic int	 delwin __P((WINDOW *));
21255990Sbostic int	 echo __P((void));
21355990Sbostic int	 endwin __P((void));
21455990Sbostic char	*fullname __P((char *, char *));
21555990Sbostic char	*getcap __P((char *));
21655990Sbostic int	 gettmode __P((void));
21755990Sbostic void	 idlok __P((WINDOW *, int));
21855990Sbostic WINDOW	*initscr __P((void));
21955990Sbostic char	*longname __P((char *, char *));
22060403Sbostic int	 mvcur __P((int, int, int, int));
22155990Sbostic int	 mvprintw __P((int, int, const char *, ...));
22255990Sbostic int	 mvscanw __P((int, int, const char *, ...));
22355990Sbostic int	 mvwin __P((WINDOW *, int, int));
22455990Sbostic int	 mvwprintw __P((WINDOW *, int, int, const char *, ...));
22555990Sbostic int	 mvwscanw __P((WINDOW *, int, int, const char *, ...));
22655990Sbostic WINDOW	*newwin __P((int, int, int, int));
22755990Sbostic int	 nl __P((void));
22855990Sbostic int	 nocbreak __P((void));
22955990Sbostic int	 noecho __P((void));
23055990Sbostic int	 nonl __P((void));
23155990Sbostic int	 noraw __P((void));
23255990Sbostic int	 overlay __P((WINDOW *, WINDOW *));
23355990Sbostic int	 overwrite __P((WINDOW *, WINDOW *));
23455990Sbostic int	 printw __P((const char *, ...));
23555990Sbostic int	 raw __P((void));
23655990Sbostic int	 resetty __P((void));
23755990Sbostic int	 savetty __P((void));
23855990Sbostic int	 scanw __P((const char *, ...));
23955990Sbostic int	 scroll __P((WINDOW *));
24055990Sbostic int	 setterm __P((char *));
24157362Selan int	 sscans __P((WINDOW *, const char *, ...));
24255990Sbostic WINDOW	*subwin __P((WINDOW *, int, int, int, int));
24355990Sbostic int	 suspendwin __P((void));
24455990Sbostic int	 touchline __P((WINDOW *, int, int, int));
24555990Sbostic int	 touchoverlap __P((WINDOW *, WINDOW *));
24655990Sbostic int	 touchwin __P((WINDOW *));
24757362Selan int 	 vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
24857362Selan int      vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_));
24955990Sbostic int	 waddch __P((WINDOW *, int));
25057972Sbostic int	 waddnstr __P((WINDOW *, const char *, int));
25155990Sbostic int	 wclear __P((WINDOW *));
25255990Sbostic int	 wclrtobot __P((WINDOW *));
25355990Sbostic int	 wclrtoeol __P((WINDOW *));
25455990Sbostic int	 wdelch __P((WINDOW *));
25555990Sbostic int	 wdeleteln __P((WINDOW *));
25655990Sbostic int	 werase __P((WINDOW *));
25755990Sbostic int	 wgetch __P((WINDOW *));
25855990Sbostic int	 wgetstr __P((WINDOW *, char *));
25955990Sbostic int	 winsch __P((WINDOW *, int));
26055990Sbostic int	 winsertln __P((WINDOW *));
26155990Sbostic int	 wmove __P((WINDOW *, int, int));
26255990Sbostic int	 wprintw __P((WINDOW *, const char *, ...));
26355990Sbostic int	 wrefresh __P((WINDOW *));
26455990Sbostic int	 wscanw __P((WINDOW *, const char *, ...));
26567630Sbostic int	 wstandend __P((WINDOW *));
26667630Sbostic int	 wstandout __P((WINDOW *));
26757477Sbostic int	 vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
2682244Sarnold 
26960107Sbostic /* Private functions that are needed for user programs prototypes. */
27060107Sbostic void	 __cputchar __P((int));
27160107Sbostic int	 __waddbytes __P((WINDOW *, const char *, int, int));
27259789Sbostic 
27360107Sbostic /* Private functions. */
27455990Sbostic #ifdef _CURSES_PRIVATE
27560058Sbostic void	 __CTRACE __P((const char *, ...));
27658048Selan u_int	 __hash __P((char *, int));
27755990Sbostic void	 __id_subwins __P((WINDOW *));
27860403Sbostic int	 __mvcur __P((int, int, int, int, int));
27961229Smarc void	 __restore_stophandler __P((void));
28061229Smarc void	 __set_stophandler __P((void));
28155990Sbostic void	 __set_subwin __P((WINDOW *, WINDOW *));
28257712Sbostic void	 __startwin __P((void));
28357712Sbostic void	 __stop_signal_handler __P((int));
28455990Sbostic void	 __swflags __P((WINDOW *));
28556650Selan int	 __touchline __P((WINDOW *, int, int, int, int));
28656650Selan int	 __touchwin __P((WINDOW *));
28767569Sbostic char	*__tscroll __P((const char *, int, int));
28858048Selan int	 __waddch __P((WINDOW *, __LDATA *));
2892244Sarnold 
29055990Sbostic /* Private #defines. */
29155990Sbostic #define	min(a,b)	(a < b ? a : b)
29255990Sbostic #define	max(a,b)	(a > b ? a : b)
2932244Sarnold 
29455990Sbostic /* Private externs. */
29555990Sbostic extern int	 __echoit;
29655990Sbostic extern int	 __endwin;
29755990Sbostic extern int	 __pfast;
29855990Sbostic extern int	 __rawmode;
29956300Selan extern int	 __noqch;
30055990Sbostic #endif
3012244Sarnold 
30255990Sbostic /* Termcap functions. */
30355990Sbostic int	 tgetent __P((char *, char *));
30455990Sbostic int	 tgetnum __P((char *));
30555990Sbostic int	 tgetflag __P((char *));
30655990Sbostic char	*tgetstr __P((char *, char **));
30755990Sbostic char	*tgoto __P((char *, int, int));
30855990Sbostic int	 tputs __P((char *, int, void (*)(int)));
3092244Sarnold 
31055990Sbostic #endif /* !_CURSES_H_ */
311