xref: /csrg-svn/lib/libcurses/curses.h (revision 56715)
122686Sdist /*
234677Sbostic  * Copyright (c) 1981 Regents of the University of California.
334677Sbostic  * All rights reserved.
422686Sdist  *
542653Sbostic  * %sccs.include.redist.c%
634677Sbostic  *
7*56715Selan  *	@(#)curses.h	5.19 (Berkeley) 11/11/92
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 
4455990Sbostic extern int	 My_term;		/* Use Def_term regardless. */
4555990Sbostic extern char	*Def_term;		/* Default terminal type. */
4655990Sbostic 
4755990Sbostic /* END BACKWARD COMPATIBILITY ONLY. */
4855990Sbostic 
4955990Sbostic /* 7-bit ASCII characters. */
5055990Sbostic #define	unctrl(c)		__unctrl[(c) & 0x7f]
5155990Sbostic #define	unctrllen(ch)		__unctrllen[(ch) & 0x7f]
5255990Sbostic 
5356238Selan /*
5456647Selan  * A window an array of __LINE structures pointed to by the 'lines' pointer.
5556647Selan  * A line is an array of __LDATA structures pointed to by the 'line' pointer.
5656647Selan  *
5756647Selan  * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new
5856647Selan  * fields are added -- padding fields with *constant values* should ensure
5956647Selan  * that the compiler will not generate any padding when storing an array of
6056647Selan  *  __LDATA structures.  This is to enable consistent use of bcmp, and bcopy
6156647Selan  * for comparing and copying arrays.
6256238Selan  */
6355990Sbostic 
6456647Selan typedef struct {
6556647Selan 	char ch;			/* the actual character */
6656647Selan 
6756647Selan #define	__STANDOUT	0x01  		/* Added characters are standout. */
6856647Selan 	char attr;			/* attributes of character */
6956647Selan } __LDATA;
7056647Selan 
7156647Selan #define __LDATASIZE	(sizeof(__LDATA))
7256647Selan 
7356647Selan typedef struct {
7456238Selan #define	__ISDIRTY	0x01		/* Line is dirty. */
7556300Selan #define __ISPASTEOL	0x02		/* Cursor is past end of line */
7656650Selan #define __FORCEPAINT	0x04		/* Force a repaint of the line */
7756238Selan 	u_int flags;
7856238Selan 	u_int hash;			/* Hash value for the line. */
79*56715Selan 	size_t *firstchp, *lastchp;	/* First and last chngd columns ptrs */
8056238Selan 	size_t firstch, lastch;		/* First and last changed columns. */
8156647Selan 	__LDATA *line;			/* Pointer to the line text. */
8256647Selan } __LINE;
8356596Selan 
8456238Selan typedef struct __window {		/* Window structure. */
8556238Selan 	struct __window	*nextp, *orig;	/* Subwindows list and parent. */
8656238Selan 	size_t begy, begx;		/* Window home. */
8756238Selan 	size_t cury, curx;		/* Current x, y coordinates. */
8856238Selan 	size_t maxy, maxx;		/* Maximum values for curx, cury. */
8956238Selan 	short ch_off;			/* x offset for firstch/lastch. */
9056647Selan 	__LINE **lines;			/* Array of pointers to the lines */
9156647Selan 	__LINE  *lspace;		/* line space (for cleanup) */
9256647Selan 	__LDATA *wspace;		/* window space (for cleanup) */
9355990Sbostic 
9456238Selan #define	__ENDLINE	0x001		/* End of screen. */
9556238Selan #define	__FLUSH		0x002		/* Fflush(stdout) after refresh. */
9656238Selan #define	__FULLLINE	0x004		/* Line width = terminal width. */
9756238Selan #define	__FULLWIN	0x008		/* Window is a screen. */
9856238Selan #define	__IDLINE	0x010		/* Insert/delete sequences. */
9956238Selan #define	__SCROLLWIN	0x020		/* Last char will scroll window. */
10056238Selan #define	__SCROLLOK	0x040		/* Scrolling ok. */
10156238Selan #define	__CLEAROK	0x080		/* Clear on next refresh. */
10256238Selan #define __WSTANDOUT	0x100		/* Standout window */
10356238Selan #define __LEAVEOK	0x200		/* If curser left */
10456238Selan 	u_int flags;
10555990Sbostic } WINDOW;
10655990Sbostic 
10755990Sbostic /* Termcap capabilities. */
10855990Sbostic extern char	AM, BS, CA, DA, EO, HC, HZ, IN, MI, MS, NC, NS, OS,
10955990Sbostic 		PC, UL, XB, XN, XT, XS, XX;
11019900Sbloom extern char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
11119900Sbloom 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
11219900Sbloom 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
11319900Sbloom 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
11419900Sbloom 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
11556300Selan 		*VE, *al, *dl, *sf, *sr,
11655990Sbostic 		*AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
11755990Sbostic 		*RIGHT_PARM;
1182244Sarnold 
11955990Sbostic /* Curses external declarations. */
12055990Sbostic extern WINDOW	*curscr;		/* Current screen. */
12155990Sbostic extern WINDOW	*stdscr;		/* Standard screen. */
1222244Sarnold 
12355990Sbostic extern struct termios origtermio;	/* Original terminal modes. */
1242244Sarnold 
12555990Sbostic extern int	 COLS;			/* Columns on the screen. */
12655990Sbostic extern int	 LINES;			/* Lines on the screen. */
1272244Sarnold 
12855990Sbostic extern char	 GT;			/* Gtty indicates tabs. */
12955990Sbostic extern char	 NONL;			/* Term can't hack LF doing a CR. */
13055990Sbostic extern char	 UPPERCASE;		/* Terminal is uppercase only. */
13155990Sbostic extern char	*ttytype;		/* Full name of current terminal. */
13255990Sbostic extern char	*__unctrl[0x80];	/* Control strings. */
13355990Sbostic extern char	 __unctrllen[0x80];	/* Control strings length. */
1342244Sarnold 
13555990Sbostic #define	ERR	(0)			/* Error return. */
13655990Sbostic #define	OK	(1)			/* Success return. */
1372244Sarnold 
13855990Sbostic /* Standard screen pseudo functions. */
13955990Sbostic #define	addbytes(da, co)	waddbytes(stdscr, da, co)
14055990Sbostic #define	addch(ch)		waddch(stdscr, ch)
14155990Sbostic #define	addstr(str)		waddbytes(stdscr, str, strlen(str))
14255990Sbostic #define	clear()			wclear(stdscr)
14355990Sbostic #define	clrtobot()		wclrtobot(stdscr)
14455990Sbostic #define	clrtoeol()		wclrtoeol(stdscr)
14555990Sbostic #define	delch()			wdelch(stdscr)
14655990Sbostic #define	deleteln()		wdeleteln(stdscr)
14755990Sbostic #define	erase()			werase(stdscr)
14855990Sbostic #define	getch()			wgetch(stdscr)
14955990Sbostic #define	getstr(str)		wgetstr(stdscr, str)
15055990Sbostic #define	inch()			winch(stdscr)
15155990Sbostic #define	insch(ch))		winsch(stdscr, ch)
15255990Sbostic #define	insertln()		winsertln(stdscr)
15355990Sbostic #define	move(y, x)		wmove(stdscr, y, x)
15455990Sbostic #define	refresh()		wrefresh(stdscr)
15555990Sbostic #define	standend()		wstandend(stdscr)
15655990Sbostic #define	standout()		wstandout(stdscr)
1572244Sarnold 
15855990Sbostic /* Standard screen plus movement pseudo functions. */
15955990Sbostic #define	mvaddbytes(y, x, da, co) \
16055990Sbostic 				mvwaddbytes(stdscr, y, x, da, co)
16155990Sbostic #define	mvaddch(y, x, ch)	mvwaddch(stdscr, y, x, ch)
16255990Sbostic #define	mvaddstr(y, x, str)	mvwaddstr(stdscr, y, x, str)
16355990Sbostic #define	mvdelch(y, x)		mvwdelch(stdscr, y, x)
16455990Sbostic #define	mvgetch(y, x)		mvwgetch(stdscr, y, x)
16555990Sbostic #define	mvgetstr(y, x, str)	mvwgetstr(stdscr, y, x, str)
16655990Sbostic #define	mvinch(y, x)		mvwinch(stdscr, y, x)
16755990Sbostic #define	mvinsch(y, x, c)	mvwinsch(stdscr, y, x, c)
16855990Sbostic #define	mvwaddbytes(win, y, x, da, co) \
16955990Sbostic 				(wmove(win, y, x) == ERR ? \
17055990Sbostic 				    ERR : waddbytes(win, da, co))
17155990Sbostic #define	mvwaddch(win, y, x, ch)	(wmove(win, y, x) == ERR ? \
17255990Sbostic 				    ERR : waddch(win, ch))
17355990Sbostic #define	mvwaddstr(win, y, x, str) \
17455990Sbostic 				(wmove(win, y, x) == ERR ? \
17555990Sbostic 				    ERR : waddbytes(win, str, strlen(str)))
17655990Sbostic #define	mvwdelch(win, y, x)	(wmove(win, y, x) == ERR ? ERR : wdelch(win))
17755990Sbostic #define	mvwgetch(win, y, x)	(wmove(win, y, x) == ERR ? ERR : wgetch(win))
17855990Sbostic #define	mvwgetstr(win, y, x, str) \
17955990Sbostic 				(wmove(win, y, x) == ERR ? \
18055990Sbostic 				    ERR : wgetstr(win, str))
18155990Sbostic #define	mvwinch(win, y, x)	(wmove(win, y, x) == ERR ? ERR : winch(win))
18255990Sbostic #define	mvwinsch(win, y, x, c)	(wmove(win, y, x) == ERR ? ERR : winsch(win, c))
1832244Sarnold 
18455990Sbostic /* Random psuedo functions. */
18556238Selan #define	clearok(win, bf)  ((bf) ? (win->flags |= __CLEAROK) : \
18656238Selan 				  (win->flags &= ~__CLEAROK))
18756238Selan #define	flushok(win, bf)  ((bf) ? (win->flags |= __FLUSH) : \
18856238Selan 				  (win->flags &= ~__FLUSH))
18956238Selan #define	scrollok(win, bf) ((bf) ? (win->flags |= __SCROLLOK) : \
19056238Selan 				  (win->flags &= ~__SCROLLOK))
19156238Selan #define	leaveok(win, bf)  ((bf) ? (win->flags |= __LEAVEOK) : \
19256238Selan 				  (win->flags &= ~__LEAVEOK))
19356238Selan #define	getyx(win, y, x)	(y) = win->cury, (x) = win->curx
19456238Selan #define	winch(win)		(win->lines[win->cury]->line[win->curx] & 0177)
1952244Sarnold 
19655990Sbostic /* Public function prototypes. */
19755990Sbostic void	 __cputchar __P((int));
19855990Sbostic int	 _sprintw __P((WINDOW *, const char *, _BSD_VA_LIST_));
19955990Sbostic int	 box __P((WINDOW *, int, int));
20055990Sbostic int	 cbreak __P((void));
20155990Sbostic int	 delwin __P((WINDOW *));
20255990Sbostic int	 echo __P((void));
20355990Sbostic int	 endwin __P((void));
20455990Sbostic char	*fullname __P((char *, char *));
20555990Sbostic char	*getcap __P((char *));
20655990Sbostic int	 gettmode __P((void));
20755990Sbostic void	 idlok __P((WINDOW *, int));
20855990Sbostic WINDOW	*initscr __P((void));
20955990Sbostic char	*longname __P((char *, char *));
21055990Sbostic int	 mvcur __P((int, int, int, int));
21155990Sbostic int	 mvprintw __P((int, int, const char *, ...));
21255990Sbostic int	 mvscanw __P((int, int, const char *, ...));
21355990Sbostic int	 mvwin __P((WINDOW *, int, int));
21455990Sbostic int	 mvwprintw __P((WINDOW *, int, int, const char *, ...));
21555990Sbostic int	 mvwscanw __P((WINDOW *, int, int, const char *, ...));
21655990Sbostic WINDOW	*newwin __P((int, int, int, int));
21755990Sbostic int	 nl __P((void));
21855990Sbostic int	 nocbreak __P((void));
21955990Sbostic int	 noecho __P((void));
22055990Sbostic int	 nonl __P((void));
22155990Sbostic int	 noraw __P((void));
22255990Sbostic int	 overlay __P((WINDOW *, WINDOW *));
22355990Sbostic int	 overwrite __P((WINDOW *, WINDOW *));
22455990Sbostic int	 printw __P((const char *, ...));
22555990Sbostic int	 raw __P((void));
22655990Sbostic int	 resetty __P((void));
22755990Sbostic int	 savetty __P((void));
22855990Sbostic int	 scanw __P((const char *, ...));
22955990Sbostic int	 scroll __P((WINDOW *));
23055990Sbostic int	 setterm __P((char *));
23155990Sbostic int	 sscans __P((WINDOW *, const char *, _BSD_VA_LIST_));
23255990Sbostic WINDOW	*subwin __P((WINDOW *, int, int, int, int));
23355990Sbostic int	 suspendwin __P((void));
23455990Sbostic int	 touchline __P((WINDOW *, int, int, int));
23555990Sbostic int	 touchoverlap __P((WINDOW *, WINDOW *));
23655990Sbostic int	 touchwin __P((WINDOW *));
23755990Sbostic void	 tstp __P((int));
23855990Sbostic int	 waddch __P((WINDOW *, int));
23955990Sbostic int	 waddstr __P((WINDOW *, char *));
24055990Sbostic int	 wclear __P((WINDOW *));
24155990Sbostic int	 wclrtobot __P((WINDOW *));
24255990Sbostic int	 wclrtoeol __P((WINDOW *));
24355990Sbostic int	 wdelch __P((WINDOW *));
24455990Sbostic int	 wdeleteln __P((WINDOW *));
24555990Sbostic int	 werase __P((WINDOW *));
24655990Sbostic int	 wgetch __P((WINDOW *));
24755990Sbostic int	 wgetstr __P((WINDOW *, char *));
24855990Sbostic int	 winsch __P((WINDOW *, int));
24955990Sbostic int	 winsertln __P((WINDOW *));
25055990Sbostic int	 wmove __P((WINDOW *, int, int));
25155990Sbostic int	 wprintw __P((WINDOW *, const char *, ...));
25255990Sbostic int	 wrefresh __P((WINDOW *));
25355990Sbostic int	 wscanw __P((WINDOW *, const char *, ...));
25455990Sbostic char	*wstandend __P((WINDOW *));
25555990Sbostic char	*wstandout __P((WINDOW *));
2562244Sarnold 
25755990Sbostic #ifdef _CURSES_PRIVATE
25855990Sbostic /* Private function prototypes. */
25956650Selan void	 __TRACE __P((const char *, ...));
26055990Sbostic void	 __id_subwins __P((WINDOW *));
26155990Sbostic void	 __set_subwin __P((WINDOW *, WINDOW *));
26255990Sbostic void	 __swflags __P((WINDOW *));
26356650Selan int	 __touchline __P((WINDOW *, int, int, int, int));
26456650Selan int	 __touchwin __P((WINDOW *));
26556650Selan char	*tscroll __P((const char *, int));
26655990Sbostic int	 waddbytes __P((WINDOW *, char *, int));
2672244Sarnold 
26855990Sbostic /* Private #defines. */
26955990Sbostic #define	min(a,b)	(a < b ? a : b)
27055990Sbostic #define	max(a,b)	(a > b ? a : b)
2712244Sarnold 
27255990Sbostic /* Private externs. */
27355990Sbostic extern int	 __echoit;
27455990Sbostic extern int	 __endwin;
27555990Sbostic extern int	 __pfast;
27655990Sbostic extern int	 __rawmode;
27756300Selan extern int	 __noqch;
27855990Sbostic #endif
2792244Sarnold 
28055990Sbostic /* Termcap functions. */
28155990Sbostic int	 tgetent __P((char *, char *));
28255990Sbostic int	 tgetnum __P((char *));
28355990Sbostic int	 tgetflag __P((char *));
28455990Sbostic char	*tgetstr __P((char *, char **));
28555990Sbostic char	*tgoto __P((char *, int, int));
28655990Sbostic int	 tputs __P((char *, int, void (*)(int)));
2872244Sarnold 
28855990Sbostic #endif /* !_CURSES_H_ */
289