xref: /csrg-svn/lib/libcurses/curses.h (revision 34677)
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 are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  *
12  *	@(#)curses.h	5.3 (Berkeley) 06/08/88
13  */
14 
15 # ifndef WINDOW
16 
17 # include	<stdio.h>
18 
19 # include	<sgtty.h>
20 
21 # define	bool	char
22 # define	reg	register
23 
24 # define	TRUE	(1)
25 # define	FALSE	(0)
26 # define	ERR	(0)
27 # define	OK	(1)
28 
29 # define	_ENDLINE	001
30 # define	_FULLWIN	002
31 # define	_SCROLLWIN	004
32 # define	_FLUSH		010
33 # define	_FULLLINE	020
34 # define	_IDLINE		040
35 # define	_STANDOUT	0200
36 # define	_NOCHANGE	-1
37 
38 # define	_puts(s)	tputs(s, 0, _putchar)
39 
40 typedef	struct sgttyb	SGTTY;
41 
42 /*
43  * Capabilities from termcap
44  */
45 
46 extern bool     AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL,
47 		XB, XN, XT, XS, XX;
48 extern char	*AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
49 		*DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
50 		*K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
51 		*KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
52 		*SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
53 		*VE, *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM,
54 		*LEFT_PARM, *RIGHT_PARM;
55 extern char	PC;
56 
57 /*
58  * From the tty modes...
59  */
60 
61 extern bool	GT, NONL, UPPERCASE, normtty, _pfast;
62 
63 struct _win_st {
64 	short		_cury, _curx;
65 	short		_maxy, _maxx;
66 	short		_begy, _begx;
67 	short		_flags;
68 	short		_ch_off;
69 	bool		_clear;
70 	bool		_leave;
71 	bool		_scroll;
72 	char		**_y;
73 	short		*_firstch;
74 	short		*_lastch;
75 	struct _win_st	*_nextp, *_orig;
76 };
77 
78 # define	WINDOW	struct _win_st
79 
80 extern bool	My_term, _echoit, _rawmode, _endwin;
81 
82 extern char	*Def_term, ttytype[];
83 
84 extern int	LINES, COLS, _tty_ch, _res_flg;
85 
86 extern SGTTY	_tty;
87 
88 extern WINDOW	*stdscr, *curscr;
89 
90 /*
91  *	Define VOID to stop lint from generating "null effect"
92  * comments.
93  */
94 # ifdef lint
95 int	__void__;
96 # define	VOID(x)	(__void__ = (int) (x))
97 # else
98 # define	VOID(x)	(x)
99 # endif
100 
101 /*
102  * psuedo functions for standard screen
103  */
104 # define	addch(ch)	VOID(waddch(stdscr, ch))
105 # define	getch()		VOID(wgetch(stdscr))
106 # define	addbytes(da,co)	VOID(waddbytes(stdscr, da,co))
107 # define	addstr(str)	VOID(waddbytes(stdscr, str, strlen(str)))
108 # define	getstr(str)	VOID(wgetstr(stdscr, str))
109 # define	move(y, x)	VOID(wmove(stdscr, y, x))
110 # define	clear()		VOID(wclear(stdscr))
111 # define	erase()		VOID(werase(stdscr))
112 # define	clrtobot()	VOID(wclrtobot(stdscr))
113 # define	clrtoeol()	VOID(wclrtoeol(stdscr))
114 # define	insertln()	VOID(winsertln(stdscr))
115 # define	deleteln()	VOID(wdeleteln(stdscr))
116 # define	refresh()	VOID(wrefresh(stdscr))
117 # define	inch()		VOID(winch(stdscr))
118 # define	insch(c)	VOID(winsch(stdscr,c))
119 # define	delch()		VOID(wdelch(stdscr))
120 # define	standout()	VOID(wstandout(stdscr))
121 # define	standend()	VOID(wstandend(stdscr))
122 
123 /*
124  * mv functions
125  */
126 #define	mvwaddch(win,y,x,ch)	VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
127 #define	mvwgetch(win,y,x)	VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
128 #define	mvwaddbytes(win,y,x,da,co) \
129 		VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co))
130 #define	mvwaddstr(win,y,x,str) \
131 		VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,str,strlen(str)))
132 #define mvwgetstr(win,y,x,str)  VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
133 #define	mvwinch(win,y,x)	VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
134 #define	mvwdelch(win,y,x)	VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
135 #define	mvwinsch(win,y,x,c)	VOID(wmove(win,y,x) == ERR ? ERR:winsch(win,c))
136 #define	mvaddch(y,x,ch)		mvwaddch(stdscr,y,x,ch)
137 #define	mvgetch(y,x)		mvwgetch(stdscr,y,x)
138 #define	mvaddbytes(y,x,da,co)	mvwaddbytes(stdscr,y,x,da,co)
139 #define	mvaddstr(y,x,str)	mvwaddstr(stdscr,y,x,str)
140 #define mvgetstr(y,x,str)       mvwgetstr(stdscr,y,x,str)
141 #define	mvinch(y,x)		mvwinch(stdscr,y,x)
142 #define	mvdelch(y,x)		mvwdelch(stdscr,y,x)
143 #define	mvinsch(y,x,c)		mvwinsch(stdscr,y,x,c)
144 
145 /*
146  * psuedo functions
147  */
148 
149 #define	clearok(win,bf)	 (win->_clear = bf)
150 #define	leaveok(win,bf)	 (win->_leave = bf)
151 #define	scrollok(win,bf) (win->_scroll = bf)
152 #define flushok(win,bf)	 (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
153 #define	getyx(win,y,x)	 y = win->_cury, x = win->_curx
154 #define	winch(win)	 (win->_y[win->_cury][win->_curx] & 0177)
155 
156 #define raw()	 (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, stty(_tty_ch,&_tty))
157 #define noraw()	 (_tty.sg_flags&=~RAW,_rawmode=FALSE,_pfast=!(_tty.sg_flags&CRMOD),stty(_tty_ch,&_tty))
158 #define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, stty(_tty_ch,&_tty))
159 #define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE,stty(_tty_ch,&_tty))
160 #define crmode() cbreak()	/* backwards compatability */
161 #define nocrmode() nocbreak()	/* backwards compatability */
162 #define echo()	 (_tty.sg_flags |= ECHO, _echoit = TRUE, stty(_tty_ch, &_tty))
163 #define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, stty(_tty_ch, &_tty))
164 #define nl()	 (_tty.sg_flags |= CRMOD,_pfast = _rawmode,stty(_tty_ch, &_tty))
165 #define nonl()	 (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, stty(_tty_ch, &_tty))
166 #define	savetty() ((void) gtty(_tty_ch, &_tty), _res_flg = _tty.sg_flags)
167 #define	resetty() (_tty.sg_flags = _res_flg, (void) stty(_tty_ch, &_tty))
168 
169 #define	erasechar()	(_tty.sg_erase)
170 #define	killchar()	(_tty.sg_kill)
171 #define baudrate()	(_tty.sg_ospeed)
172 
173 WINDOW	*initscr(), *newwin(), *subwin();
174 char	*longname(), *getcap();
175 
176 /*
177  * Used to be in unctrl.h.
178  */
179 #define	unctrl(c)	_unctrl[(c) & 0177]
180 extern char *_unctrl[];
181 # endif
182