KERNEL SPEEDUP #2
[unix-history] / usr / include / curses.h
CommitLineData
b98528ef
WJLGJ
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 * @(#)curses.h 5.9 (Berkeley) 7/1/90
34 */
35
36#ifndef WINDOW
37
38#include <stdio.h>
39
40#define USE_OLD_TTY
41#include <sys/ioctl.h>
42#undef USE_OLD_TTY
43
44#define bool char
45#define reg register
46
47#define TRUE (1)
48#define FALSE (0)
49#define ERR (0)
50#define OK (1)
51
52#define _ENDLINE 001
53#define _FULLWIN 002
54#define _SCROLLWIN 004
55#define _FLUSH 010
56#define _FULLLINE 020
57#define _IDLINE 040
58#define _STANDOUT 0200
59#define _NOCHANGE -1
60
61#define _puts(s) tputs(s, 0, _putchar)
62
63typedef struct sgttyb SGTTY;
64
65/*
66 * Capabilities from termcap
67 */
68
69extern bool AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL,
70 XB, XN, XT, XS, XX;
71extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
72 *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
73 *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
74 *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
75 *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
76 *VE, *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM,
77 *LEFT_PARM, *RIGHT_PARM;
78extern char PC;
79
80/*
81 * From the tty modes...
82 */
83
84extern bool GT, NONL, UPPERCASE, normtty, _pfast;
85
86struct _win_st {
87 short _cury, _curx;
88 short _maxy, _maxx;
89 short _begy, _begx;
90 short _flags;
91 short _ch_off;
92 bool _clear;
93 bool _leave;
94 bool _scroll;
95 char **_y;
96 short *_firstch;
97 short *_lastch;
98 struct _win_st *_nextp, *_orig;
99};
100
101#define WINDOW struct _win_st
102
103extern bool My_term, _echoit, _rawmode, _endwin;
104
105extern char *Def_term, ttytype[];
106
107extern int LINES, COLS, _tty_ch, _res_flg;
108
109extern SGTTY _tty;
110
111extern WINDOW *stdscr, *curscr;
112
113/*
114 * Define VOID to stop lint from generating "null effect"
115 * comments.
116 */
117#ifdef lint
118int __void__;
119#define VOID(x) (__void__ = (int) (x))
120#else
121#define VOID(x) (x)
122#endif
123
124/*
125 * psuedo functions for standard screen
126 */
127#define addch(ch) VOID(waddch(stdscr, ch))
128#define getch() VOID(wgetch(stdscr))
129#define addbytes(da,co) VOID(waddbytes(stdscr, da,co))
130#define addstr(str) VOID(waddbytes(stdscr, str, strlen(str)))
131#define getstr(str) VOID(wgetstr(stdscr, str))
132#define move(y, x) VOID(wmove(stdscr, y, x))
133#define clear() VOID(wclear(stdscr))
134#define erase() VOID(werase(stdscr))
135#define clrtobot() VOID(wclrtobot(stdscr))
136#define clrtoeol() VOID(wclrtoeol(stdscr))
137#define insertln() VOID(winsertln(stdscr))
138#define deleteln() VOID(wdeleteln(stdscr))
139#define refresh() VOID(wrefresh(stdscr))
140#define inch() VOID(winch(stdscr))
141#define insch(c) VOID(winsch(stdscr,c))
142#define delch() VOID(wdelch(stdscr))
143#define standout() VOID(wstandout(stdscr))
144#define standend() VOID(wstandend(stdscr))
145
146/*
147 * mv functions
148 */
149#define mvwaddch(win,y,x,ch) VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
150#define mvwgetch(win,y,x) VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
151#define mvwaddbytes(win,y,x,da,co) \
152 VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co))
153#define mvwaddstr(win,y,x,str) \
154 VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,str,strlen(str)))
155#define mvwgetstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
156#define mvwinch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
157#define mvwdelch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
158#define mvwinsch(win,y,x,c) VOID(wmove(win,y,x) == ERR ? ERR:winsch(win,c))
159#define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch)
160#define mvgetch(y,x) mvwgetch(stdscr,y,x)
161#define mvaddbytes(y,x,da,co) mvwaddbytes(stdscr,y,x,da,co)
162#define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str)
163#define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str)
164#define mvinch(y,x) mvwinch(stdscr,y,x)
165#define mvdelch(y,x) mvwdelch(stdscr,y,x)
166#define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c)
167
168/*
169 * psuedo functions
170 */
171
172#define clearok(win,bf) (win->_clear = bf)
173#define leaveok(win,bf) (win->_leave = bf)
174#define scrollok(win,bf) (win->_scroll = bf)
175#define flushok(win,bf) (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
176#define getyx(win,y,x) y = win->_cury, x = win->_curx
177#define winch(win) (win->_y[win->_cury][win->_curx] & 0177)
178
179#define raw() (_tty.sg_flags|=RAW, _pfast=_rawmode=TRUE, \
180 ioctl(_tty_ch, TIOCSETP, &_tty))
181#define noraw() (_tty.sg_flags&=~RAW,_rawmode=FALSE,\
182 _pfast=!(_tty.sg_flags&CRMOD),ioctl(_tty_ch, TIOCSETP, &_tty))
183#define cbreak() (_tty.sg_flags |= CBREAK, _rawmode = TRUE, \
184 ioctl(_tty_ch, TIOCSETP, &_tty))
185#define nocbreak() (_tty.sg_flags &= ~CBREAK,_rawmode=FALSE, \
186 ioctl(_tty_ch, TIOCSETP, &_tty))
187#define crmode() cbreak() /* backwards compatability */
188#define nocrmode() nocbreak() /* backwards compatability */
189#define echo() (_tty.sg_flags |= ECHO, _echoit = TRUE, \
190 ioctl(_tty_ch, TIOCSETP, &_tty))
191#define noecho() (_tty.sg_flags &= ~ECHO, _echoit = FALSE, \
192 ioctl(_tty_ch, TIOCSETP, &_tty))
193#define nl() (_tty.sg_flags |= CRMOD,_pfast = _rawmode, \
194 ioctl(_tty_ch, TIOCSETP, &_tty))
195#define nonl() (_tty.sg_flags &= ~CRMOD, _pfast = TRUE, \
196 ioctl(_tty_ch, TIOCSETP, &_tty))
197#define savetty() ((void) ioctl(_tty_ch, TIOCGETP, &_tty), \
198 _res_flg = _tty.sg_flags)
199#define resetty() (_tty.sg_flags = _res_flg, \
200 _echoit = ((_res_flg & ECHO) == ECHO), \
201 _rawmode = ((_res_flg & (CBREAK|RAW)) != 0), \
202 _pfast = ((_res_flg & CRMOD) ? _rawmode : TRUE), \
203 (void) ioctl(_tty_ch, TIOCSETP, &_tty))
204
205#define erasechar() (_tty.sg_erase)
206#define killchar() (_tty.sg_kill)
207#define baudrate() (_tty.sg_ospeed)
208
209WINDOW *initscr(), *newwin(), *subwin();
210char *longname(), *getcap();
211
212/*
213 * Used to be in unctrl.h.
214 */
215#define unctrl(c) _unctrl[(c) & 0177]
216extern char *_unctrl[];
217#endif