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