Source to include/curses.h
0001 /*
0002 * Copyright (c) 1981 Regents of the University of California.
0003 * All rights reserved.
0004 *
0005 * Redistribution and use in source and binary forms, with or without
0006 * modification, are permitted provided that the following conditions
0007 * are met:
0008 * 1. Redistributions of source code must retain the above copyright
0009 * notice, this list of conditions and the following disclaimer.
0010 * 2. Redistributions in binary form must reproduce the above copyright
0011 * notice, this list of conditions and the following disclaimer in the
0012 * documentation and/or other materials provided with the distribution.
0013 * 3. All advertising materials mentioning features or use of this software
0014 * must display the following acknowledgement:
0015 * This product includes software developed by the University of
0016 * California, Berkeley and its contributors.
0017 * 4. Neither the name of the University nor the names of its contributors
0018 * may be used to endorse or promote products derived from this software
0019 * without specific prior written permission.
0020 *
0021 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0031 * SUCH DAMAGE.
0032 *
0033 * @(#)curses.h 5.9 (Berkeley) 7/1/90
0034 */
0035
0036 #ifndef WINDOW
0037
0038 #include <stdio.h>
0039
0040 #define bool char
0041 #define reg register
0042
0043 typedef unsigned short chtype;
0044
0045 #define TRUE (1)
0046 #define FALSE (0)
0047 #define ERR (0)
0048 #define OK (1)
0049
0050 #define _ENDLINE 001
0051 #define _FULLWIN 002
0052 #define _SCROLLWIN 004
0053 #define _FLUSH 010
0054 #define _FULLLINE 020
0055 #define _IDLINE 040
0056 #define _STANDOUT 0400
0057 #define _NOCHANGE -1
0058
0059 #define _puts(s) tputs(s, 0, _putchar)
0060
0061 #include <termios.h>
0062 typedef struct termios SGTTY;
0063
0064 /*
0065 * Capabilities from termcap
0066 */
0067 #ifdef HZ
0068 #undef HZ
0069 #endif
0070 extern bool AM, BS, CA, DA, DB, EO, HC, HZ, IN, MI, MS, NC, NS, OS, UL,
0071 XB, XN, XT, XS, XX;
0072 extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL,
0073 *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6,
0074 *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL,
0075 *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF,
0076 *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS,
0077 *VE, *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM,
0078 *LEFT_PARM, *RIGHT_PARM;
0079 extern char PC;
0080
0081 /*
0082 * From the tty modes...
0083 */
0084
0085 extern bool GT, NONL, UPPERCASE, normtty, _pfast;
0086
0087 struct _win_st {
0088 short _cury, _curx;
0089 short _maxy, _maxx;
0090 short _begy, _begx;
0091 short _flags;
0092 short _ch_off;
0093 bool _clear;
0094 bool _leave;
0095 bool _scroll;
0096 chtype **_y;
0097 short *_firstch;
0098 short *_lastch;
0099 struct _win_st *_nextp, *_orig;
0100 };
0101
0102 #define WINDOW struct _win_st
0103
0104 extern bool My_term, _echoit, _rawmode, _endwin;
0105
0106 extern char *Def_term, ttytype[];
0107
0108 extern int LINES, COLS, _tty_ch;
0109
0110 extern SGTTY _tty, _res_flg;
0111
0112 extern WINDOW *stdscr, *curscr;
0113
0114 /*
0115 * Define VOID to stop lint from generating "null effect"
0116 * comments.
0117 */
0118 #ifdef lint
0119 int __void__;
0120 #define VOID(x) (__void__ = (int) (x))
0121 #else
0122 #define VOID(x) (x)
0123 #endif
0124
0125 /*
0126 * psuedo functions for standard screen
0127 */
0128 #define addch(ch) VOID(waddch(stdscr, ch))
0129 #define getch() VOID(wgetch(stdscr))
0130 #define addbytes(da,co) VOID(waddbytes(stdscr, da,co))
0131 #define addstr(str) VOID(waddstr(stdscr, str))
0132 #define getstr(str) VOID(wgetstr(stdscr, str))
0133 #define move(y, x) VOID(wmove(stdscr, y, x))
0134 #define clear() VOID(wclear(stdscr))
0135 #define erase() VOID(werase(stdscr))
0136 #define clrtobot() VOID(wclrtobot(stdscr))
0137 #define clrtoeol() VOID(wclrtoeol(stdscr))
0138 #define insertln() VOID(winsertln(stdscr))
0139 #define deleteln() VOID(wdeleteln(stdscr))
0140 #define refresh() VOID(wrefresh(stdscr))
0141 #define inch() VOID(winch(stdscr))
0142 #define insch(c) VOID(winsch(stdscr,c))
0143 #define delch() VOID(wdelch(stdscr))
0144 #define standout() VOID(wstandout(stdscr))
0145 #define standend() VOID(wstandend(stdscr))
0146
0147 /*
0148 * mv functions
0149 */
0150 #define mvwaddch(win,y,x,ch) VOID(wmove(win,y,x)==ERR?ERR:waddch(win,ch))
0151 #define mvwgetch(win,y,x) VOID(wmove(win,y,x)==ERR?ERR:wgetch(win))
0152 #define mvwaddbytes(win,y,x,da,co) \
0153 VOID(wmove(win,y,x)==ERR?ERR:waddbytes(win,da,co))
0154 #define mvwaddstr(win,y,x,str) \
0155 VOID(wmove(win,y,x)==ERR?ERR:waddstr(win,str))
0156 #define mvwgetstr(win,y,x,str) VOID(wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
0157 #define mvwinch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : winch(win))
0158 #define mvwdelch(win,y,x) VOID(wmove(win,y,x) == ERR ? ERR : wdelch(win))
0159 #define mvwinsch(win,y,x,c) VOID(wmove(win,y,x) == ERR ? ERR:winsch(win,c))
0160 #define mvaddch(y,x,ch) mvwaddch(stdscr,y,x,ch)
0161 #define mvgetch(y,x) mvwgetch(stdscr,y,x)
0162 #define mvaddbytes(y,x,da,co) mvwaddbytes(stdscr,y,x,da,co)
0163 #define mvaddstr(y,x,str) mvwaddstr(stdscr,y,x,str)
0164 #define mvgetstr(y,x,str) mvwgetstr(stdscr,y,x,str)
0165 #define mvinch(y,x) mvwinch(stdscr,y,x)
0166 #define mvdelch(y,x) mvwdelch(stdscr,y,x)
0167 #define mvinsch(y,x,c) mvwinsch(stdscr,y,x,c)
0168
0169 /*
0170 * psuedo functions
0171 */
0172
0173 #define clearok(win,bf) (win->_clear = bf)
0174 #define leaveok(win,bf) (win->_leave = bf)
0175 #define scrollok(win,bf) (win->_scroll = bf)
0176 #define flushok(win,bf) (bf ? (win->_flags |= _FLUSH):(win->_flags &= ~_FLUSH))
0177 #define getyx(win,y,x) y = win->_cury, x = win->_curx
0178 #define winch(win) (win->_y[win->_cury][win->_curx] & 0xFF)
0179
0180 #define raw() (_tty.c_lflag &= ~(ICANON|ECHO), _tty.c_cc[VMIN] = 1, \
0181 _tty.c_cc[VTIME] = 0, _pfast = _rawmode = TRUE, \
0182 tcsetattr(_tty_ch, TCSANOW, &_tty))
0183 #define noraw() (_tty.c_lflag |= (ICANON|ECHO), _pfast = FALSE, \
0184 tcsetattr(_tty_ch, TCSANOW, &_tty))
0185 #define cbreak() raw()
0186 #define nocbreak() noraw()
0187 #define crmode() cbreak() /* backwards compatability */
0188 #define nocrmode() nocbreak() /* backwards compatability */
0189 #define echo() (_tty.c_lflag |= ECHO, _echoit = TRUE, \
0190 tcsetattr(_tty_ch, TCSANOW, &_tty))
0191 #define noecho() (_tty.c_lflag &= ~ECHO, _echoit = FALSE, \
0192 tcsetattr(_tty_ch, TCSANOW, &_tty))
0193 #define nl()
0194 #define nonl()
0195 #define savetty() ((void) tcgetattr(_tty_ch, &_tty), \
0196 _res_flg = _tty)
0197 #define resetty() (_tty = _res_flg, \
0198 _echoit = ((_tty.c_lflag & ECHO) == ECHO), \
0199 _rawmode = ((_tty.c_lflag & (ICANON)) == 0), \
0200 _pfast = _rawmode), \
0201 (void) tcsetattr(_tty_ch, TCSANOW, &_tty)
0202
0203 #define erasechar() (_tty.c_cc[VERASE])
0204 #define killchar() (_tty.c_cc[VKILL])
0205 #define baudrate() cfgetispeed(&_tty)
0206
0207 WINDOW *initscr(), *newwin(), *subwin();
0208 char *longname(), *getcap();
0209
0210 /*
0211 * Used to be in unctrl.h.
0212 */
0213 #define unctrl(c) _unctrl[(c) & 0177]
0214 extern char *_unctrl[];
0215 #endif