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