1 /* $NetBSD: curses.h,v 1.21 1998/01/30 04:33:32 perry Exp $ */ 2 3 /* 4 * Copyright (c) 1981, 1993, 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)curses.h 8.5 (Berkeley) 4/29/95 36 */ 37 38 #ifndef _CURSES_H_ 39 #define _CURSES_H_ 40 41 #include <stdio.h> 42 #include <termcap.h> 43 44 /* 45 * The following #defines and #includes are present for backward 46 * compatibility only. They should not be used in future code. 47 * 48 * START BACKWARD COMPATIBILITY ONLY. 49 */ 50 #ifndef _CURSES_PRIVATE 51 #ifndef __cplusplus 52 #define bool char 53 #endif 54 #define reg register 55 56 #ifndef TRUE 57 #define TRUE (1) 58 #endif 59 #ifndef FALSE 60 #define FALSE (0) 61 #endif 62 63 #define _puts(s) tputs(s, 0, __cputchar) 64 #define _putchar(c) __cputchar(c) 65 66 /* Old-style terminal modes access. */ 67 #define baudrate() (cfgetospeed(&__baset)) 68 #define crmode() cbreak() 69 #define erasechar() (__baset.c_cc[VERASE]) 70 #define killchar() (__baset.c_cc[VKILL]) 71 #define nocrmode() nocbreak() 72 #define ospeed (cfgetospeed(&__baset)) 73 #endif /* _CURSES_PRIVATE */ 74 75 extern char GT; /* Gtty indicates tabs. */ 76 extern char NONL; /* Term can't hack LF doing a CR. */ 77 extern char UPPERCASE; /* Terminal is uppercase only. */ 78 79 extern int My_term; /* Use Def_term regardless. */ 80 extern char *Def_term; /* Default terminal type. */ 81 82 /* Termcap capabilities. */ 83 extern char AM, BS, CA, DA, EO, HC, IN, MI, MS, NC, NS, OS, 84 PC, UL, XB, XN, XT, XS, XX; 85 extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, 86 *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, 87 *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, 88 *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, 89 *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, 90 *VE, *al, *dl, *sf, *sr, 91 *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM, 92 *RIGHT_PARM; 93 94 /* END BACKWARD COMPATIBILITY ONLY. */ 95 96 /* 8-bit ASCII characters. */ 97 #define unctrl(c) __unctrl[(c) & 0xff] 98 #define unctrllen(ch) __unctrllen[(ch) & 0xff] 99 100 extern char *__unctrl[256]; /* Control strings. */ 101 extern char __unctrllen[256]; /* Control strings length. */ 102 103 /* 104 * A window an array of __LINE structures pointed to by the 'lines' pointer. 105 * A line is an array of __LDATA structures pointed to by the 'line' pointer. 106 * 107 * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new 108 * fields are added -- padding fields with *constant values* should ensure 109 * that the compiler will not generate any padding when storing an array of 110 * __LDATA structures. This is to enable consistent use of memcmp, and memcpy 111 * for comparing and copying arrays. 112 */ 113 typedef struct { 114 char ch; /* the actual character */ 115 116 #define __STANDOUT 0x01 /* Added characters are standout. */ 117 char attr; /* attributes of character */ 118 } __LDATA; 119 120 #define __LDATASIZE (sizeof(__LDATA)) 121 122 typedef struct { 123 #define __ISDIRTY 0x01 /* Line is dirty. */ 124 #define __ISPASTEOL 0x02 /* Cursor is past end of line */ 125 #define __FORCEPAINT 0x04 /* Force a repaint of the line */ 126 unsigned int flags; 127 unsigned int hash; /* Hash value for the line. */ 128 size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */ 129 size_t firstch, lastch; /* First and last changed columns. */ 130 __LDATA *line; /* Pointer to the line text. */ 131 } __LINE; 132 133 typedef struct __window { /* Window structure. */ 134 struct __window *nextp, *orig; /* Subwindows list and parent. */ 135 size_t begy, begx; /* Window home. */ 136 size_t cury, curx; /* Current x, y coordinates. */ 137 size_t maxy, maxx; /* Maximum values for curx, cury. */ 138 short ch_off; /* x offset for firstch/lastch. */ 139 __LINE **lines; /* Array of pointers to the lines */ 140 __LINE *lspace; /* line space (for cleanup) */ 141 __LDATA *wspace; /* window space (for cleanup) */ 142 143 #define __ENDLINE 0x001 /* End of screen. */ 144 #define __FLUSH 0x002 /* Fflush(stdout) after refresh. */ 145 #define __FULLWIN 0x004 /* Window is a screen. */ 146 #define __IDLINE 0x008 /* Insert/delete sequences. */ 147 #define __SCROLLWIN 0x010 /* Last char will scroll window. */ 148 #define __SCROLLOK 0x020 /* Scrolling ok. */ 149 #define __CLEAROK 0x040 /* Clear on next refresh. */ 150 #define __WSTANDOUT 0x080 /* Standout window */ 151 #define __LEAVEOK 0x100 /* If curser left */ 152 unsigned int flags; 153 } WINDOW; 154 155 /* Curses external declarations. */ 156 extern WINDOW *curscr; /* Current screen. */ 157 extern WINDOW *stdscr; /* Standard screen. */ 158 159 extern struct termios __orig_termios; /* Terminal state before curses */ 160 extern struct termios __baset; /* Our base terminal state */ 161 extern int __tcaction; /* If terminal hardware set. */ 162 163 extern int COLS; /* Columns on the screen. */ 164 extern int LINES; /* Lines on the screen. */ 165 166 extern char *ttytype; /* Full name of current terminal. */ 167 168 #define ERR (0) /* Error return. */ 169 #define OK (1) /* Success return. */ 170 171 /* Standard screen pseudo functions. */ 172 #define addbytes(s, n) __waddbytes(stdscr, s, n, 0) 173 #define addch(ch) waddch(stdscr, ch) 174 #define addnstr(s, n) waddnstr(stdscr, s, n) 175 #define addstr(s) __waddbytes(stdscr, s, strlen(s), 0) 176 #define clear() wclear(stdscr) 177 #define clrtobot() wclrtobot(stdscr) 178 #define clrtoeol() wclrtoeol(stdscr) 179 #define delch() wdelch(stdscr) 180 #define deleteln() wdeleteln(stdscr) 181 #define erase() werase(stdscr) 182 #define getch() wgetch(stdscr) 183 #define getstr(s) wgetstr(stdscr, s) 184 #define inch() winch(stdscr) 185 #define insch(ch) winsch(stdscr, ch) 186 #define insertln() winsertln(stdscr) 187 #define move(y, x) wmove(stdscr, y, x) 188 #define refresh() wrefresh(stdscr) 189 #define standend() wstandend(stdscr) 190 #define standout() wstandout(stdscr) 191 #define waddbytes(w, s, n) __waddbytes(w, s, n, 0) 192 #define waddstr(w, s) __waddbytes(w, s, strlen(s), 0) 193 194 /* Standard screen plus movement pseudo functions. */ 195 #define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n) 196 #define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch) 197 #define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n) 198 #define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s) 199 #define mvdelch(y, x) mvwdelch(stdscr, y, x) 200 #define mvgetch(y, x) mvwgetch(stdscr, y, x) 201 #define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s) 202 #define mvinch(y, x) mvwinch(stdscr, y, x) 203 #define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c) 204 #define mvwaddbytes(w, y, x, s, n) \ 205 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0)) 206 #define mvwaddch(w, y, x, ch) \ 207 (wmove(w, y, x) == ERR ? ERR : waddch(w, ch)) 208 #define mvwaddnstr(w, y, x, s, n) \ 209 (wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n)) 210 #define mvwaddstr(w, y, x, s) \ 211 (wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, strlen(s), 0)) 212 #define mvwdelch(w, y, x) \ 213 (wmove(w, y, x) == ERR ? ERR : wdelch(w)) 214 #define mvwgetch(w, y, x) \ 215 (wmove(w, y, x) == ERR ? ERR : wgetch(w)) 216 #define mvwgetstr(w, y, x, s) \ 217 (wmove(w, y, x) == ERR ? ERR : wgetstr(w, s)) 218 #define mvwinch(w, y, x) \ 219 (wmove(w, y, x) == ERR ? ERR : winch(w)) 220 #define mvwinsch(w, y, x, c) \ 221 (wmove(w, y, x) == ERR ? ERR : winsch(w, c)) 222 223 224 /* Psuedo functions. */ 225 #define clearok(w, bf) \ 226 ((bf) ? ((w)->flags |= __CLEAROK) : ((w)->flags &= ~__CLEAROK)) 227 #define flushok(w, bf) \ 228 ((bf) ? ((w)->flags |= __FLUSH) : ((w)->flags &= ~__FLUSH)) 229 #define leaveok(w, bf) \ 230 ((bf) ? ((w)->flags |= __LEAVEOK) : ((w)->flags &= ~__LEAVEOK)) 231 #define scrollok(w, bf) \ 232 ((bf) ? ((w)->flags |= __SCROLLOK) : ((w)->flags &= ~__SCROLLOK)) 233 #define winch(w) \ 234 ((w)->lines[(w)->cury]->line[(w)->curx].ch & 0177) 235 236 #define getyx(w, y, x) (y) = getcury(w), (x) = getcurx(w) 237 #define getbegyx(w, y, x) (y) = getbegy(w), (x) = getbegx(w) 238 #define getmaxyx(w, y, x) (y) = getmaxy(w), (x) = getmaxx(w) 239 #define getcury(w) ((w)->cury) 240 #define getcurx(w) ((w)->curx) 241 #define getbegy(w) ((w)->begy) 242 #define getbegx(w) ((w)->begx) 243 #define getmaxy(w) ((w)->maxy) 244 #define getmaxx(w) ((w)->maxx) 245 246 /* Public function prototypes. */ 247 __BEGIN_DECLS 248 int box __P((WINDOW *, int, int)); 249 int cbreak __P((void)); 250 int delwin __P((WINDOW *)); 251 int echo __P((void)); 252 int endwin __P((void)); 253 char *fullname __P((char *, char *)); 254 char *getcap __P((char *)); 255 int gettmode __P((void)); 256 void idlok __P((WINDOW *, int)); 257 WINDOW *initscr __P((void)); 258 char *longname __P((char *, char *)); 259 int mvcur __P((int, int, int, int)); 260 int mvprintw __P((int, int, const char *, ...)); 261 int mvscanw __P((int, int, const char *, ...)); 262 int mvwin __P((WINDOW *, int, int)); 263 int mvwprintw __P((WINDOW *, int, int, const char *, ...)); 264 int mvwscanw __P((WINDOW *, int, int, const char *, ...)); 265 WINDOW *newwin __P((int, int, int, int)); 266 int nl __P((void)); 267 int nocbreak __P((void)); 268 int noecho __P((void)); 269 int nonl __P((void)); 270 int noraw __P((void)); 271 int overlay __P((WINDOW *, WINDOW *)); 272 int overwrite __P((WINDOW *, WINDOW *)); 273 int printw __P((const char *, ...)); 274 int raw __P((void)); 275 int resetty __P((void)); 276 int savetty __P((void)); 277 int scanw __P((const char *, ...)); 278 int scroll __P((WINDOW *)); 279 int setterm __P((char *)); 280 int sscans __P((WINDOW *, const char *, ...)); 281 WINDOW *subwin __P((WINDOW *, int, int, int, int)); 282 int suspendwin __P((void)); 283 int touchline __P((WINDOW *, int, int, int)); 284 int touchoverlap __P((WINDOW *, WINDOW *)); 285 int touchwin __P((WINDOW *)); 286 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 287 int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 288 int waddch __P((WINDOW *, int)); 289 int waddnstr __P((WINDOW *, const char *, int)); 290 int wclear __P((WINDOW *)); 291 int wclrtobot __P((WINDOW *)); 292 int wclrtoeol __P((WINDOW *)); 293 int wdelch __P((WINDOW *)); 294 int wdeleteln __P((WINDOW *)); 295 int werase __P((WINDOW *)); 296 int wgetch __P((WINDOW *)); 297 int wgetstr __P((WINDOW *, char *)); 298 int winsch __P((WINDOW *, int)); 299 int winsertln __P((WINDOW *)); 300 int wmove __P((WINDOW *, int, int)); 301 int wprintw __P((WINDOW *, const char *, ...)); 302 int wrefresh __P((WINDOW *)); 303 int wscanw __P((WINDOW *, const char *, ...)); 304 int wstandend __P((WINDOW *)); 305 int wstandout __P((WINDOW *)); 306 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 307 308 /* Private functions that are needed for user programs prototypes. */ 309 void __cputchar __P((int)); 310 int __waddbytes __P((WINDOW *, const char *, int, int)); 311 __END_DECLS 312 313 /* Private functions. */ 314 #ifdef _CURSES_PRIVATE 315 void __CTRACE __P((const char *, ...)); 316 unsigned int __hash __P((char *, int)); 317 void __id_subwins __P((WINDOW *)); 318 int __mvcur __P((int, int, int, int, int)); 319 void __restore_stophandler __P((void)); 320 void __set_stophandler __P((void)); 321 void __set_subwin __P((WINDOW *, WINDOW *)); 322 void __startwin __P((void)); 323 void __stop_signal_handler __P((int)); 324 void __swflags __P((WINDOW *)); 325 int __touchline __P((WINDOW *, int, int, int, int)); 326 int __touchwin __P((WINDOW *)); 327 char *__tscroll __P((const char *, int, int)); 328 int __waddch __P((WINDOW *, __LDATA *)); 329 int __stopwin __P((void)); 330 void __restartwin __P((void)); 331 332 /* Private #defines. */ 333 #define min(a,b) (a < b ? a : b) 334 #define max(a,b) (a > b ? a : b) 335 336 /* Private externs. */ 337 extern int __echoit; 338 extern int __endwin; 339 extern int __pfast; 340 extern int __rawmode; 341 extern int __noqch; 342 #endif 343 344 #endif /* !_CURSES_H_ */ 345