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