Home | History | Annotate | Line # | Download | only in libcurses
curses.h revision 1.4
      1 /*
      2  * Copyright (c) 1981 Regents of the University of California.
      3  * 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. All advertising materials mentioning features or use of this software
     14  *    must display the following acknowledgement:
     15  *	This product includes software developed by the University of
     16  *	California, Berkeley and its contributors.
     17  * 4. Neither the name of the University nor the names of its contributors
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  *
     33  *	from: @(#)curses.h	5.12 (Berkeley) 9/1/92
     34  *	$Id: curses.h,v 1.4 1993/08/07 05:48:47 mycroft Exp $
     35  */
     36 
     37 #ifndef _CURSES_H_
     38 #define	_CURSES_H_
     39 
     40 #include <stdio.h>
     41 
     42 /*
     43  * The following #defines and #includes are present for backward
     44  * compatibility only.  They should not be used in future code.
     45  *
     46  * START BACKWARD COMPATIBILITY ONLY.
     47  */
     48 #ifndef _CURSES_PRIVATE
     49 #define	bool	char
     50 #define	reg	register
     51 
     52 #ifndef TRUE
     53 #define	TRUE	(1)
     54 #endif
     55 #ifndef FALSE
     56 #define	FALSE	(0)
     57 #endif
     58 
     59 #define	_puts(s)	tputs(s, 0, __cputchar)
     60 #define	_putchar(c)	__cputchar(c)
     61 
     62 /* Old-style terminal modes access. */
     63 #define	baudrate()	(cfgetospeed(&origtermio))
     64 #define	crmode()	cbreak()
     65 #define	erasechar()	(origtermio.c_cc[VERASE])
     66 #define	killchar()	(origtermio.c_cc[VKILL])
     67 #define	nocrmode()	nocbreak()
     68 #define	ospeed		(cfgetospeed(&origtermio))
     69 #endif /* _CURSES_PRIVATE */
     70 
     71 extern int	 My_term;		/* Use Def_term regardless. */
     72 extern char	*Def_term;		/* Default terminal type. */
     73 
     74 /* END BACKWARD COMPATIBILITY ONLY. */
     75 
     76 /* 7-bit ASCII characters. */
     77 #define	unctrl(c)		__unctrl[(c) & 0x7f]
     78 #define	unctrllen(ch)		__unctrllen[(ch) & 0x7f]
     79 
     80 typedef struct _win_st {		/* Window structure. */
     81 	short		_cury, _curx;	/* Current x, y coordinates. */
     82 	short		_maxy, _maxx;	/* Maximum values for curx, cury. */
     83 	short		_begy, _begx;	/* Window home. */
     84 
     85 #define	_ENDLINE	0x001		/* End of screen. */
     86 #define	_FLUSH		0x002		/* fflush(stdout) after refresh. */
     87 #define	_FULLLINE	0x004		/* Line width = terminal width. */
     88 #define	_FULLWIN	0x008		/* Window is a screen. */
     89 #define	_IDLINE		0x010		/* Insert/delete sequences. */
     90 #define	_SCROLLWIN	0x020		/* Last char will scroll window. */
     91 /*
     92  * XXX
     93  * _STANDOUT is the 8th bit, characters themselves are encoded.
     94  */
     95 #define	_STANDOUT	0x080		/* Added characters are standout. */
     96 	unsigned short	_flags;
     97 
     98 	short		_ch_off;	/* x offset for firstch/lastch. */
     99 	char		_clear;		/* If clear on next refresh. */
    100 	char		_leave;		/* If cursor left. */
    101 	char		_scroll;	/* If scrolling permitted. */
    102 	char		**_y;		/* Line describing the window. */
    103 
    104 #define	_NOCHANGE	-1		/* No change since last refresh. */
    105 	short		*_firstch;	/* First and last changed in line. */
    106 	short		*_lastch;
    107 	struct _win_st	*_nextp, *_orig;/* Subwindows list and parent. */
    108 } WINDOW;
    109 
    110 /* Termcap capabilities. */
    111 extern char	AM, BS, CA, DA, EO, HC, HZ, IN, MI, MS, NC, NS, OS,
    112 		PC, UL, XB, XN, XT, XS, XX;
    113 extern char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
    114 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
    115 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
    116 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
    117 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
    118 		*VE,
    119 		*AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM,
    120 		*RIGHT_PARM;
    121 
    122 /* Curses external declarations. */
    123 extern WINDOW	*curscr;		/* Current screen. */
    124 extern WINDOW	*stdscr;		/* Standard screen. */
    125 
    126 extern struct termios origtermio;	/* Original terminal modes. */
    127 
    128 extern int	 COLS;			/* Columns on the screen. */
    129 extern int	 LINES;			/* Lines on the screen. */
    130 
    131 extern char	 GT;			/* Gtty indicates tabs. */
    132 extern char	 NONL;			/* Term can't hack LF doing a CR. */
    133 extern char	 UPPERCASE;		/* Terminal is uppercase only. */
    134 extern char	*ttytype;		/* Full name of current terminal. */
    135 extern char	*__unctrl[0x80];	/* Control strings. */
    136 extern char	 __unctrllen[0x80];	/* Control strings length. */
    137 
    138 #define	ERR	(0)			/* Error return. */
    139 #define	OK	(1)			/* Success return. */
    140 
    141 /* Standard screen pseudo functions. */
    142 #define	addbytes(da, co)	waddbytes(stdscr, da, co)
    143 #define	addch(ch)		waddch(stdscr, ch)
    144 #define	addstr(str)		waddbytes(stdscr, str, strlen(str))
    145 #define	clear()			wclear(stdscr)
    146 #define	clrtobot()		wclrtobot(stdscr)
    147 #define	clrtoeol()		wclrtoeol(stdscr)
    148 #define	delch()			wdelch(stdscr)
    149 #define	deleteln()		wdeleteln(stdscr)
    150 #define	erase()			werase(stdscr)
    151 #define	getch()			wgetch(stdscr)
    152 #define	getstr(str)		wgetstr(stdscr, str)
    153 #define	inch()			winch(stdscr)
    154 #define	insch(ch))		winsch(stdscr, ch)
    155 #define	insertln()		winsertln(stdscr)
    156 #define	move(y, x)		wmove(stdscr, y, x)
    157 #define	refresh()		wrefresh(stdscr)
    158 #define	standend()		wstandend(stdscr)
    159 #define	standout()		wstandout(stdscr)
    160 
    161 /* Standard screen plus movement pseudo functions. */
    162 #define	mvaddbytes(y, x, da, co) \
    163 				mvwaddbytes(stdscr, y, x, da, co)
    164 #define	mvaddch(y, x, ch)	mvwaddch(stdscr, y, x, ch)
    165 #define	mvaddstr(y, x, str)	mvwaddstr(stdscr, y, x, str)
    166 #define	mvdelch(y, x)		mvwdelch(stdscr, y, x)
    167 #define	mvgetch(y, x)		mvwgetch(stdscr, y, x)
    168 #define	mvgetstr(y, x, str)	mvwgetstr(stdscr, y, x, str)
    169 #define	mvinch(y, x)		mvwinch(stdscr, y, x)
    170 #define	mvinsch(y, x, c)	mvwinsch(stdscr, y, x, c)
    171 #define	mvwaddbytes(win, y, x, da, co) \
    172 				(wmove(win, y, x) == ERR ? \
    173 				    ERR : waddbytes(win, da, co))
    174 #define	mvwaddch(win, y, x, ch)	(wmove(win, y, x) == ERR ? \
    175 				    ERR : waddch(win, ch))
    176 #define	mvwaddstr(win, y, x, str) \
    177 				(wmove(win, y, x) == ERR ? \
    178 				    ERR : waddbytes(win, str, strlen(str)))
    179 #define	mvwdelch(win, y, x)	(wmove(win, y, x) == ERR ? ERR : wdelch(win))
    180 #define	mvwgetch(win, y, x)	(wmove(win, y, x) == ERR ? ERR : wgetch(win))
    181 #define	mvwgetstr(win, y, x, str) \
    182 				(wmove(win, y, x) == ERR ? \
    183 				    ERR : wgetstr(win, str))
    184 #define	mvwinch(win, y, x)	(wmove(win, y, x) == ERR ? ERR : winch(win))
    185 #define	mvwinsch(win, y, x, c)	(wmove(win, y, x) == ERR ? ERR : winsch(win, c))
    186 
    187 /* Random psuedo functions. */
    188 #define	clearok(win, bf) 	(win->_clear = (bf))
    189 #define	flushok(win, bf)	((bf) ? (win->_flags |= _FLUSH) : \
    190 				    (win->_flags &= ~_FLUSH))
    191 #define	getyx(win, y, x)	(y) = win->_cury, (x) = win->_curx
    192 #define	leaveok(win, bf)	(win->_leave = (bf))
    193 #define	scrollok(win, bf)	(win->_scroll = (bf))
    194 #define	winch(win)		(win->_y[win->_cury][win->_curx] & 0177)
    195 
    196 /* Public function prototypes. */
    197 void	 __cputchar __P((int));
    198 int	 _sprintw __P((WINDOW *, const char *, _VA_LIST_));
    199 int	 box __P((WINDOW *, int, int));
    200 int	 cbreak __P((void));
    201 int	 delwin __P((WINDOW *));
    202 int	 echo __P((void));
    203 int	 endwin __P((void));
    204 char	*fullname __P((char *, char *));
    205 char	*getcap __P((char *));
    206 int	 gettmode __P((void));
    207 void	 idlok __P((WINDOW *, int));
    208 WINDOW	*initscr __P((void));
    209 char	*longname __P((char *, char *));
    210 int	 mvcur __P((int, int, int, int));
    211 int	 mvprintw __P((int, int, const char *, ...));
    212 int	 mvscanw __P((int, int, const char *, ...));
    213 int	 mvwin __P((WINDOW *, int, int));
    214 int	 mvwprintw __P((WINDOW *, int, int, const char *, ...));
    215 int	 mvwscanw __P((WINDOW *, int, int, const char *, ...));
    216 WINDOW	*newwin __P((int, int, int, int));
    217 int	 nl __P((void));
    218 int	 nocbreak __P((void));
    219 int	 noecho __P((void));
    220 int	 nonl __P((void));
    221 int	 noraw __P((void));
    222 int	 overlay __P((WINDOW *, WINDOW *));
    223 int	 overwrite __P((WINDOW *, WINDOW *));
    224 int	 printw __P((const char *, ...));
    225 int	 raw __P((void));
    226 int	 resetty __P((void));
    227 int	 savetty __P((void));
    228 int	 scanw __P((const char *, ...));
    229 int	 scroll __P((WINDOW *));
    230 int	 setterm __P((char *));
    231 int	 sscans __P((WINDOW *, const char *, _VA_LIST_));
    232 WINDOW	*subwin __P((WINDOW *, int, int, int, int));
    233 int	 suspendwin __P((void));
    234 int	 touchline __P((WINDOW *, int, int, int));
    235 int	 touchoverlap __P((WINDOW *, WINDOW *));
    236 int	 touchwin __P((WINDOW *));
    237 void	 tstp __P((int));
    238 int	 waddch __P((WINDOW *, int));
    239 int	 waddstr __P((WINDOW *, char *));
    240 int	 wclear __P((WINDOW *));
    241 int	 wclrtobot __P((WINDOW *));
    242 int	 wclrtoeol __P((WINDOW *));
    243 int	 wdelch __P((WINDOW *));
    244 int	 wdeleteln __P((WINDOW *));
    245 int	 werase __P((WINDOW *));
    246 int	 wgetch __P((WINDOW *));
    247 int	 wgetstr __P((WINDOW *, char *));
    248 int	 winsch __P((WINDOW *, int));
    249 int	 winsertln __P((WINDOW *));
    250 int	 wmove __P((WINDOW *, int, int));
    251 int	 wprintw __P((WINDOW *, const char *, ...));
    252 int	 wrefresh __P((WINDOW *));
    253 int	 wscanw __P((WINDOW *, const char *, ...));
    254 char	*wstandend __P((WINDOW *));
    255 char	*wstandout __P((WINDOW *));
    256 
    257 #ifdef _CURSES_PRIVATE
    258 /* Private function prototypes. */
    259 void	 __id_subwins __P((WINDOW *));
    260 void	 __set_subwin __P((WINDOW *, WINDOW *));
    261 void	 __swflags __P((WINDOW *));
    262 void	 __TRACE __P((const char *, ...));
    263 int	 waddbytes __P((WINDOW *, char *, int));
    264 
    265 /* Private #defines. */
    266 #define	min(a,b)	(a < b ? a : b)
    267 #define	max(a,b)	(a > b ? a : b)
    268 
    269 /* Private externs. */
    270 extern int	 __echoit;
    271 extern int	 __endwin;
    272 extern int	 __pfast;
    273 extern int	 __rawmode;
    274 #endif
    275 
    276 /* Termcap functions. */
    277 int	 tgetent __P((char *, char *));
    278 int	 tgetnum __P((char *));
    279 int	 tgetflag __P((char *));
    280 char	*tgetstr __P((char *, char **));
    281 char	*tgoto __P((char *, int, int));
    282 int	 tputs __P((char *, int, void (*)(int)));
    283 
    284 #endif /* !_CURSES_H_ */
    285