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.24 (Berkeley) 01/11/93 8 */ 9 10 #ifndef _CURSES_H_ 11 #define _CURSES_H_ 12 13 #include <stdio.h> 14 15 /* 16 * The following #defines and #includes are present for backward 17 * compatibility only. They should not be used in future code. 18 * 19 * START BACKWARD COMPATIBILITY ONLY. 20 */ 21 #ifndef _CURSES_PRIVATE 22 #define bool char 23 #define reg register 24 25 #ifndef TRUE 26 #define TRUE (1) 27 #endif 28 #ifndef FALSE 29 #define FALSE (0) 30 #endif 31 32 #define _puts(s) tputs(s, 0, __cputchar) 33 #define _putchar(c) __cputchar(c) 34 35 /* Old-style terminal modes access. */ 36 #define baudrate() (cfgetospeed(&origtermio)) 37 #define crmode() cbreak() 38 #define erasechar() (origtermio.c_cc[VERASE]) 39 #define killchar() (origtermio.c_cc[VKILL]) 40 #define nocrmode() nocbreak() 41 #define ospeed (cfgetospeed(&origtermio)) 42 #endif /* _CURSES_PRIVATE */ 43 44 extern char GT; /* Gtty indicates tabs. */ 45 extern char NONL; /* Term can't hack LF doing a CR. */ 46 extern char UPPERCASE; /* Terminal is uppercase only. */ 47 48 extern int My_term; /* Use Def_term regardless. */ 49 extern char *Def_term; /* Default terminal type. */ 50 51 /* Termcap capabilities. */ 52 extern char AM, BS, CA, DA, EO, HC, HZ, IN, MI, MS, NC, NS, OS, 53 PC, UL, XB, XN, XT, XS, XX; 54 extern char *AL, *BC, *BT, *CD, *CE, *CL, *CM, *CR, *CS, *DC, *DL, 55 *DM, *DO, *ED, *EI, *K0, *K1, *K2, *K3, *K4, *K5, *K6, 56 *K7, *K8, *K9, *HO, *IC, *IM, *IP, *KD, *KE, *KH, *KL, 57 *KR, *KS, *KU, *LL, *MA, *ND, *NL, *RC, *SC, *SE, *SF, 58 *SO, *SR, *TA, *TE, *TI, *UC, *UE, *UP, *US, *VB, *VS, 59 *VE, *al, *dl, *sf, *sr, 60 *AL_PARM, *DL_PARM, *UP_PARM, *DOWN_PARM, *LEFT_PARM, 61 *RIGHT_PARM; 62 63 /* END BACKWARD COMPATIBILITY ONLY. */ 64 65 /* 7-bit ASCII characters. */ 66 #define unctrl(c) __unctrl[(c) & 0x80] 67 #define unctrllen(ch) __unctrllen[(ch) & 0x80] 68 69 extern char *__unctrl[256]; /* Control strings. */ 70 extern char __unctrllen[256]; /* Control strings length. */ 71 72 /* 73 * A window an array of __LINE structures pointed to by the 'lines' pointer. 74 * A line is an array of __LDATA structures pointed to by the 'line' pointer. 75 * 76 * IMPORTANT: the __LDATA structure must NOT induce any padding, so if new 77 * fields are added -- padding fields with *constant values* should ensure 78 * that the compiler will not generate any padding when storing an array of 79 * __LDATA structures. This is to enable consistent use of bcmp, and bcopy 80 * for comparing and copying arrays. 81 */ 82 typedef struct { 83 char ch; /* the actual character */ 84 85 #define __STANDOUT 0x01 /* Added characters are standout. */ 86 char attr; /* attributes of character */ 87 } __LDATA; 88 89 #define __LDATASIZE (sizeof(__LDATA)) 90 91 typedef struct { 92 #define __ISDIRTY 0x01 /* Line is dirty. */ 93 #define __ISPASTEOL 0x02 /* Cursor is past end of line */ 94 #define __FORCEPAINT 0x04 /* Force a repaint of the line */ 95 u_int flags; 96 u_int hash; /* Hash value for the line. */ 97 size_t *firstchp, *lastchp; /* First and last chngd columns ptrs */ 98 size_t firstch, lastch; /* First and last changed columns. */ 99 __LDATA *line; /* Pointer to the line text. */ 100 } __LINE; 101 102 typedef struct __window { /* Window structure. */ 103 struct __window *nextp, *orig; /* Subwindows list and parent. */ 104 size_t begy, begx; /* Window home. */ 105 size_t cury, curx; /* Current x, y coordinates. */ 106 size_t maxy, maxx; /* Maximum values for curx, cury. */ 107 short ch_off; /* x offset for firstch/lastch. */ 108 __LINE **lines; /* Array of pointers to the lines */ 109 __LINE *lspace; /* line space (for cleanup) */ 110 __LDATA *wspace; /* window space (for cleanup) */ 111 112 #define __ENDLINE 0x001 /* End of screen. */ 113 #define __FLUSH 0x002 /* Fflush(stdout) after refresh. */ 114 #define __FULLLINE 0x004 /* Line width = terminal width. */ 115 #define __FULLWIN 0x008 /* Window is a screen. */ 116 #define __IDLINE 0x010 /* Insert/delete sequences. */ 117 #define __SCROLLWIN 0x020 /* Last char will scroll window. */ 118 #define __SCROLLOK 0x040 /* Scrolling ok. */ 119 #define __CLEAROK 0x080 /* Clear on next refresh. */ 120 #define __WSTANDOUT 0x100 /* Standout window */ 121 #define __LEAVEOK 0x200 /* If curser left */ 122 u_int flags; 123 } WINDOW; 124 125 /* Curses external declarations. */ 126 extern WINDOW *curscr; /* Current screen. */ 127 extern WINDOW *stdscr; /* Standard screen. */ 128 129 extern struct termios origtermio; /* Original terminal modes. */ 130 131 extern int COLS; /* Columns on the screen. */ 132 extern int LINES; /* Lines on the screen. */ 133 134 extern char *ttytype; /* Full name of current terminal. */ 135 136 #define ERR (0) /* Error return. */ 137 #define OK (1) /* Success return. */ 138 139 /* Standard screen pseudo functions. */ 140 #define addbytes(da, co) waddbytes(stdscr, da, co) 141 #define addch(ch) waddch(stdscr, ch) 142 #define addstr(str) waddbytes(stdscr, str, strlen(str)) 143 #define clear() wclear(stdscr) 144 #define clrtobot() wclrtobot(stdscr) 145 #define clrtoeol() wclrtoeol(stdscr) 146 #define delch() wdelch(stdscr) 147 #define deleteln() wdeleteln(stdscr) 148 #define erase() werase(stdscr) 149 #define getch() wgetch(stdscr) 150 #define getstr(str) wgetstr(stdscr, str) 151 #define inch() winch(stdscr) 152 #define insch(ch)) winsch(stdscr, ch) 153 #define insertln() winsertln(stdscr) 154 #define move(y, x) wmove(stdscr, y, x) 155 #define refresh() wrefresh(stdscr) 156 #define standend() wstandend(stdscr) 157 #define standout() wstandout(stdscr) 158 159 /* Standard screen plus movement pseudo functions. */ 160 #define mvaddbytes(y, x, da, co) mvwaddbytes(stdscr, y, x, da, co) 161 #define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch) 162 #define mvaddstr(y, x, str) mvwaddstr(stdscr, y, x, str) 163 #define mvdelch(y, x) mvwdelch(stdscr, y, x) 164 #define mvgetch(y, x) mvwgetch(stdscr, y, x) 165 #define mvgetstr(y, x, str) mvwgetstr(stdscr, y, x, str) 166 #define mvinch(y, x) mvwinch(stdscr, y, x) 167 #define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c) 168 #define mvwaddbytes(win, y, x, da, co) \ 169 (wmove(win, y, x) == ERR ? ERR : waddbytes(win, da, co)) 170 #define mvwaddch(win, y, x, ch) \ 171 (wmove(win, y, x) == ERR ? ERR : waddch(win, ch)) 172 #define mvwaddstr(win, y, x, str) \ 173 (wmove(win, y, x) == ERR ? ERR : waddbytes(win, str, strlen(str))) 174 #define mvwdelch(win, y, x) \ 175 (wmove(win, y, x) == ERR ? ERR : wdelch(win)) 176 #define mvwgetch(win, y, x) \ 177 (wmove(win, y, x) == ERR ? ERR : wgetch(win)) 178 #define mvwgetstr(win, y, x, str) \ 179 (wmove(win, y, x) == ERR ? ERR : wgetstr(win, str)) 180 #define mvwinch(win, y, x) \ 181 (wmove(win, y, x) == ERR ? ERR : winch(win)) 182 #define mvwinsch(win, y, x, c) \ 183 (wmove(win, y, x) == ERR ? ERR : winsch(win, c)) 184 185 /* Psuedo functions. */ 186 #define clearok(win, bf) \ 187 ((bf) ? (win->flags |= __CLEAROK) : (win->flags &= ~__CLEAROK)) 188 #define flushok(win, bf) \ 189 ((bf) ? (win->flags |= __FLUSH) : (win->flags &= ~__FLUSH)) 190 #define getyx(win, y, x) \ 191 (y) = win->cury, (x) = win->curx 192 #define leaveok(win, bf) \ 193 ((bf) ? (win->flags |= __LEAVEOK) : (win->flags &= ~__LEAVEOK)) 194 #define scrollok(win, bf) \ 195 ((bf) ? (win->flags |= __SCROLLOK) : (win->flags &= ~__SCROLLOK)) 196 #define winch(win) \ 197 (win->lines[win->cury]->line[win->curx].ch & 0177) 198 199 /* Public function prototypes. */ 200 int box __P((WINDOW *, int, int)); 201 int cbreak __P((void)); 202 int delwin __P((WINDOW *)); 203 int echo __P((void)); 204 int endwin __P((void)); 205 char *fullname __P((char *, char *)); 206 char *getcap __P((char *)); 207 int gettmode __P((void)); 208 void idlok __P((WINDOW *, int)); 209 WINDOW *initscr __P((void)); 210 char *longname __P((char *, char *)); 211 int mvcur __P((int, int, int, int)); 212 int mvprintw __P((int, int, const char *, ...)); 213 int mvscanw __P((int, int, const char *, ...)); 214 int mvwin __P((WINDOW *, int, int)); 215 int mvwprintw __P((WINDOW *, int, int, const char *, ...)); 216 int mvwscanw __P((WINDOW *, int, int, const char *, ...)); 217 WINDOW *newwin __P((int, int, int, int)); 218 int nl __P((void)); 219 int nocbreak __P((void)); 220 int noecho __P((void)); 221 int nonl __P((void)); 222 int noraw __P((void)); 223 int overlay __P((WINDOW *, WINDOW *)); 224 int overwrite __P((WINDOW *, WINDOW *)); 225 int printw __P((const char *, ...)); 226 int raw __P((void)); 227 int resetty __P((void)); 228 int savetty __P((void)); 229 int scanw __P((const char *, ...)); 230 int scroll __P((WINDOW *)); 231 int setterm __P((char *)); 232 int sscans __P((WINDOW *, const char *, ...)); 233 WINDOW *subwin __P((WINDOW *, int, int, int, int)); 234 int suspendwin __P((void)); 235 int touchline __P((WINDOW *, int, int, int)); 236 int touchoverlap __P((WINDOW *, WINDOW *)); 237 int touchwin __P((WINDOW *)); 238 void tstp __P((int)); 239 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 240 int vwscanw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 241 int waddbytes __P((WINDOW *, char *, int)); 242 int waddch __P((WINDOW *, int)); 243 int waddstr __P((WINDOW *, char *)); 244 int wclear __P((WINDOW *)); 245 int wclrtobot __P((WINDOW *)); 246 int wclrtoeol __P((WINDOW *)); 247 int wdelch __P((WINDOW *)); 248 int wdeleteln __P((WINDOW *)); 249 int werase __P((WINDOW *)); 250 int wgetch __P((WINDOW *)); 251 int wgetstr __P((WINDOW *, char *)); 252 int winsch __P((WINDOW *, int)); 253 int winsertln __P((WINDOW *)); 254 int wmove __P((WINDOW *, int, int)); 255 int wprintw __P((WINDOW *, const char *, ...)); 256 int wrefresh __P((WINDOW *)); 257 int wscanw __P((WINDOW *, const char *, ...)); 258 char *wstandend __P((WINDOW *)); 259 char *wstandout __P((WINDOW *)); 260 int vwprintw __P((WINDOW *, const char *, _BSD_VA_LIST_)); 261 262 #ifdef _CURSES_PRIVATE 263 /* Private function prototypes. */ 264 void __cputchar __P((int)); 265 void __TRACE __P((const char *, ...)); 266 void __id_subwins __P((WINDOW *)); 267 void __set_subwin __P((WINDOW *, WINDOW *)); 268 void __swflags __P((WINDOW *)); 269 int __touchline __P((WINDOW *, int, int, int, int)); 270 int __touchwin __P((WINDOW *)); 271 char *__tscroll __P((const char *, int)); 272 int __waddbytes __P((WINDOW *, char *, int, int)); 273 274 /* Private #defines. */ 275 #define min(a,b) (a < b ? a : b) 276 #define max(a,b) (a > b ? a : b) 277 278 /* Private externs. */ 279 extern int __echoit; 280 extern int __endwin; 281 extern int __pfast; 282 extern int __rawmode; 283 extern int __noqch; 284 #endif 285 286 /* Termcap functions. */ 287 int tgetent __P((char *, char *)); 288 int tgetnum __P((char *)); 289 int tgetflag __P((char *)); 290 char *tgetstr __P((char *, char **)); 291 char *tgoto __P((char *, int, int)); 292 int tputs __P((char *, int, void (*)(int))); 293 294 #endif /* !_CURSES_H_ */ 295