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