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